Skip to content

Commit

Permalink
Merge pull request #32 from Masterminds/fix/29
Browse files Browse the repository at this point in the history
Fixed #29: Git detached head detection only worked in english
  • Loading branch information
mattfarina committed Apr 27, 2016
2 parents 700a4d2 + 16e91dc commit c92afd1
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions git.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package vcs

import (
"bytes"
"encoding/xml"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -314,16 +316,18 @@ func (s *GitRepo) Ping() bool {

// isDetachedHead will detect if git repo is in "detached head" state.
func isDetachedHead(dir string) (bool, error) {
c := exec.Command("git", "status", "-uno")
c.Dir = dir
c.Env = envForDir(c.Dir)
out, err := c.CombinedOutput()
p := filepath.Join(dir, ".git", "HEAD")
contents, err := ioutil.ReadFile(p)
if err != nil {
return false, err
}
detached := strings.Contains(string(out), "HEAD detached at")

return detached, nil
contents = bytes.TrimSpace(contents)
if bytes.HasPrefix(contents, []byte("ref: ")) {
return false, nil
}

return true, nil
}

// isUnableToCreateDir checks for an error in Init() to see if an error
Expand Down

0 comments on commit c92afd1

Please sign in to comment.