Skip to content

Commit

Permalink
Decouple git error handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed May 4, 2016
1 parent 66acb6d commit a98b1c1
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions git.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ func (s *GitRepo) Get() error {
// There are some windows cases where Git cannot create the parent directory,
// if it does not already exist, to the location it's trying to create the
// repo. Catch that error and try to handle it.
return s.HandleError(out, err)
return s.GetError(out, err)
}

func (s *GitRepo) HandleError(out []byte, err error) error {
func (s *GitRepo) GetError(out []byte, err error) error {
if err != nil && s.isUnableToCreateDir(err) {

basePath := filepath.Dir(filepath.FromSlash(s.LocalPath()))
Expand Down Expand Up @@ -107,11 +107,7 @@ func (s *GitRepo) InitCmd() (string, []string) {
return "git", []string{"init", s.LocalPath()}
}

// Init initializes a git repository at local location.
func (s *GitRepo) Init() error {
name, args := s.InitCmd()
out, err := s.run(name, args...)

func (s *GitRepo) InitError(out []byte, err error) error {
// There are some windows cases where Git cannot create the parent directory,
// if it does not already exist, to the location it's trying to create the
// repo. Catch that error and try to handle it.
Expand All @@ -135,7 +131,15 @@ func (s *GitRepo) Init() error {
return NewLocalError("Unable to initialize repository", err, string(out))
}

return nil
return err
}

// Init initializes a git repository at local location.
func (s *GitRepo) Init() error {
name, args := s.InitCmd()
out, err := s.run(name, args...)

return s.InitError(out, err)
}

func (s *GitRepo) FetchCmd() (string, []string) {
Expand All @@ -151,6 +155,17 @@ func (s *GitRepo) Update() error {
// Perform a fetch to make sure everything is up to date.
cmd, args := s.FetchCmd()
out, err := s.RunFromDir(cmd, args...)
err = s.FetchError(out, err)
if strings.Contains(err.Error(), "In detached head state, do not pull") {
return nil
}
cmd, args = s.UpdateCmd()
out, err = s.RunFromDir(cmd, args...)

return s.UpdateError(out, err)
}

func (s *GitRepo) FetchError(out []byte, err error) error {
if err != nil {
return NewRemoteError("Unable to update repository", err, string(out))
}
Expand All @@ -163,11 +178,13 @@ func (s *GitRepo) Update() error {
}

if detached == true {
return nil
return NewLocalError("In detached head state, do not pull", err, "")
}

cmd, args = s.UpdateCmd()
out, err = s.RunFromDir(cmd, args...)
return err
}

func (s *GitRepo) UpdateError(out []byte, err error) error {
if err != nil {
return NewRemoteError("Unable to update repository", err, string(out))
}
Expand Down

0 comments on commit a98b1c1

Please sign in to comment.