Commit 243a13f59c19fd9761211d200b68b77f99f6aded

Stefan Sperling 2021-09-02T19:13:50

fix bogus error when 'got cherrypick' merges changes into a locally added file reported by + ok naddy

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"
 }