-
Notifications
You must be signed in to change notification settings - Fork 0
feat: support commit hash in --base flag #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -44,6 +44,7 @@ Branch resolution order: | |||||
|
|
||||||
| Examples: | ||||||
| bt add -b feature/auth # Creates new branch and worktree | ||||||
| bt add -b feature/new --base abc123 # Creates new branch based on a commit | ||||||
| bt add existing-local-branch # Uses existing local branch | ||||||
| bt add feature/remote # Auto-detects and tracks origin/feature/remote | ||||||
| bt add upstream/feature/test # Tracks upstream/feature/test | ||||||
|
|
@@ -54,7 +55,7 @@ Examples: | |||||
|
|
||||||
| func init() { | ||||||
| addCmd.Flags().BoolVarP(&addNewBranch, "branch", "b", false, "Create new branch") | ||||||
| addCmd.Flags().StringVar(&addBaseBranch, "base", "", "Base branch for new branch (default: HEAD)") | ||||||
| addCmd.Flags().StringVar(&addBaseBranch, "base", "", "Base branch or commit hash for new branch (default: HEAD)") | ||||||
| addCmd.Flags().BoolVar(&addDetach, "detach", false, "Create detached HEAD worktree") | ||||||
| addCmd.Flags().BoolVar(&addForce, "force", false, "Force creation even if worktree exists") | ||||||
| addCmd.Flags().BoolVar(&addNoFetch, "no-fetch", false, "Skip auto-fetch from remotes") | ||||||
|
|
@@ -114,6 +115,13 @@ func runAdd(cmd *cobra.Command, args []string) error { | |||||
| } else if baseInfo.IsRemote { | ||||||
| resolvedBaseBranch = baseInfo.RemoteRef | ||||||
| baseDisplayInfo = baseInfo.RemoteRef + " (remote)" | ||||||
| } else if wtMgr.Executor.IsCommitHash(addBaseBranch) { | ||||||
| resolvedBaseBranch = addBaseBranch | ||||||
| shortHash := addBaseBranch | ||||||
| if len(shortHash) > 7 { | ||||||
| shortHash = shortHash[:7] | ||||||
| } | ||||||
| baseDisplayInfo = shortHash + " (commit)" | ||||||
| } else { | ||||||
| return fmt.Errorf("base branch '%s' not found locally or on any remote", addBaseBranch) | ||||||
|
||||||
| return fmt.Errorf("base branch '%s' not found locally or on any remote", addBaseBranch) | |
| return fmt.Errorf("base '%s' not found as a local/remote branch or commit", addBaseBranch) |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -168,3 +168,9 @@ func (e *Executor) GetUpstreamBehindCount(localBranch string) (int, error) { | |||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| return count, nil | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // IsCommitHash checks if the given string resolves to a valid commit object | ||||||||||||||||||||||||||||||||||||
| func (e *Executor) IsCommitHash(ref string) bool { | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+172
to
+173
|
||||||||||||||||||||||||||||||||||||
| // IsCommitHash checks if the given string resolves to a valid commit object | |
| func (e *Executor) IsCommitHash(ref string) bool { | |
| // IsCommitHash checks if the given string looks like a hex SHA and resolves to a valid commit object | |
| func (e *Executor) IsCommitHash(ref string) bool { | |
| ref = strings.TrimSpace(ref) | |
| // Require a plausible abbreviated or full SHA-1 (Git allows abbreviations, typically >= 4 chars) | |
| if len(ref) < 4 || len(ref) > 40 { | |
| return false | |
| } | |
| for _, c := range ref { | |
| if !((c >= '0' && c <= '9') || | |
| (c >= 'a' && c <= 'f') || | |
| (c >= 'A' && c <= 'F')) { | |
| return false | |
| } | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This command reference row previously documented
--no-fetchbut now omits it. If--no-fetchis still supported, consider keeping it in the short description while adding the new--basemention to avoid a docs regression.