feat: improved error handling
This commit is contained in:
parent
3bb5474edf
commit
722a657676
1 changed files with 7 additions and 15 deletions
|
|
@ -1,13 +1,13 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func checkoutRepositories(repositories []Repository) {
|
||||
|
||||
for _, repo := range repositories {
|
||||
|
||||
// create clone
|
||||
|
|
@ -35,18 +35,14 @@ func checkoutRepositories(repositories []Repository) {
|
|||
descriptionPrefix := descriptionPrefixPre + repoName + " ..."
|
||||
bar.Describe(descriptionPrefix)
|
||||
|
||||
_, err := pullRepositories(repoDestination)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
pullRepositories(repoDestination)
|
||||
pulledCount = pulledCount + 1
|
||||
continue
|
||||
}
|
||||
|
||||
// in case cloning failed and the directory does not exist
|
||||
// print the clone error and continue
|
||||
log.Printf("\n❌ error cloning %s: %v\n%s\n", repoName, err, cloneOutput)
|
||||
log.Printf("failed to clone %s: %v", repoName, err)
|
||||
errorCount = errorCount + 1
|
||||
bar.Add(1)
|
||||
continue
|
||||
|
|
@ -59,7 +55,6 @@ func checkoutRepositories(repositories []Repository) {
|
|||
}
|
||||
|
||||
func cloneRepository(repoDestination string, gitlabUrl string) (string, error) {
|
||||
|
||||
cloneCmd := exec.Command("git", "clone", gitlabUrl, repoDestination)
|
||||
cloneOutput, err := cloneCmd.CombinedOutput()
|
||||
|
||||
|
|
@ -67,20 +62,17 @@ func cloneRepository(repoDestination string, gitlabUrl string) (string, error) {
|
|||
}
|
||||
|
||||
func findRemote(repoDestination string) (string, error) {
|
||||
|
||||
remoteCmd := exec.Command("git", "-C", repoDestination, "remote", "show")
|
||||
remoteOutput, err := remoteCmd.CombinedOutput()
|
||||
remote := strings.Split(strings.TrimSpace(string(remoteOutput)), "\n")[0]
|
||||
|
||||
if err != nil {
|
||||
log.Printf("\n❌ error finding remote for: %s\n", err)
|
||||
return "", fmt.Errorf("finding remote: %v", err)
|
||||
}
|
||||
|
||||
return remote, err
|
||||
remote := strings.Split(strings.TrimSpace(string(remoteOutput)), "\n")[0]
|
||||
return remote, nil
|
||||
}
|
||||
|
||||
func pullRepositories(repoDestination string) (string, error) {
|
||||
|
||||
remote, err := findRemote(repoDestination)
|
||||
pullCmd := exec.Command("git", "-C", repoDestination, "pull", remote)
|
||||
pullOutput, err := pullCmd.CombinedOutput()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue