forked from git-lfs/git-lfs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrefs_test.go
More file actions
83 lines (70 loc) · 2.62 KB
/
refs_test.go
File metadata and controls
83 lines (70 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package git
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestRefUpdateDefault(t *testing.T) {
pushModes := []string{"simple", ""}
for _, pushMode := range pushModes {
env := newEnv(map[string][]string{
"push.default": []string{pushMode},
"branch.local.remote": []string{"ignore"},
"branch.local.merge": []string{"me"},
})
u := NewRefUpdate(env, "origin", ParseRef("refs/heads/local", ""), nil)
assert.Equal(t, "local", u.RemoteRef().Name, "pushmode=%q", pushMode)
assert.Equal(t, RefTypeLocalBranch, u.RemoteRef().Type, "pushmode=%q", pushMode)
}
}
func TestRefUpdateTrackedDefault(t *testing.T) {
pushModes := []string{"simple", "upstream", "tracking", ""}
for _, pushMode := range pushModes {
env := newEnv(map[string][]string{
"push.default": []string{pushMode},
"branch.local.remote": []string{"origin"},
"branch.local.merge": []string{"refs/heads/tracked"},
})
u := NewRefUpdate(env, "origin", ParseRef("refs/heads/local", ""), nil)
assert.Equal(t, "tracked", u.RemoteRef().Name, "pushmode=%s", pushMode)
assert.Equal(t, RefTypeLocalBranch, u.RemoteRef().Type, "pushmode=%q", pushMode)
}
}
func TestRefUpdateCurrentDefault(t *testing.T) {
env := newEnv(map[string][]string{
"push.default": []string{"current"},
"branch.local.remote": []string{"origin"},
"branch.local.merge": []string{"tracked"},
})
u := NewRefUpdate(env, "origin", ParseRef("refs/heads/local", ""), nil)
assert.Equal(t, "local", u.RemoteRef().Name)
assert.Equal(t, RefTypeLocalBranch, u.RemoteRef().Type)
}
func TestRefUpdateExplicitLocalAndRemoteRefs(t *testing.T) {
u := NewRefUpdate(nil, "", ParseRef("refs/heads/local", "abc123"), ParseRef("refs/heads/remote", "def456"))
assert.Equal(t, "local", u.LocalRef().Name)
assert.Equal(t, "abc123", u.LocalRef().Sha)
assert.Equal(t, "abc123", u.LocalRefCommitish())
assert.Equal(t, "remote", u.RemoteRef().Name)
assert.Equal(t, "def456", u.RemoteRef().Sha)
assert.Equal(t, "def456", u.RemoteRefCommitish())
u = NewRefUpdate(nil, "", ParseRef("refs/heads/local", ""), ParseRef("refs/heads/remote", ""))
assert.Equal(t, "local", u.LocalRef().Name)
assert.Equal(t, "", u.LocalRef().Sha)
assert.Equal(t, "local", u.LocalRefCommitish())
assert.Equal(t, "remote", u.RemoteRef().Name)
assert.Equal(t, "", u.RemoteRef().Sha)
assert.Equal(t, "remote", u.RemoteRefCommitish())
}
func newEnv(m map[string][]string) *mapEnv {
return &mapEnv{data: m}
}
type mapEnv struct {
data map[string][]string
}
func (m *mapEnv) Get(key string) (string, bool) {
vals, ok := m.data[key]
if ok && len(vals) > 0 {
return vals[0], true
}
return "", false
}