@@ -1110,14 +1110,18 @@ def command_land(args: CommonArgs):
1110
1110
# ===----------------------------------------------------------------------=== #
1111
1111
# ABANDON
1112
1112
# ===----------------------------------------------------------------------=== #
1113
- def strip_metadata (e : StackEntry , verbose : bool ) -> str :
1113
+ def strip_metadata (e : StackEntry , needs_rebase : bool , verbose : bool ) -> str :
1114
1114
m = e .commit .commit_msg ()
1115
1115
1116
1116
m = RE_STACK_INFO_LINE .sub ("" , m )
1117
- run_shell_command (
1118
- ["git" , "rebase" , e .base , e .head , "--committer-date-is-author-date" ],
1119
- quiet = not verbose ,
1120
- )
1117
+ if needs_rebase :
1118
+ run_shell_command (
1119
+ ["git" , "rebase" , e .base , e .head , "--committer-date-is-author-date" ],
1120
+ quiet = not verbose ,
1121
+ )
1122
+ else :
1123
+ run_shell_command (["git" , "checkout" , e .head ], quiet = not verbose )
1124
+
1121
1125
run_shell_command (
1122
1126
["git" , "commit" , "--amend" , "-F" , "-" ],
1123
1127
input = m .encode (),
@@ -1146,8 +1150,13 @@ def command_abandon(args: CommonArgs):
1146
1150
log (h ("Stripping stack metadata from commit messages" ), level = 1 )
1147
1151
1148
1152
last_hash = ""
1153
+ # The first commit doesn't need to be rebased since its will not change.
1154
+ # The rest of the commits need to be rebased since their base will be
1155
+ # changed as we strip the metadata from the commit messages.
1156
+ need_rebase = False
1149
1157
for e in st :
1150
- last_hash = strip_metadata (e , args .verbose )
1158
+ last_hash = strip_metadata (e , need_rebase , args .verbose )
1159
+ need_rebase = True
1151
1160
1152
1161
log (h ("Rebasing the current branch on top of updated top branch" ), level = 1 )
1153
1162
run_shell_command (
0 commit comments