Skip to content

Commit 6b9d31b

Browse files
authored
Merge pull request #524 from bborn/task/2096-audit-and-evaluate-spotlight-function-ne
Audit spotlight: add unit tests and fix stash safety bug
2 parents 8db7f45 + b20e266 commit 6b9d31b

2 files changed

Lines changed: 723 additions & 3 deletions

File tree

internal/spotlight/spotlight.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,16 @@ func Start(worktreePath, mainRepoDir string) (string, error) {
4141
hasChanges = true // staged changes exist
4242
}
4343

44-
// Stash changes if any exist
44+
// Stash changes if any exist — fail if stash fails, since Stop()
45+
// will run git checkout . which would destroy uncommitted work.
4546
stashCreated := false
4647
if hasChanges {
4748
stashCmd := exec.Command("git", "stash", "push", "-m", "spotlight-backup-"+time.Now().Format("20060102-150405"))
4849
stashCmd.Dir = mainRepoDir
49-
if err := stashCmd.Run(); err == nil {
50-
stashCreated = true
50+
if output, err := stashCmd.CombinedOutput(); err != nil {
51+
return "", fmt.Errorf("failed to stash main repo changes (aborting to protect uncommitted work): %s", strings.TrimSpace(string(output)))
5152
}
53+
stashCreated = true
5254
}
5355

5456
// Create the state file to track that spotlight is active

0 commit comments

Comments
 (0)