| 1 | package commands |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/git-lfs/git-lfs/v3/config" |
| 7 | "github.com/stretchr/testify/assert" |
| 8 | ) |
| 9 | |
| 10 | var ( |
| 11 | testcfg = config.NewFrom(config.Values{ |
| 12 | Git: map[string][]string{ |
| 13 | "lfs.fetchinclude": []string{"/default/include"}, |
| 14 | "lfs.fetchexclude": []string{"/default/exclude"}, |
| 15 | }, |
| 16 | }) |
| 17 | ) |
| 18 | |
| 19 | func TestDetermineIncludeExcludePathsReturnsCleanedPaths(t *testing.T) { |
| 20 | inc := "/some/include" |
| 21 | exc := "/some/exclude" |
| 22 | i, e := determineIncludeExcludePaths(testcfg, &inc, &exc, true) |
| 23 | |
| 24 | assert.Equal(t, []string{"/some/include"}, i) |
| 25 | assert.Equal(t, []string{"/some/exclude"}, e) |
| 26 | } |
| 27 | |
| 28 | func TestDetermineIncludeExcludePathsReturnsEmptyPaths(t *testing.T) { |
| 29 | inc := "" |
| 30 | exc := "" |
| 31 | i, e := determineIncludeExcludePaths(testcfg, &inc, &exc, true) |
| 32 | |
| 33 | assert.Empty(t, i) |
| 34 | assert.Empty(t, e) |
| 35 | } |
| 36 | |
| 37 | func TestDetermineIncludeExcludePathsReturnsDefaultsWhenAbsent(t *testing.T) { |
| 38 | i, e := determineIncludeExcludePaths(testcfg, nil, nil, true) |
| 39 | |
| 40 | assert.Equal(t, []string{"/default/include"}, i) |
| 41 | assert.Equal(t, []string{"/default/exclude"}, e) |
| 42 | } |
| 43 | |
| 44 | func TestDetermineIncludeExcludePathsReturnsNothingWhenAbsent(t *testing.T) { |
| 45 | i, e := determineIncludeExcludePaths(testcfg, nil, nil, false) |
| 46 | |
| 47 | assert.Empty(t, i) |
| 48 | assert.Empty(t, e) |
| 49 | } |
| 50 | |
| 51 | func TestSpecialGitRefsExclusion(t *testing.T) { |
| 52 | assert.True(t, isSpecialGitRef("refs/notes/commits")) |
| 53 | assert.True(t, isSpecialGitRef("refs/bisect/bad")) |
| 54 | assert.True(t, isSpecialGitRef("refs/replace/abcdef90")) |
| 55 | assert.True(t, isSpecialGitRef("refs/stash")) |
| 56 | assert.False(t, isSpecialGitRef("refs/commits/abcdef90")) |
| 57 | } |