Repository navigation
git_cmd: pin git config settings that change printed output - #905
Merged
Merged
Conversation
A local review on a machine whose git config sets format.pretty to a one-line format reports Fixes: and other trailers as missing when the commit carries them. get_commit_show and get_commit_message run a bare git show, so the user's format.pretty decides how much of the message comes back: with a one-line format only the subject line does, and every stage reviews a commit with no body and no trailers. The same holds for every other git show and git log whose output is parsed or handed to a model, such as the cited-commit excerpt in fixes_check and the git_show tool. log.date, the color settings, log.decorate, log.showSignature, log.abbrevCommit, log.showRoot, column.ui and the diff prefix settings reshape that output too. Pin those fifteen settings with -c in the git_cmd constructors, each at the value git uses when it is unset (false for the color settings and log.decorate, whose default auto already means off on a pipe), so a config file can no longer change them. git_cmd already strips GIT_CONFIG_COUNT and GIT_CONFIG_PARAMETERS so that the environment cannot inject settings; settings in the config files still could. An option a call site passes itself, such as --format, still wins. Settings that run other programs, such as diff.external, are left alone. With format.pretty and log.date set in the user's config, four existing tests failed before this change and pass after it: test_git_log and test_git_show_virtual_head in toolbox::tools_test, and both analyze_fixes tests in fixes_check. Two new tests set those settings in a repository's config and check what git show prints: one through git_cmd directly, one through get_commit_show and get_commit_message. Fixes: ffc448e ("worker: use authentic git show output for patch context") Fixes: c917af1 ("git: extract pure commit message without diff using get_commit_message") Signed-off-by: Vlad Poenaru <vlad.wing@gmail.com>
Sashiko review✓ No issues found across 1 commit. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On a machine whose git config sets
format.prettyto a one-line format,sashiko reviewreportsFixes:and other trailers as missing when the commit has them. This PR makes thegit_cmdconstructors override fifteen settings that reshape git's output,format.prettyamong them, so a git config file can no longer set them for the commits, diffs and branch lists sashiko reads.The bug.
get_commit_showandget_commit_messagerungit showwithout a format option, soformat.prettydecides how much of the commit message comes back. With a one-line format only the subject line does, and every review stage sees a commit with no body and no trailers. Othergit showandgit logcalls whose output is parsed or sent to a model have the same problem: the cited-commit excerpt infixes_checkand thegit_showtool among them.log.date, the color settings,log.decorate,log.showSignature,log.abbrevCommit,log.showRoot,column.uiand the diff prefix settings reshape that output too.How it was found. A local review of a kernel commit with a correct
Fixes:tag, run withformat.prettyset, raised a Low finding asking for that tag. Rerun withGIT_CONFIG_GLOBALpointing at a copy of the config withoutformat.prettyandlog.date, it saw the full message and did not raise it.The fix. The
git_cmdconstructors pass-cwith each of the fifteen settings at its unconfigured value; for the color settings andlog.decorate, whose defaultautoalready means off on a pipe, that value isfalse.git_cmdalready stripsGIT_CONFIG_COUNTandGIT_CONFIG_PARAMETERS, so the environment cannot inject settings; settings in the config files still could. An option a call site passes itself, such as--format, still wins. Settings that run other programs, such asdiff.external, are left alone.Left for a follow-up. Five groups of settings can still change what git prints:
diff.context,diff.interHunkContextanddiff.renames,grep.column,i18n.logOutputEncoding,blame.*, and the notes and mailmap settings. None of them changed what the review read in the case that found this bug. I can add them to this PR if you would rather have them in one change.Testing. Every failure below also happens on
mainor is in a file this PR does not touch. All of it ran on Rust 1.99.1, because the pinned 1.93.1 could not be downloaded on the test host.format.prettyandlog.dateset in the user's config, four existing tests fail onmainand pass with this change:test_git_logandtest_git_show_virtual_headintoolbox::tools_test, and bothanalyze_fixestests infixes_check.format.prettyandlog.datein a repository's config, the first with five more of the pinned settings, and check whatgit showprints:test_user_output_settings_do_not_change_what_git_printsthroughgit_cmd, andtest_commit_show_ignores_user_format_configthroughget_commit_showandget_commit_message. Both fail without the fix.cargo test --all-features --no-fail-fast: everything passes except four lib tests (scan::tests::test_resolve_targets_and_build_chunks_with_header_prefetchand threeworker::prefetchtests). Those four also fail onmainon the test host, whose git was built without PCRE (fatal: cannot use Perl-compatible regexes when not compiled with USE_LIBPCRE).cargo fmt --checkand the sign-off check pass.cargo clippy --all-targets --all-features -- -D warningsreports nothing in the two changed files, but fails on six warnings in files this PR does not touch (server.rs,bedrock.rs,related_preexisting.rs), probably lints added after Rust 1.93.sashiko review --project sashikoon this commit: status clean, no findings, and three Low concerns, all marked pre-existing, about settings in the follow-up list above. An earlier run also flagged thecommit_resolution_repotest fixture's commit, which still follows the globalcommit.gpgsignandcore.hooksPath.