commit d51d11be9ba86c2c5cf8d36994e56eeccb905865 from: Omar Polo date: Tue Feb 21 10:33:09 2023 UTC fix 'got merge' so it parses gitconfig for author cmd_merge is the only subcommand that may create commits that doesn't parse the git config files, thusly failing for users without GOT_AUTHOR defined. Problem reported by James Cook who also provided an initial test case, thanks! ok jamsek commit - 1a0d06a3c2608bd281c3c156a9b008508983decf commit + d51d11be9ba86c2c5cf8d36994e56eeccb905865 blob - 438e15cb2486d96840625d284c94c90018d7917b blob + e75e9df1ffe98d65e09ab2c686e4f154a8854b94 --- 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 @@ cmd_merge(int argc, char *argv[]) } done: + free(gitconfig_path); free(id_str); free(merge_commit_id); free(author); blob - 43fc62a9959f02a646f8a0777654f8bce35c3878 blob + 876eced1d6b84caf0d92277204c67399f2876875 --- regress/cmdline/merge.sh +++ regress/cmdline/merge.sh @@ -1424,7 +1424,47 @@ test_merge_umask() { 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 " \ + > $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_no_op run_test test_merge_imported_branch run_test test_merge_interrupt run_test test_merge_umask +run_test test_merge_gitconfig_author