"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Christian Weisgerber <naddy@mips.inka.de>
Subject:
histedit folding "delete, re-add" is broken
To:
gameoftrees@openbsd.org
Date:
Tue, 7 Mar 2023 00:24:00 +0100

Download raw body.

Thread
Histedit folding of a file deletion and subsequent addition of the
same file is broken.

You have a file.
In commit #1 you delete that file.
In commit #2 you put a modified version of that file back into place.
Then you histedit and fold commits #1 and #2.

I would expect that this operation coalesces the commits into one
that changes the file.  In reality, the file is simply deleted.
I guess commit #1 preempts further changes.

By contrast, Git behaves as I would expect.

(I wasn't idly looking for a corner case.  One lazy way to, say,
switch the FreeBSD got port to got-portable would be to simply
delete the old port, put a newly created one into the same place,
fold the commits, and let God^Ht sort them out...)

xfail regression test below.  OK?


diff /home/naddy/got
commit - 885e96dfba200f362ddd1d9795740251bcb6e39b
path + /home/naddy/got
blob - 7f41dbf2a6228ff4edc4bb8fd6d844625b1b6dc5
file + regress/cmdline/histedit.sh
--- regress/cmdline/histedit.sh
+++ regress/cmdline/histedit.sh
@@ -1547,6 +1547,63 @@ test_histedit_fold_only() {
 	test_done "$testroot" "$ret"
 }
 
+test_histedit_fold_delete_add() {
+	local testroot=`test_init histedit_fold_delete_add`
+
+	local orig_commit=`git_show_head $testroot/repo`
+
+	(cd $testroot/repo && git rm -q alpha)
+	git_commit $testroot/repo -m "removing alpha"
+	local old_commit1=`git_show_head $testroot/repo`
+
+	echo "modified alpha" >$testroot/repo/alpha
+	(cd $testroot/repo && git add alpha)
+	git_commit $testroot/repo -m "add back modified alpha"
+	local old_commit2=`git_show_head $testroot/repo`
+
+	got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	echo "fold $old_commit1" > $testroot/histedit-script
+	echo "pick $old_commit2" >> $testroot/histedit-script
+	echo "mesg folded changes" >> $testroot/histedit-script
+
+	(cd $testroot/wt && got histedit -F $testroot/histedit-script \
+		> $testroot/stdout)
+
+	local new_commit1=`git_show_head $testroot/repo`
+	
+	local short_old_commit1=`trim_obj_id 28 $old_commit1`
+	local short_old_commit2=`trim_obj_id 28 $old_commit2`
+	local short_new_commit1=`trim_obj_id 28 $new_commit1`
+
+	echo "D  alpha" > $testroot/stdout.expected
+	echo "$short_old_commit1 ->  fold commit: removing alpha" \
+		>> $testroot/stdout.expected
+	echo "A  alpha" >> $testroot/stdout.expected
+	echo "$short_old_commit2 -> $short_new_commit1: folded changes" \
+		>> $testroot/stdout.expected
+	echo "Switching work tree to refs/heads/master" \
+		>> $testroot/stdout.expected
+
+	#cmp -s $testroot/stdout.expected $testroot/stdout
+	#ret=$?
+	#if [ $ret -ne 0 ]; then
+	#	diff -u $testroot/stdout.expected $testroot/stdout
+	#	test_done "$testroot" "$ret"
+	#	return 1
+	#fi
+
+	if [ ! -e $testroot/wt/alpha ]; then
+		ret="xfail fold deleted and added file"
+	fi
+	test_done "$testroot" "$ret"
+}
+
 test_histedit_fold_only() {
 	local testroot=`test_init histedit_fold_only`
 
@@ -2467,6 +2524,7 @@ run_test test_histedit_fold_only
 run_test test_histedit_split_commit
 run_test test_histedit_duplicate_commit_in_script
 run_test test_histedit_fold_add_delete
+run_test test_histedit_fold_delete_add
 run_test test_histedit_fold_only
 run_test test_histedit_fold_only_empty_logmsg
 run_test test_histedit_edit_only
-- 
Christian "naddy" Weisgerber                          naddy@mips.inka.de