feat: improved pullRepository function
This commit is contained in:
parent
f8c85ca0d3
commit
ea8b2356b8
1 changed files with 14 additions and 8 deletions
|
|
@ -38,11 +38,7 @@ func checkoutRepositories(repositories []Repository) {
|
||||||
if strings.Contains(string(cloneOutput),
|
if strings.Contains(string(cloneOutput),
|
||||||
"already exists and is not an empty directory") {
|
"already exists and is not an empty directory") {
|
||||||
|
|
||||||
descriptionPrefixPre := "Pulling repository "
|
pullRepository(repoName, repoDestination)
|
||||||
descriptionPrefix := descriptionPrefixPre + repoName + " ..."
|
|
||||||
bar.Describe(descriptionPrefix)
|
|
||||||
|
|
||||||
pullRepository(repoDestination)
|
|
||||||
pulledCount = pulledCount + 1
|
pulledCount = pulledCount + 1
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
@ -61,7 +57,13 @@ func checkoutRepositories(repositories []Repository) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func pullRepository(repoDestination string) (string, error) {
|
func pullRepository(repoName string, repoDestination string) {
|
||||||
|
|
||||||
|
// update the progress bar
|
||||||
|
descriptionPrefixPre := "Pulling repository "
|
||||||
|
descriptionPrefix := descriptionPrefixPre + repoName + " ..."
|
||||||
|
bar.Describe(descriptionPrefix)
|
||||||
|
|
||||||
|
|
||||||
// find remote
|
// find remote
|
||||||
findRemote := func(repoDestination string) (string, error) {
|
findRemote := func(repoDestination string) (string, error) {
|
||||||
|
|
@ -76,6 +78,7 @@ func pullRepository(repoDestination string) (string, error) {
|
||||||
}
|
}
|
||||||
remote, _ := findRemote(repoDestination)
|
remote, _ := findRemote(repoDestination)
|
||||||
|
|
||||||
|
|
||||||
// pull repository
|
// pull repository
|
||||||
pullCmd := exec.Command("git", "-C", repoDestination, "pull", remote)
|
pullCmd := exec.Command("git", "-C", repoDestination, "pull", remote)
|
||||||
pullOutput, err := pullCmd.CombinedOutput()
|
pullOutput, err := pullCmd.CombinedOutput()
|
||||||
|
|
@ -84,9 +87,12 @@ func pullRepository(repoDestination string) (string, error) {
|
||||||
errorCount = errorCount + 1
|
errorCount = errorCount + 1
|
||||||
if strings.Contains(string(pullOutput), "You have unstaged changes") {
|
if strings.Contains(string(pullOutput), "You have unstaged changes") {
|
||||||
pullErrorMsg = append(pullErrorMsg, repoDestination)
|
pullErrorMsg = append(pullErrorMsg, repoDestination)
|
||||||
|
} else {
|
||||||
|
log.Printf("pull error: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// update the progress bar
|
||||||
bar.Add(1)
|
bar.Add(1)
|
||||||
return string(pullOutput), err
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue