MCPcopy
hub / github.com/go-git/go-git / testAlternates

Function testAlternates

storage/filesystem/dotgit/dotgit_test.go:863–944  ·  view source on GitHub ↗
(t *testing.T, dotFS, altFS billy.Filesystem)

Source from the content-addressed store, hash-verified

861}
862
863func testAlternates(t *testing.T, dotFS, altFS billy.Filesystem) {
864 tests := []struct {
865 name string
866 in []string
867 inWindows []string
868 setup func()
869 wantErr bool
870 wantRoots []string
871 }{
872 {
873 name: "no alternates",
874 },
875 {
876 name: "abs path",
877 in: []string{filepath.Join(altFS.Root(), "./repo1/.git/objects")},
878 inWindows: []string{filepath.Join(altFS.Root(), ".\\repo1\\.git\\objects")},
879 setup: func() {
880 err := altFS.MkdirAll(filepath.Join("repo1", ".git", "objects"), 0o700)
881 assert.NoError(t, err)
882 },
883 wantRoots: []string{filepath.Join("repo1", ".git")},
884 },
885 {
886 name: "rel path",
887 in: []string{"../../../repo3//.git/objects"},
888 inWindows: []string{"..\\..\\..\\repo3\\.git\\objects"},
889 setup: func() {
890 err := altFS.MkdirAll(filepath.Join("repo3", ".git", "objects"), 0o700)
891 assert.NoError(t, err)
892 },
893 wantRoots: []string{filepath.Join("repo3", ".git")},
894 },
895 {
896 name: "invalid abs path",
897 in: []string{"/alt/target2"},
898 inWindows: []string{"\\alt\\target2"},
899 wantErr: true,
900 },
901 {
902 name: "invalid rel path",
903 in: []string{"../../../alt/target3"},
904 inWindows: []string{"..\\..\\..\\alt\\target3"},
905 wantErr: true,
906 },
907 }
908
909 for _, tc := range tests {
910 t.Run(tc.name, func(t *testing.T) {
911 dir := NewWithOptions(dotFS, Options{AlternatesFS: altFS})
912 err := dir.Initialize()
913 assert.NoError(t, err)
914
915 content := strings.Join(tc.in, "\n")
916 if runtime.GOOS == "windows" {
917 content = strings.Join(tc.inWindows, "\r\n")
918 }
919
920 // Create alternates file.

Callers 3

TestAlternatesDefaultFunction · 0.85
TestAlternatesWithFSFunction · 0.85

Calls 10

NewWithOptionsFunction · 0.85
JoinMethod · 0.80
RootMethod · 0.80
InitializeMethod · 0.80
AlternatesMethod · 0.80
CloseMethod · 0.65
MkdirAllMethod · 0.45
CreateMethod · 0.45
WriteMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…