fix bogus error when 'got cherrypick' merges changes into a locally added file reported by + ok naddy
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
diff --git a/lib/worktree.c b/lib/worktree.c
index d6df04c..70cbc4d 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -3133,7 +3133,8 @@ check_merge_ok(void *arg, struct got_fileindex_entry *ie)
char *ondisk_path;
/* Reject merges into a work tree with mixed base commits. */
- if (memcmp(ie->commit_sha1, a->worktree->base_commit_id->sha1,
+ if (got_fileindex_entry_has_commit(ie) &&
+ memcmp(ie->commit_sha1, a->worktree->base_commit_id->sha1,
SHA1_DIGEST_LENGTH))
return got_error(GOT_ERR_MIXED_COMMITS);
diff --git a/regress/cmdline/cherrypick.sh b/regress/cmdline/cherrypick.sh
index 5bfd952..e38f0c9 100755
--- a/regress/cmdline/cherrypick.sh
+++ b/regress/cmdline/cherrypick.sh
@@ -38,6 +38,10 @@ test_cherrypick_basic() {
local branch_rev=`git_show_head $testroot/repo`
+ echo "modified new file on branch" > $testroot/repo/epsilon/new
+ git_commit $testroot/repo -m "committing more changes on newbranch"
+ local branch_rev2=`git_show_head $testroot/repo`
+
(cd $testroot/wt && got cherrypick $branch_rev > $testroot/stdout)
echo "G alpha" > $testroot/stdout.expected
@@ -89,6 +93,33 @@ test_cherrypick_basic() {
ret="$?"
if [ "$ret" != "0" ]; then
diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ (cd $testroot/wt && got cherrypick $branch_rev2 > $testroot/stdout)
+
+ echo "G epsilon/new" > $testroot/stdout.expected
+ echo "Merged commit $branch_rev2" >> $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
+
+ echo 'M alpha' > $testroot/stdout.expected
+ echo 'D beta' >> $testroot/stdout.expected
+ echo 'A epsilon/new' >> $testroot/stdout.expected
+
+ (cd $testroot/wt && got status > $testroot/stdout)
+
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
fi
test_done "$testroot" "$ret"
}