@@ -25,7 +25,7 @@ const (
25
25
// Otherwise, it clones it.
26
26
func HandleRepository (dryRun bool , output , organization string , repositoryInfo github.RepositoryInfo , protocol CloneProtocol ) error {
27
27
repository := repositoryInfo .Name
28
- repoPath , err := filepath . Abs ( filepath . FromSlash ( fmt .Sprintf ("%s/%s" , output , repository ) ))
28
+ repoPath , err := safeAbsPath ( fmt .Sprintf ("%s/%s" , output , repository ))
29
29
if err != nil {
30
30
return err
31
31
}
@@ -37,7 +37,7 @@ func HandleRepository(dryRun bool, output, organization string, repositoryInfo g
37
37
return nil
38
38
}
39
39
log .Println ("[debug] cloning repo because local folder not found:" , repoPath )
40
- if err := clone (output , organization , repository , protocol ); err != nil {
40
+ if err := clone (repoPath , organization , repository , protocol ); err != nil {
41
41
return err
42
42
}
43
43
return nil
@@ -52,11 +52,10 @@ func HandleRepository(dryRun bool, output, organization string, repositoryInfo g
52
52
return nil
53
53
}
54
54
log .Println ("[debug] updating local clone for repo:" , repoPath )
55
- return updateLocalClone (output , organization , repositoryInfo )
55
+ return updateLocalClone (repoPath , organization , repositoryInfo )
56
56
}
57
57
58
58
func clone (output , organization string , repository string , protocol CloneProtocol ) error {
59
- repoPath := fmt .Sprintf ("%s/%s" , output , repository )
60
59
var repoUrl string
61
60
if protocol == SystemProtocol {
62
61
repoUrl = fmt .Sprintf ("%s/%s" , organization , repository )
@@ -67,6 +66,10 @@ func clone(output, organization string, repository string, protocol CloneProtoco
67
66
} else {
68
67
return fmt .Errorf ("unknown protocol for cloning: %s" , protocol )
69
68
}
69
+ repoPath , err := safeAbsPath (output )
70
+ if err != nil {
71
+ return err
72
+ }
70
73
args := []string {"repo" , "clone" , repoUrl , repoPath }
71
74
_ , stdErr , err := gh .Exec (args ... )
72
75
if stdErrString := stdErr .String (); stdErrString != "" {
@@ -75,10 +78,13 @@ func clone(output, organization string, repository string, protocol CloneProtoco
75
78
return err
76
79
}
77
80
78
- func updateLocalClone (output , organization string , repositoryInfo github.RepositoryInfo ) error {
81
+ func updateLocalClone (outputPath , organization string , repositoryInfo github.RepositoryInfo ) error {
79
82
repository := repositoryInfo .Name
80
- repoPath := fmt .Sprintf ("%s/%s" , output , repository )
81
- err := fetchAllRemotes (repoPath )
83
+ repoPath , err := safeAbsPath (outputPath )
84
+ if err != nil {
85
+ return err
86
+ }
87
+ err = fetchAllRemotes (repoPath )
82
88
if err != nil {
83
89
log .Println ("[warn]" , err )
84
90
}
@@ -91,27 +97,32 @@ func updateLocalClone(output, organization string, repositoryInfo github.Reposit
91
97
return err
92
98
}
93
99
94
- func fetchAllRemotes (repoPath string ) error {
100
+ func fetchAllRemotes (outputPath string ) error {
101
+ repoPath , err := safeAbsPath (outputPath )
102
+ if err != nil {
103
+ return err
104
+ }
95
105
r , err := git .PlainOpen (repoPath )
96
- var errorReturned error
97
106
if err != nil {
98
- errorReturned = err
99
- } else {
100
- remotes , err := r .Remotes ()
101
- if err != nil {
102
- errorReturned = err
103
- } else {
104
- var wg sync.WaitGroup
105
- wg .Add (len (remotes ))
106
- for _ , remote := range remotes {
107
- go func (rem * git.Remote ) {
108
- defer wg .Done ()
109
- log .Printf ("[debug] fetching remote '%s' in %s" , rem .Config ().Name , repoPath )
110
- _ = rem .Fetch (& git.FetchOptions {Depth : 0 , Tags : git .AllTags })
111
- }(remote )
112
- }
113
- wg .Wait ()
114
- }
107
+ return err
115
108
}
116
- return errorReturned
109
+ remotes , err := r .Remotes ()
110
+ if err != nil {
111
+ return err
112
+ }
113
+ var wg sync.WaitGroup
114
+ wg .Add (len (remotes ))
115
+ for _ , remote := range remotes {
116
+ go func (rem * git.Remote ) {
117
+ defer wg .Done ()
118
+ log .Printf ("[debug] fetching remote '%s' in %s" , rem .Config ().Name , repoPath )
119
+ _ = rem .Fetch (& git.FetchOptions {Depth : 0 , Tags : git .AllTags })
120
+ }(remote )
121
+ }
122
+ wg .Wait ()
123
+ return nil
124
+ }
125
+
126
+ func safeAbsPath (p string ) (string , error ) {
127
+ return filepath .Abs (filepath .FromSlash (p ))
117
128
}
0 commit comments