Skip to content

Commit

Permalink
branch delete: Recover from conflicts (#124)
Browse files Browse the repository at this point in the history
If the upstack onto that we run during branch delete encounters
conflicts, we should recover from that and run the rest of the
operation.
  • Loading branch information
abhinav authored May 28, 2024
1 parent 000208b commit 5e7a823
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
12 changes: 11 additions & 1 deletion branch_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,17 @@ func (cmd *branchDeleteCmd) Run(ctx context.Context, log *log.Logger, opts *glob
Branch: above,
Onto: base,
}).Run(ctx, log, opts); err != nil {
return fmt.Errorf("move %s onto %s: %w", above, base, err)
contCmd := []string{"branch", "delete"}
if cmd.Force {
contCmd = append(contCmd, "--force")
}
contCmd = append(contCmd, cmd.Name)
return svc.RebaseRescue(ctx, spice.RebaseRescueRequest{
Err: err,
Command: contCmd,
Branch: currentBranch,
Message: fmt.Sprintf("interrupted: %v: branch deleted", cmd.Name),
})
}
}
}
Expand Down
55 changes: 55 additions & 0 deletions testdata/script/branch_delete_rebase_conflict.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# 'gs branch delete' continues the deletion
# if rebasing the upstack encounters a conflict.

as 'Test <[email protected]>'
at '2024-03-30T14:59:32Z'

cd repo
git init
git commit --allow-empty -m 'initial commit'
gs repo init

git add feature1.txt
gs bc -m feature1

cp $WORK/extra/feature1-extra.txt feature1.txt
git add feature1.txt feature2.txt
gs bc -m feature2

# attempt to delete feature1
gs trunk
! gs branch delete --force feature1

# feature2 conflict
stderr 'There was a conflict while rebasing'
git status --porcelain
cmp stdout $WORK/golden/conflict.txt

env EDITOR=true

# fix the conflict
git rm feature1.txt
gs rebase continue

# verify final state
git graph --branches
cmp stdout $WORK/golden/graph.txt

gs bco feature2
! exists feature1.txt

-- repo/feature1.txt --
feature 1

-- repo/feature2.txt --
feature 2

-- extra/feature1-extra.txt --
feature 1 extra

-- golden/conflict.txt --
DU feature1.txt
A feature2.txt
-- golden/graph.txt --
* 597bc80 (feature2) feature2
* 3b9a56f (HEAD -> main) initial commit

0 comments on commit 5e7a823

Please sign in to comment.