Skip to content

Conversation

dvermd
Copy link
Contributor

@dvermd dvermd commented Sep 5, 2025

This PR always pass the user.name, user.email, core.autocrlf and commit.gpgSign git parameters to the run_command and run_command_with_output functions.

With this PR, I managed to successfully run ./y.sh prepare after a ./y.sh clean all" with and without user.nameanduser.email` parameters defined for the repo.

Fixes #731

@dvermd dvermd force-pushed the default_git_user_info branch from 7fc7ee3 to 13b4c10 Compare September 5, 2025 22:18
Copy link
Contributor

@antoyo antoyo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.
One thing to improve.
Looks good otherwise.

Comment on lines 12 to 45
fn run_git_command(
command: &dyn AsRef<OsStr>,
input: &[&dyn AsRef<OsStr>],
cwd: Option<&Path>,
) -> Result<Output, String> {
// This is needed on systems where nothing is configured.
// git really needs something here, or it will fail.
// Even using --author is not enough.
let git_cmd = &[
&"git" as &dyn AsRef<OsStr>,
&"-c" as &dyn AsRef<OsStr>,
&"user.name=None" as &dyn AsRef<OsStr>,
&"-c" as &dyn AsRef<OsStr>,
&"[email protected]" as &dyn AsRef<OsStr>,
&"-c" as &dyn AsRef<OsStr>,
&"core.autocrlf=false" as &dyn AsRef<OsStr>,
&"-c" as &dyn AsRef<OsStr>,
&"commit.gpgSign=false" as &dyn AsRef<OsStr>,
]
.into_iter()
.chain([command])
.chain(input.iter().cloned())
.collect::<Vec<_>>()[..];
run_command(git_cmd, cwd)
}

fn run_git_command_with_output(
command: &dyn AsRef<OsStr>,
input: &[&dyn AsRef<OsStr>],
cwd: Option<&Path>,
) -> Result<(), String> {
// This is needed on systems where nothing is configured.
// git really needs something here, or it will fail.
// Even using --author is not enough.
let git_cmd = &[
&"git" as &dyn AsRef<OsStr>,
&"-c" as &dyn AsRef<OsStr>,
&"user.name=None" as &dyn AsRef<OsStr>,
&"-c" as &dyn AsRef<OsStr>,
&"[email protected]" as &dyn AsRef<OsStr>,
&"-c" as &dyn AsRef<OsStr>,
&"core.autocrlf=false" as &dyn AsRef<OsStr>,
&"-c" as &dyn AsRef<OsStr>,
&"commit.gpgSign=false" as &dyn AsRef<OsStr>,
]
.into_iter()
.chain([command])
.chain(input.iter().cloned())
.collect::<Vec<_>>()[..];
run_command_with_output(git_cmd, cwd)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some duplication between these 2 functions.
Could you please refactor these functions to avoid this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the command definitions to a const

@dvermd dvermd force-pushed the default_git_user_info branch from 13b4c10 to 99fabbf Compare September 7, 2025 09:02
@dvermd dvermd force-pushed the default_git_user_info branch from 99fabbf to bd303ca Compare September 7, 2025 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

./y.sh prepare patch does not apply
2 participants