1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2015-2017 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "RepositoryFixtures.h"
24 #include "PathUtils.h"
26 extern CGitAdminDirMap g_AdminDirMap
; // not optimal yet
28 class GitIndexCBasicGitFixture
: public CBasicGitFixture
33 CBasicGitFixture::SetUp();
34 g_AdminDirMap
.clear();
38 class GitIndexCBasicGitWithEmptyRepositoryFixture
: public CBasicGitWithEmptyRepositoryFixture
43 CBasicGitWithEmptyRepositoryFixture::SetUp();
44 g_AdminDirMap
.clear();
48 class GitIndexCBasicGitWithTestRepoFixture
: public CBasicGitWithTestRepoFixture
53 CBasicGitWithTestRepoFixture::SetUp();
54 g_AdminDirMap
.clear();
58 class CBasicGitWithMultiLinkedTestWithSubmoduleRepoFixture
: public CBasicGitWithTestRepoCreatorFixture
63 CBasicGitWithTestRepoCreatorFixture::SetUp();
65 // ====Main Work Tree Setup====
66 SetUpTestRepo(m_MainWorkTreePath
);
68 m_Git
.m_CurrentDir
= m_MainWorkTreePath
;
69 EXPECT_NE(0, SetCurrentDirectory(m_MainWorkTreePath
));
72 EXPECT_EQ(0, m_Git
.Run(L
"git.exe checkout -f master", &output
, nullptr, CP_UTF8
));
73 EXPECT_STRNE(L
"", output
);
75 if (!CGit::ms_bCygwinGit
)
77 // ====Source of the Sub-Module====
78 // Setup the repository in which the submodule will be fetched from
79 SetUpTestRepo(m_SubmoduleSource
);
81 //====Sub-Module Inside of The Main Work Tree (Root Level)====
83 EXPECT_EQ(0, m_Git
.Run(L
"git.exe submodule add \"" + m_SubmoduleSource
+ "\" sub1", &output
, nullptr, CP_UTF8
));
84 EXPECT_STREQ(L
"", output
);
87 EXPECT_EQ(0, m_Git
.Run(L
"git.exe commit -a -m\"Add submodule for testing\"", &output
, nullptr, CP_UTF8
));
88 EXPECT_STRNE(L
"", output
);
91 // ====Linked Work Tree setup (Absolute Path)====
92 // Linked worktree using git worktree with an absolute path
94 EXPECT_EQ(0, m_Git
.Run(L
"git.exe worktree add -b TestBranch \"" + m_LinkedWorkTreePath
+ "\"", &output
, nullptr, CP_UTF8
));
95 EXPECT_STRNE(L
"", output
);
98 CString m_MainWorkTreePath
= m_Dir
.GetTempDir() + L
"\\MainWorkTree";
99 CString m_LinkedWorkTreePath
= m_Dir
.GetTempDir() + L
"\\LinkedWorkTree";
100 CString m_SubmoduleSource
= m_Dir
.GetTempDir() + L
"\\SubmoduleSource";
103 INSTANTIATE_TEST_CASE_P(GitIndex
, GitIndexCBasicGitFixture
, testing::Values(LIBGIT2
));
104 INSTANTIATE_TEST_CASE_P(GitIndex
, GitIndexCBasicGitWithEmptyRepositoryFixture
, testing::Values(LIBGIT2
));
105 INSTANTIATE_TEST_CASE_P(GitIndex
, GitIndexCBasicGitWithTestRepoFixture
, testing::Values(LIBGIT2
));
106 INSTANTIATE_TEST_CASE_P(GitIndex
, CBasicGitWithMultiLinkedTestWithSubmoduleRepoFixture
, testing::Values(LIBGIT2
));
108 TEST_P(GitIndexCBasicGitFixture
, EmptyDir
)
110 CGitIndexList indexList
;
111 EXPECT_EQ(-1, indexList
.ReadIndex(m_Dir
.GetTempDir()));
112 EXPECT_EQ(0, indexList
.size());
113 EXPECT_FALSE(indexList
.m_bHasConflicts
);
117 static void ReadAndCheckIndex(CGitIndexList
& indexList
, const CString
& gitdir
, int offset
= 0)
119 EXPECT_EQ(0, indexList
.ReadIndex(gitdir
));
120 ASSERT_EQ(14 + offset
, indexList
.size());
122 EXPECT_STREQ(L
"ansi.txt", indexList
[offset
].m_FileName
);
123 EXPECT_EQ(102, indexList
[offset
].m_Size
);
124 EXPECT_EQ(8, indexList
[offset
].m_Flags
);
125 EXPECT_EQ(0, indexList
[offset
].m_FlagsExtended
);
126 EXPECT_STREQ(L
"961bdffbfce1bc617fb594091c3229f1cc674d76", indexList
[offset
].m_IndexHash
.ToString());
127 EXPECT_STREQ(L
"copy/ansi.txt", indexList
[1 + offset
].m_FileName
);
128 EXPECT_EQ(103, indexList
[1 + offset
].m_Size
);
129 EXPECT_EQ(13, indexList
[1 + offset
].m_Flags
);
130 EXPECT_EQ(0, indexList
[1 + offset
].m_FlagsExtended
);
131 EXPECT_STREQ(L
"4c44667203f943dc5dbdf3cb526cb7ec24f60c09", indexList
[1 + offset
].m_IndexHash
.ToString());
132 EXPECT_STREQ(L
"copy/utf16-le-nobom.txt", indexList
[5 + offset
].m_FileName
);
133 EXPECT_EQ(218, indexList
[5 + offset
].m_Size
);
134 EXPECT_EQ(23, indexList
[5 + offset
].m_Flags
);
135 EXPECT_EQ(0, indexList
[5 + offset
].m_FlagsExtended
);
136 EXPECT_STREQ(L
"fbea9ccd85c33fcdb542d8c73f910ea0e70c3ddc", indexList
[5 + offset
].m_IndexHash
.ToString());
137 EXPECT_STREQ(L
"utf8-nobom.txt", indexList
[13 + offset
].m_FileName
);
138 EXPECT_EQ(139, indexList
[13 + offset
].m_Size
);
139 EXPECT_EQ(14, indexList
[13 + offset
].m_Flags
);
140 EXPECT_EQ(0, indexList
[13 + offset
].m_FlagsExtended
);
141 EXPECT_STREQ(L
"c225b3f14869ec8b6da32d52bd15dba0b043031d", indexList
[13 + offset
].m_IndexHash
.ToString());
142 EXPECT_FALSE(indexList
.m_bHasConflicts
);
145 TEST_P(GitIndexCBasicGitWithTestRepoFixture
, ReadIndex
)
147 CGitIndexList indexList
;
148 ReadAndCheckIndex(indexList
, m_Dir
.GetTempDir());
150 CString testFile
= m_Dir
.GetTempDir() + L
"\\1.txt";
151 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(testFile
, L
"this is testing file."));
153 EXPECT_EQ(0, m_Git
.Run(L
"git.exe add 1.txt", &output
, CP_UTF8
));
154 EXPECT_STREQ(L
"", output
);
156 ReadAndCheckIndex(indexList
, m_Dir
.GetTempDir(), 1);
158 EXPECT_STREQ(L
"1.txt", indexList
[0].m_FileName
);
159 EXPECT_EQ(21, indexList
[0].m_Size
);
160 EXPECT_EQ(5, indexList
[0].m_Flags
);
161 EXPECT_EQ(0, indexList
[0].m_FlagsExtended
);
162 EXPECT_STREQ(L
"e4aac1275dfc440ec521a76e9458476fe07038bb", indexList
[0].m_IndexHash
.ToString());
164 EXPECT_EQ(0, m_Git
.Run(L
"git.exe rm -f 1.txt", &output
, CP_UTF8
));
166 ReadAndCheckIndex(indexList
, m_Dir
.GetTempDir());
169 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(testFile
, L
"this is testing file."));
170 EXPECT_EQ(0, m_Git
.Run(L
"git.exe add -N 1.txt", &output
, CP_UTF8
));
171 EXPECT_STREQ(L
"", output
);
173 ReadAndCheckIndex(indexList
, m_Dir
.GetTempDir(), 1);
175 EXPECT_STREQ(L
"1.txt", indexList
[0].m_FileName
);
176 EXPECT_EQ(0, indexList
[0].m_Size
);
177 EXPECT_EQ(16389, indexList
[0].m_Flags
);
178 EXPECT_EQ(GIT_IDXENTRY_INTENT_TO_ADD
, indexList
[0].m_FlagsExtended
);
179 EXPECT_STREQ(L
"e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", indexList
[0].m_IndexHash
.ToString());
182 TEST_P(GitIndexCBasicGitWithTestRepoFixture
, GetFileStatus
)
184 CGitIndexList indexList
;
185 ReadAndCheckIndex(indexList
, m_Dir
.GetTempDir());
187 git_wc_status2_t status
= { git_wc_status_none
, false, false };
188 EXPECT_EQ(0, indexList
.GetFileStatus(m_Dir
.GetTempDir(), L
"does-not-exist.txt", status
, 10, 20));
189 EXPECT_EQ(git_wc_status_unversioned
, status
.status
);
192 __int64 filesize
= -1;
193 status
= { git_wc_status_none
, false, false };
194 EXPECT_EQ(-1, CGit::GetFileModifyTime(CombinePath(m_Dir
.GetTempDir(), L
"ansi.txt"), &time
, nullptr, &filesize
));
195 EXPECT_EQ(0, indexList
.GetFileStatus(m_Dir
.GetTempDir(), L
"ansi.txt", status
, time
, filesize
));
196 EXPECT_EQ(git_wc_status_deleted
, status
.status
);
197 filesize
= 42; // some arbitrary size, i.e., file exists but is changed
198 EXPECT_EQ(0, indexList
.GetFileStatus(m_Dir
.GetTempDir(), L
"ansi.txt", status
, time
, filesize
));
199 EXPECT_EQ(git_wc_status_modified
, status
.status
);
202 EXPECT_EQ(0, m_Git
.Run(L
"git.exe reset --hard", &output
, CP_UTF8
));
204 EXPECT_EQ(0, CGit::GetFileModifyTime(CombinePath(m_Dir
.GetTempDir(), L
"ansi.txt"), &time
, nullptr, &filesize
));
205 status
= { git_wc_status_none
, false, false };
206 EXPECT_EQ(0, indexList
.GetFileStatus(m_Dir
.GetTempDir(), L
"ansi.txt", status
, time
, filesize
));
207 EXPECT_EQ(git_wc_status_normal
, status
.status
);
208 EXPECT_FALSE(status
.assumeValid
);
209 EXPECT_FALSE(status
.skipWorktree
);
211 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(CombinePath(m_Dir
.GetTempDir(), L
"ansi.txt"), L
"this is testing file."));
212 EXPECT_EQ(0, CGit::GetFileModifyTime(CombinePath(m_Dir
.GetTempDir(), L
"ansi.txt"), &time
, nullptr, &filesize
));
213 status
= { git_wc_status_none
, false, false };
214 EXPECT_EQ(0, indexList
.GetFileStatus(m_Dir
.GetTempDir(), L
"ansi.txt", status
, time
, filesize
));
215 EXPECT_EQ(git_wc_status_modified
, status
.status
);
216 EXPECT_FALSE(status
.assumeValid
);
217 EXPECT_FALSE(status
.skipWorktree
);
219 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(CombinePath(m_Dir
.GetTempDir(), L
"just-added.txt"), L
"this is testing file."));
220 EXPECT_EQ(0, m_Git
.Run(L
"git.exe add -- just-added.txt", &output
, CP_UTF8
));
222 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(CombinePath(m_Dir
.GetTempDir(), L
"noted-as-added.txt"), L
"this is testing file."));
223 EXPECT_EQ(0, m_Git
.Run(L
"git.exe add -N -- noted-as-added.txt", &output
, CP_UTF8
));
225 EXPECT_EQ(0, m_Git
.Run(L
"git.exe update-index --skip-worktree -- ansi.txt", &output
, CP_UTF8
));
226 EXPECT_EQ(0, indexList
.ReadIndex(m_Dir
.GetTempDir()));
227 EXPECT_FALSE(indexList
.m_bHasConflicts
);
228 status
= { git_wc_status_none
, false, false };
229 EXPECT_EQ(0, indexList
.GetFileStatus(m_Dir
.GetTempDir(), L
"ansi.txt", status
, time
, filesize
));
230 EXPECT_EQ(git_wc_status_normal
, status
.status
);
231 EXPECT_FALSE(status
.assumeValid
);
232 EXPECT_TRUE(status
.skipWorktree
);
234 EXPECT_EQ(0, CGit::GetFileModifyTime(CombinePath(m_Dir
.GetTempDir(), L
"just-added.txt"), &time
, nullptr, &filesize
));
235 status
= { git_wc_status_none
, false, false };
236 EXPECT_EQ(0, indexList
.GetFileStatus(m_Dir
.GetTempDir(), L
"just-added.txt", status
, time
, filesize
));
237 EXPECT_EQ(git_wc_status_normal
, status
.status
);
239 EXPECT_EQ(0, CGit::GetFileModifyTime(CombinePath(m_Dir
.GetTempDir(), L
"noted-as-added.txt"), &time
, nullptr, &filesize
));
240 status
= { git_wc_status_none
, false, false };
241 EXPECT_EQ(0, indexList
.GetFileStatus(m_Dir
.GetTempDir(), L
"noted-as-added.txt", status
, time
, filesize
));
242 EXPECT_EQ(git_wc_status_added
, status
.status
);
243 EXPECT_FALSE(status
.assumeValid
);
244 EXPECT_FALSE(status
.skipWorktree
);
246 EXPECT_EQ(0, m_Git
.Run(L
"git.exe update-index --no-skip-worktree ansi.txt", &output
, CP_UTF8
));
249 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(CombinePath(m_Dir
.GetTempDir(), L
"just-added.txt"), L
"this IS testing file."));
250 EXPECT_EQ(0, CGit::GetFileModifyTime(CombinePath(m_Dir
.GetTempDir(), L
"just-added.txt"), &time
, nullptr, &filesize
));
251 status
= { git_wc_status_none
, false, false };
252 EXPECT_EQ(0, indexList
.GetFileStatus(m_Dir
.GetTempDir(), L
"just-added.txt", status
, time
, filesize
));
253 EXPECT_EQ(git_wc_status_modified
, status
.status
);
256 EXPECT_EQ(0, m_Git
.Run(L
"git.exe checkout --force forconflict", &output
, CP_UTF8
));
257 EXPECT_STRNE(L
"", output
);
260 EXPECT_EQ(1, m_Git
.Run(L
"git.exe merge simple-conflict", &output
, CP_UTF8
));
261 EXPECT_STRNE(L
"", output
);
263 EXPECT_EQ(0, indexList
.ReadIndex(m_Dir
.GetTempDir()));
264 EXPECT_EQ(9, indexList
.size());
265 EXPECT_TRUE(indexList
.m_bHasConflicts
);
267 EXPECT_EQ(0, CGit::GetFileModifyTime(CombinePath(m_Dir
.GetTempDir(), L
"ansi.txt"), &time
, nullptr, &filesize
));
268 status
= { git_wc_status_none
, false, false };
269 EXPECT_EQ(0, indexList
.GetFileStatus(m_Dir
.GetTempDir(), L
"ansi.txt", status
, time
, filesize
));
270 EXPECT_EQ(git_wc_status_conflicted
, status
.status
);
273 TEST(GitIndex
, SearchInSortVector
)
275 std::vector
<CGitFileName
> vector
;
276 EXPECT_EQ(NPOS
, SearchInSortVector(vector
, L
"something", 9));
277 EXPECT_EQ(NPOS
, SearchInSortVector(vector
, L
"something", 0));
278 EXPECT_EQ(NPOS
, SearchInSortVector(vector
, L
"something", -1));
280 vector
.push_back(CGitFileName(L
"One", 0, 0));
281 EXPECT_EQ(NPOS
, SearchInSortVector(vector
, L
"something", 9));
282 EXPECT_EQ(NPOS
, SearchInSortVector(vector
, L
"something", -1));
283 EXPECT_EQ(0, SearchInSortVector(vector
, L
"something", 0)); // do we really need this behavior?
284 EXPECT_EQ(0, SearchInSortVector(vector
, L
"One", 3));
285 EXPECT_EQ(0, SearchInSortVector(vector
, L
"One", -1));
286 EXPECT_EQ(NPOS
, SearchInSortVector(vector
, L
"One/", 4));
287 EXPECT_EQ(NPOS
, SearchInSortVector(vector
, L
"one", 3));
288 EXPECT_EQ(NPOS
, SearchInSortVector(vector
, L
"one", -1));
289 EXPECT_EQ(NPOS
, SearchInSortVector(vector
, L
"one/", 4));
291 vector
.push_back(CGitFileName(L
"tWo", 0, 0));
292 EXPECT_EQ(NPOS
, SearchInSortVector(vector
, L
"something", 9));
293 EXPECT_EQ(0, SearchInSortVector(vector
, L
"One", 3));
294 EXPECT_EQ(NPOS
, SearchInSortVector(vector
, L
"one", 3));
295 EXPECT_EQ(1, SearchInSortVector(vector
, L
"tWo", 3));
296 EXPECT_EQ(NPOS
, SearchInSortVector(vector
, L
"two", 3));
297 EXPECT_EQ(1, SearchInSortVector(vector
, L
"t", 1));
298 EXPECT_EQ(NPOS
, SearchInSortVector(vector
, L
"0", 1));
299 EXPECT_EQ(NPOS
, SearchInSortVector(vector
, L
"z", 1));
301 vector
.push_back(CGitFileName(L
"a", 0, 0));
302 vector
.push_back(CGitFileName(L
"b/1", 0, 0));
303 vector
.push_back(CGitFileName(L
"b/2", 0, 0));
304 vector
.push_back(CGitFileName(L
"b/3", 0, 0));
305 vector
.push_back(CGitFileName(L
"b/4", 0, 0));
306 vector
.push_back(CGitFileName(L
"b/5", 0, 0));
307 std::sort(vector
.begin(), vector
.end(), SortCGitFileName
);
308 EXPECT_EQ(0, SearchInSortVector(vector
, L
"One", 3));
309 EXPECT_EQ(3, SearchInSortVector(vector
, L
"b/2", 3));
310 EXPECT_EQ(3, SearchInSortVector(vector
, L
"b/2", -1));
311 EXPECT_LT(2, SearchInSortVector(vector
, L
"b/", 2));
312 EXPECT_GE(6, SearchInSortVector(vector
, L
"b/", 2));
313 EXPECT_EQ(NPOS
, SearchInSortVector(vector
, L
"b/6", 3));
314 EXPECT_EQ(1, SearchInSortVector(vector
, L
"a", 1));
315 EXPECT_EQ(7, SearchInSortVector(vector
, L
"tWo", 3));
318 TEST(GitIndex
, GetRangeInSortVector
)
320 std::vector
<CGitFileName
> vector
;
324 EXPECT_EQ(-1, GetRangeInSortVector(vector
, L
"something", 9, &start
, &end
, NPOS
));
325 EXPECT_EQ(-1, GetRangeInSortVector(vector
, L
"something", 9, &start
, &end
, 0));
326 EXPECT_EQ(-1, GetRangeInSortVector(vector
, L
"something", 9, &start
, nullptr, 0));
327 EXPECT_EQ(-1, GetRangeInSortVector(vector
, L
"something", 9, nullptr, &end
, 0));
328 EXPECT_EQ(-1, GetRangeInSortVector(vector
, L
"something", 9, nullptr, &end
, 1));
329 EXPECT_EQ(-1, GetRangeInSortVector(vector
, L
"", 0, &start
, &end
, 0));
330 EXPECT_EQ(NPOS
, start
);
331 EXPECT_EQ(NPOS
, end
);
333 vector
.push_back(CGitFileName(L
"a", 0, 0));
335 EXPECT_EQ(-1, GetRangeInSortVector(vector
, L
"something", 9, &start
, &end
, NPOS
));
336 EXPECT_EQ(-1, GetRangeInSortVector(vector
, L
"something", 9, &start
, nullptr, 0));
337 EXPECT_EQ(-1, GetRangeInSortVector(vector
, L
"something", 9, nullptr, &end
, 0));
338 EXPECT_EQ(-1, GetRangeInSortVector(vector
, L
"something", 9, nullptr, &end
, 1));
340 EXPECT_EQ(-1, GetRangeInSortVector(vector
, L
"a", 1, &start
, &end
, NPOS
));
341 EXPECT_EQ(-1, GetRangeInSortVector(vector
, L
"a", 1, &start
, nullptr, 0));
342 EXPECT_EQ(-1, GetRangeInSortVector(vector
, L
"a", 1, nullptr, &end
, 0));
343 EXPECT_EQ(-1, GetRangeInSortVector(vector
, L
"a", 1, nullptr, &end
, 1));
345 EXPECT_EQ(0, GetRangeInSortVector(vector
, L
"", 0, &start
, &end
, 0));
349 EXPECT_EQ(-1, GetRangeInSortVector(vector
, L
"", 0, &start
, &end
, 1));
352 EXPECT_EQ(-1, GetRangeInSortVector(vector
, L
"0", 1, &start
, &end
, 0));
353 EXPECT_EQ(NPOS
, start
);
354 EXPECT_EQ(NPOS
, end
);
356 EXPECT_EQ(-1, GetRangeInSortVector(vector
, L
"b", 1, &start
, &end
, 0));
357 EXPECT_EQ(NPOS
, start
);
358 EXPECT_EQ(NPOS
, end
);
361 EXPECT_EQ(0, GetRangeInSortVector(vector
, L
"a", 1, &start
, &end
, 0));
365 vector
.push_back(CGitFileName(L
"b/1", 0, 0));
366 vector
.push_back(CGitFileName(L
"b/2", 0, 0));
367 vector
.push_back(CGitFileName(L
"b/3", 0, 0));
368 vector
.push_back(CGitFileName(L
"b/4", 0, 0));
369 vector
.push_back(CGitFileName(L
"b/5", 0, 0));
372 EXPECT_EQ(0, GetRangeInSortVector(vector
, L
"a", 1, &start
, &end
, 0));
377 EXPECT_EQ(0, GetRangeInSortVector(vector
, L
"b/", 2, &start
, &end
, 1));
382 EXPECT_EQ(0, GetRangeInSortVector(vector
, L
"b/", 2, &start
, &end
, 2));
387 EXPECT_EQ(0, GetRangeInSortVector(vector
, L
"b/", 2, &start
, &end
, 4));
392 EXPECT_EQ(0, GetRangeInSortVector(vector
, L
"b/", 2, &start
, &end
, 5));
396 EXPECT_EQ(-1, GetRangeInSortVector(vector
, L
"b/", 2, &start
, &end
, 6)); // 6 is >= vector.size()
399 EXPECT_EQ(-1, GetRangeInSortVector(vector
, L
"c/", 2, &start
, &end
, 0));
400 EXPECT_EQ(NPOS
, start
);
401 EXPECT_EQ(NPOS
, end
);
404 EXPECT_EQ(-1, GetRangeInSortVector(vector
, L
"c/", 2, &start
, &end
, 5));
405 EXPECT_EQ(NPOS
, start
);
406 EXPECT_EQ(NPOS
, end
);
408 vector
.push_back(CGitFileName(L
"c", 0, 0));
409 vector
.push_back(CGitFileName(L
"d", 0, 0));
412 EXPECT_EQ(0, GetRangeInSortVector(vector
, L
"b/", 2, &start
, &end
, 1));
417 EXPECT_EQ(0, GetRangeInSortVector(vector
, L
"b/", 2, &start
, &end
, 2));
422 EXPECT_EQ(0, GetRangeInSortVector(vector
, L
"b/", 2, &start
, &end
, 4));
427 EXPECT_EQ(0, GetRangeInSortVector(vector
, L
"b/", 2, &start
, &end
, 5));
432 EXPECT_EQ(-1, GetRangeInSortVector(vector
, L
"c/", 2, &start
, &end
, 6));
433 EXPECT_EQ(NPOS
, start
);
434 EXPECT_EQ(NPOS
, end
);
437 EXPECT_EQ(0, GetRangeInSortVector(vector
, L
"c", 1, &start
, &end
, 6));
442 EXPECT_EQ(0, GetRangeInSortVector(vector
, L
"", 0, &start
, &end
, 0));
447 TEST(GitIndex
, CGitIgnoreItem
)
449 CAutoTempDir tempDir
;
450 CGitIgnoreItem ignoreItem
;
454 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("not-ignored", type
));
455 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/not-ignored", type
));
457 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("not-ignored", type
));
458 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/not-ignored", type
));
460 EXPECT_EQ(-1, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), L
"does-not-exist", false, &ignoreCase
));
461 EXPECT_EQ(-1, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), L
"does-not-exist", true, &ignoreCase
));
463 CString ignoreFile
= tempDir
.GetTempDir() + L
"\\.gitignore";
465 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(ignoreFile
, L
""));
466 EXPECT_EQ(0, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), ignoreFile
, false, &ignoreCase
));
467 EXPECT_STREQ("", ignoreItem
.m_BaseDir
);
468 EXPECT_EQ(0, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), ignoreFile
, true, &ignoreCase
));
469 EXPECT_STREQ("", ignoreItem
.m_BaseDir
);
471 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(ignoreFile
, L
"#"));
472 EXPECT_EQ(0, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), ignoreFile
, false, &ignoreCase
));
473 EXPECT_EQ(0, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), ignoreFile
, true, &ignoreCase
));
475 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(ignoreFile
, L
"# comment"));
476 EXPECT_EQ(0, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), ignoreFile
, false, &ignoreCase
));
477 EXPECT_EQ(0, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), ignoreFile
, true, &ignoreCase
));
479 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(ignoreFile
, L
"\n"));
480 EXPECT_EQ(0, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), ignoreFile
, false, &ignoreCase
));
481 EXPECT_EQ(0, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), ignoreFile
, true, &ignoreCase
));
483 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(ignoreFile
, L
"\n#"));
484 EXPECT_EQ(0, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), ignoreFile
, false, &ignoreCase
));
485 EXPECT_EQ(0, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), ignoreFile
, true, &ignoreCase
));
487 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(ignoreFile
, L
"*.tmp\n"));
488 EXPECT_EQ(0, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), ignoreFile
, false, &ignoreCase
));
490 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("not-ignored", type
));
491 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("text.tmp", type
));
492 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/text.tmp", type
));
493 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("1.tmp.1", type
));
494 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("text.tMp", type
));
496 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("not-ignored", type
));
497 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("text.tmp", type
));
498 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/text.tmp", type
));
499 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("1.tmp.1", type
));
500 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("text.tMp", type
));
503 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("not-ignored", type
));
504 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("text.tmp", type
));
505 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/text.tmp", type
));
506 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("1.tmp.1", type
));
507 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("text.tMp", type
));
509 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("not-ignored", type
));
510 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("text.tmp", type
));
511 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/text.tmp", type
));
512 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("1.tmp.1", type
));
513 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("text.tMp", type
));
515 EXPECT_EQ(0, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), ignoreFile
, true, &ignoreCase
));
517 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("not-ignored", type
));
518 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("text.tmp", type
));
519 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/text.tmp", type
));
520 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("1.tmp.1", type
));
521 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("text.tMp", type
));
523 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("not-ignored", type
));
524 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("text.tmp", type
));
525 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/text.tmp", type
));
526 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("1.tmp.1", type
));
527 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("text.tMp", type
));
529 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(ignoreFile
, L
"*.tMp\n"));
530 EXPECT_EQ(0, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), ignoreFile
, false, &ignoreCase
));
532 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("not-ignored", type
));
533 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("text.tMp", type
));
534 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/text.tMp", type
));
535 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("1.tMp.1", type
));
536 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("text.tmp", type
));
538 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("not-ignored", type
));
539 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("text.tMp", type
));
540 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/text.tMp", type
));
541 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("1.tmp.1", type
));
542 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("text.tmp", type
));
545 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("not-ignored", type
));
546 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("text.tMp", type
));
547 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/text.tMp", type
));
548 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("1.tMp.1", type
));
549 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("text.tmp", type
));
551 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("not-ignored", type
));
552 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("text.tMp", type
));
553 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/text.tMp", type
));
554 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("1.tMp.1", type
));
555 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("text.tmp", type
));
557 EXPECT_EQ(0, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), ignoreFile
, true, &ignoreCase
));
559 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("not-ignored", type
));
560 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("text.tMp", type
));
561 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/text.tMp", type
));
562 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("1.tMp.1", type
));
563 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("text.tmp", type
));
565 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("not-ignored", type
));
566 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("text.tMp", type
));
567 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/text.tMp", type
));
568 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("1.tMp.1", type
));
569 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("text.tmp", type
));
571 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(ignoreFile
, L
"some-file\n"));
572 EXPECT_EQ(0, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), ignoreFile
, false, &ignoreCase
));
574 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("not-ignored", type
));
575 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/not-ignored", type
));
576 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-file", type
));
577 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/some-file", type
));
578 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subDir/some-file", type
));
579 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/some-File", type
));
581 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("not-ignored", type
));
582 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/not-ignored", type
));
583 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-file", type
));
584 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/some-file", type
));
585 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subDir/some-file", type
));
586 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/some-File", type
));
589 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("not-ignored", type
));
590 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/not-ignored", type
));
591 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-file", type
));
592 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/some-file", type
));
593 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subDir/some-file", type
));
594 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/some-File", type
));
596 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("not-ignored", type
));
597 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/not-ignored", type
));
598 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-file", type
));
599 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/some-file", type
));
600 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subDir/some-file", type
));
601 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/some-File", type
));
603 EXPECT_EQ(0, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), ignoreFile
, true, &ignoreCase
));
605 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("not-ignored", type
));
606 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/not-ignored", type
));
607 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-file", type
));
608 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/some-file", type
));
609 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subDir/some-file", type
));
610 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/some-File", type
));
612 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("not-ignored", type
));
613 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/not-ignored", type
));
614 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-file", type
));
615 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/some-file", type
));
616 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subDir/some-file", type
));
617 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/some-File", type
));
620 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("not-ignored", type
));
621 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/not-ignored", type
));
622 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-file", type
));
623 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/some-file", type
));
624 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subDir/some-file", type
));
625 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/some-File", type
));
627 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("not-ignored", type
));
628 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/not-ignored", type
));
629 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-file", type
));
630 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/some-file", type
));
631 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subDir/some-file", type
));
632 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/some-File", type
));
634 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(ignoreFile
, L
"some-File\n"));
636 EXPECT_EQ(0, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), ignoreFile
, false, &ignoreCase
));
638 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("not-ignored", type
));
639 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/not-ignored", type
));
640 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-File", type
));
641 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/some-File", type
));
642 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subDir/some-File", type
));
643 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/some-file", type
));
645 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("not-ignored", type
));
646 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/not-ignored", type
));
647 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-file", type
));
648 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/some-File", type
));
649 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subDir/some-File", type
));
650 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/some-file", type
));
653 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("not-ignored", type
));
654 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/not-ignored", type
));
655 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-File", type
));
656 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/some-File", type
));
657 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subDir/some-File", type
));
658 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/some-file", type
));
660 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("not-ignored", type
));
661 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/not-ignored", type
));
662 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-File", type
));
663 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/some-File", type
));
664 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subDir/some-File", type
));
665 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/some-file", type
));
668 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(ignoreFile
, L
"\n\nsome-file\n"));
669 EXPECT_EQ(0, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), ignoreFile
, false, &ignoreCase
));
671 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-file", type
));
672 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/some-file", type
));
674 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-file", type
));
675 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/some-file", type
));
676 EXPECT_EQ(0, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), ignoreFile
, true, &ignoreCase
));
678 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-file", type
));
679 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/some-file", type
));
681 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-file", type
));
682 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/some-file", type
));
684 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(ignoreFile
, L
"/some-file"));
685 EXPECT_EQ(0, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), ignoreFile
, false, &ignoreCase
));
687 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-file", type
));
688 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/some-file", type
));
690 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-file", type
));
691 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/some-file", type
));
692 EXPECT_EQ(0, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), ignoreFile
, true, &ignoreCase
));
694 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-file", type
));
695 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/some-file", type
));
697 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-file", type
));
698 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/some-file", type
));
700 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(ignoreFile
, L
"some-dir/"));
701 EXPECT_EQ(0, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), ignoreFile
, false, &ignoreCase
));
703 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-dir", type
));
704 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("some-dir/some-file", type
));
706 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("some-file", type
));
707 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("some-dir", type
));
708 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("some-dir/some-file", type
));
709 EXPECT_EQ(0, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), ignoreFile
, true, &ignoreCase
));
711 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-dir", type
));
712 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("some-dir/some-file", type
));
714 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("some-file", type
));
715 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("some-dir", type
));
716 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("some-dir/some-file", type
));
718 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(ignoreFile
, L
"some-*\n!some-file"));
719 EXPECT_EQ(0, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), ignoreFile
, false, &ignoreCase
));
721 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-dir", type
));
722 EXPECT_EQ(0, ignoreItem
.IsPathIgnored("some-file", type
));
723 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("something", type
));
725 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-dir", type
));
726 EXPECT_EQ(0, ignoreItem
.IsPathIgnored("some-file", type
));
727 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("something", type
));
728 EXPECT_EQ(0, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), ignoreFile
, true, &ignoreCase
));
730 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-dir", type
));
731 EXPECT_EQ(0, ignoreItem
.IsPathIgnored("some-file", type
));
732 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("something", type
));
734 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-dir", type
));
735 EXPECT_EQ(0, ignoreItem
.IsPathIgnored("some-file", type
));
736 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("something", type
));
738 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(ignoreFile
, L
"some-file\nanother/dir/*"));
739 EXPECT_EQ(0, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), ignoreFile
, false, &ignoreCase
));
741 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("some-dir", type
));
742 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-file", type
));
743 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("another", type
));
744 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("another/dir", type
));
745 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("another/dir/some", type
));
747 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("some-dir", type
));
748 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-file", type
));
749 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("another", type
));
750 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("another/dir", type
));
751 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("another/dir/some", type
));
752 EXPECT_EQ(0, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), ignoreFile
, true, &ignoreCase
));
754 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("some-dir", type
));
755 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-file", type
));
756 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("another", type
));
757 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("another/dir", type
));
758 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("another/dir/some", type
));
760 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("some-dir", type
));
761 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-file", type
));
762 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("another", type
));
763 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("another/dir", type
));
764 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("another/dir/some", type
));
766 EXPECT_TRUE(::CreateDirectory(tempDir
.GetTempDir() + L
"\\subdir", nullptr));
767 ignoreFile
= tempDir
.GetTempDir() + L
"\\subdir\\.gitignore";
768 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(ignoreFile
, L
"/something"));
769 EXPECT_EQ(0, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), ignoreFile
, false, &ignoreCase
));
770 EXPECT_STREQ("subdir/", ignoreItem
.m_BaseDir
);
772 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("something", type
));
773 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("something/more", type
));
774 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("some-dir/something", type
));
775 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/something", type
));
776 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/something/more", type
));
777 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/some-dir/something", type
));
779 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("something", type
));
780 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("something/more", type
));
781 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("some-dir/something", type
));
782 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/something", type
));
783 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/something/more", type
));
784 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/some-dir/something", type
));
785 EXPECT_EQ(0, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), ignoreFile
, true, &ignoreCase
));
786 EXPECT_STREQ("", ignoreItem
.m_BaseDir
);
788 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("something", type
));
789 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("something/more", type
));
790 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("some-dir/something", type
));
791 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/something", type
));
792 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/something/more", type
));
793 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/some-dir/something", type
));
795 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("something", type
));
796 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("something/more", type
));
797 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("some-dir/something", type
));
798 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/something", type
));
799 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/something/more", type
));
800 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/some-dir/something", type
));
802 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(ignoreFile
, L
"something"));
803 EXPECT_EQ(0, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), ignoreFile
, false, &ignoreCase
));
804 EXPECT_STREQ("subdir/", ignoreItem
.m_BaseDir
);
806 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("something", type
));
807 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("something/more", type
));
808 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-dir/something", type
));
809 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/something", type
));
810 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/something/more", type
));
811 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/some-dir/something", type
));
813 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("something", type
));
814 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("something/more", type
));
815 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-dir/something", type
));
816 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/something", type
));
817 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/something/more", type
));
818 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/some-dir/something", type
));
819 EXPECT_EQ(0, ignoreItem
.FetchIgnoreList(tempDir
.GetTempDir(), ignoreFile
, true, &ignoreCase
));
820 EXPECT_STREQ("", ignoreItem
.m_BaseDir
);
822 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("something", type
));
823 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("something/more", type
));
824 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-dir/something", type
));
825 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/something", type
));
826 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/something/more", type
));
827 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/some-dir/something", type
));
829 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("something", type
));
830 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("something/more", type
));
831 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("some-dir/something", type
));
832 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/something", type
));
833 EXPECT_EQ(-1, ignoreItem
.IsPathIgnored("subdir/something/more", type
));
834 EXPECT_EQ(1, ignoreItem
.IsPathIgnored("subdir/some-dir/something", type
));
837 TEST_P(CBasicGitWithMultiLinkedTestWithSubmoduleRepoFixture
, AdminDirMap
) // Submodule & Test
842 // Test if the main work tree admin directory can be found
843 adminDir
= g_AdminDirMap
.GetAdminDir(m_MainWorkTreePath
);
844 EXPECT_TRUE(CPathUtils::IsSamePath(CPathUtils::BuildPathWithPathDelimiter(m_MainWorkTreePath
) + L
".git", adminDir
));
846 // Test test main work tree reverse lookup
847 workDir
= g_AdminDirMap
.GetWorkingCopy(CPathUtils::BuildPathWithPathDelimiter(m_MainWorkTreePath
) + L
".git");
848 EXPECT_TRUE(CPathUtils::IsSamePath(m_MainWorkTreePath
, workDir
));
850 if (CGit::ms_bCygwinGit
)
853 // Test if the linked repository admin directory can be found (**WITHOUT** trailing path delimiter)
854 adminDir
= g_AdminDirMap
.GetAdminDir(m_LinkedWorkTreePath
);
855 EXPECT_TRUE(CPathUtils::IsSamePath(CPathUtils::BuildPathWithPathDelimiter(m_MainWorkTreePath
) + L
".git", adminDir
));
857 // Test if the linked worktree admin directory can be found (**WITH** trailing path delimiter)
858 adminDir
= g_AdminDirMap
.GetWorktreeAdminDir(CPathUtils::BuildPathWithPathDelimiter(m_LinkedWorkTreePath
));
859 EXPECT_TRUE(CPathUtils::IsSamePath(CPathUtils::BuildPathWithPathDelimiter(m_MainWorkTreePath
) + L
".git\\worktrees\\LinkedWorkTree", adminDir
));
861 // Test if the linked worktree admin directory can be found (**WITHOUT** trailing path delimiter)
862 adminDir
= g_AdminDirMap
.GetWorktreeAdminDir(m_LinkedWorkTreePath
);
863 EXPECT_TRUE(CPathUtils::IsSamePath(CPathUtils::BuildPathWithPathDelimiter(m_MainWorkTreePath
) + L
".git\\worktrees\\LinkedWorkTree", adminDir
));
865 // Test reverse lookup on linked worktree admin directory (**WITH** trailing path delimiter)
866 workDir
= g_AdminDirMap
.GetWorkingCopy(CPathUtils::BuildPathWithPathDelimiter(m_MainWorkTreePath
) + L
".git\\worktrees\\LinkedWorkTree\\");
867 EXPECT_TRUE(CPathUtils::IsSamePath(m_LinkedWorkTreePath
, workDir
));
869 // Test reverse lookup on linked worktree admin directory (**WITHOUT** trailing path delimiter)
870 workDir
= g_AdminDirMap
.GetWorkingCopy(CPathUtils::BuildPathWithPathDelimiter(m_MainWorkTreePath
) + L
".git\\worktrees\\LinkedWorkTree");
871 EXPECT_TRUE(CPathUtils::IsSamePath(m_LinkedWorkTreePath
, workDir
));
873 // Test if the sub-module admin directory can be found (**WITH** trailing path delimiter)
874 adminDir
= g_AdminDirMap
.GetAdminDir(CPathUtils::BuildPathWithPathDelimiter(m_MainWorkTreePath
) + L
"sub1\\");
875 EXPECT_TRUE(CPathUtils::IsSamePath(CPathUtils::BuildPathWithPathDelimiter(m_MainWorkTreePath
) + L
".git\\modules\\sub1", adminDir
));
877 // Test if the sub-module admin directory can be found (**WITHOUT** trailing path delimiter)
878 adminDir
= g_AdminDirMap
.GetAdminDir(CPathUtils::BuildPathWithPathDelimiter(m_MainWorkTreePath
) + L
"sub1");
879 EXPECT_TRUE(CPathUtils::IsSamePath(CPathUtils::BuildPathWithPathDelimiter(m_MainWorkTreePath
) + L
".git\\modules\\sub1", adminDir
));
881 // Test if reverse lookup on submodule works (**WITH** trailing path delimiter)
882 workDir
= g_AdminDirMap
.GetWorkingCopy(CPathUtils::BuildPathWithPathDelimiter(m_MainWorkTreePath
) + L
".git\\modules\\sub1\\");
883 EXPECT_TRUE(CPathUtils::IsSamePath(CPathUtils::BuildPathWithPathDelimiter(m_MainWorkTreePath
) + L
"sub1", workDir
));
885 // Test if reverse lookup on submodule works (**WITHOUT** trailing path delimiter)
886 workDir
= g_AdminDirMap
.GetWorkingCopy(CPathUtils::BuildPathWithPathDelimiter(m_MainWorkTreePath
) + L
".git\\modules\\sub1");
887 EXPECT_TRUE(CPathUtils::IsSamePath(CPathUtils::BuildPathWithPathDelimiter(m_MainWorkTreePath
) + L
"sub1", workDir
));