Skip to content

Commit c164484

Browse files
committed
GitCommand: Fix order of return values
I seem to be coding too much with node these days.
1 parent eac8e50 commit c164484

File tree

5 files changed

+13
-12
lines changed

5 files changed

+13
-12
lines changed

common/author.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var errNoGitAuthorEmail = errors.New("Missing git author email")
1111
var errNoGitAuthorName = errors.New("Missing git author name")
1212

1313
func ensureGitAuthor(repoPath string) error {
14-
err, _ := GitCommand(repoPath, []string{"config", "user.email"})
14+
_, err := GitCommand(repoPath, []string{"config", "user.email"})
1515
if err != nil {
1616
var exerr *exec.ExitError
1717
if errors.As(err, &exerr) && exerr.ExitCode() == 1 {
@@ -20,7 +20,7 @@ func ensureGitAuthor(repoPath string) error {
2020
return tracerr.Wrap(err)
2121
}
2222

23-
err, _ = GitCommand(repoPath, []string{"config", "user.name"})
23+
_, err = GitCommand(repoPath, []string{"config", "user.name"})
2424
if err != nil {
2525
var exerr *exec.ExitError
2626
if errors.As(err, &exerr) && exerr.ExitCode() == 1 {

common/commit.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,28 @@ import (
99
)
1010

1111
func commit(repoPath string) error {
12-
err, outb := GitCommand(repoPath, []string{"status", "--porcelain"})
12+
outb, err := GitCommand(repoPath, []string{"status", "--porcelain"})
1313

1414
if err == nil {
1515
if len(outb.Bytes()) == 0 {
1616
return nil
1717
}
1818
}
1919

20-
err, _ = GitCommand(repoPath, []string{"add", "--all"})
20+
_, err = GitCommand(repoPath, []string{"add", "--all"})
2121
if err != nil {
2222
return tracerr.Wrap(err)
2323
}
2424

25-
err, _ = GitCommand(repoPath, []string{"commit", "-m", outb.String()})
25+
_, err = GitCommand(repoPath, []string{"commit", "-m", outb.String()})
2626
if err != nil {
2727
return tracerr.Wrap(err)
2828
}
2929

3030
return nil
3131
}
3232

33-
func GitCommand(repoPath string, args []string) (error, bytes.Buffer) {
33+
func GitCommand(repoPath string, args []string) (bytes.Buffer, error) {
3434
var outb, errb bytes.Buffer
3535

3636
statusCmd := exec.Command("git", args...)
@@ -41,7 +41,8 @@ func GitCommand(repoPath string, args []string) (error, bytes.Buffer) {
4141

4242
if err != nil {
4343
fullCmd := "git " + strings.Join(args, " ")
44-
return tracerr.Errorf("%w: Command: %s\nStdOut: %s\nStdErr: %s", err, fullCmd, outb.String(), errb.String()), outb
44+
err := tracerr.Errorf("%w: Command: %s\nStdOut: %s\nStdErr: %s", err, fullCmd, outb.String(), errb.String())
45+
return outb, err
4546
}
46-
return nil, outb
47+
return outb, nil
4748
}

common/fetch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func fetch(repoPath string) error {
1919
for _, remote := range remotes {
2020
remoteName := remote.Config().Name
2121

22-
err, _ := GitCommand(repoPath, []string{"fetch", remoteName})
22+
_, err := GitCommand(repoPath, []string{"fetch", remoteName})
2323
if err != nil {
2424
return tracerr.Wrap(err)
2525
}

common/push.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func push(repoPath string) error {
1414
return nil
1515
}
1616

17-
err, _ = GitCommand(repoPath, []string{"push", bi.UpstreamRemote, bi.UpstreamBranch})
17+
_, err = GitCommand(repoPath, []string{"push", bi.UpstreamRemote, bi.UpstreamBranch})
1818
if err != nil {
1919
return tracerr.Wrap(err)
2020
}

common/rebase.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func rebase(repoPath string) error {
1919
return tracerr.Wrap(err)
2020
}
2121

22-
rebaseErr, _ := GitCommand(repoPath, []string{"rebase", bi.UpstreamRemote + "/" + bi.UpstreamBranch})
22+
_, rebaseErr := GitCommand(repoPath, []string{"rebase", bi.UpstreamRemote + "/" + bi.UpstreamBranch})
2323
if rebaseErr != nil {
2424
rebaseInProgress, err := isRebasing(repoPath)
2525
if err != nil {
@@ -28,7 +28,7 @@ func rebase(repoPath string) error {
2828

2929
var exerr *exec.ExitError
3030
if errors.As(rebaseErr, &exerr) && exerr.ExitCode() == 1 && rebaseInProgress {
31-
err, _ := GitCommand(repoPath, []string{"rebase", "--abort"})
31+
_, err := GitCommand(repoPath, []string{"rebase", "--abort"})
3232
if err != nil {
3333
return tracerr.Wrap(err)
3434
}

0 commit comments

Comments
 (0)