Skip to content

Commit

Permalink
Support renaming local-only branches (#2710)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevgo committed Nov 29, 2023
1 parent 2393395 commit c2a93f5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 32 additions & 0 deletions features/rename_branch/features/local_branch.feature
@@ -0,0 +1,32 @@
Feature: rename a local-only branch

Background:
Given the current branch is a local feature branch "old"
And the commits
| BRANCH | LOCATION | MESSAGE |
| main | local, origin | main commit |
| old | local | old commit |
When I run "git-town rename-branch new"

Scenario: result
Then it runs the commands
| BRANCH | COMMAND |
| old | git fetch --prune --tags |
| | git branch new old |
| | git checkout new |
| new | git branch -D old |
And the current branch is now "new"
And now these commits exist
| BRANCH | LOCATION | MESSAGE |
| main | local, origin | main commit |
| new | local | old commit |

Scenario: undo
When I run "git-town undo"
Then it runs the commands
| BRANCH | COMMAND |
| new | git branch old {{ sha 'old commit' }} |
| | git checkout old |
| old | git branch -D new |
And the current branch is now "old"
And the initial branches and hierarchy exist
2 changes: 1 addition & 1 deletion src/cmd/rename_branch.go
Expand Up @@ -143,7 +143,7 @@ func determineRenameBranchConfig(args []string, forceFlag bool, repo *execute.Op
if oldBranch == nil {
return nil, branchesSnapshot, stashSnapshot, false, fmt.Errorf(messages.BranchDoesntExist, oldBranchName)
}
if oldBranch.SyncStatus != domain.SyncStatusUpToDate {
if oldBranch.SyncStatus != domain.SyncStatusUpToDate && oldBranch.SyncStatus != domain.SyncStatusLocalOnly {
return nil, branchesSnapshot, stashSnapshot, false, fmt.Errorf(messages.RenameBranchNotInSync, oldBranchName)
}
if branches.All.HasLocalBranch(newBranchName) {
Expand Down

0 comments on commit c2a93f5

Please sign in to comment.