Skip to content

Commit 91a5cdf

Browse files
committed
Log git configs
1 parent 3f5e7bb commit 91a5cdf

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎main.go‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import (
4141
"syscall"
4242
"time"
4343

44+
"github.com/go-logr/logr/funcr"
4445
"github.com/golang-jwt/jwt/v4"
4546
"github.com/prometheus/client_golang/prometheus"
4647
"github.com/prometheus/client_golang/prometheus/promhttp"
@@ -827,6 +828,28 @@ func main() {
827828
}
828829
}
829830

831+
// Log configs for debug. The -z means to produce a list of NUL-delimted KV
832+
// pairs, where the first newline is the key/value separator and any
833+
// additional newlines are part of the value.
834+
if stdout, stderr, err := cmdRunner.Run(ctx, "", nil, *flGitCmd, "config", "list", "-z"); err != nil {
835+
log.Error(err, "can't list git config")
836+
os.Exit(1)
837+
} else if stderr != "" {
838+
log.V(0).Info("unexpected stderr reading git config", "stdout", stdout, "stderr", stderr)
839+
os.Exit(1)
840+
} else {
841+
cfgs := strings.Split(stdout, string(rune(0)))
842+
kvs := funcr.PseudoStruct{} // like a map but ordered
843+
for _, cfg := range cfgs {
844+
if cfg == "" {
845+
continue
846+
}
847+
parts := strings.SplitN(cfg, "\n", 2) // any additional newlines are part of the value
848+
kvs = append(kvs, parts[0], parts[1])
849+
}
850+
log.V(0).Info("git config", "configs", kvs)
851+
}
852+
830853
// The scope of the initialization context ends here, so we call cancel to release resources associated with it.
831854
cancel()
832855

0 commit comments

Comments
 (0)