Skip to content

Commit

Permalink
Fixed #29: Git detached head detection only worked in english
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfarina committed Apr 26, 2016
1 parent fa85cce commit 16e91dc
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 @@ -313,16 +315,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 16e91dc

Please sign in to comment.