diff --git a/cmd/bd/sync.go b/cmd/bd/sync.go index e3c23a82..82deb7ff 100644 --- a/cmd/bd/sync.go +++ b/cmd/bd/sync.go @@ -2156,17 +2156,21 @@ func checkOrphanedChildrenInJSONL(jsonlPath string) (*OrphanedChildren, error) { // runGitCmdWithTimeoutMsg runs a git command and prints a helpful message if it takes too long. // This helps when git operations hang waiting for credential/browser auth. func runGitCmdWithTimeoutMsg(ctx context.Context, cmd *exec.Cmd, cmdName string, timeoutDelay time.Duration) ([]byte, error) { - // Start a timer to print a message if the command takes too long + // Use done channel to cleanly exit goroutine when command completes + done := make(chan struct{}) go func() { select { case <-time.After(timeoutDelay): fmt.Fprintf(os.Stderr, "⏳ %s is taking longer than expected (possibly waiting for authentication). If this hangs, check for a browser auth prompt or run 'git status' in another terminal.\n", cmdName) + case <-done: + // Command completed, exit cleanly case <-ctx.Done(): // Context canceled, don't print message } }() output, err := cmd.CombinedOutput() + close(done) return output, err } diff --git a/internal/syncbranch/worktree.go b/internal/syncbranch/worktree.go index 4bf75a72..9a7536aa 100644 --- a/internal/syncbranch/worktree.go +++ b/internal/syncbranch/worktree.go @@ -785,17 +785,21 @@ func fetchAndRebaseInWorktree(ctx context.Context, worktreePath, branch, remote // // Returns: combined output and error from the command func runCmdWithTimeoutMessage(ctx context.Context, timeoutMsg string, timeoutDelay time.Duration, cmd *exec.Cmd) ([]byte, error) { - // Start a timer to print a message if the command takes too long + // Use done channel to cleanly exit goroutine when command completes + done := make(chan struct{}) go func() { select { case <-time.After(timeoutDelay): fmt.Fprintf(os.Stderr, "⏳ %s\n", timeoutMsg) + case <-done: + // Command completed, exit cleanly case <-ctx.Done(): // Context canceled, don't print message } }() output, err := cmd.CombinedOutput() + close(done) return output, err }