Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log cleanups #887

Merged
merged 3 commits into from
Jun 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
flVersion := pflag.Bool("version", false, "print the version and exit")
flHelp := pflag.BoolP("help", "h", false, "print help text and exit")
pflag.BoolVarP(flHelp, "__?", "?", false, "print help text and exit") // support -? as an alias to -h
pflag.CommandLine.MarkHidden("__?")

Check failure on line 145 in main.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `pflag.CommandLine.MarkHidden` is not checked (errcheck)
flManual := pflag.Bool("man", false, "print the full manual and exit")

flVerbose := pflag.IntP("verbose", "v",
Expand Down Expand Up @@ -544,6 +544,7 @@
//

log.V(0).Info("starting up",
"version", version.VERSION,
"pid", os.Getpid(),
"uid", os.Getuid(),
"gid", os.Getgid(),
Expand Down Expand Up @@ -621,18 +622,6 @@
}
}

// 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.
git := &repoSync{
cmd: *flGitCmd,
Expand All @@ -654,6 +643,26 @@
// no long-running operations like `git fetch`, so hopefully 30 seconds will be enough.
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.
if err := git.SetupDefaultGitConfigs(ctx); err != nil {
log.Error(err, "can't set default git configs")
Expand Down Expand Up @@ -968,6 +977,10 @@
func logSafeFlags(v int) []string {
ret := []string{}
pflag.VisitAll(func(fl *pflag.Flag) {
// Don't log hidden flags
if fl.Hidden {
return
}
// Don't log unchanged values
if !fl.Changed && v <= 3 {
return
Expand Down
Loading