Add more debugging output to git commands when debug mode is enabled (#412)

This commit is contained in:
gabrie30
2024-05-15 17:17:51 -07:00
committed by GitHub
parent 427225564c
commit e8303f96cc
4 changed files with 46 additions and 4 deletions

View File

@@ -342,5 +342,5 @@ Alternatively, Windows users can also install ghorg using [scoop](https://scoop.
- If your GitHub Personal Access Token is only finding public repos, give your token all the repos permissions
- Make sure your `$ git --version` is >= 2.19.0
- Check for other software, such as anti-malware, that could interfere with ghorgs ability to create large number of connections, see [issue 132](https://github.com/gabrie30/ghorg/issues/132#issuecomment-889357960). You can also lower the concurrency with `--concurrency=n` default is 25.
- To debug yourself you can call ghorg with the GHORG_DEBUG=true env e.g `GHORG_DEBUG=true ghorg clone kubernetes --concurrency=1`
- To debug yourself you can call ghorg with the GHORG_DEBUG=true env e.g `GHORG_DEBUG=true ghorg clone kubernetes`. Note, when this env is set concurrency is set to a value of 1
- If you've gotten this far and still have an issue feel free to raise an issue

View File

@@ -207,6 +207,10 @@ func InitConfig() {
if os.Getenv("GHORG_DEBUG") != "" {
fmt.Println("-------- Setting Default ENV values ---------")
if os.Getenv("GHORG_CONCURRENCY_DEBUG") == "" {
fmt.Println("Setting concurrency to 1, this can be overwritten by setting GHORG_CONCURRENCY_DEBUG; however when using concurrency with GHORG_DEBUG, not all debugging output will be printed in serial order.")
os.Setenv("GHORG_CONCURRENCY", "1")
}
}
getOrSetDefaults("GHORG_ABSOLUTE_PATH_TO_CLONE_TO")

View File

@@ -27,10 +27,19 @@ func NewGit() GitClient {
return GitClient{}
}
func printDebugCmd(cmd *exec.Cmd) {
func printDebugCmd(cmd *exec.Cmd, repo scm.Repo) error {
fmt.Println("------------- GIT DEBUG -------------")
fmt.Print("Repo Data: ")
spew.Dump(repo)
fmt.Print("Command Ran: ")
spew.Dump(*cmd)
fmt.Println("")
output, err := cmd.CombinedOutput()
fmt.Printf("Command Output: %s\n", string(output))
if err != nil {
fmt.Printf("Error: %v\n", err)
}
return err
}
func (g GitClient) Clone(repo scm.Repo) error {
@@ -61,7 +70,7 @@ func (g GitClient) Clone(repo scm.Repo) error {
cmd := exec.Command("git", args...)
if os.Getenv("GHORG_DEBUG") != "" {
printDebugCmd(cmd)
return printDebugCmd(cmd, repo)
}
err := cmd.Run()
@@ -72,6 +81,9 @@ func (g GitClient) SetOriginWithCredentials(repo scm.Repo) error {
args := []string{"remote", "set-url", "origin", repo.CloneURL}
cmd := exec.Command("git", args...)
cmd.Dir = repo.HostPath
if os.Getenv("GHORG_DEBUG") != "" {
return printDebugCmd(cmd, repo)
}
return cmd.Run()
}
@@ -79,24 +91,38 @@ func (g GitClient) SetOrigin(repo scm.Repo) error {
args := []string{"remote", "set-url", "origin", repo.URL}
cmd := exec.Command("git", args...)
cmd.Dir = repo.HostPath
if os.Getenv("GHORG_DEBUG") != "" {
return printDebugCmd(cmd, repo)
}
return cmd.Run()
}
func (g GitClient) Checkout(repo scm.Repo) error {
cmd := exec.Command("git", "checkout", repo.CloneBranch)
cmd.Dir = repo.HostPath
if os.Getenv("GHORG_DEBUG") != "" {
return printDebugCmd(cmd, repo)
}
return cmd.Run()
}
func (g GitClient) Clean(repo scm.Repo) error {
cmd := exec.Command("git", "clean", "-f", "-d")
cmd.Dir = repo.HostPath
if os.Getenv("GHORG_DEBUG") != "" {
return printDebugCmd(cmd, repo)
}
return cmd.Run()
}
func (g GitClient) UpdateRemote(repo scm.Repo) error {
cmd := exec.Command("git", "remote", "update")
cmd.Dir = repo.HostPath
if os.Getenv("GHORG_DEBUG") != "" {
return printDebugCmd(cmd, repo)
}
return cmd.Run()
}
@@ -119,7 +145,7 @@ func (g GitClient) Pull(repo scm.Repo) error {
cmd.Dir = repo.HostPath
if os.Getenv("GHORG_DEBUG") != "" {
printDebugCmd(cmd)
return printDebugCmd(cmd, repo)
}
return cmd.Run()
@@ -128,6 +154,9 @@ func (g GitClient) Pull(repo scm.Repo) error {
func (g GitClient) Reset(repo scm.Repo) error {
cmd := exec.Command("git", "reset", "--hard", "origin/"+repo.CloneBranch)
cmd.Dir = repo.HostPath
if os.Getenv("GHORG_DEBUG") != "" {
return printDebugCmd(cmd, repo)
}
return cmd.Run()
}
@@ -141,5 +170,8 @@ func (g GitClient) FetchAll(repo scm.Repo) error {
}
cmd := exec.Command("git", args...)
cmd.Dir = repo.HostPath
if os.Getenv("GHORG_DEBUG") != "" {
return printDebugCmd(cmd, repo)
}
return cmd.Run()
}

View File

@@ -157,6 +157,12 @@ GHORG_NO_TOKEN: false
# flag (--config)
# GHORG_CONFIG:
# Get verbose debugging output
# NOTE: This setting cannot be configured through the configuration file or the CLI. It can only be set as an environment variable.
# For example: GHORG_DEBUG=true ghorg clone kubernetes
# When using this env concurrency is set to a value of 1, this behavior can be overwritten for debugging concurrency issues by setting GHORG_CONCURRENCY_DEBUG=true in addition to setting GHORG_DEBUG=true
# GHORG_DEBUG:
# +-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
# |G|I|T|H|U|B| |S|P|E|C|I|F|I|C|
# +-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+