|
1 | 1 | package git_test |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "runtime" |
4 | 5 | "testing" |
5 | 6 |
|
6 | 7 | "github.com/stretchr/testify/assert" |
@@ -101,3 +102,70 @@ func TestListFilesPaths_unmerged(t *testing.T) { |
101 | 102 | assert.Equal(t, []string{"conflict.txt"}, paths) |
102 | 103 | }) |
103 | 104 | } |
| 105 | + |
| 106 | +func TestListFilesPaths_specialCharacters(t *testing.T) { |
| 107 | + t.Parallel() |
| 108 | + |
| 109 | + // Windows doesn't like files with some of these names. |
| 110 | + // Skip this test on Windows. |
| 111 | + if runtime.GOOS == "windows" { |
| 112 | + t.Skip("skipping test on Windows") |
| 113 | + } |
| 114 | + |
| 115 | + fixture, err := gittest.LoadFixtureScript([]byte(text.Dedent(` |
| 116 | + |
| 117 | + at '2025-06-21T09:27:19Z' |
| 118 | +
|
| 119 | + git init |
| 120 | + mv just-blank.txt ' ' |
| 121 | + git add ' ' |
| 122 | + git add *.txt |
| 123 | + git commit -m 'Add files with special characters' |
| 124 | +
|
| 125 | + -- just-blank.txt -- |
| 126 | + file with a name that's just " ". |
| 127 | +
|
| 128 | + -- file with spaces.txt -- |
| 129 | + Contents with spaces |
| 130 | +
|
| 131 | + -- file"quotes".txt -- |
| 132 | + Contents with double quotes |
| 133 | +
|
| 134 | + -- file'single'.txt -- |
| 135 | + Contents with single quotes |
| 136 | +
|
| 137 | + -- file (parens).txt -- |
| 138 | + Contents with parentheses |
| 139 | +
|
| 140 | + -- file[brackets].txt -- |
| 141 | + Contents with brackets |
| 142 | +
|
| 143 | + -- file&ersand.txt -- |
| 144 | + Contents with ampersand |
| 145 | +
|
| 146 | + -- файл.txt -- |
| 147 | + Unicode content |
| 148 | + `))) |
| 149 | + require.NoError(t, err) |
| 150 | + t.Cleanup(fixture.Cleanup) |
| 151 | + |
| 152 | + wt, err := git.OpenWorktree(t.Context(), fixture.Dir(), git.OpenOptions{ |
| 153 | + Log: silogtest.New(t), |
| 154 | + }) |
| 155 | + require.NoError(t, err) |
| 156 | + |
| 157 | + paths, err := sliceutil.CollectErr(wt.ListFilesPaths(t.Context(), nil)) |
| 158 | + require.NoError(t, err) |
| 159 | + |
| 160 | + expected := []string{ |
| 161 | + "file with spaces.txt", |
| 162 | + `file"quotes".txt`, |
| 163 | + "file'single'.txt", |
| 164 | + "file (parens).txt", |
| 165 | + "file[brackets].txt", |
| 166 | + "file&ersand.txt", |
| 167 | + "файл.txt", |
| 168 | + " ", |
| 169 | + } |
| 170 | + assert.ElementsMatch(t, expected, paths) |
| 171 | +} |
0 commit comments