Commit ad324bf53a11587dc227a2c00b65020595aa18dc

Stefan Sperling 2021-09-21T20:27:45

fix histedit_no_op test which was failing randomly A no-op replayed history ends up having exactly the same commit IDs if all commits are created at roughly the same moment in time. There are no content changes involved so if commit timestamps do not differ then commit hashes will be the same. In which case there is no fork in history for 'got histedit -l' to display, yet the test was always expecting a fork in history to be displayed. Update the test to take this issue into account. The test will now pass no matter which result is produced by the histedit operation. Problem found by Lucas who observed that this test was randomly failing. Patch also provided by Lucas.

diff --git a/regress/cmdline/histedit.sh b/regress/cmdline/histedit.sh
index 8c612fa..61bcebf 100755
--- a/regress/cmdline/histedit.sh
+++ b/regress/cmdline/histedit.sh
@@ -28,6 +28,7 @@ test_histedit_no_op() {
 	(cd $testroot/repo && git add epsilon/new)
 	git_commit $testroot/repo -m "committing changes"
 	local old_commit1=`git_show_head $testroot/repo`
+	local old_author_time1=`git_show_author_time $testroot/repo`
 
 	echo "modified zeta on master" > $testroot/repo/epsilon/zeta
 	git_commit $testroot/repo -m "committing to zeta on master"
@@ -152,6 +153,7 @@ test_histedit_no_op() {
 
 	# We should have a backup of old commits
 	(cd $testroot/repo && got histedit -l > $testroot/stdout)
+	d_orig1=`date -u -r $old_author_time1 +"%G-%m-%d"`
 	d_orig2=`date -u -r $old_author_time2 +"%a %b %e %X %Y UTC"`
 	d_new2=`date -u -r $new_author_time2 +"%G-%m-%d"`
 	d_orig=`date -u -r $orig_author_time +"%G-%m-%d"`
@@ -165,9 +167,29 @@ date: $d_orig2
  
 has become commit $new_commit2 (master)
  $d_new2 $GOT_AUTHOR_11  committing to zeta on master
-history forked at $orig_commit
- $d_orig $GOT_AUTHOR_11  adding the test tree
 EOF
+
+	local is_forked=true d_fork fork_commit fork_commit_msg
+
+	if [ "$old_commit1" = "$new_commit1" ]; then
+		if [ "$old_commit2" = "$new_commit2" ]; then
+			is_forked=false
+		else
+			d_fork=$d_orig1
+			fork_commit=$new_commit1
+			fork_commit_msg="committing changes"
+		fi
+	else
+		d_fork=$d_orig
+		fork_commit=$orig_commit
+		fork_commit_msg="adding the test tree"
+	fi
+
+	$is_forked && cat >> $testroot/stdout.expected <<EOF
+history forked at $fork_commit
+ $d_fork $GOT_AUTHOR_11  $fork_commit_msg
+EOF
+
 	cmp -s $testroot/stdout.expected $testroot/stdout
 	ret="$?"
 	if [ "$ret" != "0" ]; then