Log the git version

This commit is contained in:
Tim Hockin 2024-06-08 23:01:17 -07:00
parent cd1d050a67
commit b4dfc82490
1 changed files with 20 additions and 12 deletions

32
main.go
View File

@ -622,18 +622,6 @@ func main() {
} }
} }
// Don't pollute the user's .gitconfig if this is being run directly.
if f, err := os.CreateTemp("", "git-sync.gitconfig.*"); err != nil {
log.Error(err, "ERROR: can't create gitconfig file")
os.Exit(1)
} else {
gitConfig := f.Name()
f.Close()
os.Setenv("GIT_CONFIG_GLOBAL", gitConfig)
os.Setenv("GIT_CONFIG_NOSYSTEM", "true")
log.V(2).Info("created private gitconfig file", "path", gitConfig)
}
// Capture the various git parameters. // Capture the various git parameters.
git := &repoSync{ git := &repoSync{
cmd: *flGitCmd, cmd: *flGitCmd,
@ -655,6 +643,26 @@ func main() {
// no long-running operations like `git fetch`, so hopefully 30 seconds will be enough. // no long-running operations like `git fetch`, so hopefully 30 seconds will be enough.
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
// Log the git version.
if ver, _, err := cmdRunner.Run(ctx, "", nil, *flGitCmd, "version"); err != nil {
log.Error(err, "can't get git version")
os.Exit(1)
} else {
log.V(0).Info("git version", "version", ver)
}
// Don't pollute the user's .gitconfig if this is being run directly.
if f, err := os.CreateTemp("", "git-sync.gitconfig.*"); err != nil {
log.Error(err, "ERROR: can't create gitconfig file")
os.Exit(1)
} else {
gitConfig := f.Name()
f.Close()
os.Setenv("GIT_CONFIG_GLOBAL", gitConfig)
os.Setenv("GIT_CONFIG_NOSYSTEM", "true")
log.V(2).Info("created private gitconfig file", "path", gitConfig)
}
// Set various configs we want, but users might override. // Set various configs we want, but users might override.
if err := git.SetupDefaultGitConfigs(ctx); err != nil { if err := git.SetupDefaultGitConfigs(ctx); err != nil {
log.Error(err, "can't set default git configs") log.Error(err, "can't set default git configs")