@@ -14,20 +14,20 @@ import (
14
14
"sync"
15
15
"syscall"
16
16
17
+ "github.com/guywithnose/commandBuilder"
17
18
"github.com/guywithnose/pull-request-parser/config"
18
- "github.com/guywithnose/pull-request-parser/execWrapper"
19
19
"github.com/urfave/cli"
20
20
)
21
21
22
22
// CmdAutoRebase parses the pull requests
23
- func CmdAutoRebase (cmdWrapper execWrapper. CommandBuilder ) func (* cli.Context ) error {
23
+ func CmdAutoRebase (cmdWrapper commandBuilder. Builder ) func (* cli.Context ) error {
24
24
return func (c * cli.Context ) error {
25
25
return cmdAutoRebaseHelper (c , cmdWrapper )
26
26
}
27
27
}
28
28
29
29
// CmdAutoRebase parses the pull requests
30
- func cmdAutoRebaseHelper (c * cli.Context , cmdWrapper execWrapper. CommandBuilder ) error {
30
+ func cmdAutoRebaseHelper (c * cli.Context , cmdWrapper commandBuilder. Builder ) error {
31
31
configData , profileName , err := loadProfile (c )
32
32
if err != nil {
33
33
return err
@@ -152,7 +152,7 @@ func handleCompletion(c *cli.Context) {
152
152
fmt .Fprintln (c .App .Writer , strings .Join (completions , "\n " ))
153
153
}
154
154
155
- func rebasePullRequest (output * prInfo , errorWriter , verboseWriter io.Writer , cmdWrapper execWrapper. CommandBuilder ) error {
155
+ func rebasePullRequest (output * prInfo , errorWriter , verboseWriter io.Writer , cmdWrapper commandBuilder. Builder ) error {
156
156
path , ownedRemote , upstreamRemote , localChanges , err := getRepoData (output , verboseWriter , cmdWrapper )
157
157
if err != nil {
158
158
return err
@@ -178,7 +178,7 @@ func rebasePullRequest(output *prInfo, errorWriter, verboseWriter io.Writer, cmd
178
178
return handleRebase (path , ownedRemote , upstreamRemote , tempBranch , output , verboseWriter , cmdWrapper )
179
179
}
180
180
181
- func handleRebase (path , ownedRemote , upstreamRemote , tempBranch string , output * prInfo , verboseWriter io.Writer , cmdWrapper execWrapper. CommandBuilder ) error {
181
+ func handleRebase (path , ownedRemote , upstreamRemote , tempBranch string , output * prInfo , verboseWriter io.Writer , cmdWrapper commandBuilder. Builder ) error {
182
182
myRemoteBranch := fmt .Sprintf ("%s/%s" , ownedRemote , output .Branch )
183
183
fmt .Fprintf (verboseWriter , "Resetting code to %s\n " , myRemoteBranch )
184
184
err := runCommand (path , cmdWrapper , "git" , "reset" , "--hard" , myRemoteBranch )
@@ -202,7 +202,7 @@ func handleRebase(path, ownedRemote, upstreamRemote, tempBranch string, output *
202
202
return nil
203
203
}
204
204
205
- func fetchRemote (path , remoteName string , verboseWriter io.Writer , cmdWrapper execWrapper. CommandBuilder ) error {
205
+ func fetchRemote (path , remoteName string , verboseWriter io.Writer , cmdWrapper commandBuilder. Builder ) error {
206
206
fmt .Fprintf (verboseWriter , "Fetching from remote: %s\n " , remoteName )
207
207
err := runCommand (path , cmdWrapper , "git" , "fetch" , remoteName )
208
208
if err != nil {
@@ -220,7 +220,7 @@ func wrapExitError(err error, extra string) error {
220
220
return errors .New (extra )
221
221
}
222
222
223
- func checkoutTempBranch (path , branch string , verboseWriter io.Writer , cmdWrapper execWrapper. CommandBuilder ) (string , string , error ) {
223
+ func checkoutTempBranch (path , branch string , verboseWriter io.Writer , cmdWrapper commandBuilder. Builder ) (string , string , error ) {
224
224
fmt .Fprintln (verboseWriter , "Saving current branch name" )
225
225
currentBranchName , err := getCurrentBranch (path , cmdWrapper )
226
226
if err != nil {
@@ -244,7 +244,7 @@ func checkoutTempBranch(path, branch string, verboseWriter io.Writer, cmdWrapper
244
244
return currentBranchName , tempBranch , nil
245
245
}
246
246
247
- func getRepoData (output * prInfo , verboseWriter io.Writer , cmdWrapper execWrapper. CommandBuilder ) (string , string , string , bool , error ) {
247
+ func getRepoData (output * prInfo , verboseWriter io.Writer , cmdWrapper commandBuilder. Builder ) (string , string , string , bool , error ) {
248
248
fmt .Fprintln (verboseWriter , "Requesting repo data from config" )
249
249
if output .Repo .LocalPath == "" {
250
250
return "" , "" , "" , false , errors .New ("Path was not set for this repo" )
@@ -283,7 +283,7 @@ func getRepoData(output *prInfo, verboseWriter io.Writer, cmdWrapper execWrapper
283
283
return output .Repo .LocalPath , ownedRemote , upstreamRemote , localChanges , nil
284
284
}
285
285
286
- func cleanUp (currentBranchName , tempBranch , path string , errorWriter , verboseWriter io.Writer , cmdWrapper execWrapper. CommandBuilder ) {
286
+ func cleanUp (currentBranchName , tempBranch , path string , errorWriter , verboseWriter io.Writer , cmdWrapper commandBuilder. Builder ) {
287
287
fmt .Fprintf (verboseWriter , "Going back to branch %s\n " , currentBranchName )
288
288
err := runCommand (path , cmdWrapper , "git" , "checkout" , currentBranchName )
289
289
if err != nil {
@@ -298,15 +298,15 @@ func cleanUp(currentBranchName, tempBranch, path string, errorWriter, verboseWri
298
298
}
299
299
}
300
300
301
- func popStash (path string , errorWriter , verboseWriter io.Writer , cmdWrapper execWrapper. CommandBuilder ) {
301
+ func popStash (path string , errorWriter , verboseWriter io.Writer , cmdWrapper commandBuilder. Builder ) {
302
302
fmt .Fprintln (verboseWriter , "Popping the stash" )
303
303
err := runCommand (path , cmdWrapper , "git" , "stash" , "pop" )
304
304
if err != nil {
305
305
fmt .Fprintf (errorWriter , "%v\n Warning: Could not pop stash in %s\n " , wrapExitError (err , "" ), path )
306
306
}
307
307
}
308
308
309
- func detectLocalChanges (path string , cmdWrapper execWrapper. CommandBuilder ) (bool , error ) {
309
+ func detectLocalChanges (path string , cmdWrapper commandBuilder. Builder ) (bool , error ) {
310
310
localChangesCommand := cmdWrapper .CreateCommand (path , "git" , "diff-index" , "--quiet" , "HEAD" )
311
311
_ , err := localChangesCommand .Output ()
312
312
if err != nil {
@@ -321,13 +321,13 @@ func detectLocalChanges(path string, cmdWrapper execWrapper.CommandBuilder) (boo
321
321
return false , nil
322
322
}
323
323
324
- func runCommand (path string , cmdWrapper execWrapper. CommandBuilder , command ... string ) error {
324
+ func runCommand (path string , cmdWrapper commandBuilder. Builder , command ... string ) error {
325
325
cmd := cmdWrapper .CreateCommand (path , command ... )
326
326
_ , err := cmd .Output ()
327
327
return err
328
328
}
329
329
330
- func getCurrentBranch (path string , cmdWrapper execWrapper. CommandBuilder ) (string , error ) {
330
+ func getCurrentBranch (path string , cmdWrapper commandBuilder. Builder ) (string , error ) {
331
331
getCurrentBranch := cmdWrapper .CreateCommand (path , "git" , "symbolic-ref" , "HEAD" )
332
332
currentBranchOutput , err := getCurrentBranch .CombinedOutput ()
333
333
if err != nil {
@@ -352,7 +352,7 @@ func getErrorCode(err error) int {
352
352
return - 1
353
353
}
354
354
355
- func getRemotes (path string , cmdWrapper execWrapper. CommandBuilder , output * prInfo ) (string , string , error ) {
355
+ func getRemotes (path string , cmdWrapper commandBuilder. Builder , output * prInfo ) (string , string , error ) {
356
356
getRemotes := cmdWrapper .CreateCommand (path , "git" , "remote" , "-v" )
357
357
remotesOutput , err := getRemotes .CombinedOutput ()
358
358
if err != nil {
0 commit comments