forked from go-git/go-git
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepository_windows_test.go
More file actions
69 lines (54 loc) · 1.41 KB
/
repository_windows_test.go
File metadata and controls
69 lines (54 loc) · 1.41 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
//go:build !plan9 && !unix && windows
package git
import (
"fmt"
"path/filepath"
"regexp"
"testing"
"github.com/go-git/go-billy/v6/util"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/go-git/go-git/v6/storage/memory"
)
// preReceiveHook returns the bytes of a pre-receive hook script
// that prints m before exiting successfully
func preReceiveHook(m string) []byte {
return fmt.Appendf(nil, "#!C:/Program\\ Files/Git/usr/bin/sh.exe\nprintf '%s'\n", m)
}
func TestCloneFileUrlWindows(t *testing.T) {
t.Parallel()
dir := t.TempDir()
r, err := PlainInit(dir, false)
require.NoError(t, err)
err = util.WriteFile(r.wt, "foo", nil, 0o755)
require.NoError(t, err)
w, err := r.Worktree()
require.NoError(t, err)
_, err = w.Add("foo")
require.NoError(t, err)
_, err = w.Commit("foo", &CommitOptions{
Author: defaultSignature(),
Committer: defaultSignature(),
})
require.NoError(t, err)
tests := []struct {
url string
pattern string
}{
{
url: "file://" + filepath.ToSlash(dir),
pattern: `^file://[A-Z]:/(?:[^/]+/)*\d+$`,
},
{
url: "file:///" + filepath.ToSlash(dir),
pattern: `^file:///[A-Z]:/(?:[^/]+/)*\d+$`,
},
}
for _, tc := range tests {
assert.Regexp(t, regexp.MustCompile(tc.pattern), tc.url)
_, err = Clone(memory.NewStorage(), nil, &CloneOptions{
URL: tc.url,
})
assert.NoError(t, err, "url: %q", tc.url)
}
}