commit b16f18320c2d00bb467b50672a03e2665791ceda from: Omar Polo via: Thomas Adam date: Tue Feb 21 12:31:55 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 - c12ab9ad7f32b9eb712734e776de2f7b0370e643 commit + b16f18320c2d00bb467b50672a03e2665791ceda blob - b891d7925d4d755ef4a58c41f98faa442f669735 blob + 9d58d1d4f3c73ef9a8754f4cbf4e8532acff5a2a --- 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