зеркало из https://github.com/mislav/hub.git
Fix git head on older git
Not all git has `--short` for `symbolic-ref`
This commit is contained in:
Родитель
4ef9c6a08f
Коммит
c3298db234
|
@ -0,0 +1,14 @@
|
||||||
|
package git
|
||||||
|
|
||||||
|
import (
|
||||||
|
"regexp"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Branch struct {
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Branch) ShortName() string {
|
||||||
|
reg := regexp.MustCompile("^refs/(remotes/)?.+?/")
|
||||||
|
return reg.ReplaceAllString(b.Name, "")
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package git
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/bmizerany/assert"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestShortName(t *testing.T) {
|
||||||
|
b := Branch{"refs/heads/master"}
|
||||||
|
assert.Equal(t, "master", b.ShortName())
|
||||||
|
}
|
|
@ -73,13 +73,13 @@ func EditorPath() (string, error) {
|
||||||
return editorPath, nil
|
return editorPath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Head() (string, error) {
|
func Head() (*Branch, error) {
|
||||||
output, err := execGitCmd("symbolic-ref", "-q", "--short", "HEAD")
|
output, err := execGitCmd("symbolic-ref", "-q", "HEAD")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "master", errors.New("Can't load git HEAD")
|
return nil, errors.New("Can't load git HEAD")
|
||||||
}
|
}
|
||||||
|
|
||||||
return output[0], nil
|
return &Branch{output[0]}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Ref(ref string) (string, error) {
|
func Ref(ref string) (string, error) {
|
||||||
|
|
|
@ -53,7 +53,9 @@ func (p *Project) LocalRepoWith(base, head string) *Repo {
|
||||||
base = "master"
|
base = "master"
|
||||||
}
|
}
|
||||||
if head == "" {
|
if head == "" {
|
||||||
head, _ = git.Head()
|
headBranch, err := git.Head()
|
||||||
|
utils.Check(err)
|
||||||
|
head = headBranch.ShortName()
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Repo{base, head, p}
|
return &Repo{base, head, p}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче