forked from go-git/go-git
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmodule_windows_test.go
More file actions
66 lines (55 loc) · 1.77 KB
/
Copy pathsubmodule_windows_test.go
File metadata and controls
66 lines (55 loc) · 1.77 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
//go:build windows
package git
import (
"testing"
"github.com/go-git/go-billy/v6/memfs"
"github.com/stretchr/testify/require"
"github.com/go-git/go-git/v6/config"
"github.com/go-git/go-git/v6/storage/memory"
)
// TestSubmoduleWindowsAbsoluteURLNotJoined verifies that absolute
// Windows paths in a submodule URL are recognised as absolute and
// therefore skip the relative-URL resolution branch. `path.IsAbs`
// alone returns false for `C:\…` and `\\server\share\…`; the
// production code pairs it with `filepath.IsAbs` so those cases
// don't get wrongly joined onto the superproject's remote URL.
func TestSubmoduleWindowsAbsoluteURLNotJoined(t *testing.T) {
t.Parallel()
for _, url := range []string{
`C:\path\to\submodule`,
`\\server\share\submodule`,
} {
t.Run(url, func(t *testing.T) {
t.Parallel()
parent := &Repository{
Storer: memory.NewStorage(),
wt: memfs.New(),
}
cfg, err := parent.Config()
require.NoError(t, err)
cfg.Remotes["origin"] = &config.RemoteConfig{
Name: "origin",
URLs: []string{"file:///parent/origin"},
}
require.NoError(t, parent.Storer.SetConfig(cfg))
sub := &Submodule{
initialized: true,
w: &Worktree{filesystem: newWorktreeFilesystem(memfs.New(), defaultProtectNTFS(), defaultProtectHFS()), r: parent},
c: &config.Submodule{
Name: "child",
Path: "child",
URL: url,
},
}
subRepo, err := sub.Repository()
require.NoError(t, err)
defer func() { _ = subRepo.Close() }()
remotes, err := subRepo.Remotes()
require.NoError(t, err)
require.Len(t, remotes, 1)
got := remotes[0].Config().URLs[0]
require.NotContains(t, got, "/parent/origin",
"absolute Windows submodule URL was wrongly joined onto the parent's remote: %q", got)
})
}
}