fix histedit 'rebase commit ID mismatch' error when splitting a commit Commit IDs on histedit's temporary branch can change arbitrarily because the user may create new commits on this branch while editing past commits. So there is no point in trying to verify these IDs like we do during rebase. Add a test case which demonstrates the problem.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
diff --git a/include/got_error.h b/include/got_error.h
index cd15a3a..80f9b0e 100644
--- a/include/got_error.h
+++ b/include/got_error.h
@@ -108,7 +108,7 @@
#define GOT_ERR_NO_HISTEDIT_CMD 92
#define GOT_ERR_HISTEDIT_SYNTAX 93
#define GOT_ERR_HISTEDIT_CANCEL 94
-#define GOT_ERR_HISTEDIT_COMMITID 95
+/* 95 is currently unused */
#define GOT_ERR_HISTEDIT_BUSY 96
#define GOT_ERR_HISTEDIT_CMD 97
#define GOT_ERR_HISTEDIT_PATH 98
@@ -238,7 +238,7 @@ static const struct got_error {
{ GOT_ERR_NO_HISTEDIT_CMD,"no histedit commands provided" },
{ GOT_ERR_HISTEDIT_SYNTAX,"syntax error in histedit command list" },
{ GOT_ERR_HISTEDIT_CANCEL,"histedit operation cancelled" },
- { GOT_ERR_HISTEDIT_COMMITID,"histedit commit ID mismatch" },
+ { 95, "unused error code" },
{ GOT_ERR_HISTEDIT_BUSY,"histedit operation is in progress in this "
"work tree and must be continued or aborted first" },
{ GOT_ERR_HISTEDIT_CMD, "bad histedit command" },
diff --git a/lib/worktree.c b/lib/worktree.c
index 0e0bef7..c9da5df 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -4980,7 +4980,7 @@ got_worktree_rebase_pathlist_free(struct got_pathlist_head *merged_paths)
static const struct got_error *
store_commit_id(const char *commit_ref_name, struct got_object_id *commit_id,
- struct got_repository *repo)
+ int is_rebase, struct got_repository *repo)
{
const struct got_error *err;
struct got_reference *commit_ref = NULL;
@@ -4995,7 +4995,7 @@ store_commit_id(const char *commit_ref_name, struct got_object_id *commit_id,
err = got_ref_write(commit_ref, repo);
if (err)
goto done;
- } else {
+ } else if (is_rebase) {
struct got_object_id *stored_id;
int cmp;
@@ -5060,7 +5060,7 @@ got_worktree_rebase_merge_files(struct got_pathlist_head *merged_paths,
if (err)
return err;
- err = store_commit_id(commit_ref_name, commit_id, repo);
+ err = store_commit_id(commit_ref_name, commit_id, 1, repo);
if (err)
goto done;
@@ -5087,7 +5087,7 @@ got_worktree_histedit_merge_files(struct got_pathlist_head *merged_paths,
if (err)
return err;
- err = store_commit_id(commit_ref_name, commit_id, repo);
+ err = store_commit_id(commit_ref_name, commit_id, 0, repo);
if (err)
goto done;
@@ -5263,7 +5263,6 @@ got_worktree_histedit_commit(struct got_object_id **new_commit_id,
const struct got_error *err;
char *commit_ref_name;
struct got_reference *commit_ref = NULL;
- struct got_object_id *commit_id = NULL;
err = get_histedit_commit_ref_name(&commit_ref_name, worktree);
if (err)
@@ -5272,13 +5271,6 @@ got_worktree_histedit_commit(struct got_object_id **new_commit_id,
err = got_ref_open(&commit_ref, repo, commit_ref_name, 0);
if (err)
goto done;
- err = got_ref_resolve(&commit_id, repo, commit_ref);
- if (err)
- goto done;
- if (got_object_id_cmp(commit_id, orig_commit_id) != 0) {
- err = got_error(GOT_ERR_HISTEDIT_COMMITID);
- goto done;
- }
err = rebase_commit(new_commit_id, merged_paths, commit_ref,
worktree, fileindex, tmp_branch, orig_commit, new_logmsg, repo);
@@ -5286,7 +5278,6 @@ done:
if (commit_ref)
got_ref_close(commit_ref);
free(commit_ref_name);
- free(commit_id);
return err;
}
@@ -5882,7 +5873,7 @@ got_worktree_histedit_skip_commit(struct got_worktree *worktree,
if (err)
return err;
- err = store_commit_id(commit_ref_name, commit_id, repo);
+ err = store_commit_id(commit_ref_name, commit_id, 0, repo);
if (err)
goto done;
diff --git a/regress/cmdline/histedit.sh b/regress/cmdline/histedit.sh
old mode 100755
new mode 100744
index 30628b7..11f94a5
--- a/regress/cmdline/histedit.sh
+++ b/regress/cmdline/histedit.sh
@@ -1183,6 +1183,112 @@ function test_histedit_fold_last_commit_swap {
test_done "$testroot" "$ret"
}
+function test_histedit_split_commit {
+ local testroot=`test_init histedit_split_commit`
+
+ local orig_commit=`git_show_head $testroot/repo`
+
+ echo "modified alpha on master" > $testroot/repo/alpha
+ (cd $testroot/repo && git rm -q beta)
+ echo "new file on master" > $testroot/repo/epsilon/new
+ (cd $testroot/repo && git add epsilon/new)
+ git_commit $testroot/repo -m "committing changes 1"
+ local old_commit1=`git_show_head $testroot/repo`
+ local short_old_commit1=`trim_obj_id 28 $old_commit1`
+
+ echo "modified zeta on master" > $testroot/repo/epsilon/zeta
+ git_commit $testroot/repo -m "committing changes 2"
+ local old_commit2=`git_show_head $testroot/repo`
+ local short_old_commit2=`trim_obj_id 28 $old_commit2`
+
+ got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ # split commit1 into commitA and commitB and commitC
+ echo "e $old_commit1" > $testroot/histedit-script
+ echo "p $old_commit2" >> $testroot/histedit-script
+
+ (cd $testroot/wt && got histedit -F $testroot/histedit-script \
+ > $testroot/stdout 2> $testroot/stderr)
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ echo "histedit failed unexpectedly:" >&2
+ cat $testroot/stderr >&2
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo "G alpha" > $testroot/stdout.expected
+ echo "D beta" >> $testroot/stdout.expected
+ echo "A epsilon/new" >> $testroot/stdout.expected
+ echo "Stopping histedit for amending commit $old_commit1" \
+ >> $testroot/stdout.expected
+
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ (cd $testroot/wt && got ci -m "commitA" alpha >/dev/null)
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ echo "commit failed unexpectedly" >&2
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ (cd $testroot/wt && got ci -m "commitB" beta >/dev/null)
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ echo "commit failed unexpectedly" >&2
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ (cd $testroot/wt && got ci -m "commitC" epsilon/new >/dev/null)
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ echo "commit failed unexpectedly" >&2
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ (cd $testroot/wt && got histedit -c \
+ > $testroot/stdout 2> $testroot/stderr)
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ echo "histedit failed unexpectedly:" >&2
+ cat $testroot/stderr >&2
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+ local new_commit2=`git_show_head $testroot/repo`
+ local short_new_commit2=`trim_obj_id 28 $new_commit2`
+
+ echo "$short_old_commit1 -> no-op change: committing changes 1" \
+ > $testroot/stdout.expected
+ echo "G epsilon/zeta" >> $testroot/stdout.expected
+ echo "$short_old_commit2 -> $short_new_commit2: committing changes 2" \
+ >> $testroot/stdout.expected
+ echo "Switching work tree to refs/heads/master" \
+ >> $testroot/stdout.expected
+
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ fi
+ test_done "$testroot" "$ret"
+
+}
+
run_test test_histedit_no_op
run_test test_histedit_swap
run_test test_histedit_drop
@@ -1195,3 +1301,4 @@ run_test test_histedit_path_prefix_drop
run_test test_histedit_path_prefix_edit
run_test test_histedit_outside_refs_heads
run_test test_histedit_fold_last_commit_swap
+run_test test_histedit_split_commit