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

add detectGitRemoteUrlChange #197

Merged
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion g10k_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,7 @@ func TestConfigRetryGitCommands(t *testing.T) {
if exitCode != 0 {
t.Errorf("terminated with %v, but we expected exit status %v", exitCode, 0)
}
//fmt.Println(string(out))
// fmt.Println(string(out))
if !strings.Contains(string(out), "WARN: git command failed: git --git-dir /tmp/g10k/modules/https-__github.com_puppetlabs_puppetlabs-firewall.git remote update --prune deleting local cached repository and retrying...") {
t.Errorf("terminated with the correct exit code, but the expected output was missing. out: %s", string(out))
}
Expand Down
24 changes: 23 additions & 1 deletion git.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ func doMirrorOrUpdate(gitModule GitModule, workDir string, retryCount int) bool
gitCmd = "git clone --single-branch --branch " + gitModule.tree + " " + gitModule.git + " " + workDir
}
if isDir(workDir) {
gitCmd = "git --git-dir " + workDir + " remote update --prune"
if detectGitRemoteURLChange(workDir, gitModule.git) && isControlRepo {
purgeDir(workDir, "git remote url changed")
} else {
gitCmd = "git --git-dir " + workDir + " remote update --prune"
}
}

if explicitlyLoadSSHKey {
Expand Down Expand Up @@ -317,3 +321,21 @@ func detectDefaultBranch(gitDir string) string {
//fmt.Println(defaultBranch)
return defaultBranch
}

func detectGitRemoteURLChange(d string, url string) bool {
gitRemoteCmd := "git --git-dir " + d + " remote -v"

er := executeCommand(gitRemoteCmd, config.Timeout, false)
if er.returnCode != 0 {
Warnf("WARN: Could not detect remote URL for git repository " + d + " trying to purge it and mirror it again")
return true
}

f := strings.Fields(er.output)
if len(f) < 3 {
Warnf("WARN: Could not detect remote URL for git repository " + d + " trying to purge it and mirror it again")
return true
}
configuredRemote := f[1]
return configuredRemote != url
}
2 changes: 1 addition & 1 deletion stale.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func checkForStaleContent(workDir string) {
}

if stale {
Infof("Removing unmanaged path " + path)
Debugf("Removing unmanaged path " + path)
purgeDir(path, "checkForStaleContent()")
}
return nil
Expand Down