Commit Diff


commit - c736b84ab8efb53399d58afe57a2e40c4c7dd1b5
commit + 2b70695630ead3274d31727f6b477f3544dc9c9a
blob - df29e65f90431310315474962e5c738ec544f38d
blob + 2bc8caf5426fa97b5db0fe63e371b0cbd9347786
--- lib/worktree.c
+++ lib/worktree.c
@@ -6252,7 +6252,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