add a test for rebase file index corruption problem fix in previous commit ok tracey
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
diff --git a/regress/cmdline/common.sh b/regress/cmdline/common.sh
index 34f0880..ff453b2 100644
--- a/regress/cmdline/common.sh
+++ b/regress/cmdline/common.sh
@@ -84,7 +84,8 @@ function git_show_tagger_time
function git_show_parent_commit
{
local repo="$1"
- (cd $repo && git show --no-patch --pretty='format:%P')
+ local commit="$2"
+ (cd $repo && git show --no-patch --pretty='format:%P' $commit)
}
function git_show_tree
diff --git a/regress/cmdline/rebase.sh b/regress/cmdline/rebase.sh
index e6f7a88..e54de3f 100755
--- a/regress/cmdline/rebase.sh
+++ b/regress/cmdline/rebase.sh
@@ -1163,6 +1163,113 @@ function test_rebase_delete_missing_file {
test_done "$testroot" "$ret"
}
+function test_rebase_rm_add_rm_file {
+ local testroot=`test_init rebase_rm_add_rm_file`
+
+ (cd $testroot/repo && git checkout -q -b newbranch)
+ (cd $testroot/repo && git rm -q beta)
+ git_commit $testroot/repo -m "removing beta from newbranch"
+ local orig_commit1=`git_show_head $testroot/repo`
+
+ echo 'restored beta' > $testroot/repo/beta
+ (cd $testroot/repo && git add beta)
+ git_commit $testroot/repo -m "restoring beta on newbranch"
+ local orig_commit2=`git_show_head $testroot/repo`
+
+ (cd $testroot/repo && git rm -q beta)
+ git_commit $testroot/repo -m "removing beta from newbranch again"
+ local orig_commit3=`git_show_head $testroot/repo`
+
+ (cd $testroot/repo && git checkout -q master)
+ echo "modified zeta on master" > $testroot/repo/epsilon/zeta
+ git_commit $testroot/repo -m "committing to zeta on master"
+ local master_commit=`git_show_head $testroot/repo`
+
+ got checkout $testroot/repo $testroot/wt > /dev/null
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
+
+ # this would error out with 'got: file index is corrupt'
+ (cd $testroot/wt && got status > /dev/null)
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ echo "got status command failed unexpectedly" >&2
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ (cd $testroot/repo && git checkout -q newbranch)
+ local new_commit3=`git_show_head $testroot/repo`
+ local new_commit2=`git_show_parent_commit $testroot/repo`
+ local new_commit1=`git_show_parent_commit $testroot/repo $new_commit2`
+
+ (cd $testroot/repo && git checkout -q newbranch)
+
+ local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
+ local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
+ local short_orig_commit3=`trim_obj_id 28 $orig_commit3`
+ local short_new_commit1=`trim_obj_id 28 $new_commit1`
+ local short_new_commit2=`trim_obj_id 28 $new_commit2`
+ local short_new_commit3=`trim_obj_id 28 $new_commit3`
+
+ echo "D beta" > $testroot/stdout.expected
+ echo -n "$short_orig_commit1 -> $short_new_commit1" \
+ >> $testroot/stdout.expected
+ echo ": removing beta from newbranch" >> $testroot/stdout.expected
+ echo "A beta" >> $testroot/stdout.expected
+ echo -n "$short_orig_commit2 -> $short_new_commit2" \
+ >> $testroot/stdout.expected
+ echo ": restoring beta on newbranch" >> $testroot/stdout.expected
+ echo "D beta" >> $testroot/stdout.expected
+ echo -n "$short_orig_commit3 -> $short_new_commit3" \
+ >> $testroot/stdout.expected
+ echo ": removing beta from newbranch again" >> $testroot/stdout.expected
+ echo "Switching work tree to refs/heads/newbranch" \
+ >> $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 status > $testroot/stdout)
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ echo "got status command failed unexpectedly" >&2
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo -n > $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 log -l4 | grep ^commit > $testroot/stdout)
+ echo "commit $new_commit3 (newbranch)" > $testroot/stdout.expected
+ echo "commit $new_commit2" >> $testroot/stdout.expected
+ echo "commit $new_commit1" >> $testroot/stdout.expected
+ echo "commit $master_commit (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_rebase_basic
run_test test_rebase_ancestry_check
run_test test_rebase_continue
@@ -1176,3 +1283,4 @@ run_test test_rebase_forward
run_test test_rebase_out_of_date
run_test test_rebase_trims_empty_dir
run_test test_rebase_delete_missing_file
+run_test test_rebase_rm_add_rm_file