1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2015-2018 - TortoiseGit
4 // Copyright (C) 2003-2008 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "StringUtils.h"
25 #include "PreserveChdir.h"
26 #include "AutoTempDir.h"
28 TEST(CTGitPath
, GetDirectoryTest
)
30 // Bit tricky, this test, because we need to know something about the file
31 // layout on the machine which is running the test
32 TCHAR winDir
[MAX_PATH
+ 1] = { 0 };
33 GetWindowsDirectory(winDir
, _countof(winDir
));
34 CString
sWinDir(winDir
);
37 // This is a file which we know will always be there
38 testPath
.SetFromUnknown(sWinDir
+ L
"\\win.ini");
39 EXPECT_FALSE(testPath
.IsDirectory());
40 EXPECT_STREQ(sWinDir
,testPath
.GetDirectory().GetWinPathString());
41 EXPECT_STREQ(sWinDir
, testPath
.GetContainingDirectory().GetWinPathString());
43 // Now do the test on the win directory itself - It's hard to be sure about the containing directory
44 // but we know it must be different to the directory itself
45 testPath
.SetFromUnknown(sWinDir
);
46 EXPECT_TRUE(testPath
.IsDirectory());
47 EXPECT_STREQ(sWinDir
, testPath
.GetDirectory().GetWinPathString());
48 EXPECT_STRNE(sWinDir
, testPath
.GetContainingDirectory().GetWinPathString());
49 EXPECT_GT(sWinDir
.GetLength(), testPath
.GetContainingDirectory().GetWinPathString().GetLength());
52 testPath
.SetFromUnknown(L
"C:\\");
53 EXPECT_TRUE(testPath
.IsDirectory());
54 EXPECT_TRUE(testPath
.GetDirectory().GetWinPathString().CompareNoCase(L
"C:\\") == 0);
55 EXPECT_TRUE(testPath
.GetContainingDirectory().IsEmpty());
56 // Try a root UNC path
57 testPath
.SetFromUnknown(L
"\\MYSTATION");
58 EXPECT_TRUE(testPath
.GetContainingDirectory().IsEmpty());
60 // test the UI path methods
61 testPath
.SetFromUnknown(L
"c:\\testing%20test");
62 EXPECT_TRUE(testPath
.GetUIFileOrDirectoryName().CompareNoCase(L
"testing%20test") == 0);
64 //testPath.SetFromUnknown(L"http://server.com/testing%20special%20chars%20%c3%a4%c3%b6%c3%bc");
65 //EXPECT_TRUE(testPath.GetUIFileOrDirectoryName().CompareNoCase(L"testing special chars \344\366\374") == 0);
68 TEST(CTGitPath
, AdminDirTest
)
71 testPath
.SetFromUnknown(L
"c:\\.gitdir");
72 EXPECT_FALSE(testPath
.IsAdminDir());
73 testPath
.SetFromUnknown(L
"c:\\test.git");
74 EXPECT_FALSE(testPath
.IsAdminDir());
75 testPath
.SetFromUnknown(L
"c:\\.git");
76 EXPECT_TRUE(testPath
.IsAdminDir());
77 testPath
.SetFromUnknown(L
"c:\\.gitdir\\test");
78 EXPECT_FALSE(testPath
.IsAdminDir());
79 testPath
.SetFromUnknown(L
"c:\\.git\\test");
80 EXPECT_TRUE(testPath
.IsAdminDir());
82 CTGitPathList pathList
;
83 pathList
.AddPath(CTGitPath(L
"c:\\.gitdir"));
84 pathList
.AddPath(CTGitPath(L
"c:\\.git"));
85 pathList
.AddPath(CTGitPath(L
"c:\\.git\\test"));
86 pathList
.AddPath(CTGitPath(L
"c:\\test"));
87 pathList
.RemoveAdminPaths();
88 EXPECT_EQ(2, pathList
.GetCount());
90 EXPECT_EQ(0, pathList
.GetCount());
91 pathList
.AddPath(CTGitPath(L
"c:\\test"));
92 pathList
.RemoveAdminPaths();
93 EXPECT_EQ(1, pathList
.GetCount());
96 TEST(CTGitPath
, SortTest
)
98 CTGitPathList testList
;
100 testPath
.SetFromUnknown(L
"c:/Z");
101 testList
.AddPath(testPath
);
102 testPath
.SetFromUnknown(L
"c:/B");
103 testList
.AddPath(testPath
);
104 testPath
.SetFromUnknown(L
"c:\\a");
105 testList
.AddPath(testPath
);
106 testPath
.SetFromUnknown(L
"c:/Test");
107 testList
.AddPath(testPath
);
109 EXPECT_EQ(4, testList
.GetCount());
111 testList
.SortByPathname();
113 EXPECT_EQ(4, testList
.GetCount());
114 EXPECT_EQ(L
"c:\\a", testList
[0].GetWinPathString());
115 EXPECT_EQ(L
"c:\\B", testList
[1].GetWinPathString());
116 EXPECT_EQ(L
"c:\\Test", testList
[2].GetWinPathString());
117 EXPECT_EQ(L
"c:\\Z",testList
[3].GetWinPathString());
120 TEST(CTGitPath
, RawAppendTest
)
122 CTGitPath
testPath(L
"c:/test/");
123 testPath
.AppendRawString(L
"/Hello");
124 EXPECT_EQ(L
"c:\\test\\Hello", testPath
.GetWinPathString());
126 testPath
.AppendRawString(L
"\\T2");
127 EXPECT_EQ(L
"c:\\test\\Hello\\T2", testPath
.GetWinPathString());
129 CTGitPath
testFilePath(L
"C:\\windows\\win.ini");
130 CTGitPath
testBasePath(L
"c:/temp/myfile.txt");
131 testBasePath
.AppendRawString(testFilePath
.GetFileExtension());
132 EXPECT_EQ(L
"c:\\temp\\myfile.txt.ini", testBasePath
.GetWinPathString());
135 TEST(CTGitPath
, PathAppendTest
)
137 CTGitPath
testPath(L
"c:/test/");
138 testPath
.AppendPathString(L
"/Hello");
139 EXPECT_EQ(L
"c:\\test\\Hello", testPath
.GetWinPathString());
141 testPath
.AppendPathString(L
"T2");
142 EXPECT_EQ(L
"c:\\test\\Hello\\T2", testPath
.GetWinPathString());
144 CTGitPath
testFilePath(L
"C:\\windows\\win.ini");
145 CTGitPath
testBasePath(L
"c:/temp/myfile.txt");
146 // You wouldn't want to do this in real life - you'd use append-raw
147 testBasePath
.AppendPathString(testFilePath
.GetFileExtension());
148 EXPECT_EQ(L
"c:\\temp\\myfile.txt\\.ini", testBasePath
.GetWinPathString());
149 EXPECT_EQ(L
"c:/temp/myfile.txt/.ini", testBasePath
.GetGitPathString());
152 TEST(CTGitPath
, RemoveDuplicatesTest
)
155 list
.AddPath(CTGitPath(L
"Z"));
156 list
.AddPath(CTGitPath(L
"A"));
157 list
.AddPath(CTGitPath(L
"E"));
158 list
.AddPath(CTGitPath(L
"E"));
160 EXPECT_TRUE(list
[2].IsEquivalentTo(list
[3]));
161 EXPECT_EQ(list
[2], list
[3]);
163 EXPECT_EQ(4, list
.GetCount());
165 list
.RemoveDuplicates();
167 EXPECT_EQ(3, list
.GetCount());
169 EXPECT_STREQ(L
"A", list
[0].GetWinPathString());
170 EXPECT_STREQ(L
"E", list
[1].GetWinPathString());
171 EXPECT_STREQ(L
"Z", list
[2].GetWinPathString());
174 TEST(CTGitPath
, RemoveChildrenTest
)
177 list
.AddPath(CTGitPath(L
"c:\\test"));
178 list
.AddPath(CTGitPath(L
"c:\\test\\file"));
179 list
.AddPath(CTGitPath(L
"c:\\testfile"));
180 list
.AddPath(CTGitPath(L
"c:\\parent"));
181 list
.AddPath(CTGitPath(L
"c:\\parent\\child"));
182 list
.AddPath(CTGitPath(L
"c:\\parent\\child1"));
183 list
.AddPath(CTGitPath(L
"c:\\parent\\child2"));
185 EXPECT_EQ(7, list
.GetCount());
187 list
.RemoveChildren();
189 EXPECT_EQ(3, list
.GetCount());
191 list
.SortByPathname();
193 EXPECT_STREQ(L
"c:\\parent", list
[0].GetWinPathString());
194 EXPECT_STREQ(L
"c:\\test", list
[1].GetWinPathString());
195 EXPECT_STREQ(L
"c:\\testfile", list
[2].GetWinPathString());
198 TEST(CTGitPath
, ContainingDirectoryTest
)
201 testPath
.SetFromWin(L
"c:\\a\\b\\c\\d\\e");
203 dir
= testPath
.GetContainingDirectory();
204 EXPECT_STREQ(L
"c:\\a\\b\\c\\d", dir
.GetWinPathString());
205 dir
= dir
.GetContainingDirectory();
206 EXPECT_STREQ(L
"c:\\a\\b\\c", dir
.GetWinPathString());
207 dir
= dir
.GetContainingDirectory();
208 EXPECT_STREQ(L
"c:\\a\\b", dir
.GetWinPathString());
209 dir
= dir
.GetContainingDirectory();
210 EXPECT_STREQ(L
"c:\\a", dir
.GetWinPathString());
211 dir
= dir
.GetContainingDirectory();
212 EXPECT_STREQ(L
"c:\\", dir
.GetWinPathString());
213 dir
= dir
.GetContainingDirectory();
214 EXPECT_TRUE(dir
.IsEmpty());
215 EXPECT_STREQ(L
"", dir
.GetWinPathString());
218 TEST(CTGitPath
, AncestorTest
)
221 testPath
.SetFromWin(L
"c:\\windows");
222 EXPECT_FALSE(testPath
.IsAncestorOf(CTGitPath(L
"c:\\")));
223 EXPECT_TRUE(testPath
.IsAncestorOf(CTGitPath(L
"c:\\windows")));
224 EXPECT_FALSE(testPath
.IsAncestorOf(CTGitPath(L
"c:\\windows test")));
225 EXPECT_FALSE(testPath
.IsAncestorOf(CTGitPath(L
"c:\\windowsdummy")));
226 EXPECT_TRUE(testPath
.IsAncestorOf(CTGitPath(L
"c:\\windows\\test.txt")));
227 EXPECT_TRUE(testPath
.IsAncestorOf(CTGitPath(L
"c:\\windows\\system32\\test.txt")));
230 /*TEST(CTGitPath, SubversionPathTest)
233 testPath.SetFromWin(L"c:\\");
234 EXPECT_TRUE((testPath.GetGitApiPath(pool), "c:") == 0);
235 testPath.SetFromWin(L"c:\\folder");
236 EXPECT_TRUE(strcmp(testPath.GetGitApiPath(pool), "c:/folder") == 0);
237 testPath.SetFromWin(L"c:\\a\\b\\c\\d\\e");
238 EXPECT_TRUE(strcmp(testPath.GetGitApiPath(pool), "c:/a/b/c/d/e") == 0);
239 testPath.SetFromUnknown(L"http://testing/");
240 EXPECT_TRUE(strcmp(testPath.GetGitApiPath(pool), "http://testing") == 0);
241 testPath.SetFromGit(NULL);
242 EXPECT_TRUE(strlen(testPath.GetGitApiPath(pool)) == 0);
244 testPath.SetFromUnknown(L"http://testing again");
245 EXPECT_TRUE(strcmp(testPath.GetGitApiPath(pool), "http://testing%20again") == 0);
246 testPath.SetFromUnknown(L"http://testing%20again");
247 EXPECT_TRUE(strcmp(testPath.GetGitApiPath(pool), "http://testing%20again") == 0);
248 testPath.SetFromUnknown(L"http://testing special chars \344\366\374");
249 EXPECT_TRUE(strcmp(testPath.GetGitApiPath(pool), "http://testing%20special%20chars%20%c3%a4%c3%b6%c3%bc") == 0);
252 TEST(CTGitPath
, GetCommonRootTest
)
254 CTGitPath
pathA(L
"C:\\Development\\LogDlg.cpp");
255 CTGitPath
pathB(L
"C:\\Development\\LogDlg.h");
256 CTGitPath
pathC(L
"C:\\Development\\SomeDir\\LogDlg.h");
260 EXPECT_TRUE(list
.GetCommonRoot().GetWinPathString().CompareNoCase(L
"C:\\Development\\LogDlg.cpp") == 0);
262 EXPECT_TRUE(list
.GetCommonRoot().GetWinPathString().CompareNoCase(L
"C:\\Development") == 0);
264 EXPECT_TRUE(list
.GetCommonRoot().GetWinPathString().CompareNoCase(L
"C:\\Development") == 0);
267 CString sPathList
= L
"D:\\Development\\StExBar\\StExBar\\src\\setup\\Setup64.wxs*D:\\Development\\StExBar\\StExBar\\src\\setup\\Setup.wxs*D:\\Development\\StExBar\\SKTimeStamp\\src\\setup\\Setup.wxs*D:\\Development\\StExBar\\SKTimeStamp\\src\\setup\\Setup64.wxs";
268 list
.LoadFromAsteriskSeparatedString(sPathList
);
269 EXPECT_TRUE(list
.GetCommonRoot().GetWinPathString().CompareNoCase(L
"D:\\Development\\StExBar") == 0);
272 sPathList
= L
"D:\\Development\\StEYBar\\StExBar\\src\\setup\\Setup64.wxs*D:\\Development\\StExBar\\StExBar\\src\\setup\\Setup.wxs*D:\\Development\\StExBar\\SKTimeStamp\\src\\setup\\Setup.wxs*D:\\Development\\StExBar\\SKTimeStamp\\src\\setup\\Setup64.wxs";
273 list
.LoadFromAsteriskSeparatedString(sPathList
);
274 EXPECT_TRUE(list
.GetCommonRoot().GetWinPathString().CompareNoCase(L
"D:\\Development") == 0);
277 sPathList
= L
"c:\\windows\\explorer.exe*c:\\windows";
278 list
.LoadFromAsteriskSeparatedString(sPathList
);
279 EXPECT_TRUE(list
.GetCommonRoot().GetWinPathString().CompareNoCase(L
"c:\\windows") == 0);
282 sPathList
= L
"c:\\windows\\*c:\\windows";
283 list
.LoadFromAsteriskSeparatedString(sPathList
);
284 EXPECT_TRUE(list
.GetCommonRoot().GetWinPathString().CompareNoCase(L
"c:\\windows") == 0);
287 sPathList
= L
"c:\\windows\\system32*c:\\windows\\system";
288 list
.LoadFromAsteriskSeparatedString(sPathList
);
289 EXPECT_TRUE(list
.GetCommonRoot().GetWinPathString().CompareNoCase(L
"c:\\windows") == 0);
292 sPathList
= L
"c:\\windowsdummy*c:\\windows";
293 list
.LoadFromAsteriskSeparatedString(sPathList
);
294 EXPECT_TRUE(list
.GetCommonRoot().GetWinPathString().CompareNoCase(L
"c:\\") == 0);
297 sPathList
= L
"c:\\windows*d:\\windows";
298 list
.LoadFromAsteriskSeparatedString(sPathList
);
299 EXPECT_STREQ(L
"", list
.GetCommonRoot().GetWinPathString());
302 TEST(CTGitPath
, ValidPathAndUrlTest
)
305 testPath
.SetFromWin(L
"c:\\a\\b\\c.test.txt");
306 EXPECT_TRUE(testPath
.IsValidOnWindows());
307 testPath
.SetFromWin(L
"c:\\");
308 EXPECT_TRUE(testPath
.IsValidOnWindows());
309 testPath
.SetFromWin(L
"D:\\.Net\\SpindleSearch\\");
310 EXPECT_TRUE(testPath
.IsValidOnWindows());
311 testPath
.SetFromWin(L
"c");
312 EXPECT_TRUE(testPath
.IsValidOnWindows());
313 testPath
.SetFromWin(L
"c:\\test folder\\file");
314 EXPECT_TRUE(testPath
.IsValidOnWindows());
315 testPath
.SetFromWin(L
"c:\\folder\\");
316 EXPECT_TRUE(testPath
.IsValidOnWindows());
317 testPath
.SetFromWin(L
"c:\\ext.ext.ext\\ext.ext.ext.ext");
318 EXPECT_TRUE(testPath
.IsValidOnWindows());
319 testPath
.SetFromWin(L
"c:\\.git");
320 EXPECT_TRUE(testPath
.IsValidOnWindows());
321 testPath
.SetFromWin(L
"c:\\com\\file");
322 EXPECT_TRUE(testPath
.IsValidOnWindows());
323 testPath
.SetFromWin(L
"c:\\test\\conf");
324 EXPECT_TRUE(testPath
.IsValidOnWindows());
325 testPath
.SetFromWin(L
"c:\\LPT");
326 EXPECT_TRUE(testPath
.IsValidOnWindows());
327 testPath
.SetFromWin(L
"c:\\test\\LPT");
328 EXPECT_TRUE(testPath
.IsValidOnWindows());
329 testPath
.SetFromWin(L
"c:\\com1test");
330 EXPECT_TRUE(testPath
.IsValidOnWindows());
331 testPath
.SetFromWin(L
"\\\\?\\c:\\test\\com1test");
332 EXPECT_TRUE(testPath
.IsValidOnWindows());
334 testPath
.SetFromWin(L
"\\\\Share\\filename");
335 EXPECT_TRUE(testPath
.IsValidOnWindows());
336 testPath
.SetFromWin(L
"\\\\Share\\filename.extension");
337 EXPECT_TRUE(testPath
.IsValidOnWindows());
338 testPath
.SetFromWin(L
"\\\\Share\\.git");
339 EXPECT_TRUE(testPath
.IsValidOnWindows());
341 // now the negative tests
342 testPath
.SetFromWin(L
"c:\\test:folder");
343 EXPECT_FALSE(testPath
.IsValidOnWindows());
344 testPath
.SetFromWin(L
"c:\\file<name");
345 EXPECT_FALSE(testPath
.IsValidOnWindows());
346 testPath
.SetFromWin(L
"c:\\something*else");
347 EXPECT_FALSE(testPath
.IsValidOnWindows());
348 testPath
.SetFromWin(L
"c:\\folder\\file?nofile");
349 EXPECT_FALSE(testPath
.IsValidOnWindows());
350 testPath
.SetFromWin(L
"c:\\ext.>ension");
351 EXPECT_FALSE(testPath
.IsValidOnWindows());
352 testPath
.SetFromWin(L
"c:\\com1\\filename");
353 EXPECT_FALSE(testPath
.IsValidOnWindows());
354 testPath
.SetFromWin(L
"c:\\com1");
355 EXPECT_FALSE(testPath
.IsValidOnWindows());
356 testPath
.SetFromWin(L
"c:\\com1\\AuX");
357 EXPECT_FALSE(testPath
.IsValidOnWindows());
359 testPath
.SetFromWin(L
"\\\\Share\\lpt9\\filename");
360 EXPECT_FALSE(testPath
.IsValidOnWindows());
361 testPath
.SetFromWin(L
"\\\\Share\\prn");
362 EXPECT_FALSE(testPath
.IsValidOnWindows());
363 testPath
.SetFromWin(L
"\\\\Share\\NUL");
364 EXPECT_FALSE(testPath
.IsValidOnWindows());
366 // now come some URL tests
367 /*testPath.SetFromGit(L"http://myserver.com/repos/trunk");
368 EXPECT_TRUE(testPath.IsValidOnWindows());
369 testPath.SetFromGit(L"https://myserver.com/repos/trunk/file%20with%20spaces");
370 EXPECT_TRUE(testPath.IsValidOnWindows());
371 testPath.SetFromGit(L"svn://myserver.com/repos/trunk/file with spaces");
372 EXPECT_TRUE(testPath.IsValidOnWindows());
373 testPath.SetFromGit(L"svn+ssh://www.myserver.com/repos/trunk");
374 EXPECT_TRUE(testPath.IsValidOnWindows());
375 testPath.SetFromGit(L"http://localhost:90/repos/trunk");
376 EXPECT_TRUE(testPath.IsValidOnWindows());
377 testPath.SetFromGit(L"file:///C:/GitRepos/Tester/Proj1/tags/t2");
378 EXPECT_TRUE(testPath.IsValidOnWindows());
379 // and some negative URL tests
380 testPath.SetFromGit(L"httpp://myserver.com/repos/trunk");
381 EXPECT_FALSE(testPath.IsValidOnWindows());
382 testPath.SetFromGit(L"https://myserver.com/rep:os/trunk/file%20with%20spaces");
383 EXPECT_FALSE(testPath.IsValidOnWindows());
384 testPath.SetFromGit(L"svn://myserver.com/rep<os/trunk/file with spaces");
385 EXPECT_FALSE(testPath.IsValidOnWindows());
386 testPath.SetFromGit(L"svn+ssh://www.myserver.com/repos/trunk/prn/");
387 EXPECT_FALSE(testPath.IsValidOnWindows());
388 testPath.SetFromGit(L"http://localhost:90/repos/trunk/com1");
389 EXPECT_FALSE(testPath.IsValidOnWindows());*/
392 TEST(CTGitPath
, ListLoadingTest
)
394 TCHAR buf
[MAX_PATH
] = { 0 };
395 GetCurrentDirectory(MAX_PATH
, buf
);
396 CString
sPathList(L
"Path1*c:\\path2 with spaces and stuff*\\funnypath\\*");
397 CTGitPathList testList
;
398 testList
.LoadFromAsteriskSeparatedString(sPathList
);
400 EXPECT_EQ(3, testList
.GetCount());
401 EXPECT_STREQ(CString(buf
) + L
"\\Path1", testList
[0].GetWinPathString());
402 EXPECT_STREQ(L
"c:\\path2 with spaces and stuff", testList
[1].GetWinPathString());
403 EXPECT_STREQ(L
"\\funnypath", testList
[2].GetWinPathString());
405 EXPECT_STREQ(L
"", testList
.GetCommonRoot().GetWinPathString());
407 sPathList
= L
"c:\\path2 with spaces and stuff*c:\\funnypath\\*";
408 testList
.LoadFromAsteriskSeparatedString(sPathList
);
409 EXPECT_STREQ(L
"c:\\", testList
.GetCommonRoot().GetWinPathString());
412 TEST(CTGitPath
, GetBaseFilename
)
415 EXPECT_STREQ(L
"", testPath
.GetBaseFilename());
417 testPath
.SetFromWin(L
"filename.extension");
418 EXPECT_STREQ(L
"filename", testPath
.GetBaseFilename());
419 testPath
.SetFromWin(L
"c:\\test.txt");
420 EXPECT_STREQ(L
"test", testPath
.GetBaseFilename());
421 testPath
.SetFromWin(L
"c:\\subfolder\\file.txt");
422 EXPECT_STREQ(L
"file", testPath
.GetBaseFilename());
423 testPath
.SetFromWin(L
"c:\\without");
424 EXPECT_STREQ(L
"without", testPath
.GetBaseFilename());
425 testPath
.SetFromWin(L
"c:\\folder\\");
426 EXPECT_STREQ(L
"", testPath
.GetBaseFilename()); // this is the behavior right now, dunno if this is the best one
427 testPath
.SetFromWin(L
".gitignore");
428 EXPECT_STREQ(L
".gitignore", testPath
.GetBaseFilename());
429 testPath
.SetFromWin(L
"c:\\.gitignore");
430 EXPECT_STREQ(L
".gitignore", testPath
.GetBaseFilename());
431 testPath
.SetFromWin(L
"c:\\test.double.extension");
432 EXPECT_STREQ(L
"test.double", testPath
.GetBaseFilename());
435 TEST(CTGitPath
, IsEquivalentTo
)
440 EXPECT_TRUE(testPath
.IsEquivalentTo(testPath2
));
442 testPath
.SetFromUnknown(L
"c:\\folder");
443 testPath2
.SetFromUnknown(L
"c:\\folder\\");
444 EXPECT_TRUE(testPath
.IsEquivalentTo(testPath2
));
446 testPath
.SetFromUnknown(L
"c:\\folder\\");
447 testPath2
.SetFromUnknown(L
"c:\\folder");
448 EXPECT_TRUE(testPath
.IsEquivalentTo(testPath2
));
450 testPath
.SetFromUnknown(L
"\\unc\\path");
451 testPath2
.SetFromUnknown(L
"\\unc\\path");
452 EXPECT_TRUE(testPath
.IsEquivalentTo(testPath2
));
454 testPath
.SetFromUnknown(L
"c:\\");
455 testPath2
.SetFromUnknown(L
"c:\\");
456 EXPECT_TRUE(testPath
.IsEquivalentTo(testPath2
));
458 testPath2
.SetFromUnknown(L
"c:/");
459 EXPECT_TRUE(testPath
.IsEquivalentTo(testPath2
));
461 testPath2
.SetFromUnknown(L
"c:");
462 EXPECT_TRUE(testPath
.IsEquivalentTo(testPath2
));
464 testPath
.SetFromUnknown(L
"c:\\test\\1.txt");
465 testPath2
.SetFromUnknown(L
"c:\\test\\1.txt");
466 EXPECT_TRUE(testPath
.IsEquivalentTo(testPath2
));
468 testPath2
.SetFromUnknown(L
"c:/test/1.txt");
469 EXPECT_TRUE(testPath
.IsEquivalentTo(testPath2
));
471 testPath2
.SetFromUnknown(L
"c:\\test\\2.txt");
472 EXPECT_FALSE(testPath
.IsEquivalentTo(testPath2
));
474 testPath2
.SetFromUnknown(L
"c:\\text\\1.txt");
475 EXPECT_FALSE(testPath
.IsEquivalentTo(testPath2
));
477 testPath2
.SetFromUnknown(L
"c:\\tesT\\1.txt");
478 EXPECT_FALSE(testPath
.IsEquivalentTo(testPath2
));
480 testPath2
.SetFromUnknown(L
"c:\\test\\1.tXt");
481 EXPECT_FALSE(testPath
.IsEquivalentTo(testPath2
));
483 testPath
.SetFromUnknown(L
"test/1.txt");
484 testPath2
.SetFromUnknown(L
"test/1.txt");
485 EXPECT_TRUE(testPath
.IsEquivalentTo(testPath2
));
487 testPath2
.SetFromUnknown(L
"test\\1.txt");
488 EXPECT_TRUE(testPath
.IsEquivalentTo(testPath2
));
490 testPath2
.SetFromUnknown(L
"tesT\\1.txt");
491 EXPECT_FALSE(testPath
.IsEquivalentTo(testPath2
));
493 testPath2
.SetFromUnknown(L
"text\\1.txt");
494 EXPECT_FALSE(testPath
.IsEquivalentTo(testPath2
));
496 testPath2
.SetFromUnknown(L
"test\\2.txt");
497 EXPECT_FALSE(testPath
.IsEquivalentTo(testPath2
));
500 TEST(CTGitPath
, IsEquivalentToWithoutCase
)
505 EXPECT_TRUE(testPath
.IsEquivalentToWithoutCase(testPath2
));
507 testPath
.SetFromUnknown(L
"c:\\folder");
508 testPath2
.SetFromUnknown(L
"c:\\folder\\");
509 EXPECT_TRUE(testPath
.IsEquivalentToWithoutCase(testPath2
));
511 testPath
.SetFromUnknown(L
"c:\\folder\\");
512 testPath2
.SetFromUnknown(L
"c:\\folder");
513 EXPECT_TRUE(testPath
.IsEquivalentToWithoutCase(testPath2
));
515 testPath
.SetFromUnknown(L
"\\unc\\path");
516 testPath2
.SetFromUnknown(L
"\\unc\\path");
517 EXPECT_TRUE(testPath
.IsEquivalentToWithoutCase(testPath2
));
519 testPath
.SetFromUnknown(L
"c:\\");
520 testPath2
.SetFromUnknown(L
"c:\\");
521 EXPECT_TRUE(testPath
.IsEquivalentToWithoutCase(testPath2
));
523 testPath2
.SetFromUnknown(L
"c:/");
524 EXPECT_TRUE(testPath
.IsEquivalentToWithoutCase(testPath2
));
526 testPath2
.SetFromUnknown(L
"c:");
527 EXPECT_TRUE(testPath
.IsEquivalentToWithoutCase(testPath2
));
529 testPath
.SetFromUnknown(L
"c:\\test\\1.txt");
530 testPath2
.SetFromUnknown(L
"c:\\test\\1.txt");
531 EXPECT_TRUE(testPath
.IsEquivalentToWithoutCase(testPath2
));
533 testPath2
.SetFromUnknown(L
"c:/test/1.txt");
534 EXPECT_TRUE(testPath
.IsEquivalentToWithoutCase(testPath2
));
536 testPath2
.SetFromUnknown(L
"c:\\test\\2.txt");
537 EXPECT_FALSE(testPath
.IsEquivalentToWithoutCase(testPath2
));
539 testPath2
.SetFromUnknown(L
"c:\\text\\1.txt");
540 EXPECT_FALSE(testPath
.IsEquivalentToWithoutCase(testPath2
));
542 testPath2
.SetFromUnknown(L
"c:\\tesT\\1.txt");
543 EXPECT_TRUE(testPath
.IsEquivalentToWithoutCase(testPath2
));
545 testPath2
.SetFromUnknown(L
"c:\\test\\1.tXt");
546 EXPECT_TRUE(testPath
.IsEquivalentToWithoutCase(testPath2
));
548 testPath
.SetFromUnknown(L
"test/1.txt");
549 testPath2
.SetFromUnknown(L
"test/1.txt");
550 EXPECT_TRUE(testPath
.IsEquivalentToWithoutCase(testPath2
));
552 testPath2
.SetFromUnknown(L
"test\\1.txt");
553 EXPECT_TRUE(testPath
.IsEquivalentToWithoutCase(testPath2
));
555 testPath2
.SetFromUnknown(L
"tesT\\1.txt");
556 EXPECT_TRUE(testPath
.IsEquivalentToWithoutCase(testPath2
));
558 testPath2
.SetFromUnknown(L
"text\\1.txt");
559 EXPECT_FALSE(testPath
.IsEquivalentToWithoutCase(testPath2
));
561 testPath2
.SetFromUnknown(L
"test\\2.txt");
562 EXPECT_FALSE(testPath
.IsEquivalentToWithoutCase(testPath2
));
565 TEST(CTGitPath
, ParserFromLog_Empty
)
567 CGitByteArray byteArray
;
568 CTGitPathList testList
;
569 EXPECT_EQ(0, testList
.ParserFromLog(byteArray
));
570 EXPECT_EQ(0, testList
.GetCount());
573 TEST(CTGitPath
, ParserFromLog_Conflict
)
575 // as used in CGit::GetWorkingTreeChanges
576 BYTE git_ls_file_u_t_z_output
[] = { "M 100644 1f9f46da1ee155aa765d6e379d9d19853358cb07 1 bla.txt\0M 100644 3aa011e7d3609ab9af90c4b10f616312d2be422f 2 bla.txt\0M 100644 56d252d69d535834b9fbfa6f6a633ecd505ea2e6 3 bla.txt\0" };
577 CGitByteArray byteArray
;
578 byteArray
.append(git_ls_file_u_t_z_output
, sizeof(git_ls_file_u_t_z_output
));
579 CTGitPathList testList
;
580 EXPECT_EQ(0, testList
.ParserFromLog(byteArray
));
581 ASSERT_EQ(1, testList
.GetCount());
582 EXPECT_STREQ(L
"bla.txt", testList
[0].GetGitPathString());
583 EXPECT_EQ(0, testList
[0].m_Stage
); // not set
584 EXPECT_EQ(0U, testList
[0].m_Action
);
587 /* git status output for the following tests marked with "(*)"
588 * gpl.txt was deleted in index, but still on disk
589 * build.txt deleted on disk, but not in index
590 * src/Debug-Hints.txt deleted on disk and in index
591 * zzz-added-only-in-index-missing-on-fs.txt added in index, and then removed on disk
592 * signedness.txt new file
593 * renamed release.txt -> release-renamed.txt
594 * changed on disk but not in index test/UnitTests/TGitPathTest.cpp
597 Your branch and 'origin/tests' have diverged,
598 and have 2 and 1 different commit each, respectively.
599 (use "git pull" to merge the remote branch into yours)
601 Changes to be committed:
602 (use "git reset HEAD <file>..." to unstage)
604 renamed: release.txt -> release-renamed.txt
605 new file: signedness.txt
606 deleted: src/Debug-Hints.txt
608 new file: zzz-added-only-in-index-missing-on-fs.txt
610 Changes not staged for commit:
611 (use "git add/rm <file>..." to update what will be committed)
612 (use "git checkout -- <file>..." to discard changes in working directory)
613 (commit or discard the untracked or modified content in submodules)
616 modified: ext/apr (untracked content)
617 modified: ext/apr-util (modified content, untracked content)
618 modified: ext/libgit2 (new commits)
619 modified: test/UnitTests/TGitPathTest.cpp
620 deleted: zzz-added-only-in-index-missing-on-fs.txt
623 (use "git add <file>..." to include in what will be committed)
628 TEST(CTGitPath
, ParserFromLog_Deleted_From_LsFiles
)
630 // as used in CGit::GetWorkingTreeChanges, based on (*)
631 CGitByteArray byteArray
;
632 CTGitPathList testList
;
633 EXPECT_EQ(0, testList
.ParserFromLog(byteArray
, true));
634 ASSERT_EQ(0, testList
.GetCount());
636 BYTE git_ls_file_d_z_output
[] = { "build.txt\0" };
637 byteArray
.append(git_ls_file_d_z_output
, sizeof(git_ls_file_d_z_output
));
638 EXPECT_EQ(0, testList
.ParserFromLog(byteArray
, true));
639 ASSERT_EQ(1, testList
.GetCount());
640 EXPECT_STREQ(L
"build.txt", testList
[0].GetGitPathString());
641 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
| CTGitPath::LOGACTIONS_MISSING
, testList
[0].m_Action
);
643 BYTE git_ls_file_d_z_output2
[] = { "zzz-added-only-in-index-missing-on-fs.txt\0" };
644 byteArray
.append(git_ls_file_d_z_output2
, sizeof(git_ls_file_d_z_output2
));
645 EXPECT_EQ(0, testList
.ParserFromLog(byteArray
, true));
646 ASSERT_EQ(2, testList
.GetCount());
647 EXPECT_STREQ(L
"build.txt", testList
[0].GetGitPathString());
648 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
| CTGitPath::LOGACTIONS_MISSING
, testList
[0].m_Action
);
649 EXPECT_STREQ(L
"zzz-added-only-in-index-missing-on-fs.txt", testList
[1].GetGitPathString());
650 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
| CTGitPath::LOGACTIONS_MISSING
, testList
[1].m_Action
);
653 TEST(CTGitPath
, ParserFromLog_DiffIndex_Raw_M_C_z
)
655 // as used in DiffCommand::Execute, based on (*)
656 BYTE git_DiffIndex_Raw_M_C_z_output
[] = { ":100644 000000 39bba2f577adc09d9706703340daf6e1138cfc71 0000000000000000000000000000000000000000 D\0build.txt\0:160000 160000 6dcb2184662c5b50fd2f6adc63f24398ced2b98c 6dcb2184662c5b50fd2f6adc63f24398ced2b98c M\0ext/apr\0:160000 160000 ca83ff5fbeb9c27454b4f0242f17ebf584ed0521 ca83ff5fbeb9c27454b4f0242f17ebf584ed0521 M\0ext/apr-util\0:160000 160000 a291790a8d42579dafe8684151931847921a9578 0000000000000000000000000000000000000000 M\0ext/libgit2\0:100644 100644 f523fd2eb6ea2328e46d88f6406ccebbcb173c9f f523fd2eb6ea2328e46d88f6406ccebbcb173c9f R100\0release.txt\0release-renamed.txt\0:000000 100644 0000000000000000000000000000000000000000 9c752c94669d3319973c5c363045881d8466af3a A\0signedness.txt\0:100644 000000 53b6e6cefd7fc7d68e5aa73678c2895406614c1e 0000000000000000000000000000000000000000 D\0src/Debug-Hints.txt\0:100644 000000 36488d58658d63f9d7a8d5e0637c530df987c4e5 0000000000000000000000000000000000000000 D\0src/gpl.txt\0:100644 100644 9a59162db1af7a7c7cf7da0417b89065ac71b987 0000000000000000000000000000000000000000 M\0test/UnitTests/TGitPathTest.cpp\0" };
657 // gpl.txt still exists, but deleted in index
658 // build.txt deleted, still in index
659 CGitByteArray byteArray
;
660 byteArray
.append(git_DiffIndex_Raw_M_C_z_output
, sizeof(git_DiffIndex_Raw_M_C_z_output
));
661 CTGitPathList testList
;
662 EXPECT_EQ(0, testList
.ParserFromLog(byteArray
));
663 ASSERT_EQ(9, testList
.GetCount());
664 EXPECT_STREQ(L
"build.txt", testList
[0].GetGitPathString());
665 EXPECT_STREQ(L
"", testList
[0].GetGitOldPathString());
666 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[0].m_Action
);
667 EXPECT_STREQ(L
"", testList
[0].m_StatAdd
);
668 EXPECT_STREQ(L
"", testList
[0].m_StatDel
);
669 EXPECT_EQ(0, testList
[0].m_Stage
);
670 EXPECT_FALSE(testList
[0].IsDirectory());
671 EXPECT_STREQ(L
"ext/apr", testList
[1].GetGitPathString());
672 EXPECT_STREQ(L
"", testList
[1].GetGitOldPathString());
673 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[1].m_Action
);
674 EXPECT_STREQ(L
"", testList
[1].m_StatAdd
);
675 EXPECT_STREQ(L
"", testList
[1].m_StatDel
);
676 EXPECT_EQ(0, testList
[1].m_Stage
);
677 EXPECT_TRUE(testList
[1].IsDirectory());
678 EXPECT_STREQ(L
"ext/apr-util", testList
[2].GetGitPathString());
679 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[2].m_Action
);
680 EXPECT_STREQ(L
"", testList
[2].m_StatAdd
);
681 EXPECT_STREQ(L
"", testList
[2].m_StatDel
);
682 EXPECT_EQ(0, testList
[2].m_Stage
);
683 EXPECT_TRUE(testList
[2].IsDirectory());
684 EXPECT_STREQ(L
"ext/libgit2", testList
[3].GetGitPathString());
685 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[3].m_Action
);
686 EXPECT_STREQ(L
"", testList
[3].m_StatAdd
);
687 EXPECT_STREQ(L
"", testList
[3].m_StatDel
);
688 EXPECT_EQ(0, testList
[3].m_Stage
);
689 EXPECT_TRUE(testList
[3].IsDirectory());
690 EXPECT_STREQ(L
"release-renamed.txt", testList
[4].GetGitPathString());
691 EXPECT_EQ(CTGitPath::LOGACTIONS_REPLACED
, testList
[4].m_Action
);
692 EXPECT_STREQ(L
"", testList
[4].m_StatAdd
);
693 EXPECT_STREQ(L
"", testList
[4].m_StatDel
);
694 EXPECT_EQ(0, testList
[4].m_Stage
);
695 EXPECT_FALSE(testList
[4].IsDirectory());
696 EXPECT_STREQ(L
"release.txt", testList
[4].GetGitOldPathString());
697 EXPECT_STREQ(L
"signedness.txt", testList
[5].GetGitPathString());
698 EXPECT_STREQ(L
"", testList
[5].GetGitOldPathString());
699 EXPECT_EQ(CTGitPath::LOGACTIONS_ADDED
, testList
[5].m_Action
);
700 EXPECT_STREQ(L
"", testList
[5].m_StatAdd
);
701 EXPECT_STREQ(L
"", testList
[5].m_StatDel
);
702 EXPECT_EQ(0, testList
[5].m_Stage
);
703 EXPECT_FALSE(testList
[5].IsDirectory());
704 EXPECT_STREQ(L
"src/Debug-Hints.txt", testList
[6].GetGitPathString());
705 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[6].m_Action
);
706 EXPECT_STREQ(L
"", testList
[6].m_StatAdd
);
707 EXPECT_STREQ(L
"", testList
[6].m_StatDel
);
708 EXPECT_EQ(0, testList
[6].m_Stage
);
709 EXPECT_FALSE(testList
[6].IsDirectory());
710 EXPECT_STREQ(L
"src/gpl.txt", testList
[7].GetGitPathString());
711 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[7].m_Action
);
712 EXPECT_STREQ(L
"", testList
[7].m_StatAdd
);
713 EXPECT_STREQ(L
"", testList
[7].m_StatDel
);
714 EXPECT_EQ(0, testList
[7].m_Stage
);
715 EXPECT_FALSE(testList
[7].IsDirectory());
716 EXPECT_STREQ(L
"test/UnitTests/TGitPathTest.cpp", testList
[8].GetGitPathString());
717 EXPECT_STREQ(L
"", testList
[8].GetGitOldPathString());
718 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[8].m_Action
);
719 EXPECT_STREQ(L
"", testList
[8].m_StatAdd
);
720 EXPECT_STREQ(L
"", testList
[8].m_StatDel
);
721 EXPECT_EQ(0, testList
[8].m_Stage
);
722 EXPECT_FALSE(testList
[8].IsDirectory());
725 TEST(CTGitPath
, ParserFromLog_DiffIndex_Raw_M_C_Numstat_z
)
727 // as used in CGit::GetWorkingTreeChanges, but here separated; based on (*)
728 BYTE git_DiffIndex_Raw_M_C_z_output
[] = { ":100644 000000 39bba2f577adc09d9706703340daf6e1138cfc71 0000000000000000000000000000000000000000 D\0build.txt\0:160000 160000 6dcb2184662c5b50fd2f6adc63f24398ced2b98c 6dcb2184662c5b50fd2f6adc63f24398ced2b98c M\0ext/apr\0:160000 160000 ca83ff5fbeb9c27454b4f0242f17ebf584ed0521 ca83ff5fbeb9c27454b4f0242f17ebf584ed0521 M\0ext/apr-util\0:160000 160000 a291790a8d42579dafe8684151931847921a9578 0000000000000000000000000000000000000000 M\0ext/libgit2\0:100644 100644 f523fd2eb6ea2328e46d88f6406ccebbcb173c9f f523fd2eb6ea2328e46d88f6406ccebbcb173c9f R100\0release.txt\0release-renamed.txt\0:000000 100644 0000000000000000000000000000000000000000 9c752c94669d3319973c5c363045881d8466af3a A\0signedness.txt\0:100644 000000 53b6e6cefd7fc7d68e5aa73678c2895406614c1e 0000000000000000000000000000000000000000 D\0src/Debug-Hints.txt\0:100644 000000 36488d58658d63f9d7a8d5e0637c530df987c4e5 0000000000000000000000000000000000000000 D\0src/gpl.txt\0:100644 100644 9a59162db1af7a7c7cf7da0417b89065ac71b987 0000000000000000000000000000000000000000 M\0test/UnitTests/TGitPathTest.cpp\0""0 61 build.txt\0""0 0 ext/apr\0""0 0 ext/apr-util\0""1 1 ext/libgit2\0""0 0 \0release.txt\0release-renamed.txt\0""1176 0 signedness.txt\0""0 74 src/Debug-Hints.txt\0""0 340 src/gpl.txt\0""162 2 test/UnitTests/TGitPathTest.cpp\0" };
729 CGitByteArray byteArray
;
730 byteArray
.append(git_DiffIndex_Raw_M_C_z_output
, sizeof(git_DiffIndex_Raw_M_C_z_output
));
731 CTGitPathList testList
;
732 EXPECT_EQ(0, testList
.ParserFromLog(byteArray
));
733 ASSERT_EQ(9, testList
.GetCount());
734 EXPECT_STREQ(L
"build.txt", testList
[0].GetGitPathString());
735 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[0].m_Action
);
736 EXPECT_STREQ(L
"0", testList
[0].m_StatAdd
);
737 EXPECT_STREQ(L
"61", testList
[0].m_StatDel
);
738 EXPECT_EQ(0, testList
[0].m_Stage
);
739 EXPECT_FALSE(testList
[0].IsDirectory());
740 EXPECT_STREQ(L
"ext/apr", testList
[1].GetGitPathString());
741 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[1].m_Action
);
742 EXPECT_STREQ(L
"0", testList
[1].m_StatAdd
);
743 EXPECT_STREQ(L
"0", testList
[1].m_StatDel
);
744 EXPECT_EQ(0, testList
[1].m_Stage
);
745 EXPECT_TRUE(testList
[1].IsDirectory());
746 EXPECT_STREQ(L
"ext/apr-util", testList
[2].GetGitPathString());
747 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[2].m_Action
);
748 EXPECT_STREQ(L
"0", testList
[2].m_StatAdd
);
749 EXPECT_STREQ(L
"0", testList
[2].m_StatDel
);
750 EXPECT_EQ(0, testList
[2].m_Stage
);
751 EXPECT_TRUE(testList
[2].IsDirectory());
752 EXPECT_STREQ(L
"ext/libgit2", testList
[3].GetGitPathString());
753 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[3].m_Action
);
754 EXPECT_STREQ(L
"1", testList
[3].m_StatAdd
);
755 EXPECT_STREQ(L
"1", testList
[3].m_StatDel
);
756 EXPECT_EQ(0, testList
[3].m_Stage
);
757 EXPECT_TRUE(testList
[3].IsDirectory());
758 EXPECT_STREQ(L
"release-renamed.txt", testList
[4].GetGitPathString());
759 EXPECT_EQ(CTGitPath::LOGACTIONS_REPLACED
, testList
[4].m_Action
);
760 EXPECT_STREQ(L
"0", testList
[4].m_StatAdd
);
761 EXPECT_STREQ(L
"0", testList
[4].m_StatDel
);
762 EXPECT_EQ(0, testList
[4].m_Stage
);
763 EXPECT_FALSE(testList
[4].IsDirectory());
764 EXPECT_STREQ(L
"release.txt", testList
[4].GetGitOldPathString());
765 EXPECT_STREQ(L
"signedness.txt", testList
[5].GetGitPathString());
766 EXPECT_EQ(CTGitPath::LOGACTIONS_ADDED
, testList
[5].m_Action
);
767 EXPECT_STREQ(L
"1176", testList
[5].m_StatAdd
);
768 EXPECT_STREQ(L
"0", testList
[5].m_StatDel
);
769 EXPECT_EQ(0, testList
[5].m_Stage
);
770 EXPECT_FALSE(testList
[5].IsDirectory());
771 EXPECT_STREQ(L
"src/Debug-Hints.txt", testList
[6].GetGitPathString());
772 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[6].m_Action
);
773 EXPECT_STREQ(L
"0", testList
[6].m_StatAdd
);
774 EXPECT_STREQ(L
"74", testList
[6].m_StatDel
);
775 EXPECT_EQ(0, testList
[6].m_Stage
);
776 EXPECT_FALSE(testList
[6].IsDirectory());
777 EXPECT_STREQ(L
"src/gpl.txt", testList
[7].GetGitPathString());
778 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[7].m_Action
);
779 EXPECT_STREQ(L
"0", testList
[7].m_StatAdd
);
780 EXPECT_STREQ(L
"340", testList
[7].m_StatDel
);
781 EXPECT_EQ(0, testList
[7].m_Stage
);
782 EXPECT_FALSE(testList
[7].IsDirectory());
783 EXPECT_STREQ(L
"test/UnitTests/TGitPathTest.cpp", testList
[8].GetGitPathString());
784 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[8].m_Action
);
785 EXPECT_STREQ(L
"162", testList
[8].m_StatAdd
);
786 EXPECT_STREQ(L
"2", testList
[8].m_StatDel
);
787 EXPECT_EQ(0, testList
[8].m_Stage
);
788 EXPECT_FALSE(testList
[8].IsDirectory());
791 TEST(CTGitPath
, ParserFromLog_DiffIndex_Raw_Cached_M_C_Numstat_z
)
793 // as used in CGit::GetWorkingTreeChanges, but here separated; based on (*)
794 BYTE git_DiffIndex_Raw_Cached_M_C_z_output
[] = { ":100644 100644 f523fd2eb6ea2328e46d88f6406ccebbcb173c9f f523fd2eb6ea2328e46d88f6406ccebbcb173c9f R100\0release.txt\0release-renamed.txt\0:000000 100644 0000000000000000000000000000000000000000 9c752c94669d3319973c5c363045881d8466af3a A\0signedness.txt\0:100644 000000 53b6e6cefd7fc7d68e5aa73678c2895406614c1e 0000000000000000000000000000000000000000 D\0src/Debug-Hints.txt\0:100644 000000 36488d58658d63f9d7a8d5e0637c530df987c4e5 0000000000000000000000000000000000000000 D\0src/gpl.txt\0:000000 100644 0000000000000000000000000000000000000000 285fc7c8fe9f37876efe56dbb31e34da8b75be24 A\0zzz-added-only-in-index-missing-on-fs.txt\0""0 0 \0release.txt\0release-renamed.txt\0""1176 0 signedness.txt\0""0 74 src/Debug-Hints.txt\0""0 340 src/gpl.txt\0""1 0 zzz-added-only-in-index-missing-on-fs.txt\0" };
795 CGitByteArray byteArray
;
796 byteArray
.append(git_DiffIndex_Raw_Cached_M_C_z_output
, sizeof(git_DiffIndex_Raw_Cached_M_C_z_output
));
797 CTGitPathList testList
;
798 EXPECT_EQ(0, testList
.ParserFromLog(byteArray
));
799 ASSERT_EQ(5, testList
.GetCount());
800 EXPECT_STREQ(L
"release-renamed.txt", testList
[0].GetGitPathString());
801 EXPECT_EQ(CTGitPath::LOGACTIONS_REPLACED
, testList
[0].m_Action
);
802 EXPECT_STREQ(L
"0", testList
[0].m_StatAdd
);
803 EXPECT_STREQ(L
"0", testList
[0].m_StatDel
);
804 EXPECT_EQ(0, testList
[0].m_Stage
);
805 EXPECT_FALSE(testList
[0].IsDirectory());
806 EXPECT_STREQ(L
"release.txt", testList
[0].GetGitOldPathString());
807 EXPECT_STREQ(L
"signedness.txt", testList
[1].GetGitPathString());
808 EXPECT_EQ(CTGitPath::LOGACTIONS_ADDED
, testList
[1].m_Action
);
809 EXPECT_STREQ(L
"1176", testList
[1].m_StatAdd
);
810 EXPECT_STREQ(L
"0", testList
[1].m_StatDel
);
811 EXPECT_EQ(0, testList
[1].m_Stage
);
812 EXPECT_FALSE(testList
[1].IsDirectory());
813 EXPECT_STREQ(L
"src/Debug-Hints.txt", testList
[2].GetGitPathString());
814 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[2].m_Action
);
815 EXPECT_STREQ(L
"0", testList
[2].m_StatAdd
);
816 EXPECT_STREQ(L
"74", testList
[2].m_StatDel
);
817 EXPECT_EQ(0, testList
[2].m_Stage
);
818 EXPECT_STREQ(L
"src/gpl.txt", testList
[3].GetGitPathString());
819 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[3].m_Action
);
820 EXPECT_STREQ(L
"0", testList
[3].m_StatAdd
);
821 EXPECT_STREQ(L
"340", testList
[3].m_StatDel
);
822 EXPECT_EQ(0, testList
[3].m_Stage
);
823 EXPECT_FALSE(testList
[3].IsDirectory());
824 EXPECT_STREQ(L
"zzz-added-only-in-index-missing-on-fs.txt", testList
[4].GetGitPathString());
825 EXPECT_EQ(CTGitPath::LOGACTIONS_ADDED
, testList
[4].m_Action
);
826 EXPECT_STREQ(L
"1", testList
[4].m_StatAdd
);
827 EXPECT_STREQ(L
"0", testList
[4].m_StatDel
);
828 EXPECT_EQ(0, testList
[4].m_Stage
);
829 EXPECT_FALSE(testList
[4].IsDirectory());
832 TEST(CTGitPath
, ParserFromLog_DiffIndex_Raw_Cached_M_C_Numstat_z_AND_DiffIndex_Raw_M_C_Numstat_z
)
834 // as used in CGit::GetWorkingTreeChanges; based on (*)
835 BYTE git_DiffIndex_Raw_Cached_M_C_z_output
[] = { ":100644 100644 f523fd2eb6ea2328e46d88f6406ccebbcb173c9f f523fd2eb6ea2328e46d88f6406ccebbcb173c9f R100\0release.txt\0release-renamed.txt\0:000000 100644 0000000000000000000000000000000000000000 9c752c94669d3319973c5c363045881d8466af3a A\0signedness.txt\0:100644 000000 53b6e6cefd7fc7d68e5aa73678c2895406614c1e 0000000000000000000000000000000000000000 D\0src/Debug-Hints.txt\0:100644 000000 36488d58658d63f9d7a8d5e0637c530df987c4e5 0000000000000000000000000000000000000000 D\0src/gpl.txt\0:000000 100644 0000000000000000000000000000000000000000 285fc7c8fe9f37876efe56dbb31e34da8b75be24 A\0zzz-added-only-in-index-missing-on-fs.txt\0""0 0 \0release.txt\0release-renamed.txt\0""1176 0 signedness.txt\0""0 74 src/Debug-Hints.txt\0""0 340 src/gpl.txt\0""1 0 zzz-added-only-in-index-missing-on-fs.txt\0:100644 000000 39bba2f577adc09d9706703340daf6e1138cfc71 0000000000000000000000000000000000000000 D\0build.txt\0:160000 160000 6dcb2184662c5b50fd2f6adc63f24398ced2b98c 6dcb2184662c5b50fd2f6adc63f24398ced2b98c M\0ext/apr\0:160000 160000 ca83ff5fbeb9c27454b4f0242f17ebf584ed0521 ca83ff5fbeb9c27454b4f0242f17ebf584ed0521 M\0ext/apr-util\0:160000 160000 a291790a8d42579dafe8684151931847921a9578 0000000000000000000000000000000000000000 M\0ext/libgit2\0:100644 100644 f523fd2eb6ea2328e46d88f6406ccebbcb173c9f f523fd2eb6ea2328e46d88f6406ccebbcb173c9f R100\0release.txt\0release-renamed.txt\0:000000 100644 0000000000000000000000000000000000000000 9c752c94669d3319973c5c363045881d8466af3a A\0signedness.txt\0:100644 000000 53b6e6cefd7fc7d68e5aa73678c2895406614c1e 0000000000000000000000000000000000000000 D\0src/Debug-Hints.txt\0:100644 000000 36488d58658d63f9d7a8d5e0637c530df987c4e5 0000000000000000000000000000000000000000 D\0src/gpl.txt\0:100644 100644 9a59162db1af7a7c7cf7da0417b89065ac71b987 0000000000000000000000000000000000000000 M\0test/UnitTests/TGitPathTest.cpp\0""0 61 build.txt\0""0 0 ext/apr\0""0 0 ext/apr-util\0""1 1 ext/libgit2\0""0 0 \0release.txt\0release-renamed.txt\0""1176 0 signedness.txt\0""0 74 src/Debug-Hints.txt\0""0 340 src/gpl.txt\0""162 2 test/UnitTests/TGitPathTest.cpp\0" };
836 CGitByteArray byteArray
;
837 byteArray
.append(git_DiffIndex_Raw_Cached_M_C_z_output
, sizeof(git_DiffIndex_Raw_Cached_M_C_z_output
));
838 CTGitPathList testList
;
839 EXPECT_EQ(0, testList
.ParserFromLog(byteArray
));
840 ASSERT_EQ(10, testList
.GetCount());
841 EXPECT_STREQ(L
"release-renamed.txt", testList
[0].GetGitPathString());
842 EXPECT_EQ(CTGitPath::LOGACTIONS_REPLACED
, testList
[0].m_Action
);
843 EXPECT_STREQ(L
"release.txt", testList
[0].GetGitOldPathString());
844 EXPECT_STREQ(L
"0", testList
[0].m_StatAdd
);
845 EXPECT_STREQ(L
"0", testList
[0].m_StatDel
);
846 EXPECT_EQ(0, testList
[0].m_Stage
);
847 EXPECT_FALSE(testList
[0].IsDirectory());
848 EXPECT_STREQ(L
"signedness.txt", testList
[1].GetGitPathString());
849 EXPECT_STREQ(L
"", testList
[1].GetGitOldPathString());
850 EXPECT_EQ(CTGitPath::LOGACTIONS_ADDED
, testList
[1].m_Action
);
851 EXPECT_STREQ(L
"1176", testList
[1].m_StatAdd
);
852 EXPECT_STREQ(L
"0", testList
[1].m_StatDel
);
853 EXPECT_EQ(0, testList
[1].m_Stage
);
854 EXPECT_FALSE(testList
[1].IsDirectory());
855 EXPECT_STREQ(L
"src/Debug-Hints.txt", testList
[2].GetGitPathString());
856 EXPECT_STREQ(L
"", testList
[2].GetGitOldPathString());
857 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[2].m_Action
);
858 EXPECT_STREQ(L
"0", testList
[2].m_StatAdd
);
859 EXPECT_STREQ(L
"74", testList
[2].m_StatDel
);
860 EXPECT_EQ(0, testList
[2].m_Stage
);
861 EXPECT_FALSE(testList
[2].IsDirectory());
862 EXPECT_STREQ(L
"src/gpl.txt", testList
[3].GetGitPathString());
863 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[3].m_Action
);
864 EXPECT_STREQ(L
"0", testList
[3].m_StatAdd
);
865 EXPECT_STREQ(L
"340", testList
[3].m_StatDel
);
866 EXPECT_EQ(0, testList
[3].m_Stage
);
867 EXPECT_FALSE(testList
[3].IsDirectory());
868 EXPECT_STREQ(L
"zzz-added-only-in-index-missing-on-fs.txt", testList
[4].GetGitPathString());
869 EXPECT_EQ(CTGitPath::LOGACTIONS_ADDED
, testList
[4].m_Action
);
870 EXPECT_STREQ(L
"1", testList
[4].m_StatAdd
);
871 EXPECT_STREQ(L
"0", testList
[4].m_StatDel
);
872 EXPECT_EQ(0, testList
[4].m_Stage
);
873 EXPECT_FALSE(testList
[4].IsDirectory());
874 EXPECT_STREQ(L
"build.txt", testList
[5].GetGitPathString());
875 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[5].m_Action
);
876 EXPECT_STREQ(L
"0", testList
[5].m_StatAdd
);
877 EXPECT_STREQ(L
"61", testList
[5].m_StatDel
);
878 EXPECT_EQ(0, testList
[5].m_Stage
);
879 EXPECT_FALSE(testList
[5].IsDirectory());
880 EXPECT_STREQ(L
"ext/apr", testList
[6].GetGitPathString());
881 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[6].m_Action
);
882 EXPECT_STREQ(L
"0", testList
[6].m_StatAdd
);
883 EXPECT_STREQ(L
"0", testList
[6].m_StatDel
);
884 EXPECT_EQ(0, testList
[6].m_Stage
);
885 EXPECT_TRUE(testList
[6].IsDirectory());
886 EXPECT_STREQ(L
"ext/apr-util", testList
[7].GetGitPathString());
887 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[7].m_Action
);
888 EXPECT_STREQ(L
"0", testList
[7].m_StatAdd
);
889 EXPECT_STREQ(L
"0", testList
[7].m_StatDel
);
890 EXPECT_EQ(0, testList
[7].m_Stage
);
891 EXPECT_TRUE(testList
[7].IsDirectory());
892 EXPECT_STREQ(L
"ext/libgit2", testList
[8].GetGitPathString());
893 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[8].m_Action
);
894 EXPECT_STREQ(L
"1", testList
[8].m_StatAdd
);
895 EXPECT_STREQ(L
"1", testList
[8].m_StatDel
);
896 EXPECT_EQ(0, testList
[8].m_Stage
);
897 EXPECT_TRUE(testList
[8].IsDirectory());
898 EXPECT_STREQ(L
"test/UnitTests/TGitPathTest.cpp", testList
[9].GetGitPathString());
899 EXPECT_STREQ(L
"", testList
[9].GetGitOldPathString());
900 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[9].m_Action
);
901 EXPECT_STREQ(L
"162", testList
[9].m_StatAdd
);
902 EXPECT_STREQ(L
"2", testList
[9].m_StatDel
);
903 EXPECT_EQ(0, testList
[9].m_Stage
);
904 EXPECT_FALSE(testList
[9].IsDirectory());
907 TEST(CTGitPath
, ParserFromLog_Diff_r_raw_C_M_numstat_z_HEAD
)
910 BYTE git_Diff_r_raw_C_M_numstat_z_HEAD_output
[] = { ":100644 000000 39bba2f... 0000000... D\0build.txt\0:160000 160000 6dcb218... 6dcb218... M\0ext/apr\0:160000 160000 ca83ff5... ca83ff5... M\0ext/apr-util\0:160000 160000 a291790... 0000000... M\0ext/libgit2\0:100644 100644 f523fd2... f523fd2... R100\0release.txt\0release-renamed.txt\0:000000 100644 0000000... 9c752c9... A\0signedness.txt\0:100644 000000 53b6e6c... 0000000... D\0src/Debug-Hints.txt\0:100644 000000 36488d5... 0000000... D\0src/gpl.txt\0:100644 100644 9a59162... 0000000... M\0test/UnitTests/TGitPathTest.cpp\0""0 61 build.txt\0""0 0 ext/apr\0""0 0 ext/apr-util\0""1 1 ext/libgit2\0""0 0 \0release.txt\0release-renamed.txt\0""1176 0 signedness.txt\0""0 74 src/Debug-Hints.txt\0""0 340 src/gpl.txt\0""162 2 test/UnitTests/TGitPathTest.cpp\0" };
911 CGitByteArray byteArray
;
912 byteArray
.append(git_Diff_r_raw_C_M_numstat_z_HEAD_output
, sizeof(git_Diff_r_raw_C_M_numstat_z_HEAD_output
));
913 CTGitPathList testList
;
914 EXPECT_EQ(0, testList
.ParserFromLog(byteArray
));
915 ASSERT_EQ(9, testList
.GetCount());
916 EXPECT_STREQ(L
"build.txt", testList
[0].GetGitPathString());
917 EXPECT_STREQ(L
"", testList
[0].GetGitOldPathString());
918 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[0].m_Action
);
919 EXPECT_STREQ(L
"0", testList
[0].m_StatAdd
);
920 EXPECT_STREQ(L
"61", testList
[0].m_StatDel
);
921 EXPECT_EQ(0, testList
[0].m_Stage
);
922 EXPECT_FALSE(testList
[0].IsDirectory());
923 EXPECT_STREQ(L
"ext/apr", testList
[1].GetGitPathString());
924 EXPECT_STREQ(L
"", testList
[1].GetGitOldPathString());
925 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[1].m_Action
);
926 EXPECT_STREQ(L
"0", testList
[1].m_StatAdd
);
927 EXPECT_STREQ(L
"0", testList
[1].m_StatDel
);
928 EXPECT_EQ(0, testList
[1].m_Stage
);
929 EXPECT_TRUE(testList
[1].IsDirectory());
930 EXPECT_STREQ(L
"ext/apr-util", testList
[2].GetGitPathString());
931 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[2].m_Action
);
932 EXPECT_STREQ(L
"0", testList
[2].m_StatAdd
);
933 EXPECT_STREQ(L
"0", testList
[2].m_StatDel
);
934 EXPECT_EQ(0, testList
[2].m_Stage
);
935 EXPECT_TRUE(testList
[2].IsDirectory());
936 EXPECT_STREQ(L
"ext/libgit2", testList
[3].GetGitPathString());
937 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[3].m_Action
);
938 EXPECT_STREQ(L
"1", testList
[3].m_StatAdd
);
939 EXPECT_STREQ(L
"1", testList
[3].m_StatDel
);
940 EXPECT_EQ(0, testList
[3].m_Stage
);
941 EXPECT_TRUE(testList
[3].IsDirectory());
942 EXPECT_STREQ(L
"release-renamed.txt", testList
[4].GetGitPathString());
943 EXPECT_EQ(CTGitPath::LOGACTIONS_REPLACED
, testList
[4].m_Action
);
944 EXPECT_STREQ(L
"0", testList
[4].m_StatAdd
);
945 EXPECT_STREQ(L
"0", testList
[4].m_StatDel
);
946 EXPECT_EQ(0, testList
[4].m_Stage
);
947 EXPECT_FALSE(testList
[4].IsDirectory());
948 EXPECT_STREQ(L
"release.txt", testList
[4].GetGitOldPathString());
949 EXPECT_STREQ(L
"signedness.txt", testList
[5].GetGitPathString());
950 EXPECT_EQ(CTGitPath::LOGACTIONS_ADDED
, testList
[5].m_Action
);
951 EXPECT_STREQ(L
"1176", testList
[5].m_StatAdd
);
952 EXPECT_STREQ(L
"0", testList
[5].m_StatDel
);
953 EXPECT_EQ(0, testList
[5].m_Stage
);
954 EXPECT_FALSE(testList
[5].IsDirectory());
955 EXPECT_STREQ(L
"src/Debug-Hints.txt", testList
[6].GetGitPathString());
956 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[6].m_Action
);
957 EXPECT_STREQ(L
"0", testList
[6].m_StatAdd
);
958 EXPECT_STREQ(L
"74", testList
[6].m_StatDel
);
959 EXPECT_EQ(0, testList
[6].m_Stage
);
960 EXPECT_FALSE(testList
[6].IsDirectory());
961 EXPECT_STREQ(L
"src/gpl.txt", testList
[7].GetGitPathString());
962 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[7].m_Action
);
963 EXPECT_STREQ(L
"0", testList
[7].m_StatAdd
);
964 EXPECT_STREQ(L
"340", testList
[7].m_StatDel
);
965 EXPECT_EQ(0, testList
[7].m_Stage
);
966 EXPECT_FALSE(testList
[7].IsDirectory());
967 EXPECT_STREQ(L
"test/UnitTests/TGitPathTest.cpp", testList
[8].GetGitPathString());
968 EXPECT_STREQ(L
"", testList
[8].GetGitOldPathString());
969 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[8].m_Action
);
970 EXPECT_STREQ(L
"162", testList
[8].m_StatAdd
);
971 EXPECT_STREQ(L
"2", testList
[8].m_StatDel
);
972 EXPECT_EQ(0, testList
[8].m_Stage
);
973 EXPECT_FALSE(testList
[8].IsDirectory());
976 TEST(CTGitPath
, ParserFromLog_DiffTree
)
978 // git.exe diff-tree -r --raw -C -M --numstat -z 8a75b51cc7f10b9755fc89837fe78b0c646b8b12~1 8a75b51cc7f10b9755fc89837fe78b0c646b8b12
979 BYTE git_difftree_output
[] = { ":100644 100644 748cb10e524d745ccd55bdeff67a00bed35144f5 d8899ee55a66b2bfa7f497bfef90e951d846de03 M\0src/Git/Git.cpp\0:100644 100644 ca24882eb4ef523381c2a179697d0f0e069c4f85 569c603dae424b8dda6726f8fb6157bd6e527d9a M\0src/Git/Git.h\0:100644 100644 575645aee2c712ee92f31b6a57d594297e2e5370 71bff876b3465c6eb621f3f3ecb0657e4a8764d7 M\0src/Git/Git.vcxproj\0:100644 100644 d5a11fbc6da73c8070a5359c78d45075fadba6eb 7284c5914b55eae97078df4a97f9ec791446133d M\0src/Git/Git.vcxproj.filters\0:100644 000000 c298e597d65a049782f03e197d654c01579b4990 0000000000000000000000000000000000000000 D\0src/Git/GitConfig.cpp\0:100644 100644 0667abe736182c63d2f2e6c0f29d85e1d9fd0775 a58a0cd9e08d9d849387fdfa2adfc3066cbb85df R081\0src/Git/GitConfig.h\0src/Git/GitForWindows.h\0:100644 100644 582db6c063e34903ee1348bdffbb48dfe484f8e4 ec5178786fcf587fdd6b19349d53c22f1dbcdfbe M\0src/Git/GitIndex.cpp\0:100644 100644 e4d6608dcb8fe635515f42ed9c9e6fdc1fc6c216 4c0e326cda7a479e02a650367561a8b79a3082f2 M\0src/TortoiseProc/Settings/SetMainPage.cpp\0:100644 100644 52aa2c94e5cfa9a5287c84b20687b3365836f1f8 7eb74479bbc3a2e2089a5d32acdd915aacc0f40b M\0src/TortoiseProc/TortoiseProc.cpp\0""1 1 src/Git/Git.cpp\0""3 0 src/Git/Git.h\0""0 2 src/Git/Git.vcxproj\0""0 6 src/Git/Git.vcxproj.filters\0""0 29 src/Git/GitConfig.cpp\0""1 11 \0src/Git/GitConfig.h\0src/Git/GitForWindows.h\0""0 1 src/Git/GitIndex.cpp\0""1 1 src/TortoiseProc/Settings/SetMainPage.cpp\0""0 1 src/TortoiseProc/TortoiseProc.cpp\0" };
980 CGitByteArray byteArray
;
981 byteArray
.append(git_difftree_output
, sizeof(git_difftree_output
));
982 CTGitPathList testList
;
983 EXPECT_EQ(0, testList
.ParserFromLog(byteArray
));
984 ASSERT_EQ(9, testList
.GetCount());
985 EXPECT_STREQ(L
"src/Git/Git.cpp", testList
[0].GetGitPathString());
986 EXPECT_STREQ(L
"", testList
[0].GetGitOldPathString());
987 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[0].m_Action
);
988 EXPECT_STREQ(L
"1", testList
[0].m_StatAdd
);
989 EXPECT_STREQ(L
"1", testList
[0].m_StatDel
);
990 EXPECT_EQ(0, testList
[0].m_Stage
);
991 EXPECT_FALSE(testList
[0].IsDirectory());
992 EXPECT_STREQ(L
"src/Git/Git.h", testList
[1].GetGitPathString());
993 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[1].m_Action
);
994 EXPECT_STREQ(L
"3", testList
[1].m_StatAdd
);
995 EXPECT_STREQ(L
"0", testList
[1].m_StatDel
);
996 EXPECT_EQ(0, testList
[1].m_Stage
);
997 EXPECT_FALSE(testList
[1].IsDirectory());
998 EXPECT_STREQ(L
"src/Git/Git.vcxproj", testList
[2].GetGitPathString());
999 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[2].m_Action
);
1000 EXPECT_STREQ(L
"0", testList
[2].m_StatAdd
);
1001 EXPECT_STREQ(L
"2", testList
[2].m_StatDel
);
1002 EXPECT_EQ(0, testList
[2].m_Stage
);
1003 EXPECT_FALSE(testList
[2].IsDirectory());
1004 EXPECT_STREQ(L
"src/Git/Git.vcxproj.filters", testList
[3].GetGitPathString());
1005 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[3].m_Action
);
1006 EXPECT_STREQ(L
"0", testList
[3].m_StatAdd
);
1007 EXPECT_STREQ(L
"6", testList
[3].m_StatDel
);
1008 EXPECT_EQ(0, testList
[3].m_Stage
);
1009 EXPECT_FALSE(testList
[3].IsDirectory());
1010 EXPECT_STREQ(L
"src/Git/GitConfig.cpp", testList
[4].GetGitPathString());
1011 EXPECT_STREQ(L
"", testList
[4].GetGitOldPathString());
1012 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[4].m_Action
);
1013 EXPECT_STREQ(L
"0", testList
[4].m_StatAdd
);
1014 EXPECT_STREQ(L
"29", testList
[4].m_StatDel
);
1015 EXPECT_EQ(0, testList
[4].m_Stage
);
1016 EXPECT_FALSE(testList
[4].IsDirectory());
1017 EXPECT_STREQ(L
"src/Git/GitForWindows.h", testList
[5].GetGitPathString());
1018 EXPECT_EQ(CTGitPath::LOGACTIONS_REPLACED
, testList
[5].m_Action
);
1019 EXPECT_STREQ(L
"src/Git/GitConfig.h", testList
[5].GetGitOldPathString());
1020 EXPECT_STREQ(L
"1", testList
[5].m_StatAdd
);
1021 EXPECT_STREQ(L
"11", testList
[5].m_StatDel
);
1022 EXPECT_EQ(0, testList
[5].m_Stage
);
1023 EXPECT_FALSE(testList
[5].IsDirectory());
1024 EXPECT_STREQ(L
"src/Git/GitIndex.cpp", testList
[6].GetGitPathString());
1025 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[6].m_Action
);
1026 EXPECT_STREQ(L
"0", testList
[6].m_StatAdd
);
1027 EXPECT_STREQ(L
"1", testList
[6].m_StatDel
);
1028 EXPECT_EQ(0, testList
[6].m_Stage
);
1029 EXPECT_FALSE(testList
[6].IsDirectory());
1030 EXPECT_STREQ(L
"src/TortoiseProc/Settings/SetMainPage.cpp", testList
[7].GetGitPathString());
1031 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[7].m_Action
);
1032 EXPECT_STREQ(L
"1", testList
[7].m_StatAdd
);
1033 EXPECT_STREQ(L
"1", testList
[7].m_StatDel
);
1034 EXPECT_EQ(0, testList
[7].m_Stage
);
1035 EXPECT_FALSE(testList
[7].IsDirectory());
1036 EXPECT_STREQ(L
"src/TortoiseProc/TortoiseProc.cpp", testList
[8].GetGitPathString());
1037 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[8].m_Action
);
1038 EXPECT_STREQ(L
"0", testList
[8].m_StatAdd
);
1039 EXPECT_STREQ(L
"1", testList
[8].m_StatDel
);
1040 EXPECT_EQ(0, testList
[8].m_Stage
);
1041 EXPECT_FALSE(testList
[8].IsDirectory());
1044 TEST(CTGitPath
, ParserFromLog_DiffTree_Submodule
)
1046 // git.exe diff-tree -r --raw -C -M --numstat -z b299da8c23c6258faaf7258ab23fd3e3da971efa~1 b299da8c23c6258faaf7258ab23fd3e3da971efa --
1047 BYTE git_difftree_output
[] = { ":100644 100644 06c316bd39ea34a10bc069e6cdfac0a3513e7f3c 2ef08cd1cd3b365de242114e66790968534e4588 M\0.gitmodules\0:100644 100644 714bfa6587240be5af0aea261871becbf071da77 0652d174054ee07d457bfdd3dd81ffc65b179852 M\0appveyor.yml\0:100644 100644 5cf50b0900b7754658bc545ea70935d821ba7181 21cb193e2b064cd0b998cd3d568f77f2681a3497 R082\0ext/build/gtest.vcxproj\0ext/build/googletest.vcxproj\0:100644 100644 48992d1ca6d569e6b909c0f914b547dcfd11d695 9addb288e4b4ca5ecf942bcb4e5761093c6dd3a1 R075\0ext/build/gtest.vcxproj.filters\0ext/build/googletest.vcxproj.filters\0:160000 000000 0421b6f358139f02e102c9c332ce19a33faf75be 0000000000000000000000000000000000000000 D\0ext/gmock\0:000000 160000 0000000000000000000000000000000000000000 a2b8a8e07628e5fd60644b6dd99c1b5e7d7f1f47 A\0ext/googletest\0:160000 000000 86dec5c00225b34a0061127e5cc35b6cf1485b79 0000000000000000000000000000000000000000 D\0ext/gtest\0:100644 100644 5170beb2d475f7fad8f6fc43e4c1c77d490067c1 9f24e5fa5488635c15744b048f554ceb9fc9ac46 M\0src/TortoiseGit.sln\0:100644 100644 405bfa8909480496e1024f99b70823e5452b40f3 48fa98e71d415f1b7d775a2f023a75552b8c74a9 M\0test/UnitTests/UnitTests.vcxproj\0""3 6 .gitmodules\0""1 1 appveyor.yml\0""4 4 \0ext/build/gtest.vcxproj\0ext/build/googletest.vcxproj\0""3 3 \0ext/build/gtest.vcxproj.filters\0ext/build/googletest.vcxproj.filters\0""0 1 ext/gmock\0""1 0 ext/googletest\0""0 1 ext/gtest\0""1 1 src/TortoiseGit.sln\0""2 2 test/UnitTests/UnitTests.vcxproj\0" };
1048 CGitByteArray byteArray
;
1049 byteArray
.append(git_difftree_output
, sizeof(git_difftree_output
));
1050 CTGitPathList testList
;
1051 EXPECT_EQ(0, testList
.ParserFromLog(byteArray
));
1052 ASSERT_EQ(9, testList
.GetCount());
1053 EXPECT_STREQ(L
".gitmodules", testList
[0].GetGitPathString());
1054 EXPECT_STREQ(L
"", testList
[0].GetGitOldPathString());
1055 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[0].m_Action
);
1056 EXPECT_STREQ(L
"3", testList
[0].m_StatAdd
);
1057 EXPECT_STREQ(L
"6", testList
[0].m_StatDel
);
1058 EXPECT_EQ(0, testList
[0].m_Stage
);
1059 EXPECT_FALSE(testList
[0].IsDirectory());
1060 EXPECT_STREQ(L
"appveyor.yml", testList
[1].GetGitPathString());
1061 EXPECT_STREQ(L
"", testList
[1].GetGitOldPathString());
1062 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[1].m_Action
);
1063 EXPECT_STREQ(L
"1", testList
[1].m_StatAdd
);
1064 EXPECT_STREQ(L
"1", testList
[1].m_StatDel
);
1065 EXPECT_EQ(0, testList
[1].m_Stage
);
1066 EXPECT_FALSE(testList
[1].IsDirectory());
1067 EXPECT_STREQ(L
"ext/build/googletest.vcxproj", testList
[2].GetGitPathString());
1068 EXPECT_STREQ(L
"ext/build/gtest.vcxproj", testList
[2].GetGitOldPathString());
1069 EXPECT_EQ(CTGitPath::LOGACTIONS_REPLACED
, testList
[2].m_Action
); // TODO: CTGitPath::LOGACTIONS_MODIFIED?, LOGACTIONS_MODIFIED has highter precedence in CTGitPath::GetActionName
1070 EXPECT_STREQ(L
"4", testList
[2].m_StatAdd
);
1071 EXPECT_STREQ(L
"4", testList
[2].m_StatDel
);
1072 EXPECT_EQ(0, testList
[2].m_Stage
);
1073 EXPECT_FALSE(testList
[2].IsDirectory());
1074 EXPECT_STREQ(L
"ext/build/googletest.vcxproj.filters", testList
[3].GetGitPathString());
1075 EXPECT_STREQ(L
"ext/build/gtest.vcxproj.filters", testList
[3].GetGitOldPathString());
1076 EXPECT_EQ(CTGitPath::LOGACTIONS_REPLACED
, testList
[3].m_Action
); // TODO: CTGitPath::LOGACTIONS_MODIFIED?, LOGACTIONS_MODIFIED has highter precedence in CTGitPath::GetActionName
1077 EXPECT_STREQ(L
"3", testList
[3].m_StatAdd
);
1078 EXPECT_STREQ(L
"3", testList
[3].m_StatDel
);
1079 EXPECT_EQ(0, testList
[3].m_Stage
);
1080 EXPECT_FALSE(testList
[3].IsDirectory());
1081 EXPECT_STREQ(L
"ext/gmock", testList
[4].GetGitPathString());
1082 EXPECT_STREQ(L
"", testList
[4].GetGitOldPathString());
1083 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[4].m_Action
);
1084 EXPECT_STREQ(L
"0", testList
[4].m_StatAdd
);
1085 EXPECT_STREQ(L
"1", testList
[4].m_StatDel
);
1086 EXPECT_EQ(0, testList
[4].m_Stage
);
1087 EXPECT_TRUE(testList
[4].IsDirectory());
1088 EXPECT_STREQ(L
"ext/googletest", testList
[5].GetGitPathString());
1089 EXPECT_STREQ(L
"", testList
[5].GetGitOldPathString());
1090 EXPECT_EQ(CTGitPath::LOGACTIONS_ADDED
, testList
[5].m_Action
);
1091 EXPECT_STREQ(L
"1", testList
[5].m_StatAdd
);
1092 EXPECT_STREQ(L
"0", testList
[5].m_StatDel
);
1093 EXPECT_EQ(0, testList
[5].m_Stage
);
1094 EXPECT_TRUE(testList
[5].IsDirectory());
1095 EXPECT_STREQ(L
"ext/gtest", testList
[6].GetGitPathString());
1096 EXPECT_STREQ(L
"", testList
[6].GetGitOldPathString());
1097 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[6].m_Action
);
1098 EXPECT_STREQ(L
"0", testList
[6].m_StatAdd
);
1099 EXPECT_STREQ(L
"1", testList
[6].m_StatDel
);
1100 EXPECT_EQ(0, testList
[6].m_Stage
);
1101 EXPECT_TRUE(testList
[6].IsDirectory());
1102 EXPECT_STREQ(L
"src/TortoiseGit.sln", testList
[7].GetGitPathString());
1103 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[7].m_Action
);
1104 EXPECT_STREQ(L
"1", testList
[7].m_StatAdd
);
1105 EXPECT_STREQ(L
"1", testList
[7].m_StatDel
);
1106 EXPECT_EQ(0, testList
[7].m_Stage
);
1107 EXPECT_FALSE(testList
[7].IsDirectory());
1108 EXPECT_STREQ(L
"test/UnitTests/UnitTests.vcxproj", testList
[8].GetGitPathString());
1109 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[8].m_Action
);
1110 EXPECT_STREQ(L
"2", testList
[8].m_StatAdd
);
1111 EXPECT_STREQ(L
"2", testList
[8].m_StatDel
);
1112 EXPECT_EQ(0, testList
[8].m_Stage
);
1113 EXPECT_FALSE(testList
[8].IsDirectory());
1116 static void setFlagOnFileInIndex(CAutoIndex
& gitindex
, const CString
& filename
, bool assumevalid
, bool skipworktree
)
1119 EXPECT_TRUE(git_index_find(&idx
, gitindex
, CUnicodeUtils::GetUTF8(filename
)) == 0);
1120 git_index_entry
*e
= const_cast<git_index_entry
*>(git_index_get_byindex(gitindex
, idx
));
1122 if (assumevalid
== BST_UNCHECKED
)
1123 e
->flags
&= ~GIT_IDXENTRY_VALID
;
1124 else if (assumevalid
== BST_CHECKED
)
1125 e
->flags
|= GIT_IDXENTRY_VALID
;
1126 if (skipworktree
== BST_UNCHECKED
)
1127 e
->flags_extended
&= ~GIT_IDXENTRY_SKIP_WORKTREE
;
1128 else if (skipworktree
== BST_CHECKED
)
1129 e
->flags_extended
|= GIT_IDXENTRY_SKIP_WORKTREE
;
1130 EXPECT_TRUE(git_index_add(gitindex
, e
) == 0);
1133 TEST(CTGitPath
, FillBasedOnIndexFlags
)
1135 CAutoTempDir tmpDir
;
1138 CAutoRepository repo
;
1139 EXPECT_TRUE(git_repository_init(repo
.GetPointer(), CUnicodeUtils::GetUTF8(tmpDir
.GetTempDir()), 0) == 0);
1141 ASSERT_TRUE(CreateDirectory(tmpDir
.GetTempDir() + L
"\\a", nullptr));
1142 ASSERT_TRUE(CreateDirectory(tmpDir
.GetTempDir() + L
"\\b", nullptr));
1144 CAutoIndex gitindex
;
1145 EXPECT_TRUE(git_repository_index(gitindex
.GetPointer(), repo
) == 0);
1147 CString filenames
[] = { L
"versioned", L
"assume-unchanged", L
"skip-worktree", L
"unversioned", L
"a/versioned", L
"a/assume-unchanged", L
"a/skip-worktree", L
"a/unversioned", L
"b/versioned", L
"b/assume-unchanged", L
"b/skip-worktree", L
"b/unversioned" };
1148 for (const CString
& filename
: filenames
)
1150 CString filenameWithPath
= tmpDir
.GetTempDir() + L
'\\' + filename
;
1151 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(filenameWithPath
, L
"something"));
1152 EXPECT_TRUE(git_index_add_bypath(gitindex
, CUnicodeUtils::GetUTF8(filename
)) == 0);
1155 setFlagOnFileInIndex(gitindex
, L
"assume-unchanged", true, false);
1156 setFlagOnFileInIndex(gitindex
, L
"a/assume-unchanged", true, false);
1157 setFlagOnFileInIndex(gitindex
, L
"b/assume-unchanged", true, false);
1158 setFlagOnFileInIndex(gitindex
, L
"skip-worktree", false, true);
1159 setFlagOnFileInIndex(gitindex
, L
"a/skip-worktree", false, true);
1160 setFlagOnFileInIndex(gitindex
, L
"b/skip-worktree", false, true);
1162 EXPECT_TRUE(git_index_write(gitindex
) == 0);
1166 g_Git
.m_CurrentDir
= tmpDir
.GetTempDir();
1168 CTGitPathList testList
;
1169 EXPECT_TRUE(testList
.FillBasedOnIndexFlags(0, 0) == 0);
1170 EXPECT_EQ(0, testList
.GetCount());
1173 EXPECT_TRUE(testList
.FillBasedOnIndexFlags(GIT_IDXENTRY_VALID
, 0) == 0);
1174 EXPECT_EQ(3, testList
.GetCount());
1175 EXPECT_STREQ(L
"a/assume-unchanged", testList
[0].GetGitPathString());
1176 EXPECT_STREQ(L
"assume-unchanged", testList
[1].GetGitPathString());
1177 EXPECT_STREQ(L
"b/assume-unchanged", testList
[2].GetGitPathString());
1180 EXPECT_TRUE(testList
.FillBasedOnIndexFlags(0, GIT_IDXENTRY_SKIP_WORKTREE
) == 0);
1181 EXPECT_EQ(3, testList
.GetCount());
1182 EXPECT_STREQ(L
"a/skip-worktree", testList
[0].GetGitPathString());
1183 EXPECT_STREQ(L
"b/skip-worktree", testList
[1].GetGitPathString());
1184 EXPECT_STREQ(L
"skip-worktree", testList
[2].GetGitPathString());
1187 EXPECT_TRUE(testList
.FillBasedOnIndexFlags(GIT_IDXENTRY_VALID
, GIT_IDXENTRY_SKIP_WORKTREE
) == 0);
1188 EXPECT_EQ(6, testList
.GetCount());
1189 EXPECT_STREQ(L
"a/assume-unchanged", testList
[0].GetGitPathString());
1190 EXPECT_STREQ(L
"a/skip-worktree", testList
[1].GetGitPathString());
1191 EXPECT_STREQ(L
"assume-unchanged", testList
[2].GetGitPathString());
1192 EXPECT_STREQ(L
"b/assume-unchanged", testList
[3].GetGitPathString());
1193 EXPECT_STREQ(L
"b/skip-worktree", testList
[4].GetGitPathString());
1194 EXPECT_STREQ(L
"skip-worktree", testList
[5].GetGitPathString());
1196 CTGitPathList selectList
;
1197 selectList
.AddPath(CTGitPath(L
"versioned"));
1198 selectList
.AddPath(CTGitPath(L
"assume-unchanged"));
1199 selectList
.AddPath(CTGitPath(L
"skip-worktree"));
1200 selectList
.AddPath(CTGitPath(L
"a/skip-worktree"));
1201 EXPECT_TRUE(testList
.FillBasedOnIndexFlags(GIT_IDXENTRY_VALID
, GIT_IDXENTRY_SKIP_WORKTREE
, &selectList
) == 0);
1202 EXPECT_EQ(3, testList
.GetCount());
1203 EXPECT_STREQ(L
"a/skip-worktree", testList
[0].GetGitPathString());
1204 EXPECT_STREQ(L
"assume-unchanged", testList
[1].GetGitPathString());
1205 EXPECT_STREQ(L
"skip-worktree", testList
[2].GetGitPathString());
1208 selectList
.AddPath(CTGitPath(L
"a"));
1209 EXPECT_TRUE(testList
.FillBasedOnIndexFlags(GIT_IDXENTRY_VALID
, GIT_IDXENTRY_SKIP_WORKTREE
, &selectList
) == 0);
1210 EXPECT_EQ(2, testList
.GetCount());
1211 EXPECT_STREQ(L
"a/assume-unchanged", testList
[0].GetGitPathString());
1212 EXPECT_STREQ(L
"a/skip-worktree", testList
[1].GetGitPathString());
1215 selectList
.AddPath(CTGitPath(L
"a"));
1216 EXPECT_TRUE(testList
.FillBasedOnIndexFlags(GIT_IDXENTRY_VALID
, 0, &selectList
) == 0);
1217 EXPECT_EQ(1, testList
.GetCount());
1218 EXPECT_STREQ(L
"a/assume-unchanged", testList
[0].GetGitPathString());
1221 TEST(CTGitPath
, ParserFromLsFile_Empty
)
1223 CGitByteArray byteArray
;
1224 CTGitPathList testList
;
1225 EXPECT_EQ(0, testList
.ParserFromLsFile(byteArray
));
1226 EXPECT_EQ(0, testList
.GetCount());
1229 TEST(CTGitPath
, ParserFromLsFile_SingleFileConflict
)
1231 BYTE git_ls_file_u_t_z_output
[] = { "M 100644 1f9f46da1ee155aa765d6e379d9d19853358cb07 1 bla.txt\0M 100644 3aa011e7d3609ab9af90c4b10f616312d2be422f 2 bla.txt\0M 100644 56d252d69d535834b9fbfa6f6a633ecd505ea2e6 3 bla.txt\0" };
1232 CGitByteArray byteArray
;
1233 byteArray
.append(git_ls_file_u_t_z_output
, sizeof(git_ls_file_u_t_z_output
));
1234 CTGitPathList testList
;
1235 EXPECT_EQ(0, testList
.ParserFromLsFile(byteArray
));
1236 EXPECT_EQ(3, testList
.GetCount());
1237 EXPECT_STREQ(L
"bla.txt", testList
[0].GetGitPathString());
1238 EXPECT_STREQ(L
"bla.txt", testList
[1].GetGitPathString());
1239 EXPECT_STREQ(L
"bla.txt", testList
[2].GetGitPathString());
1240 EXPECT_STREQ(L
"", testList
[0].GetGitOldPathString());
1241 EXPECT_STREQ(L
"", testList
[1].GetGitOldPathString());
1242 EXPECT_STREQ(L
"", testList
[2].GetGitOldPathString());
1243 EXPECT_EQ(1, testList
[0].m_Stage
);
1244 EXPECT_EQ(2, testList
[1].m_Stage
);
1245 EXPECT_EQ(3, testList
[2].m_Stage
);
1246 EXPECT_EQ(0U, testList
[0].m_Action
);
1247 EXPECT_EQ(0U, testList
[1].m_Action
);
1248 EXPECT_EQ(0U, testList
[2].m_Action
);
1249 EXPECT_FALSE(testList
[0].IsDirectory());
1250 EXPECT_FALSE(testList
[1].IsDirectory());
1251 EXPECT_FALSE(testList
[2].IsDirectory());
1254 TEST(CTGitPath
, ParserFromLsFile_SubmoduleConflict_Simple
)
1256 BYTE git_ls_files_u_t_z_output
[] = { "M 160000 46a2b8e855d5f6d8b60b81500a9f6779c7f63e63 1 libgit2\0M 160000 533da4ea00703f4ad6d5518e1ce81d20261c40c0 2 libgit2\0M 160000 ab2af775ec467ebb328a7374653f247920f258f3 3 libgit2\0" };
1257 CGitByteArray byteArray
;
1258 byteArray
.append(git_ls_files_u_t_z_output
, sizeof(git_ls_files_u_t_z_output
));
1259 CTGitPathList testList
;
1260 EXPECT_EQ(0, testList
.ParserFromLsFile(byteArray
));
1261 ASSERT_EQ(3, testList
.GetCount());
1262 EXPECT_STREQ(L
"libgit2", testList
[0].GetGitPathString());
1263 EXPECT_STREQ(L
"libgit2", testList
[1].GetGitPathString());
1264 EXPECT_STREQ(L
"libgit2", testList
[2].GetGitPathString());
1265 EXPECT_STREQ(L
"", testList
[0].GetGitOldPathString());
1266 EXPECT_STREQ(L
"", testList
[1].GetGitOldPathString());
1267 EXPECT_STREQ(L
"", testList
[2].GetGitOldPathString());
1268 EXPECT_EQ(1, testList
[0].m_Stage
);
1269 EXPECT_EQ(2, testList
[1].m_Stage
);
1270 EXPECT_EQ(3, testList
[2].m_Stage
);
1271 EXPECT_EQ(0U, testList
[0].m_Action
);
1272 EXPECT_EQ(0U, testList
[1].m_Action
);
1273 EXPECT_EQ(0U, testList
[2].m_Action
);
1274 EXPECT_TRUE(testList
[0].IsDirectory());
1275 EXPECT_TRUE(testList
[1].IsDirectory());
1276 EXPECT_TRUE(testList
[2].IsDirectory());
1279 TEST(CTGitPath
, ParserFromLsFile_SubmoduleConflict_DeletedModified
)
1281 // merged commit where submodule was modified into commit where it was deleted (git status says "deleted by us: libgit2")
1282 BYTE git_ls_files_u_t_z_output
[] = { "M 160000 46a2b8e855d5f6d8b60b81500a9f6779c7f63e63 1 libgit2\0M 160000 ab2af775ec467ebb328a7374653f247920f258f3 3 libgit2\0" };
1283 CGitByteArray byteArray
;
1284 byteArray
.append(git_ls_files_u_t_z_output
, sizeof(git_ls_files_u_t_z_output
));
1285 CTGitPathList testList
;
1286 EXPECT_EQ(0, testList
.ParserFromLsFile(byteArray
));
1287 ASSERT_EQ(2, testList
.GetCount());
1288 EXPECT_STREQ(L
"libgit2", testList
[0].GetGitPathString());
1289 EXPECT_STREQ(L
"libgit2", testList
[1].GetGitPathString());
1290 EXPECT_STREQ(L
"", testList
[0].GetGitOldPathString());
1291 EXPECT_STREQ(L
"", testList
[1].GetGitOldPathString());
1292 EXPECT_EQ(1, testList
[0].m_Stage
);
1293 EXPECT_EQ(3, testList
[1].m_Stage
);
1294 EXPECT_EQ(0U, testList
[0].m_Action
);
1295 EXPECT_EQ(0U, testList
[1].m_Action
);
1296 EXPECT_TRUE(testList
[0].IsDirectory());
1297 EXPECT_TRUE(testList
[1].IsDirectory());
1300 TEST(CTGitPath
, ParserFromLsFile_SubmoduleConflict_ToNormalDir
)
1302 // merged commit where libgit2 is a normal folder (git status says "added by us: libgit2" and "new file: libgit2/Neues Textdokument.txt")
1303 BYTE git_ls_files_u_t_z_output
[] = { "M 160000 533da4ea00703f4ad6d5518e1ce81d20261c40c0 2 libgit2\0" };
1304 CGitByteArray byteArray
;
1305 byteArray
.append(git_ls_files_u_t_z_output
, sizeof(git_ls_files_u_t_z_output
));
1306 CTGitPathList testList
;
1307 EXPECT_EQ(0, testList
.ParserFromLsFile(byteArray
));
1308 ASSERT_EQ(1, testList
.GetCount());
1309 EXPECT_STREQ(L
"libgit2", testList
[0].GetGitPathString());
1310 EXPECT_STREQ(L
"", testList
[0].GetGitOldPathString());
1311 EXPECT_EQ(2, testList
[0].m_Stage
);
1312 EXPECT_EQ(0U, testList
[0].m_Action
);
1313 EXPECT_TRUE(testList
[0].IsDirectory());
1316 TEST(CTGitPath
, ParserFromLsFile_SubmoduleConflict_FileSubmodule
)
1318 // merged commit where a file with the same name was created (git status says "both added: libgit2")
1319 BYTE git_ls_files_u_t_z_output
[] = { "M 160000 533da4ea00703f4ad6d5518e1ce81d20261c40c0 2 libgit2\0M 100644 9ae3e601584cc03f8f03f93761416b6599ac7c0d 3 libgit2\0" };
1320 CGitByteArray byteArray
;
1321 byteArray
.append(git_ls_files_u_t_z_output
, sizeof(git_ls_files_u_t_z_output
));
1322 CTGitPathList testList
;
1323 EXPECT_EQ(0, testList
.ParserFromLsFile(byteArray
));
1324 ASSERT_EQ(2, testList
.GetCount());
1325 EXPECT_STREQ(L
"libgit2", testList
[0].GetGitPathString());
1326 EXPECT_STREQ(L
"libgit2", testList
[1].GetGitPathString());
1327 EXPECT_STREQ(L
"", testList
[0].GetGitOldPathString());
1328 EXPECT_STREQ(L
"", testList
[1].GetGitOldPathString());
1329 EXPECT_EQ(2, testList
[0].m_Stage
);
1330 EXPECT_EQ(3, testList
[1].m_Stage
);
1331 EXPECT_EQ(0U, testList
[0].m_Action
);
1332 EXPECT_EQ(0U, testList
[1].m_Action
);
1333 EXPECT_TRUE(testList
[0].IsDirectory());
1334 EXPECT_FALSE(testList
[1].IsDirectory());
1337 TEST(CTGitPath
, ParserFromLsFile_DeletedFileConflict
)
1339 // file added, modified on branch A, deleted on branch B, merge branch A on B (git status says: "deleted by us")
1340 BYTE git_ls_file_u_t_z_output
[] = { "M 100644 24091f0add7afc47ac7cdc80ae4d3866b2ef588c 1 Neues Textdokument.txt\0M 100644 293b6f6293106b6ebb5d54ad482d7561b0f1c9ae 3 Neues Textdokument.txt\0" };
1341 CGitByteArray byteArray
;
1342 byteArray
.append(git_ls_file_u_t_z_output
, sizeof(git_ls_file_u_t_z_output
));
1343 CTGitPathList testList
;
1344 EXPECT_EQ(0, testList
.ParserFromLsFile(byteArray
));
1345 EXPECT_EQ(2, testList
.GetCount());
1346 EXPECT_STREQ(L
"Neues Textdokument.txt", testList
[0].GetGitPathString());
1347 EXPECT_STREQ(L
"Neues Textdokument.txt", testList
[1].GetGitPathString());
1348 EXPECT_STREQ(L
"", testList
[0].GetGitOldPathString());
1349 EXPECT_STREQ(L
"", testList
[1].GetGitOldPathString());
1350 EXPECT_EQ(1, testList
[0].m_Stage
);
1351 EXPECT_EQ(3, testList
[1].m_Stage
);
1352 EXPECT_EQ(0U, testList
[0].m_Action
);
1353 EXPECT_EQ(0U, testList
[1].m_Action
);
1354 EXPECT_FALSE(testList
[0].IsDirectory());
1355 EXPECT_FALSE(testList
[1].IsDirectory());
1358 TEST(CTGitPath
, ParserFromLsFile_MultipleFilesConflict
)
1360 BYTE git_ls_file_u_t_z_output
[] = { "M 100644 0ead9277724fc163fe64e1163cc2ff97d5670e41 1 OSMtracker.sln\0M 100644 7a8a41c7c26d259caba707adea36a8b9ae493c97 2 OSMtracker.sln\0M 100644 dcdd1c25bb0ebfd91082b3de5bd45d3f25418027 3 OSMtracker.sln\0M 100644 cbb00533d69b53e40a97f9bcf1c507a71f3c7353 1 OSMtracker/frmMain.vb\0M 100644 1cbfa36fef1af473884ad2e5820075b581fe33af 2 OSMtracker/frmMain.vb\0M 100644 337331224f438f5f49d5e8a4d4c1bafb66f2e67d 3 OSMtracker/frmMain.vb\0M 100644 786e60a550be11ef8e321222ffe6c0fa0f51f23d 1 OSMtracker/osmTileMap.vb\0M 100644 7fe8b75f56cf0202b4640d74d46240d2ba894115 2 OSMtracker/osmTileMap.vb\0M 100644 53d75915e78d0a53ba05c124d613fd75d625c142 3 OSMtracker/osmTileMap.vb\0" };
1361 CGitByteArray byteArray
;
1362 byteArray
.append(git_ls_file_u_t_z_output
, sizeof(git_ls_file_u_t_z_output
));
1363 CTGitPathList testList
;
1364 EXPECT_EQ(0, testList
.ParserFromLsFile(byteArray
));
1365 EXPECT_EQ(3 * 3, testList
.GetCount()); // 3 files are conflicted with 3 stages
1366 EXPECT_STREQ(L
"OSMtracker.sln", testList
[0].GetGitPathString());
1367 EXPECT_STREQ(L
"OSMtracker.sln", testList
[1].GetGitPathString());
1368 EXPECT_STREQ(L
"OSMtracker.sln", testList
[2].GetGitPathString());
1369 EXPECT_STREQ(L
"OSMtracker/frmMain.vb", testList
[3].GetGitPathString());
1370 EXPECT_STREQ(L
"OSMtracker/frmMain.vb", testList
[4].GetGitPathString());
1371 EXPECT_STREQ(L
"OSMtracker/frmMain.vb", testList
[5].GetGitPathString());
1372 EXPECT_STREQ(L
"OSMtracker/osmTileMap.vb", testList
[6].GetGitPathString());
1373 EXPECT_STREQ(L
"OSMtracker/osmTileMap.vb", testList
[7].GetGitPathString());
1374 EXPECT_STREQ(L
"OSMtracker/osmTileMap.vb", testList
[8].GetGitPathString());
1375 EXPECT_EQ(1, testList
[0].m_Stage
);
1376 EXPECT_EQ(2, testList
[1].m_Stage
);
1377 EXPECT_EQ(3, testList
[2].m_Stage
);
1378 EXPECT_EQ(1, testList
[3].m_Stage
);
1379 EXPECT_EQ(2, testList
[4].m_Stage
);
1380 EXPECT_EQ(3, testList
[5].m_Stage
);
1381 EXPECT_EQ(1, testList
[6].m_Stage
);
1382 EXPECT_EQ(2, testList
[7].m_Stage
);
1383 EXPECT_EQ(3, testList
[8].m_Stage
);
1384 EXPECT_EQ(0U, testList
[0].m_Action
);
1385 EXPECT_EQ(0U, testList
[1].m_Action
);
1386 EXPECT_EQ(0U, testList
[2].m_Action
);
1387 EXPECT_EQ(0U, testList
[3].m_Action
);
1388 EXPECT_EQ(0U, testList
[4].m_Action
);
1389 EXPECT_EQ(0U, testList
[5].m_Action
);
1390 EXPECT_EQ(0U, testList
[6].m_Action
);
1391 EXPECT_EQ(0U, testList
[7].m_Action
);
1392 EXPECT_EQ(0U, testList
[8].m_Action
);
1393 EXPECT_FALSE(testList
[0].IsDirectory());
1394 EXPECT_FALSE(testList
[1].IsDirectory());
1395 EXPECT_FALSE(testList
[2].IsDirectory());
1396 EXPECT_FALSE(testList
[3].IsDirectory());
1397 EXPECT_FALSE(testList
[4].IsDirectory());
1398 EXPECT_FALSE(testList
[5].IsDirectory());
1399 EXPECT_FALSE(testList
[6].IsDirectory());
1400 EXPECT_FALSE(testList
[7].IsDirectory());
1401 EXPECT_FALSE(testList
[8].IsDirectory());
1404 TEST(CTGitPath
, ParserFromLsFile_NormalRepo
)
1406 BYTE git_ls_file_u_t_z_output
[] = { "H 100644 73aea48a4ede6d3ca43bc3273c52e81a5d739447 0 README.md\0H 100644 e2780959232e32e0cce8c1866d36b04db85481a6 0 taskxml.xsd\0H 100644 49aa0e1b2e9fcd752767863a1208ad5b5afb254f 0 whitepaper.md\0" };
1407 CGitByteArray byteArray
;
1408 byteArray
.append(git_ls_file_u_t_z_output
, sizeof(git_ls_file_u_t_z_output
));
1409 CTGitPathList testList
;
1410 EXPECT_EQ(0, testList
.ParserFromLsFile(byteArray
));
1411 EXPECT_EQ(3, testList
.GetCount());
1412 EXPECT_STREQ(L
"README.md", testList
[0].GetGitPathString());
1413 EXPECT_STREQ(L
"taskxml.xsd", testList
[1].GetGitPathString());
1414 EXPECT_STREQ(L
"whitepaper.md", testList
[2].GetGitPathString());
1415 EXPECT_STREQ(L
"", testList
[0].GetGitOldPathString());
1416 EXPECT_STREQ(L
"", testList
[1].GetGitOldPathString());
1417 EXPECT_STREQ(L
"", testList
[2].GetGitOldPathString());
1418 EXPECT_EQ(0, testList
[0].m_Stage
);
1419 EXPECT_EQ(0, testList
[1].m_Stage
);
1420 EXPECT_EQ(0, testList
[2].m_Stage
);
1421 EXPECT_EQ(0U, testList
[0].m_Action
);
1422 EXPECT_EQ(0U, testList
[1].m_Action
);
1423 EXPECT_EQ(0U, testList
[2].m_Action
);
1424 EXPECT_FALSE(testList
[0].IsDirectory());
1425 EXPECT_FALSE(testList
[1].IsDirectory());
1426 EXPECT_FALSE(testList
[2].IsDirectory());
1429 TEST(CTGitPath
, ParserFromLsFile_RepoWithSubmodule
)
1431 BYTE git_ls_file_u_t_z_output
[] = { "H 160000 d4eaf3c5d0994eb0112c17aa3c732022eb9fdf6b 0 ext/gtest\0" };
1432 CGitByteArray byteArray
;
1433 byteArray
.append(git_ls_file_u_t_z_output
, sizeof(git_ls_file_u_t_z_output
));
1434 CTGitPathList testList
;
1435 EXPECT_EQ(0, testList
.ParserFromLsFile(byteArray
));
1436 EXPECT_EQ(1, testList
.GetCount());
1437 EXPECT_STREQ(L
"ext/gtest", testList
[0].GetGitPathString());
1438 EXPECT_STREQ(L
"", testList
[0].GetGitOldPathString());
1439 EXPECT_EQ(0, testList
[0].m_Stage
);
1440 EXPECT_EQ(0U, testList
[0].m_Action
);
1441 EXPECT_TRUE(testList
[0].IsDirectory());
1444 TEST(CTGitPath
, FillUnRev
)
1446 CAutoTempDir tmpDir
;
1448 CAutoRepository repo
;
1449 ASSERT_TRUE(git_repository_init(repo
.GetPointer(), CUnicodeUtils::GetUTF8(tmpDir
.GetTempDir()), false) == 0);
1451 g_Git
.m_CurrentDir
= tmpDir
.GetTempDir();
1453 CTGitPathList testList
;
1454 EXPECT_EQ(0, testList
.FillUnRev(0));
1455 EXPECT_EQ(0, testList
.GetCount());
1457 EXPECT_EQ(0, testList
.FillUnRev(CTGitPath::LOGACTIONS_IGNORE
));
1458 EXPECT_EQ(0, testList
.GetCount());
1460 CString fileOne
= tmpDir
.GetTempDir() + L
"\\one";
1461 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(fileOne
, L
"something"));
1463 EXPECT_EQ(0, testList
.FillUnRev(0));
1464 EXPECT_EQ(1, testList
.GetCount());
1465 EXPECT_STREQ(L
"one", testList
[0].GetGitPathString());
1467 EXPECT_EQ(0, testList
.FillUnRev(CTGitPath::LOGACTIONS_IGNORE
));
1468 EXPECT_EQ(0, testList
.GetCount());
1470 CTGitPathList selectList
;
1471 selectList
.AddPath(CTGitPath(L
"one"));
1473 EXPECT_EQ(0, testList
.FillUnRev(0, &selectList
));
1474 EXPECT_EQ(1, testList
.GetCount());
1475 EXPECT_STREQ(L
"one", testList
[0].GetGitPathString());
1477 EXPECT_EQ(0, testList
.FillUnRev(CTGitPath::LOGACTIONS_IGNORE
, &selectList
));
1478 EXPECT_EQ(0, testList
.GetCount());
1480 CString gitIgnore
= tmpDir
.GetTempDir() + L
"\\.gitignore";
1481 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(gitIgnore
, L
""));
1483 EXPECT_EQ(0, testList
.FillUnRev(0));
1484 EXPECT_EQ(2, testList
.GetCount());
1485 EXPECT_STREQ(L
".gitignore", testList
[0].GetGitPathString());
1486 EXPECT_STREQ(L
"one", testList
[1].GetGitPathString());
1488 EXPECT_EQ(0, testList
.FillUnRev(CTGitPath::LOGACTIONS_IGNORE
));
1489 EXPECT_EQ(0, testList
.GetCount());
1491 EXPECT_EQ(0, testList
.FillUnRev(0, &selectList
));
1492 EXPECT_EQ(1, testList
.GetCount());
1493 EXPECT_STREQ(L
"one", testList
[0].GetGitPathString());
1495 EXPECT_EQ(0, testList
.FillUnRev(CTGitPath::LOGACTIONS_IGNORE
, &selectList
));
1496 EXPECT_EQ(0, testList
.GetCount());
1498 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(gitIgnore
, L
"/one"));
1500 EXPECT_EQ(0, testList
.FillUnRev(0));
1501 EXPECT_EQ(1, testList
.GetCount());
1502 EXPECT_STREQ(L
".gitignore", testList
[0].GetGitPathString());
1504 EXPECT_EQ(0, testList
.FillUnRev(CTGitPath::LOGACTIONS_IGNORE
));
1505 EXPECT_EQ(1, testList
.GetCount());
1506 EXPECT_STREQ(L
"one", testList
[0].GetGitPathString());
1508 EXPECT_EQ(0, testList
.FillUnRev(0, &selectList
));
1509 EXPECT_EQ(0, testList
.GetCount());
1511 EXPECT_EQ(0, testList
.FillUnRev(CTGitPath::LOGACTIONS_IGNORE
, &selectList
));
1512 EXPECT_EQ(1, testList
.GetCount());
1513 EXPECT_STREQ(L
"one", testList
[0].GetGitPathString());
1515 EXPECT_TRUE(CreateDirectory(tmpDir
.GetTempDir() + L
"\\subdir", nullptr));
1517 selectList
.AddPath(CTGitPath(L
"subdir"));
1518 EXPECT_EQ(0, testList
.FillUnRev(0, &selectList
));
1519 EXPECT_EQ(0, testList
.GetCount());
1521 EXPECT_EQ(0, testList
.FillUnRev(CTGitPath::LOGACTIONS_IGNORE
, &selectList
));
1522 EXPECT_EQ(0, testList
.GetCount());
1524 fileOne
= tmpDir
.GetTempDir() + L
"\\subdir\\one";
1525 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(fileOne
, L
"something"));
1527 EXPECT_EQ(0, testList
.FillUnRev(0));
1528 EXPECT_EQ(2, testList
.GetCount());
1529 EXPECT_STREQ(L
".gitignore", testList
[0].GetGitPathString());
1530 EXPECT_STREQ(L
"subdir/one", testList
[1].GetGitPathString());
1532 EXPECT_EQ(0, testList
.FillUnRev(CTGitPath::LOGACTIONS_IGNORE
));
1533 EXPECT_EQ(1, testList
.GetCount());
1534 EXPECT_STREQ(L
"one", testList
[0].GetGitPathString());
1536 EXPECT_EQ(0, testList
.FillUnRev(0, &selectList
));
1537 EXPECT_EQ(1, testList
.GetCount());
1538 EXPECT_STREQ(L
"subdir/one", testList
[0].GetGitPathString());
1540 EXPECT_EQ(0, testList
.FillUnRev(CTGitPath::LOGACTIONS_IGNORE
, &selectList
));
1541 EXPECT_EQ(0, testList
.GetCount());
1543 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(gitIgnore
, L
"one"));
1545 EXPECT_EQ(0, testList
.FillUnRev(0));
1546 EXPECT_EQ(1, testList
.GetCount());
1547 EXPECT_STREQ(L
".gitignore", testList
[0].GetGitPathString());
1549 EXPECT_EQ(0, testList
.FillUnRev(CTGitPath::LOGACTIONS_IGNORE
));
1550 EXPECT_STREQ(L
"one", testList
[0].GetGitPathString());
1551 EXPECT_STREQ(L
"subdir/one", testList
[1].GetGitPathString());
1553 EXPECT_EQ(0, testList
.FillUnRev(CTGitPath::LOGACTIONS_IGNORE
, &selectList
));
1554 EXPECT_EQ(1, testList
.GetCount());
1555 EXPECT_STREQ(L
"subdir/one", testList
[0].GetGitPathString());
1558 TEST(CTGitPath
, GetAbbreviatedRename
)
1561 CString newName
, oldName
;
1564 test
.SetFromGit(newName
, &oldName
);
1565 EXPECT_STREQ(L
"", test
.GetAbbreviatedRename());
1569 test
.SetFromGit(newName
, &oldName
);
1570 EXPECT_STREQ(L
"B => A", test
.GetAbbreviatedRename());
1574 test
.SetFromGit(newName
, &oldName
);
1575 EXPECT_STREQ(L
"C/B/A => A/B/C", test
.GetAbbreviatedRename());
1579 test
.SetFromGit(newName
, &oldName
);
1580 EXPECT_STREQ(L
"{B => A}/C", test
.GetAbbreviatedRename());
1584 test
.SetFromGit(newName
, &oldName
);
1585 EXPECT_STREQ(L
"C/{B => A}", test
.GetAbbreviatedRename());
1589 test
.SetFromGit(newName
, &oldName
);
1590 EXPECT_STREQ(L
"C/{D/E => B/A}", test
.GetAbbreviatedRename());
1594 test
.SetFromGit(newName
, &oldName
);
1595 EXPECT_STREQ(L
"{C/D => D}/A", test
.GetAbbreviatedRename());
1597 oldName
= L
"A1/B/C/F";
1598 newName
= L
"A2/B/C/F";
1599 test
.SetFromGit(newName
, &oldName
);
1600 EXPECT_STREQ(L
"{A1 => A2}/B/C/F", test
.GetAbbreviatedRename());
1604 test
.SetFromGit(newName
, &oldName
);
1605 EXPECT_STREQ(L
"{C/D => D}/E", test
.GetAbbreviatedRename());
1609 test
.SetFromGit(newName
, &oldName
);
1610 EXPECT_STREQ(L
"D/{ => F}/E", test
.GetAbbreviatedRename());
1613 newName
= L
"D/F/F/E";
1614 test
.SetFromGit(newName
, &oldName
);
1615 EXPECT_STREQ(L
"D/F/{ => F}/E", test
.GetAbbreviatedRename());
1618 TEST(CTGitPath
, HashStashDir
)
1620 CAutoTempDir tmpDir
;
1622 CTGitPath
path(tmpDir
.GetTempDir());
1623 // no repository -> no stash
1624 EXPECT_FALSE(path
.HasStashDir());
1627 path
.SetFromWin(tmpDir
.GetTempDir());
1629 CAutoRepository repo
;
1630 ASSERT_TRUE(git_repository_init(repo
.GetPointer(), CUnicodeUtils::GetUTF8(tmpDir
.GetTempDir()), false) == 0);
1631 // "git commit" follows and requires user to be set
1632 CString configFile
= tmpDir
.GetTempDir() + L
"\\.git\\config";
1634 ASSERT_TRUE(CStringUtils::ReadStringFromTextFile(configFile
, text
));
1635 text
+= L
"[user]\n name = User\n email = user@example.com\n";
1636 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(configFile
, text
));
1638 g_Git
.m_CurrentDir
= tmpDir
.GetTempDir();
1640 // empty repository no stash
1641 EXPECT_FALSE(path
.HasStashDir());
1643 CString
file(tmpDir
.GetTempDir() + L
"\\file");
1644 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(file
, L
"don't care"));
1647 EXPECT_EQ(0, g_Git
.Run(L
"git add file", &output
, CP_UTF8
));
1648 EXPECT_EQ(0, g_Git
.Run(L
"git commit -m \"test\"", &output
, CP_UTF8
));
1649 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(file
, L
"don't care even more"));
1650 EXPECT_EQ(0, g_Git
.Run(L
"git stash", &output
, CP_UTF8
));
1651 EXPECT_TRUE(path
.HasStashDir());
1653 // check for packed stash
1654 EXPECT_EQ(0, g_Git
.Run(L
"git pack-refs --all", &output
, CP_UTF8
));
1655 EXPECT_TRUE(path
.HasStashDir());
1657 EXPECT_EQ(0, g_Git
.Run(L
"git stash clear", &output
, CP_UTF8
));
1658 EXPECT_FALSE(path
.HasStashDir());
1660 file
= tmpDir
.GetTempDir() + L
"\\.git\\packed-refs";
1661 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(file
, L
"# pack-refs with: peeled fully-peeled\nf3a76c72d89aebd63a0346dd92ecafecdc780822 refs/stashNotReal\n"));
1662 EXPECT_FALSE(path
.HasStashDir());
1665 class MockCTGitPath
: public CTGitPath
1670 ON_CALL(*this, UpdateAttributes()).WillByDefault(testing::Invoke(this, &MockCTGitPath::UpdateAttributes_Real
));
1672 MOCK_CONST_METHOD0(UpdateAttributes
, void());
1675 void UpdateAttributes_Real() { CTGitPath::UpdateAttributes(); }
1678 TEST(CTGitPath
, SetDirectory_DiskAccess
)
1681 path
.SetFromGit(L
"bla");
1682 EXPECT_CALL(path
, UpdateAttributes()).Times(1);
1683 EXPECT_FALSE(path
.IsDirectory());
1684 EXPECT_FALSE(path
.IsDirectory());
1685 EXPECT_FALSE(path
.Exists());
1686 path
.UnsetDirectoryStatus();
1687 EXPECT_FALSE(path
.IsDirectory());
1688 EXPECT_FALSE(path
.Exists());
1690 TCHAR winDir
[MAX_PATH
+ 1] = { 0 };
1691 GetWindowsDirectory(winDir
, _countof(winDir
));
1692 MockCTGitPath pathWin
;
1693 pathWin
.SetFromGit(winDir
);
1694 EXPECT_CALL(pathWin
, UpdateAttributes()).Times(1);
1695 EXPECT_TRUE(pathWin
.IsDirectory());
1696 EXPECT_TRUE(pathWin
.IsDirectory());
1697 EXPECT_TRUE(pathWin
.Exists());
1699 MockCTGitPath pathDir
;
1700 pathDir
.SetFromGit(L
"bla", false);
1701 EXPECT_CALL(pathDir
, UpdateAttributes()).Times(0);
1702 EXPECT_FALSE(pathDir
.IsDirectory());
1703 pathDir
.UnsetDirectoryStatus();
1704 EXPECT_FALSE(pathDir
.IsDirectory());
1706 MockCTGitPath pathDir2
;
1707 pathDir2
.SetFromGit(L
"bla", true);
1708 EXPECT_CALL(pathDir2
, UpdateAttributes()).Times(0);
1709 EXPECT_TRUE(pathDir2
.IsDirectory());
1710 pathDir2
.UnsetDirectoryStatus();
1711 EXPECT_FALSE(pathDir2
.IsDirectory());
1713 MockCTGitPath path2
;
1714 path2
.SetFromGit(L
"bla", nullptr, nullptr);
1715 EXPECT_CALL(path2
, UpdateAttributes()).Times(1);
1716 EXPECT_FALSE(path2
.IsDirectory());
1717 EXPECT_FALSE(path2
.IsDirectory());
1718 path2
.UnsetDirectoryStatus();
1719 EXPECT_FALSE(path2
.IsDirectory());
1722 MockCTGitPath path3
;
1723 path3
.SetFromGit(L
"bla", nullptr, &isDir
);
1724 EXPECT_CALL(path3
, UpdateAttributes()).Times(0);
1725 EXPECT_FALSE(path3
.IsDirectory());
1726 EXPECT_FALSE(path3
.IsDirectory());
1727 path3
.UnsetDirectoryStatus();
1728 EXPECT_FALSE(path3
.IsDirectory());
1731 MockCTGitPath pathDir3
;
1732 pathDir3
.SetFromGit(L
"bla", nullptr, &isDir
);
1733 EXPECT_CALL(pathDir3
, UpdateAttributes()).Times(0);
1734 EXPECT_TRUE(pathDir3
.IsDirectory());
1735 EXPECT_TRUE(pathDir3
.IsDirectory());
1736 pathDir3
.UnsetDirectoryStatus();
1737 EXPECT_FALSE(pathDir3
.IsDirectory());
1740 TEST(CTGitPath
, AreAllPathsFiles
)
1743 EXPECT_TRUE(list
.AreAllPathsFiles());
1745 list
.AddPath(CTGitPath(L
"C:\\Windows\\explorer.exe"));
1746 EXPECT_TRUE(list
.AreAllPathsFiles());
1748 list
.AddPath(CTGitPath(L
"C:\\Windows"));
1749 EXPECT_FALSE(list
.AreAllPathsFiles());
1752 EXPECT_TRUE(list
.AreAllPathsFiles());
1754 // now test relative paths
1755 PreserveChdir chdir
;
1757 SetCurrentDirectory(tmp
.GetTempDir());
1759 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(tmp
.GetTempDir() + L
"\\file1", L
"something"));
1760 list
.AddPath(CTGitPath(L
"file1"));
1761 EXPECT_TRUE(list
.AreAllPathsFiles());
1763 EXPECT_TRUE(CreateDirectory(tmp
.GetTempDir() + L
"\\dir", nullptr));
1764 list
.AddPath(CTGitPath(L
"dir"));
1765 EXPECT_FALSE(list
.AreAllPathsFiles());
1768 list
.AddPath(CTGitPath()); // equivalent of "."
1769 EXPECT_FALSE(list
.AreAllPathsFiles());
1771 list
.AddPath(CTGitPath(L
"file1"));
1772 EXPECT_FALSE(list
.AreAllPathsFiles());