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

From:
Omar Polo <op@omarpolo.com>
Subject:
[bug] histedit and the first line of a file
To:
gameoftrees@openbsd.org
Date:
Sat, 02 Oct 2021 18:04:30 +0200

Download raw body.

Thread
Hello,

I think I've found an error in the way histedit manages diffs: if a
commit adds a line *as the first one in the file*, after a histedit
operation that line is mis-placed (even if the histedit operation for
that commit was a plain 'pick'.)

I've found this while working with GNU-style ChangeLog files: news
entries are added at the top of the file, and every time I did a
histedit the ChangeLog was corrupted.

I'm attaching a diff with a test that exposes the problems, but I don't
have any idea on how to actually fix it, sorry.  It fails with

  % ./histedit.sh -q -r /tmp
  M  alpha
  Created commit b13fd327b6b9f9d51827adcc4129d44218b48b91
  U  alpha
  Updated to refs/heads/master: dccc3ac37ab55c3347cf40ff6dff882cfe93d5bd
  G  alpha
  b13fd327b6b9 -> 831486a4e469: modified alpha on master
  Switching work tree to refs/heads/master
  --- /tmp/got-test-histedit_prepend_line-EdfGRt41/alpha.expected Sat Oct  2 18:32:14 2021
  +++ /tmp/got-test-histedit_prepend_line-EdfGRt41/wt/alpha       Sat Oct  2 18:32:15 2021
  @@ -1,2 +1,2 @@
  -first line
   alpha
  +first line
  test failed; leaving test data in /tmp/got-test-histedit_prepend_line-EdfGRt41

Cheers,

Omar Polo


diff c5930c8fc1010eee083d2154c74160f5bbbd2ac3 /home/op/w/got
blob - 65ef292945ab5a14c0c1674cbd8aec70fc5e9418
file + regress/cmdline/histedit.sh
--- regress/cmdline/histedit.sh
+++ regress/cmdline/histedit.sh
@@ -1913,6 +1913,47 @@ EOF
 	test_done "$testroot" "$ret"
 }
 
+test_histedit_prepend_line() {
+	local testroot=`test_init histedit_prepend_line`
+	local orig_commit=`git_show_head $testroot/repo`
+
+	got checkout $testroot/repo $testroot/wt > /dev/null
+
+	ed "$testroot/wt/alpha" <<EOF >/dev/null 2>&1
+0i
+first line
+.
+wq
+EOF
+
+	cp $testroot/wt/alpha $testroot/alpha.expected
+
+	(cd $testroot/wt/ && got commit -m 'modified alpha on master' alpha)
+
+	local top_commit=`git_show_head $testroot/repo`
+	echo "pick $top_commit" > "$testroot/histedit-script"
+
+	(cd "$testroot/wt/" && \
+		got update -c $orig_commit && \
+		got histedit -F "$testroot/histedit-script")
+
+	ret="$?"
+	if [ "$?" != 0 ]; then
+		echo "histedit failed unexpectedly" >&2
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	ret=0
+	first_line="$(head -n1 "$testroot/repo/alpha")"
+	if [ "$first_line" != "first line" ]; then
+		ret=1
+		diff -u $testroot/alpha.expected $testroot/wt/alpha
+	fi
+
+	test_done "$testroot" $ret
+}
+
 test_parseargs "$@"
 run_test test_histedit_no_op
 run_test test_histedit_swap
@@ -1932,3 +1973,4 @@ run_test test_histedit_fold_add_delete
 run_test test_histedit_fold_only
 run_test test_histedit_fold_only_empty_logmsg
 run_test test_histedit_edit_only
+run_test test_histedit_prepend_line