Commit Diff


commit - 9d9cab5e3aa27db5354b22d7d638230bbc4e92e7
commit + 538aebb56b973dea6dee4dbde0ecfc4043bd6738
blob - aa1a140fd4731f9766992eb2ba3bac8928d901dd
blob + a8d2babaa86a60ad22efe11a8b27f7976cea11e9
--- lib/worktree.c
+++ lib/worktree.c
@@ -6249,7 +6249,7 @@ commit_worktree(struct got_object_id **new_commit_id,
 	if (err)
 		goto done;
 
-	err = got_object_qid_alloc(&pid, worktree->base_commit_id);
+	err = got_object_qid_alloc(&pid, head_commit_id);
 	if (err)
 		goto done;
 	STAILQ_INSERT_TAIL(&parent_ids, pid, entry);
blob - 26a31c050dfc034e8c024f4e945dafbc2d72cf28
blob + eb1ede54ba534e112737b56c1fb19c02b9d70ddb
--- regress/cmdline/commit.sh
+++ regress/cmdline/commit.sh
@@ -2075,6 +2075,41 @@ EOF
 		diff -u $testroot/stdout.expected $testroot/stdout
 	fi
 	test_done "$testroot" "$ret"
+}
+
+test_commit_from_different_worktrees() {
+	local testroot=$(test_init commit_from_different_worktrees)
+
+	got checkout $testroot/repo $testroot/wt > /dev/null
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	got checkout $testroot/repo $testroot/wt2 > /dev/null
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	echo "new file" > $testroot/wt2/new
+	(cd $testroot/wt2 && got add new >/dev/null)
+	(cd $testroot/wt2 && got commit -m 'add new file from wt2' > \
+	    $testroot/stdout)
+	local wt2_head_id=$(git_show_head $testroot/repo)
+
+	echo "modified alpha" > $testroot/wt/alpha
+	(cd $testroot/wt && got commit -m 'mod alpha in wt' > $testroot/stdout)
+	local wt1_parent_id=$(git_show_parent_commit $testroot/repo)
+
+	if [ $wt2_head_id != $wt1_parent_id ]; then
+		echo "commit lost from different work tree" >&2
+		test_done "$testroot" "1"
+	fi
+
+	test_done "$testroot" "0"
 }
 
 test_parseargs "$@"
@@ -2108,3 +2143,4 @@ run_test test_commit_large_file
 run_test test_commit_gitignore
 run_test test_commit_bad_author
 run_test test_commit_logmsg_ref
+run_test test_commit_from_different_worktrees