Skip to content

Commit

Permalink
Clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
doriable committed May 16, 2024
1 parent 8316881 commit 9aff322
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 6 additions & 3 deletions private/buf/cmd/buf/command/push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ func getGitMetadataUploadOptions(
}
runner := command.NewRunner()
// validate that input is a dirRef and is a valid git checkout
if err := validateInput(ctx, runner, container, input); err != nil {
if err := validateInputIsValidDirAndGitCheckout(ctx, runner, container, input); err != nil {
return nil, err
}
uncommittedFiles, err := git.CheckForUncommittedGitChanges(ctx, runner, input)
Expand Down Expand Up @@ -482,7 +482,7 @@ func getGitMetadataUploadOptions(
return gitMetadataUploadOptions, nil
}

func validateInput(
func validateInputIsValidDirAndGitCheckout(
ctx context.Context,
runner command.Runner,
container appext.Container,
Expand All @@ -492,7 +492,10 @@ func validateInput(
return appcmd.NewInvalidArgumentErrorf("input %q is not a valid directory: %w", input, err)
}
if err := git.CheckDirectoryIsValidGitCheckout(ctx, runner, container, input); err != nil {
return appcmd.NewInvalidArgumentErrorf("input %q is not a local Git repository checkout: %w", input, err)
if errors.Is(err, git.ErrInvalidGitCheckout) {
return appcmd.NewInvalidArgumentErrorf("input %q is not a local Git repository checkout", input)
}
return err
}
return nil
}
Expand Down
3 changes: 2 additions & 1 deletion private/pkg/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"bytes"
"context"
"errors"
"fmt"
"os/exec"
"regexp"
"strings"
Expand Down Expand Up @@ -227,7 +228,7 @@ func CheckDirectoryIsValidGitCheckout(
var exitErr *exec.ExitError
if errors.As(err, &exitErr) {
if exitErr.ProcessState.ExitCode() == 128 {
return ErrInvalidGitCheckout
return fmt.Errorf("dir %s: %w", dir, ErrInvalidGitCheckout)
}
}
return err
Expand Down

0 comments on commit 9aff322

Please sign in to comment.