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

From:
Omar Polo <op@omarpolo.com>
Subject:
Re: got merge vs gitconfig
To:
gameoftrees@openbsd.org
Date:
Tue, 21 Feb 2023 09:46:10 +0100

Download raw body.

Thread
On 2023/02/21 09:36:26 +0100, Omar Polo <op@omarpolo.com> wrote:
> `got merge' ignores the gitconfig, so users that don't have set
> GOT_AUTHOR are unable to merge, while they can commit.  Diff below
> fixes it by assing the path to the gitconfig to got_repo_open, as the
> other cmd_* that creates commits do.
> 
> It was reported on IRC by James, who also kindly provided a repro
> script and tested the diff below (except the regress bit that I've
> added today.)  Thanks!
> 
> ok?

stupid copy-paste error in a comment of the regress, now fixed

diff /home/op/w/gotd
commit - 45e6b2f427b11e0fc760c10ee96eae3a6a5f06e7
path + /home/op/w/gotd
blob - 438e15cb2486d96840625d284c94c90018d7917b
file + got/got.c
--- got/got.c
+++ got/got.c
@@ -13079,6 +13079,7 @@ cmd_merge(int argc, char *argv[])
 	struct got_repository *repo = NULL;
 	struct got_fileindex *fileindex = NULL;
 	char *cwd = NULL, *id_str = NULL, *author = NULL;
+	char *gitconfig_path = NULL;
 	struct got_reference *branch = NULL, *wt_branch = NULL;
 	struct got_object_id *branch_tip = NULL, *yca_id = NULL;
 	struct got_object_id *wt_branch_tip = NULL;
@@ -13151,9 +13152,12 @@ cmd_merge(int argc, char *argv[])
 		goto done;
 	}
 
+	error = get_gitconfig_path(&gitconfig_path);
+	if (error)
+		goto done;
 	error = got_repo_open(&repo,
-	    worktree ? got_worktree_get_repo_path(worktree) : cwd, NULL,
-	    pack_fds);
+	    worktree ? got_worktree_get_repo_path(worktree) : cwd,
+	    gitconfig_path, pack_fds);
 	if (error != NULL)
 		goto done;
 
@@ -13329,6 +13333,7 @@ done:
 
 	}
 done:
+	free(gitconfig_path);
 	free(id_str);
 	free(merge_commit_id);
 	free(author);
blob - 43fc62a9959f02a646f8a0777654f8bce35c3878
file + regress/cmdline/merge.sh
--- regress/cmdline/merge.sh
+++ regress/cmdline/merge.sh
@@ -1425,6 +1425,46 @@ test_parseargs "$@"
 	test_done "$testroot" 0
 }
 
+test_merge_gitconfig_author() {
+	local testroot=`test_init merge_gitconfig_author`
+
+	(cd $testroot/repo && git config user.name 'Flan Luck')
+	(cd $testroot/repo && git config user.email 'flan_luck@openbsd.org')
+
+	(cd $testroot/repo && git checkout -q -b newbranch)
+	echo "modified alpha on branch" >$testroot/repo/alpha
+	git_commit "$testroot/repo" -m "committing alpha on newbranch"
+	echo "modified delta on branch" >$testroot/repo/gamma/delta
+	git_commit "$testroot/repo" -m "committing delta on newbranch"
+
+	# diverge from newbranch
+	(cd "$testroot/repo" && git checkout -q master)
+	echo "modified beta on master" >$testroot/repo/beta
+	git_commit "$testroot/repo" -m "committing zeto no master"
+
+	got checkout "$testroot/repo" "$testroot/wt" >/dev/null
+
+	# unset in a subshell to avoid affecting our environment
+	(unset GOT_IGNORE_GITCONFIG && cd $testroot/wt && \
+		 got merge newbranch > /dev/null)
+
+	(cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	echo "from: Flan Luck <flan_luck@openbsd.org>" \
+		> $testroot/stdout.expected
+	cmp -s $testroot/stdout.expected $testroot/stdout
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
+	fi
+	test_done "$testroot" "$ret"
+}
+
 test_parseargs "$@"
 run_test test_merge_basic
 run_test test_merge_continue
@@ -1436,3 +1476,4 @@ run_test test_merge_umask
 run_test test_merge_imported_branch
 run_test test_merge_interrupt
 run_test test_merge_umask
+run_test test_merge_gitconfig_author