histedit: make folding work across dropped commits
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
diff --git a/got/got.c b/got/got.c
index 3dd118c..b5341e1 100644
--- a/got/got.c
+++ b/got/got.c
@@ -4132,8 +4132,10 @@ get_folded_commits(struct got_histedit_list_entry *hle)
struct got_histedit_list_entry *prev, *folded = NULL;
prev = TAILQ_PREV(hle, got_histedit_list, entry);
- while (prev && prev->cmd->code == GOT_HISTEDIT_FOLD) {
- folded = prev;
+ while (prev && (prev->cmd->code == GOT_HISTEDIT_FOLD ||
+ prev->cmd->code == GOT_HISTEDIT_DROP)) {
+ if (prev->cmd->code == GOT_HISTEDIT_FOLD)
+ folded = prev;
prev = TAILQ_PREV(prev, got_histedit_list, entry);
}
@@ -4158,6 +4160,10 @@ histedit_edit_logmsg(struct got_histedit_list_entry *hle,
folded = get_folded_commits(hle);
if (folded) {
while (folded != hle) {
+ if (folded->cmd->code == GOT_HISTEDIT_DROP) {
+ folded = TAILQ_NEXT(folded, entry);
+ continue;
+ }
err = append_folded_commit_msg(&new_msg, folded,
logmsg, repo);
if (err)
diff --git a/regress/cmdline/histedit.sh b/regress/cmdline/histedit.sh
index 98604e6..cafb3a5 100755
--- a/regress/cmdline/histedit.sh
+++ b/regress/cmdline/histedit.sh
@@ -338,6 +338,10 @@ function test_histedit_fold {
git_commit $testroot/repo -m "committing to zeta on master"
local old_commit2=`git_show_head $testroot/repo`
+ echo "modified delta on master" > $testroot/repo/gamma/delta
+ git_commit $testroot/repo -m "committing to delta on master"
+ local old_commit3=`git_show_head $testroot/repo`
+
got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
ret="$?"
if [ "$ret" != "0" ]; then
@@ -346,7 +350,8 @@ function test_histedit_fold {
fi
echo "fold $old_commit1" > $testroot/histedit-script
- echo "pick $old_commit2" >> $testroot/histedit-script
+ echo "drop $old_commit2" >> $testroot/histedit-script
+ echo "pick $old_commit3" >> $testroot/histedit-script
echo "mesg committing folded changes" >> $testroot/histedit-script
(cd $testroot/wt && got histedit -F $testroot/histedit-script \
@@ -357,6 +362,7 @@ function test_histedit_fold {
local short_old_commit1=`trim_obj_id 28 $old_commit1`
local short_old_commit2=`trim_obj_id 28 $old_commit2`
+ local short_old_commit3=`trim_obj_id 28 $old_commit3`
local short_new_commit1=`trim_obj_id 28 $new_commit1`
local short_new_commit2=`trim_obj_id 28 $new_commit2`
@@ -365,8 +371,11 @@ function test_histedit_fold {
echo "A epsilon/new" >> $testroot/stdout.expected
echo "$short_old_commit1 -> fold commit: committing changes" \
>> $testroot/stdout.expected
- echo "G epsilon/zeta" >> $testroot/stdout.expected
- echo -n "$short_old_commit2 -> $short_new_commit2: " \
+ echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
+ echo "drop commit: committing to zeta on master" \
+ >> $testroot/stdout.expected
+ echo "G gamma/delta" >> $testroot/stdout.expected
+ echo -n "$short_old_commit3 -> $short_new_commit2: " \
>> $testroot/stdout.expected
echo "committing folded changes" >> $testroot/stdout.expected
echo "Switching work tree to refs/heads/master" \