Skip to content

Commit e34ffd6

Browse files
philzsketch
andcommitted
sketch: fix diff view editing of gitignore'd files and forward more http errors to logs
Fixes #213 We had "sketch" git ignored, so "git add sketch/cmd/sketch/main.go" was failing when a user was editing it in diff view. The gitignore was incorrectly specified. ("git ls-files -i -c --exclude-standard" returning main.go should have tipped us off, but who knew!) Anyway, fixed that, and improved the logging. Co-Authored-By: sketch <hello@sketch.dev> Change-ID: s3ed65211dd497f76k
1 parent 783ab31 commit e34ffd6

File tree

3 files changed

+84
-83
lines changed

3 files changed

+84
-83
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ node_modules
77
dist
88

99
# makefile artifact
10-
sketch
10+
/sketch

git_tools/git_tools.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -434,20 +434,15 @@ func AutoCommitDiffViewChanges(ctx context.Context, repoDir, filePath string) er
434434
const expectedMsg = "User changes from diff view."
435435
amend := err == nil && commitMsg == expectedMsg
436436

437-
// Add the file to git
438-
cmd = exec.CommandContext(ctx, "git", "add", filePath)
439-
cmd.Dir = repoDir
440-
if out, err := cmd.CombinedOutput(); err != nil {
441-
return fmt.Errorf("error adding file to git: %w - git output: %s", err, string(out))
442-
}
443-
444437
// Commit the changes
438+
// Instead of calling git add first, we call git commit with a filepsec, which works the same,
439+
// but would fail if the file isn't tracked by git already.
445440
if amend {
446441
// Amend the previous commit
447-
cmd = exec.CommandContext(ctx, "git", "commit", "--amend", "--no-edit")
442+
cmd = exec.CommandContext(ctx, "git", "commit", "--amend", "--no-edit", "--", filePath)
448443
} else {
449444
// Create a new commit
450-
cmd = exec.CommandContext(ctx, "git", "commit", "-m", expectedMsg, filePath)
445+
cmd = exec.CommandContext(ctx, "git", "commit", "-m", expectedMsg, "--", filePath)
451446
}
452447
cmd.Dir = repoDir
453448

0 commit comments

Comments
 (0)