Skip to content

feat: create branch testing with cli command#4

Merged
MusicMaster4 merged 2 commits into
mainfrom
testing
Jul 10, 2026
Merged

feat: create branch testing with cli command#4
MusicMaster4 merged 2 commits into
mainfrom
testing

Conversation

@MusicMaster4

Copy link
Copy Markdown
Owner

Summary

  • Fixed handling of dirty state when creating a new branch
  • Updated CLI to use a more informative message when pushing a clean branch
  • Removed unnecessary git add and git commit when the working directory is clean

Test plan

  • Run npm test to verify all tests pass
  • Manually test the CLI by creating a new branch with and without changes in the working directory
  • Verify the correct commit message is used in each case
  • Confirm the branch is successfully pushed to the remote repository

@greptile-apps

greptile-apps Bot commented Jul 10, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes the branch command so that git add . and git commit are only run when the working directory is actually dirty. Previously, a commit was always attempted even on a clean repo, and resolveMessage (which may invoke the AI API) was always called before the steps began.

  • hasChanges() is now called upfront to capture dirty state; the message-resolution and commit steps are skipped entirely on a clean working tree, avoiding unnecessary AI API calls.
  • When clean, an informative \"nothing to commit — pushing branch only\" message is logged, and the branch is pushed directly.
  • The change is consistent with the pattern used in the pr, merge, and save commands.

Confidence Score: 5/5

The change is a straightforward guard that correctly short-circuits staging and committing on a clean working tree, matching the same pattern used in the surrounding pr, merge, and save commands.

The dirty-state check is captured before git checkout -b, so it accurately reflects the working tree before the branch switch. The AI API call in resolveMessage is now skipped when unneeded. The overall flow — create branch, conditionally commit, always push — is correct and consistent with the rest of the CLI.

No files require special attention.

Important Files Changed

Filename Overview
scripts/cli.ts Adds a hasChanges() guard in the branch case so that staging, committing, and AI message generation are skipped on a clean working tree; push always runs.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant User
    participant CLI as cli.ts (branch case)
    participant Git
    participant AI as resolveMessage / AI API

    User->>CLI: gg branch feature/login
    CLI->>Git: git status --porcelain -u
    Git-->>CLI: "dirty = true/false"

    CLI->>Git: git checkout -b feature/login

    alt "dirty === true"
        CLI->>AI: resolveMessage(messageFlag, "feat: new branch")
        AI-->>CLI: commit message
        CLI->>Git: git add .
        CLI->>Git: git commit -m message
    else "dirty === false"
        CLI->>CLI: log("nothing to commit — pushing branch only")
    end

    CLI->>Git: git push -u origin feature/login
    Git-->>CLI: success
    CLI-->>User: done
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant User
    participant CLI as cli.ts (branch case)
    participant Git
    participant AI as resolveMessage / AI API

    User->>CLI: gg branch feature/login
    CLI->>Git: git status --porcelain -u
    Git-->>CLI: "dirty = true/false"

    CLI->>Git: git checkout -b feature/login

    alt "dirty === true"
        CLI->>AI: resolveMessage(messageFlag, "feat: new branch")
        AI-->>CLI: commit message
        CLI->>Git: git add .
        CLI->>Git: git commit -m message
    else "dirty === false"
        CLI->>CLI: log("nothing to commit — pushing branch only")
    end

    CLI->>Git: git push -u origin feature/login
    Git-->>CLI: success
    CLI-->>User: done
Loading

Reviews (2): Last reviewed commit: "fix: handle dirty state when creating ne..." | Re-trigger Greptile

Comment thread scripts/cli.ts
@MusicMaster4 MusicMaster4 merged commit 5308678 into main Jul 10, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant