Skip to content

Commit c7c39fd

Browse files
authored
fix: c Command Checkout Locally Only (#123)
**Problem** Contrary to what's highlighted in the README > Review changes before applying them, checkout changes before pushing them You cannot checkout changes locally before pushing them. The `c` command to checkout pushes your changes to GitHub first before allowing you to checkout locally. Push functionality already exists with the `p` command, so it makes sense to have `c` only commit to a branch locally and not push. This pull request addresses this bug with the `c` command to only commit locally and not push to GitHub. Resolves - #122 - #68
1 parent abac421 commit c7c39fd

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

app/help.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ func (h helpType) ToContent(instance *session.Instance) string {
9595
content := lipgloss.JoinVertical(lipgloss.Left,
9696
titleStyle.Render("Checkout Instance"),
9797
"",
98-
"Changes will be committed and pushed to GitHub. The branch name has been copied to your clipboard for you to checkout.",
98+
"Changes will be committed locally. The branch name has been copied to your clipboard for you to checkout.",
9999
"",
100100
"Feel free to make changes to the branch and commit them. When resuming, the session will continue from where you left off.",
101101
"",
102102
headerStyle.Render("Commands:"),
103-
keyStyle.Render("c")+descStyle.Render(" - Checkout: commit changes and pause session"),
103+
keyStyle.Render("c")+descStyle.Render(" - Checkout: commit changes locally and pause session"),
104104
keyStyle.Render("r")+descStyle.Render(" - Resume a paused session"),
105105
)
106106
return content

session/git/worktree_git.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,31 @@ func (g *GitWorktree) PushChanges(commitMessage string, open bool) error {
7878
return nil
7979
}
8080

81+
// CommitChanges commits changes locally without pushing to remote
82+
func (g *GitWorktree) CommitChanges(commitMessage string) error {
83+
// Check if there are any changes to commit
84+
isDirty, err := g.IsDirty()
85+
if err != nil {
86+
return fmt.Errorf("failed to check for changes: %w", err)
87+
}
88+
89+
if isDirty {
90+
// Stage all changes
91+
if _, err := g.runGitCommand(g.worktreePath, "add", "."); err != nil {
92+
log.ErrorLog.Print(err)
93+
return fmt.Errorf("failed to stage changes: %w", err)
94+
}
95+
96+
// Create commit (local only)
97+
if _, err := g.runGitCommand(g.worktreePath, "commit", "-m", commitMessage, "--no-verify"); err != nil {
98+
log.ErrorLog.Print(err)
99+
return fmt.Errorf("failed to commit changes: %w", err)
100+
}
101+
}
102+
103+
return nil
104+
}
105+
81106
// IsDirty checks if the worktree has uncommitted changes
82107
func (g *GitWorktree) IsDirty() (bool, error) {
83108
output, err := g.runGitCommand(g.worktreePath, "status", "--porcelain")

session/instance.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,9 @@ func (i *Instance) Pause() error {
381381
errs = append(errs, fmt.Errorf("failed to check if worktree is dirty: %w", err))
382382
log.ErrorLog.Print(err)
383383
} else if dirty {
384-
// Commit changes with timestamp
384+
// Commit changes locally (without pushing to GitHub)
385385
commitMsg := fmt.Sprintf("[claudesquad] update from '%s' on %s (paused)", i.Title, time.Now().Format(time.RFC822))
386-
if err := i.gitWorktree.PushChanges(commitMsg, false); err != nil {
386+
if err := i.gitWorktree.CommitChanges(commitMsg); err != nil {
387387
errs = append(errs, fmt.Errorf("failed to commit changes: %w", err))
388388
log.ErrorLog.Print(err)
389389
// Return early if we can't commit changes to avoid corrupted state

0 commit comments

Comments
 (0)