1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2015 - 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"
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
+ _T("\\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(_T("C:\\"));
53 EXPECT_TRUE(testPath
.IsDirectory());
54 EXPECT_TRUE(testPath
.GetDirectory().GetWinPathString().CompareNoCase(_T("C:\\")) == 0);
55 EXPECT_TRUE(testPath
.GetContainingDirectory().IsEmpty());
56 // Try a root UNC path
57 testPath
.SetFromUnknown(_T("\\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(_T("c:\\.gitdir"));
72 EXPECT_FALSE(testPath
.IsAdminDir());
73 testPath
.SetFromUnknown(_T("c:\\test.git"));
74 EXPECT_FALSE(testPath
.IsAdminDir());
75 testPath
.SetFromUnknown(_T("c:\\.git"));
76 EXPECT_TRUE(testPath
.IsAdminDir());
77 testPath
.SetFromUnknown(_T("c:\\.gitdir\\test"));
78 EXPECT_FALSE(testPath
.IsAdminDir());
79 testPath
.SetFromUnknown(_T("c:\\.git\\test"));
80 EXPECT_TRUE(testPath
.IsAdminDir());
82 CTGitPathList pathList
;
83 pathList
.AddPath(CTGitPath(_T("c:\\.gitdir")));
84 pathList
.AddPath(CTGitPath(_T("c:\\.git")));
85 pathList
.AddPath(CTGitPath(_T("c:\\.git\\test")));
86 pathList
.AddPath(CTGitPath(_T("c:\\test")));
87 pathList
.RemoveAdminPaths();
88 EXPECT_EQ(2, pathList
.GetCount());
90 EXPECT_EQ(0, pathList
.GetCount());
91 pathList
.AddPath(CTGitPath(_T("c:\\test")));
92 pathList
.RemoveAdminPaths();
93 EXPECT_EQ(1, pathList
.GetCount());
96 TEST(CTGitPath
, SortTest
)
98 CTGitPathList testList
;
100 testPath
.SetFromUnknown(_T("c:/Z"));
101 testList
.AddPath(testPath
);
102 testPath
.SetFromUnknown(_T("c:/B"));
103 testList
.AddPath(testPath
);
104 testPath
.SetFromUnknown(_T("c:\\a"));
105 testList
.AddPath(testPath
);
106 testPath
.SetFromUnknown(_T("c:/Test"));
107 testList
.AddPath(testPath
);
109 EXPECT_EQ(4, testList
.GetCount());
111 testList
.SortByPathname();
113 EXPECT_EQ(4, testList
.GetCount());
114 EXPECT_EQ(_T("c:\\a"), testList
[0].GetWinPathString());
115 EXPECT_EQ(_T("c:\\B"), testList
[1].GetWinPathString());
116 EXPECT_EQ(_T("c:\\Test"), testList
[2].GetWinPathString());
117 EXPECT_EQ(_T("c:\\Z"),testList
[3].GetWinPathString());
120 TEST(CTGitPath
, RawAppendTest
)
122 CTGitPath
testPath(_T("c:/test/"));
123 testPath
.AppendRawString(_T("/Hello"));
124 EXPECT_EQ(_T("c:\\test\\Hello"), testPath
.GetWinPathString());
126 testPath
.AppendRawString(_T("\\T2"));
127 EXPECT_EQ(_T("c:\\test\\Hello\\T2"), testPath
.GetWinPathString());
129 CTGitPath
testFilePath(_T("C:\\windows\\win.ini"));
130 CTGitPath
testBasePath(_T("c:/temp/myfile.txt"));
131 testBasePath
.AppendRawString(testFilePath
.GetFileExtension());
132 EXPECT_EQ(_T("c:\\temp\\myfile.txt.ini"), testBasePath
.GetWinPathString());
135 TEST(CTGitPath
, PathAppendTest
)
137 CTGitPath
testPath(_T("c:/test/"));
138 testPath
.AppendPathString(_T("/Hello"));
139 EXPECT_EQ(_T("c:\\test\\Hello"), testPath
.GetWinPathString());
141 testPath
.AppendPathString(_T("T2"));
142 EXPECT_EQ(_T("c:\\test\\Hello\\T2"), testPath
.GetWinPathString());
144 CTGitPath
testFilePath(_T("C:\\windows\\win.ini"));
145 CTGitPath
testBasePath(_T("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(_T("c:\\temp\\myfile.txt\\.ini"), testBasePath
.GetWinPathString());
149 EXPECT_EQ(_T("c:/temp/myfile.txt/.ini"), testBasePath
.GetGitPathString());
152 TEST(CTGitPath
, RemoveDuplicatesTest
)
155 list
.AddPath(CTGitPath(_T("Z")));
156 list
.AddPath(CTGitPath(_T("A")));
157 list
.AddPath(CTGitPath(_T("E")));
158 list
.AddPath(CTGitPath(_T("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(_T("A"), list
[0].GetWinPathString());
170 EXPECT_STREQ(_T("E"), list
[1].GetWinPathString());
171 EXPECT_STREQ(_T("Z"), list
[2].GetWinPathString());
174 TEST(CTGitPath
, RemoveChildrenTest
)
177 list
.AddPath(CTGitPath(_T("c:\\test")));
178 list
.AddPath(CTGitPath(_T("c:\\test\\file")));
179 list
.AddPath(CTGitPath(_T("c:\\testfile")));
180 list
.AddPath(CTGitPath(_T("c:\\parent")));
181 list
.AddPath(CTGitPath(_T("c:\\parent\\child")));
182 list
.AddPath(CTGitPath(_T("c:\\parent\\child1")));
183 list
.AddPath(CTGitPath(_T("c:\\parent\\child2")));
185 EXPECT_EQ(7, list
.GetCount());
187 list
.RemoveChildren();
189 EXPECT_EQ(3, list
.GetCount());
191 list
.SortByPathname();
193 EXPECT_STREQ(_T("c:\\parent"), list
[0].GetWinPathString());
194 EXPECT_STREQ(_T("c:\\test"), list
[1].GetWinPathString());
195 EXPECT_STREQ(_T("c:\\testfile"), list
[2].GetWinPathString());
198 TEST(CTGitPath
, ContainingDirectoryTest
)
201 testPath
.SetFromWin(_T("c:\\a\\b\\c\\d\\e"));
203 dir
= testPath
.GetContainingDirectory();
204 EXPECT_STREQ(_T("c:\\a\\b\\c\\d"), dir
.GetWinPathString());
205 dir
= dir
.GetContainingDirectory();
206 EXPECT_STREQ(_T("c:\\a\\b\\c"), dir
.GetWinPathString());
207 dir
= dir
.GetContainingDirectory();
208 EXPECT_STREQ(_T("c:\\a\\b"), dir
.GetWinPathString());
209 dir
= dir
.GetContainingDirectory();
210 EXPECT_STREQ(_T("c:\\a"), dir
.GetWinPathString());
211 dir
= dir
.GetContainingDirectory();
212 EXPECT_STREQ(_T("c:\\"), dir
.GetWinPathString());
213 dir
= dir
.GetContainingDirectory();
214 EXPECT_TRUE(dir
.IsEmpty());
215 EXPECT_STREQ(_T(""), dir
.GetWinPathString());
218 TEST(CTGitPath
, AncestorTest
)
221 testPath
.SetFromWin(_T("c:\\windows"));
222 EXPECT_FALSE(testPath
.IsAncestorOf(CTGitPath(_T("c:\\"))));
223 EXPECT_TRUE(testPath
.IsAncestorOf(CTGitPath(_T("c:\\windows"))));
224 EXPECT_FALSE(testPath
.IsAncestorOf(CTGitPath(_T("c:\\windowsdummy"))));
225 EXPECT_TRUE(testPath
.IsAncestorOf(CTGitPath(_T("c:\\windows\\test.txt"))));
226 EXPECT_TRUE(testPath
.IsAncestorOf(CTGitPath(_T("c:\\windows\\system32\\test.txt"))));
229 /*TEST(CTGitPath, SubversionPathTest)
232 testPath.SetFromWin(_T("c:\\"));
233 EXPECT_TRUE((testPath.GetGitApiPath(pool), "c:") == 0);
234 testPath.SetFromWin(_T("c:\\folder"));
235 EXPECT_TRUE(strcmp(testPath.GetGitApiPath(pool), "c:/folder") == 0);
236 testPath.SetFromWin(_T("c:\\a\\b\\c\\d\\e"));
237 EXPECT_TRUE(strcmp(testPath.GetGitApiPath(pool), "c:/a/b/c/d/e") == 0);
238 testPath.SetFromUnknown(_T("http://testing/"));
239 EXPECT_TRUE(strcmp(testPath.GetGitApiPath(pool), "http://testing") == 0);
240 testPath.SetFromGit(NULL);
241 EXPECT_TRUE(strlen(testPath.GetGitApiPath(pool)) == 0);
243 testPath.SetFromUnknown(_T("http://testing again"));
244 EXPECT_TRUE(strcmp(testPath.GetGitApiPath(pool), "http://testing%20again") == 0);
245 testPath.SetFromUnknown(_T("http://testing%20again"));
246 EXPECT_TRUE(strcmp(testPath.GetGitApiPath(pool), "http://testing%20again") == 0);
247 testPath.SetFromUnknown(_T("http://testing special chars \344\366\374"));
248 EXPECT_TRUE(strcmp(testPath.GetGitApiPath(pool), "http://testing%20special%20chars%20%c3%a4%c3%b6%c3%bc") == 0);
251 TEST(CTGitPath
, GetCommonRootTest
)
253 CTGitPath
pathA(_T("C:\\Development\\LogDlg.cpp"));
254 CTGitPath
pathB(_T("C:\\Development\\LogDlg.h"));
255 CTGitPath
pathC(_T("C:\\Development\\SomeDir\\LogDlg.h"));
259 EXPECT_TRUE(list
.GetCommonRoot().GetWinPathString().CompareNoCase(_T("C:\\Development\\LogDlg.cpp")) == 0);
261 EXPECT_TRUE(list
.GetCommonRoot().GetWinPathString().CompareNoCase(_T("C:\\Development")) == 0);
263 EXPECT_TRUE(list
.GetCommonRoot().GetWinPathString().CompareNoCase(_T("C:\\Development")) == 0);
266 CString sPathList
= _T("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");
267 list
.LoadFromAsteriskSeparatedString(sPathList
);
268 EXPECT_TRUE(list
.GetCommonRoot().GetWinPathString().CompareNoCase(_T("D:\\Development\\StExBar")) == 0);
271 sPathList
= _T("c:\\windows\\explorer.exe*c:\\windows");
272 list
.LoadFromAsteriskSeparatedString(sPathList
);
273 EXPECT_TRUE(list
.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\windows")) == 0);
276 sPathList
= _T("c:\\windows\\*c:\\windows");
277 list
.LoadFromAsteriskSeparatedString(sPathList
);
278 EXPECT_TRUE(list
.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\windows")) == 0);
281 sPathList
= _T("c:\\windows\\system32*c:\\windows\\system");
282 list
.LoadFromAsteriskSeparatedString(sPathList
);
283 EXPECT_TRUE(list
.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\windows")) == 0);
286 sPathList
= _T("c:\\windowsdummy*c:\\windows");
287 list
.LoadFromAsteriskSeparatedString(sPathList
);
288 EXPECT_TRUE(list
.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\")) == 0);
291 TEST(CTGitPath
, ValidPathAndUrlTest
)
294 testPath
.SetFromWin(_T("c:\\a\\b\\c.test.txt"));
295 EXPECT_TRUE(testPath
.IsValidOnWindows());
296 testPath
.SetFromWin(_T("c:\\"));
297 EXPECT_TRUE(testPath
.IsValidOnWindows());
298 testPath
.SetFromWin(_T("D:\\.Net\\SpindleSearch\\"));
299 EXPECT_TRUE(testPath
.IsValidOnWindows());
300 testPath
.SetFromWin(_T("c"));
301 EXPECT_TRUE(testPath
.IsValidOnWindows());
302 testPath
.SetFromWin(_T("c:\\test folder\\file"));
303 EXPECT_TRUE(testPath
.IsValidOnWindows());
304 testPath
.SetFromWin(_T("c:\\folder\\"));
305 EXPECT_TRUE(testPath
.IsValidOnWindows());
306 testPath
.SetFromWin(_T("c:\\ext.ext.ext\\ext.ext.ext.ext"));
307 EXPECT_TRUE(testPath
.IsValidOnWindows());
308 testPath
.SetFromWin(_T("c:\\.git"));
309 EXPECT_TRUE(testPath
.IsValidOnWindows());
310 testPath
.SetFromWin(_T("c:\\com\\file"));
311 EXPECT_TRUE(testPath
.IsValidOnWindows());
312 testPath
.SetFromWin(_T("c:\\test\\conf"));
313 EXPECT_TRUE(testPath
.IsValidOnWindows());
314 testPath
.SetFromWin(_T("c:\\LPT"));
315 EXPECT_TRUE(testPath
.IsValidOnWindows());
316 testPath
.SetFromWin(_T("c:\\test\\LPT"));
317 EXPECT_TRUE(testPath
.IsValidOnWindows());
318 testPath
.SetFromWin(_T("c:\\com1test"));
319 EXPECT_TRUE(testPath
.IsValidOnWindows());
320 testPath
.SetFromWin(_T("\\\\?\\c:\\test\\com1test"));
321 EXPECT_TRUE(testPath
.IsValidOnWindows());
323 testPath
.SetFromWin(_T("\\\\Share\\filename"));
324 EXPECT_TRUE(testPath
.IsValidOnWindows());
325 testPath
.SetFromWin(_T("\\\\Share\\filename.extension"));
326 EXPECT_TRUE(testPath
.IsValidOnWindows());
327 testPath
.SetFromWin(_T("\\\\Share\\.git"));
328 EXPECT_TRUE(testPath
.IsValidOnWindows());
330 // now the negative tests
331 testPath
.SetFromWin(_T("c:\\test:folder"));
332 EXPECT_FALSE(testPath
.IsValidOnWindows());
333 testPath
.SetFromWin(_T("c:\\file<name"));
334 EXPECT_FALSE(testPath
.IsValidOnWindows());
335 testPath
.SetFromWin(_T("c:\\something*else"));
336 EXPECT_FALSE(testPath
.IsValidOnWindows());
337 testPath
.SetFromWin(_T("c:\\folder\\file?nofile"));
338 EXPECT_FALSE(testPath
.IsValidOnWindows());
339 testPath
.SetFromWin(_T("c:\\ext.>ension"));
340 EXPECT_FALSE(testPath
.IsValidOnWindows());
341 testPath
.SetFromWin(_T("c:\\com1\\filename"));
342 EXPECT_FALSE(testPath
.IsValidOnWindows());
343 testPath
.SetFromWin(_T("c:\\com1"));
344 EXPECT_FALSE(testPath
.IsValidOnWindows());
345 testPath
.SetFromWin(_T("c:\\com1\\AuX"));
346 EXPECT_FALSE(testPath
.IsValidOnWindows());
348 testPath
.SetFromWin(_T("\\\\Share\\lpt9\\filename"));
349 EXPECT_FALSE(testPath
.IsValidOnWindows());
350 testPath
.SetFromWin(_T("\\\\Share\\prn"));
351 EXPECT_FALSE(testPath
.IsValidOnWindows());
352 testPath
.SetFromWin(_T("\\\\Share\\NUL"));
353 EXPECT_FALSE(testPath
.IsValidOnWindows());
355 // now come some URL tests
356 /*testPath.SetFromGit(_T("http://myserver.com/repos/trunk"));
357 EXPECT_TRUE(testPath.IsValidOnWindows());
358 testPath.SetFromGit(_T("https://myserver.com/repos/trunk/file%20with%20spaces"));
359 EXPECT_TRUE(testPath.IsValidOnWindows());
360 testPath.SetFromGit(_T("svn://myserver.com/repos/trunk/file with spaces"));
361 EXPECT_TRUE(testPath.IsValidOnWindows());
362 testPath.SetFromGit(_T("svn+ssh://www.myserver.com/repos/trunk"));
363 EXPECT_TRUE(testPath.IsValidOnWindows());
364 testPath.SetFromGit(_T("http://localhost:90/repos/trunk"));
365 EXPECT_TRUE(testPath.IsValidOnWindows());
366 testPath.SetFromGit(_T("file:///C:/GitRepos/Tester/Proj1/tags/t2"));
367 EXPECT_TRUE(testPath.IsValidOnWindows());
368 // and some negative URL tests
369 testPath.SetFromGit(_T("httpp://myserver.com/repos/trunk"));
370 EXPECT_FALSE(testPath.IsValidOnWindows());
371 testPath.SetFromGit(_T("https://myserver.com/rep:os/trunk/file%20with%20spaces"));
372 EXPECT_FALSE(testPath.IsValidOnWindows());
373 testPath.SetFromGit(_T("svn://myserver.com/rep<os/trunk/file with spaces"));
374 EXPECT_FALSE(testPath.IsValidOnWindows());
375 testPath.SetFromGit(_T("svn+ssh://www.myserver.com/repos/trunk/prn/"));
376 EXPECT_FALSE(testPath.IsValidOnWindows());
377 testPath.SetFromGit(_T("http://localhost:90/repos/trunk/com1"));
378 EXPECT_FALSE(testPath.IsValidOnWindows());*/
381 TEST(CTGitPath
, ListLoadingTest
)
383 TCHAR buf
[MAX_PATH
] = { 0 };
384 GetCurrentDirectory(MAX_PATH
, buf
);
385 CString
sPathList(_T("Path1*c:\\path2 with spaces and stuff*\\funnypath\\*"));
386 CTGitPathList testList
;
387 testList
.LoadFromAsteriskSeparatedString(sPathList
);
389 EXPECT_EQ(3, testList
.GetCount());
390 EXPECT_STREQ(CString(buf
) + _T("\\Path1"), testList
[0].GetWinPathString());
391 EXPECT_STREQ(_T("c:\\path2 with spaces and stuff"), testList
[1].GetWinPathString());
392 EXPECT_STREQ(_T("\\funnypath"), testList
[2].GetWinPathString());
394 EXPECT_STREQ(_T(""), testList
.GetCommonRoot().GetWinPathString());
396 sPathList
= _T("c:\\path2 with spaces and stuff*c:\\funnypath\\*");
397 testList
.LoadFromAsteriskSeparatedString(sPathList
);
398 EXPECT_STREQ(_T("c:\\"), testList
.GetCommonRoot().GetWinPathString());
401 TEST(CTGitPath
, ParserFromLog_Empty
)
403 CGitByteArray byteArray
;
404 CTGitPathList testList
;
405 EXPECT_EQ(0, testList
.ParserFromLog(byteArray
));
406 EXPECT_EQ(0, testList
.GetCount());
409 TEST(CTGitPath
, ParserFromLog_Conflict
)
411 // as used in CGit::GetWorkingTreeChanges
412 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" };
413 CGitByteArray byteArray
;
414 byteArray
.append(git_ls_file_u_t_z_output
, sizeof(git_ls_file_u_t_z_output
));
415 CTGitPathList testList
;
416 EXPECT_EQ(0, testList
.ParserFromLog(byteArray
));
417 ASSERT_EQ(1, testList
.GetCount());
418 EXPECT_STREQ(_T("bla.txt"), testList
[0].GetGitPathString());
419 EXPECT_EQ(0, testList
[0].m_Stage
); // not set
420 EXPECT_EQ(0, testList
[0].m_Action
);
423 /* git status output for the following tests marked with "(*)"
424 * gpl.txt was deleted in index, but still on disk
425 * build.txt deleted on disk, but not in index
426 * src/Debug-Hints.txt deleted on disk and in index
427 * zzz-added-only-in-index-missing-on-fs.txt added in index, and then removed on disk
428 * signedness.txt new file
429 * renamed release.txt -> release-renamed.txt
430 * changed on disk but not in index test/UnitTests/TGitPathTest.cpp
433 Your branch and 'origin/tests' have diverged,
434 and have 2 and 1 different commit each, respectively.
435 (use "git pull" to merge the remote branch into yours)
437 Changes to be committed:
438 (use "git reset HEAD <file>..." to unstage)
440 renamed: release.txt -> release-renamed.txt
441 new file: signedness.txt
442 deleted: src/Debug-Hints.txt
444 new file: zzz-added-only-in-index-missing-on-fs.txt
446 Changes not staged for commit:
447 (use "git add/rm <file>..." to update what will be committed)
448 (use "git checkout -- <file>..." to discard changes in working directory)
449 (commit or discard the untracked or modified content in submodules)
452 modified: ext/apr (untracked content)
453 modified: ext/apr-util (modified content, untracked content)
454 modified: ext/libgit2 (new commits)
455 modified: test/UnitTests/TGitPathTest.cpp
456 deleted: zzz-added-only-in-index-missing-on-fs.txt
459 (use "git add <file>..." to include in what will be committed)
464 TEST(CTGitPath
, ParserFromLog_Deleted_From_LsFiles
)
466 // as used in CGit::GetWorkingTreeChanges, based on (*)
467 CGitByteArray byteArray
;
468 CTGitPathList testList
;
469 EXPECT_EQ(0, testList
.ParserFromLog(byteArray
, true));
470 ASSERT_EQ(0, testList
.GetCount());
472 BYTE git_ls_file_d_z_output
[] = { "build.txt\0" };
473 byteArray
.append(git_ls_file_d_z_output
, sizeof(git_ls_file_d_z_output
));
474 EXPECT_EQ(0, testList
.ParserFromLog(byteArray
, true));
475 ASSERT_EQ(1, testList
.GetCount());
476 EXPECT_STREQ(_T("build.txt"), testList
[0].GetGitPathString());
477 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
| CTGitPath::LOGACTIONS_MISSING
, testList
[0].m_Action
);
479 BYTE git_ls_file_d_z_output2
[] = { "zzz-added-only-in-index-missing-on-fs.txt\0" };
480 byteArray
.append(git_ls_file_d_z_output2
, sizeof(git_ls_file_d_z_output2
));
481 EXPECT_EQ(0, testList
.ParserFromLog(byteArray
, true));
482 ASSERT_EQ(2, testList
.GetCount());
483 EXPECT_STREQ(_T("build.txt"), testList
[0].GetGitPathString());
484 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
| CTGitPath::LOGACTIONS_MISSING
, testList
[0].m_Action
);
485 EXPECT_STREQ(_T("zzz-added-only-in-index-missing-on-fs.txt"), testList
[1].GetGitPathString());
486 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
| CTGitPath::LOGACTIONS_MISSING
, testList
[1].m_Action
);
489 TEST(CTGitPath
, ParserFromLog_DiffIndex_Raw_M_C_z
)
491 // as used in DiffCommand::Execute, based on (*)
492 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" };
493 // gpl.txt still exists, but deleted in index
494 // build.txt deleted, still in index
495 CGitByteArray byteArray
;
496 byteArray
.append(git_DiffIndex_Raw_M_C_z_output
, sizeof(git_DiffIndex_Raw_M_C_z_output
));
497 CTGitPathList testList
;
498 EXPECT_EQ(0, testList
.ParserFromLog(byteArray
));
499 ASSERT_EQ(9, testList
.GetCount());
500 EXPECT_STREQ(_T("build.txt"), testList
[0].GetGitPathString());
501 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[0].m_Action
);
502 EXPECT_STREQ(_T(""), testList
[0].m_StatAdd
);
503 EXPECT_STREQ(_T(""), testList
[0].m_StatDel
);
504 EXPECT_EQ(0, testList
[0].m_Stage
);
505 EXPECT_STREQ(_T("ext/apr"), testList
[1].GetGitPathString());
506 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[1].m_Action
);
507 EXPECT_STREQ(_T(""), testList
[1].m_StatAdd
);
508 EXPECT_STREQ(_T(""), testList
[1].m_StatDel
);
509 EXPECT_EQ(0, testList
[1].m_Stage
);
510 EXPECT_STREQ(_T("ext/apr-util"), testList
[2].GetGitPathString());
511 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[2].m_Action
);
512 EXPECT_STREQ(_T(""), testList
[2].m_StatAdd
);
513 EXPECT_STREQ(_T(""), testList
[2].m_StatDel
);
514 EXPECT_EQ(0, testList
[2].m_Stage
);
515 EXPECT_STREQ(_T("ext/libgit2"), testList
[3].GetGitPathString());
516 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[3].m_Action
);
517 EXPECT_STREQ(_T(""), testList
[3].m_StatAdd
);
518 EXPECT_STREQ(_T(""), testList
[3].m_StatDel
);
519 EXPECT_EQ(0, testList
[3].m_Stage
);
520 EXPECT_STREQ(_T("release-renamed.txt"), testList
[4].GetGitPathString());
521 EXPECT_EQ(CTGitPath::LOGACTIONS_REPLACED
, testList
[4].m_Action
);
522 EXPECT_STREQ(_T(""), testList
[4].m_StatAdd
);
523 EXPECT_STREQ(_T(""), testList
[4].m_StatDel
);
524 EXPECT_EQ(0, testList
[4].m_Stage
);
525 EXPECT_STREQ(_T("release.txt"), testList
[4].GetGitOldPathString());
526 EXPECT_STREQ(_T("signedness.txt"), testList
[5].GetGitPathString());
527 EXPECT_EQ(CTGitPath::LOGACTIONS_ADDED
, testList
[5].m_Action
);
528 EXPECT_STREQ(_T(""), testList
[5].m_StatAdd
);
529 EXPECT_STREQ(_T(""), testList
[5].m_StatDel
);
530 EXPECT_EQ(0, testList
[5].m_Stage
);
531 EXPECT_STREQ(_T("src/Debug-Hints.txt"), testList
[6].GetGitPathString());
532 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[6].m_Action
);
533 EXPECT_STREQ(_T(""), testList
[6].m_StatAdd
);
534 EXPECT_STREQ(_T(""), testList
[6].m_StatDel
);
535 EXPECT_EQ(0, testList
[6].m_Stage
);
536 EXPECT_STREQ(_T("src/gpl.txt"), testList
[7].GetGitPathString());
537 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[7].m_Action
);
538 EXPECT_STREQ(_T(""), testList
[7].m_StatAdd
);
539 EXPECT_STREQ(_T(""), testList
[7].m_StatDel
);
540 EXPECT_EQ(0, testList
[7].m_Stage
);
541 EXPECT_STREQ(_T("test/UnitTests/TGitPathTest.cpp"), testList
[8].GetGitPathString());
542 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[8].m_Action
);
543 EXPECT_STREQ(_T(""), testList
[8].m_StatAdd
);
544 EXPECT_STREQ(_T(""), testList
[8].m_StatDel
);
545 EXPECT_EQ(0, testList
[8].m_Stage
);
548 TEST(CTGitPath
, ParserFromLog_DiffIndex_Raw_M_C_Numstat_z
)
550 // as used in CGit::GetWorkingTreeChanges, but here separated; based on (*)
551 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" };
552 CGitByteArray byteArray
;
553 byteArray
.append(git_DiffIndex_Raw_M_C_z_output
, sizeof(git_DiffIndex_Raw_M_C_z_output
));
554 CTGitPathList testList
;
555 EXPECT_EQ(0, testList
.ParserFromLog(byteArray
));
556 ASSERT_EQ(9, testList
.GetCount());
557 EXPECT_STREQ(_T("build.txt"), testList
[0].GetGitPathString());
558 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[0].m_Action
);
559 EXPECT_STREQ(_T("0"), testList
[0].m_StatAdd
);
560 EXPECT_STREQ(_T("61"), testList
[0].m_StatDel
);
561 EXPECT_EQ(0, testList
[0].m_Stage
);
562 EXPECT_STREQ(_T("ext/apr"), testList
[1].GetGitPathString());
563 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[1].m_Action
);
564 EXPECT_STREQ(_T("0"), testList
[1].m_StatAdd
);
565 EXPECT_STREQ(_T("0"), testList
[1].m_StatDel
);
566 EXPECT_EQ(0, testList
[1].m_Stage
);
567 EXPECT_STREQ(_T("ext/apr-util"), testList
[2].GetGitPathString());
568 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[2].m_Action
);
569 EXPECT_STREQ(_T("0"), testList
[2].m_StatAdd
);
570 EXPECT_STREQ(_T("0"), testList
[2].m_StatDel
);
571 EXPECT_EQ(0, testList
[2].m_Stage
);
572 EXPECT_STREQ(_T("ext/libgit2"), testList
[3].GetGitPathString());
573 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[3].m_Action
);
574 EXPECT_STREQ(_T("1"), testList
[3].m_StatAdd
);
575 EXPECT_STREQ(_T("1"), testList
[3].m_StatDel
);
576 EXPECT_EQ(0, testList
[3].m_Stage
);
577 EXPECT_STREQ(_T("release-renamed.txt"), testList
[4].GetGitPathString());
578 EXPECT_EQ(CTGitPath::LOGACTIONS_REPLACED
, testList
[4].m_Action
);
579 EXPECT_STREQ(_T("0"), testList
[4].m_StatAdd
);
580 EXPECT_STREQ(_T("0"), testList
[4].m_StatDel
);
581 EXPECT_EQ(0, testList
[4].m_Stage
);
582 EXPECT_STREQ(_T("release.txt"), testList
[4].GetGitOldPathString());
583 EXPECT_STREQ(_T("signedness.txt"), testList
[5].GetGitPathString());
584 EXPECT_EQ(CTGitPath::LOGACTIONS_ADDED
, testList
[5].m_Action
);
585 EXPECT_STREQ(_T("1176"), testList
[5].m_StatAdd
);
586 EXPECT_STREQ(_T("0"), testList
[5].m_StatDel
);
587 EXPECT_EQ(0, testList
[5].m_Stage
);
588 EXPECT_STREQ(_T("src/Debug-Hints.txt"), testList
[6].GetGitPathString());
589 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[6].m_Action
);
590 EXPECT_STREQ(_T("0"), testList
[6].m_StatAdd
);
591 EXPECT_STREQ(_T("74"), testList
[6].m_StatDel
);
592 EXPECT_EQ(0, testList
[6].m_Stage
);
593 EXPECT_STREQ(_T("src/gpl.txt"), testList
[7].GetGitPathString());
594 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[7].m_Action
);
595 EXPECT_STREQ(_T("0"), testList
[7].m_StatAdd
);
596 EXPECT_STREQ(_T("340"), testList
[7].m_StatDel
);
597 EXPECT_EQ(0, testList
[7].m_Stage
);
598 EXPECT_STREQ(_T("test/UnitTests/TGitPathTest.cpp"), testList
[8].GetGitPathString());
599 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[8].m_Action
);
600 EXPECT_STREQ(_T("162"), testList
[8].m_StatAdd
);
601 EXPECT_STREQ(_T("2"), testList
[8].m_StatDel
);
602 EXPECT_EQ(0, testList
[8].m_Stage
);
605 TEST(CTGitPath
, ParserFromLog_DiffIndex_Raw_Cached_M_C_Numstat_z
)
607 // as used in CGit::GetWorkingTreeChanges, but here separated; based on (*)
608 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" };
609 CGitByteArray byteArray
;
610 byteArray
.append(git_DiffIndex_Raw_Cached_M_C_z_output
, sizeof(git_DiffIndex_Raw_Cached_M_C_z_output
));
611 CTGitPathList testList
;
612 EXPECT_EQ(0, testList
.ParserFromLog(byteArray
));
613 ASSERT_EQ(5, testList
.GetCount());
614 EXPECT_STREQ(_T("release-renamed.txt"), testList
[0].GetGitPathString());
615 EXPECT_EQ(CTGitPath::LOGACTIONS_REPLACED
, testList
[0].m_Action
);
616 EXPECT_STREQ(_T("0"), testList
[0].m_StatAdd
);
617 EXPECT_STREQ(_T("0"), testList
[0].m_StatDel
);
618 EXPECT_EQ(0, testList
[0].m_Stage
);
619 EXPECT_STREQ(_T("release.txt"), testList
[0].GetGitOldPathString());
620 EXPECT_STREQ(_T("signedness.txt"), testList
[1].GetGitPathString());
621 EXPECT_EQ(CTGitPath::LOGACTIONS_ADDED
, testList
[1].m_Action
);
622 EXPECT_STREQ(_T("1176"), testList
[1].m_StatAdd
);
623 EXPECT_STREQ(_T("0"), testList
[1].m_StatDel
);
624 EXPECT_EQ(0, testList
[1].m_Stage
);
625 EXPECT_STREQ(_T("src/Debug-Hints.txt"), testList
[2].GetGitPathString());
626 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[2].m_Action
);
627 EXPECT_STREQ(_T("0"), testList
[2].m_StatAdd
);
628 EXPECT_STREQ(_T("74"), testList
[2].m_StatDel
);
629 EXPECT_EQ(0, testList
[2].m_Stage
);
630 EXPECT_STREQ(_T("src/gpl.txt"), testList
[3].GetGitPathString());
631 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[3].m_Action
);
632 EXPECT_STREQ(_T("0"), testList
[3].m_StatAdd
);
633 EXPECT_STREQ(_T("340"), testList
[3].m_StatDel
);
634 EXPECT_EQ(0, testList
[3].m_Stage
);
635 EXPECT_STREQ(_T("zzz-added-only-in-index-missing-on-fs.txt"), testList
[4].GetGitPathString());
636 EXPECT_EQ(CTGitPath::LOGACTIONS_ADDED
, testList
[4].m_Action
);
637 EXPECT_STREQ(_T("1"), testList
[4].m_StatAdd
);
638 EXPECT_STREQ(_T("0"), testList
[4].m_StatDel
);
639 EXPECT_EQ(0, testList
[4].m_Stage
);
642 TEST(CTGitPath
, ParserFromLog_DiffIndex_Raw_Cached_M_C_Numstat_z_AND_DiffIndex_Raw_M_C_Numstat_z
)
644 // as used in CGit::GetWorkingTreeChanges; based on (*)
645 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" };
646 CGitByteArray byteArray
;
647 byteArray
.append(git_DiffIndex_Raw_Cached_M_C_z_output
, sizeof(git_DiffIndex_Raw_Cached_M_C_z_output
));
648 CTGitPathList testList
;
649 EXPECT_EQ(0, testList
.ParserFromLog(byteArray
));
650 ASSERT_EQ(10, testList
.GetCount());
651 EXPECT_STREQ(_T("release-renamed.txt"), testList
[0].GetGitPathString());
652 EXPECT_EQ(CTGitPath::LOGACTIONS_REPLACED
, testList
[0].m_Action
);
653 EXPECT_STREQ(_T("release.txt"), testList
[0].GetGitOldPathString());
654 EXPECT_STREQ(_T("0"), testList
[0].m_StatAdd
);
655 EXPECT_STREQ(_T("0"), testList
[0].m_StatDel
);
656 EXPECT_EQ(0, testList
[0].m_Stage
);
657 EXPECT_STREQ(_T("signedness.txt"), testList
[1].GetGitPathString());
658 EXPECT_EQ(CTGitPath::LOGACTIONS_ADDED
, testList
[1].m_Action
);
659 EXPECT_STREQ(_T("1176"), testList
[1].m_StatAdd
);
660 EXPECT_STREQ(_T("0"), testList
[1].m_StatDel
);
661 EXPECT_EQ(0, testList
[1].m_Stage
);
662 EXPECT_STREQ(_T("src/Debug-Hints.txt"), testList
[2].GetGitPathString());
663 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[2].m_Action
);
664 EXPECT_STREQ(_T("0"), testList
[2].m_StatAdd
);
665 EXPECT_STREQ(_T("74"), testList
[2].m_StatDel
);
666 EXPECT_EQ(0, testList
[2].m_Stage
);
667 EXPECT_STREQ(_T("src/gpl.txt"), testList
[3].GetGitPathString());
668 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[3].m_Action
);
669 EXPECT_STREQ(_T("0"), testList
[3].m_StatAdd
);
670 EXPECT_STREQ(_T("340"), testList
[3].m_StatDel
);
671 EXPECT_EQ(0, testList
[3].m_Stage
);
672 EXPECT_STREQ(_T("zzz-added-only-in-index-missing-on-fs.txt"), testList
[4].GetGitPathString());
673 EXPECT_EQ(CTGitPath::LOGACTIONS_ADDED
, testList
[4].m_Action
);
674 EXPECT_STREQ(_T("1"), testList
[4].m_StatAdd
);
675 EXPECT_STREQ(_T("0"), testList
[4].m_StatDel
);
676 EXPECT_EQ(0, testList
[4].m_Stage
);
677 EXPECT_STREQ(_T("build.txt"), testList
[5].GetGitPathString());
678 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[5].m_Action
);
679 EXPECT_STREQ(_T("0"), testList
[5].m_StatAdd
);
680 EXPECT_STREQ(_T("61"), testList
[5].m_StatDel
);
681 EXPECT_EQ(0, testList
[5].m_Stage
);
682 EXPECT_STREQ(_T("ext/apr"), testList
[6].GetGitPathString());
683 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[6].m_Action
);
684 EXPECT_STREQ(_T("0"), testList
[6].m_StatAdd
);
685 EXPECT_STREQ(_T("0"), testList
[6].m_StatDel
);
686 EXPECT_EQ(0, testList
[6].m_Stage
);
687 EXPECT_STREQ(_T("ext/apr-util"), testList
[7].GetGitPathString());
688 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[7].m_Action
);
689 EXPECT_STREQ(_T("0"), testList
[7].m_StatAdd
);
690 EXPECT_STREQ(_T("0"), testList
[7].m_StatDel
);
691 EXPECT_EQ(0, testList
[7].m_Stage
);
692 EXPECT_STREQ(_T("ext/libgit2"), testList
[8].GetGitPathString());
693 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[8].m_Action
);
694 EXPECT_STREQ(_T("1"), testList
[8].m_StatAdd
);
695 EXPECT_STREQ(_T("1"), testList
[8].m_StatDel
);
696 EXPECT_EQ(0, testList
[8].m_Stage
);
697 EXPECT_STREQ(_T("test/UnitTests/TGitPathTest.cpp"), testList
[9].GetGitPathString());
698 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[9].m_Action
);
699 EXPECT_STREQ(_T("162"), testList
[9].m_StatAdd
);
700 EXPECT_STREQ(_T("2"), testList
[9].m_StatDel
);
701 EXPECT_EQ(0, testList
[9].m_Stage
);
704 TEST(CTGitPath
, ParserFromLog_Diff_r_raw_C_M_numstat_z_HEAD
)
707 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" };
708 CGitByteArray byteArray
;
709 byteArray
.append(git_Diff_r_raw_C_M_numstat_z_HEAD_output
, sizeof(git_Diff_r_raw_C_M_numstat_z_HEAD_output
));
710 CTGitPathList testList
;
711 EXPECT_EQ(0, testList
.ParserFromLog(byteArray
));
712 ASSERT_EQ(9, testList
.GetCount());
713 EXPECT_STREQ(_T("build.txt"), testList
[0].GetGitPathString());
714 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[0].m_Action
);
715 EXPECT_STREQ(_T("0"), testList
[0].m_StatAdd
);
716 EXPECT_STREQ(_T("61"), testList
[0].m_StatDel
);
717 EXPECT_EQ(0, testList
[0].m_Stage
);
718 EXPECT_STREQ(_T("ext/apr"), testList
[1].GetGitPathString());
719 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[1].m_Action
);
720 EXPECT_STREQ(_T("0"), testList
[1].m_StatAdd
);
721 EXPECT_STREQ(_T("0"), testList
[1].m_StatDel
);
722 EXPECT_EQ(0, testList
[1].m_Stage
);
723 EXPECT_STREQ(_T("ext/apr-util"), testList
[2].GetGitPathString());
724 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[2].m_Action
);
725 EXPECT_STREQ(_T("0"), testList
[2].m_StatAdd
);
726 EXPECT_STREQ(_T("0"), testList
[2].m_StatDel
);
727 EXPECT_EQ(0, testList
[2].m_Stage
);
728 EXPECT_STREQ(_T("ext/libgit2"), testList
[3].GetGitPathString());
729 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[3].m_Action
);
730 EXPECT_STREQ(_T("1"), testList
[3].m_StatAdd
);
731 EXPECT_STREQ(_T("1"), testList
[3].m_StatDel
);
732 EXPECT_EQ(0, testList
[3].m_Stage
);
733 EXPECT_STREQ(_T("release-renamed.txt"), testList
[4].GetGitPathString());
734 EXPECT_EQ(CTGitPath::LOGACTIONS_REPLACED
, testList
[4].m_Action
);
735 EXPECT_STREQ(_T("0"), testList
[4].m_StatAdd
);
736 EXPECT_STREQ(_T("0"), testList
[4].m_StatDel
);
737 EXPECT_EQ(0, testList
[4].m_Stage
);
738 EXPECT_STREQ(_T("release.txt"), testList
[4].GetGitOldPathString());
739 EXPECT_STREQ(_T("signedness.txt"), testList
[5].GetGitPathString());
740 EXPECT_EQ(CTGitPath::LOGACTIONS_ADDED
, testList
[5].m_Action
);
741 EXPECT_STREQ(_T("1176"), testList
[5].m_StatAdd
);
742 EXPECT_STREQ(_T("0"), testList
[5].m_StatDel
);
743 EXPECT_EQ(0, testList
[5].m_Stage
);
744 EXPECT_STREQ(_T("src/Debug-Hints.txt"), testList
[6].GetGitPathString());
745 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[6].m_Action
);
746 EXPECT_STREQ(_T("0"), testList
[6].m_StatAdd
);
747 EXPECT_STREQ(_T("74"), testList
[6].m_StatDel
);
748 EXPECT_EQ(0, testList
[6].m_Stage
);
749 EXPECT_STREQ(_T("src/gpl.txt"), testList
[7].GetGitPathString());
750 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[7].m_Action
);
751 EXPECT_STREQ(_T("0"), testList
[7].m_StatAdd
);
752 EXPECT_STREQ(_T("340"), testList
[7].m_StatDel
);
753 EXPECT_EQ(0, testList
[7].m_Stage
);
754 EXPECT_STREQ(_T("test/UnitTests/TGitPathTest.cpp"), testList
[8].GetGitPathString());
755 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[8].m_Action
);
756 EXPECT_STREQ(_T("162"), testList
[8].m_StatAdd
);
757 EXPECT_STREQ(_T("2"), testList
[8].m_StatDel
);
758 EXPECT_EQ(0, testList
[8].m_Stage
);
761 TEST(CTGitPath
, ParserFromLog_DiffTree
)
763 // git.exe diff-tree -r --raw -C -M --numstat -z 8a75b51cc7f10b9755fc89837fe78b0c646b8b12~1 8a75b51cc7f10b9755fc89837fe78b0c646b8b12
764 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" };
765 CGitByteArray byteArray
;
766 byteArray
.append(git_difftree_output
, sizeof(git_difftree_output
));
767 CTGitPathList testList
;
768 EXPECT_EQ(0, testList
.ParserFromLog(byteArray
));
769 ASSERT_EQ(9, testList
.GetCount());
770 EXPECT_STREQ(_T("src/Git/Git.cpp"), testList
[0].GetGitPathString());
771 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[0].m_Action
);
772 EXPECT_STREQ(_T("1"), testList
[0].m_StatAdd
);
773 EXPECT_STREQ(_T("1"), testList
[0].m_StatDel
);
774 EXPECT_EQ(0, testList
[0].m_Stage
);
775 EXPECT_STREQ(_T("src/Git/Git.h"), testList
[1].GetGitPathString());
776 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[1].m_Action
);
777 EXPECT_STREQ(_T("3"), testList
[1].m_StatAdd
);
778 EXPECT_STREQ(_T("0"), testList
[1].m_StatDel
);
779 EXPECT_EQ(0, testList
[1].m_Stage
);
780 EXPECT_STREQ(_T("src/Git/Git.vcxproj"), testList
[2].GetGitPathString());
781 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[2].m_Action
);
782 EXPECT_STREQ(_T("0"), testList
[2].m_StatAdd
);
783 EXPECT_STREQ(_T("2"), testList
[2].m_StatDel
);
784 EXPECT_EQ(0, testList
[2].m_Stage
);
785 EXPECT_STREQ(_T("src/Git/Git.vcxproj.filters"), testList
[3].GetGitPathString());
786 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[3].m_Action
);
787 EXPECT_STREQ(_T("0"), testList
[3].m_StatAdd
);
788 EXPECT_STREQ(_T("6"), testList
[3].m_StatDel
);
789 EXPECT_EQ(0, testList
[3].m_Stage
);
790 EXPECT_STREQ(_T("src/Git/GitConfig.cpp"), testList
[4].GetGitPathString());
791 EXPECT_EQ(CTGitPath::LOGACTIONS_DELETED
, testList
[4].m_Action
);
792 EXPECT_STREQ(_T("0"), testList
[4].m_StatAdd
);
793 EXPECT_STREQ(_T("29"), testList
[4].m_StatDel
);
794 EXPECT_EQ(0, testList
[4].m_Stage
);
795 EXPECT_STREQ(_T("src/Git/GitForWindows.h"), testList
[5].GetGitPathString());
796 EXPECT_EQ(CTGitPath::LOGACTIONS_REPLACED
, testList
[5].m_Action
);
797 EXPECT_STREQ(_T("src/Git/GitConfig.h"), testList
[5].GetGitOldPathString());
798 EXPECT_STREQ(_T("1"), testList
[5].m_StatAdd
);
799 EXPECT_STREQ(_T("11"), testList
[5].m_StatDel
);
800 EXPECT_EQ(0, testList
[5].m_Stage
);
801 EXPECT_STREQ(_T("src/Git/GitIndex.cpp"), testList
[6].GetGitPathString());
802 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[6].m_Action
);
803 EXPECT_STREQ(_T("0"), testList
[6].m_StatAdd
);
804 EXPECT_STREQ(_T("1"), testList
[6].m_StatDel
);
805 EXPECT_EQ(0, testList
[6].m_Stage
);
806 EXPECT_STREQ(_T("src/TortoiseProc/Settings/SetMainPage.cpp"), testList
[7].GetGitPathString());
807 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[7].m_Action
);
808 EXPECT_STREQ(_T("1"), testList
[7].m_StatAdd
);
809 EXPECT_STREQ(_T("1"), testList
[7].m_StatDel
);
810 EXPECT_EQ(0, testList
[7].m_Stage
);
811 EXPECT_STREQ(_T("src/TortoiseProc/TortoiseProc.cpp"), testList
[8].GetGitPathString());
812 EXPECT_EQ(CTGitPath::LOGACTIONS_MODIFIED
, testList
[8].m_Action
);
813 EXPECT_STREQ(_T("0"), testList
[8].m_StatAdd
);
814 EXPECT_STREQ(_T("1"), testList
[8].m_StatDel
);
815 EXPECT_EQ(0, testList
[8].m_Stage
);
818 static void setFlagOnFileInIndex(CAutoIndex
& gitindex
, const CString
& filename
, bool assumevalid
, bool skipworktree
)
821 EXPECT_TRUE(git_index_find(&idx
, gitindex
, CUnicodeUtils::GetUTF8(filename
)) == 0);
822 git_index_entry
*e
= const_cast<git_index_entry
*>(git_index_get_byindex(gitindex
, idx
));
824 if (assumevalid
== BST_UNCHECKED
)
825 e
->flags
&= ~GIT_IDXENTRY_VALID
;
826 else if (assumevalid
== BST_CHECKED
)
827 e
->flags
|= GIT_IDXENTRY_VALID
;
828 if (skipworktree
== BST_UNCHECKED
)
829 e
->flags_extended
&= ~GIT_IDXENTRY_SKIP_WORKTREE
;
830 else if (skipworktree
== BST_CHECKED
)
831 e
->flags_extended
|= GIT_IDXENTRY_SKIP_WORKTREE
;
832 EXPECT_TRUE(git_index_add(gitindex
, e
) == 0);
835 TEST(CTGitPath
, FillBasedOnIndexFlags
)
840 CAutoRepository repo
= nullptr;
841 EXPECT_TRUE(git_repository_init(repo
.GetPointer(), CUnicodeUtils::GetUTF8(tmpDir
.GetTempDir()), 0) == 0);
843 ASSERT_TRUE(CreateDirectory(tmpDir
.GetTempDir() + _T("\\a"), nullptr));
844 ASSERT_TRUE(CreateDirectory(tmpDir
.GetTempDir() + _T("\\b"), nullptr));
847 EXPECT_TRUE(git_repository_index(gitindex
.GetPointer(), repo
) == 0);
849 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" };
850 for (const CString
& filename
: filenames
)
852 CString filenameWithPath
= tmpDir
.GetTempDir() + _T("\\") + filename
;
853 EXPECT_TRUE(CStringUtils::WriteStringToTextFile((LPCTSTR
)filenameWithPath
, L
"something"));
854 EXPECT_TRUE(git_index_add_bypath(gitindex
, CUnicodeUtils::GetUTF8(filename
)) == 0);
857 setFlagOnFileInIndex(gitindex
, L
"assume-unchanged", true, false);
858 setFlagOnFileInIndex(gitindex
, L
"a/assume-unchanged", true, false);
859 setFlagOnFileInIndex(gitindex
, L
"b/assume-unchanged", true, false);
860 setFlagOnFileInIndex(gitindex
, L
"skip-worktree", false, true);
861 setFlagOnFileInIndex(gitindex
, L
"a/skip-worktree", false, true);
862 setFlagOnFileInIndex(gitindex
, L
"b/skip-worktree", false, true);
864 EXPECT_TRUE(git_index_write(gitindex
) == 0);
868 g_Git
.m_CurrentDir
= tmpDir
.GetTempDir();
870 CTGitPathList testList
;
871 EXPECT_TRUE(testList
.FillBasedOnIndexFlags(0) == 0);
872 EXPECT_EQ(0, testList
.GetCount());
875 EXPECT_TRUE(testList
.FillBasedOnIndexFlags(GIT_IDXENTRY_VALID
) == 0);
876 EXPECT_EQ(3, testList
.GetCount());
877 EXPECT_STREQ(_T("a/assume-unchanged"), testList
[0].GetGitPathString());
878 EXPECT_STREQ(_T("assume-unchanged"), testList
[1].GetGitPathString());
879 EXPECT_STREQ(_T("b/assume-unchanged"), testList
[2].GetGitPathString());
882 EXPECT_TRUE(testList
.FillBasedOnIndexFlags(GIT_IDXENTRY_SKIP_WORKTREE
) == 0);
883 EXPECT_EQ(3, testList
.GetCount());
884 EXPECT_STREQ(_T("a/skip-worktree"), testList
[0].GetGitPathString());
885 EXPECT_STREQ(_T("b/skip-worktree"), testList
[1].GetGitPathString());
886 EXPECT_STREQ(_T("skip-worktree"), testList
[2].GetGitPathString());
889 EXPECT_TRUE(testList
.FillBasedOnIndexFlags(GIT_IDXENTRY_VALID
| GIT_IDXENTRY_SKIP_WORKTREE
) == 0);
890 EXPECT_EQ(6, testList
.GetCount());
891 EXPECT_STREQ(_T("a/assume-unchanged"), testList
[0].GetGitPathString());
892 EXPECT_STREQ(_T("a/skip-worktree"), testList
[1].GetGitPathString());
893 EXPECT_STREQ(_T("assume-unchanged"), testList
[2].GetGitPathString());
894 EXPECT_STREQ(_T("b/assume-unchanged"), testList
[3].GetGitPathString());
895 EXPECT_STREQ(_T("b/skip-worktree"), testList
[4].GetGitPathString());
896 EXPECT_STREQ(_T("skip-worktree"), testList
[5].GetGitPathString());
898 CTGitPathList selectList
;
899 selectList
.AddPath(CTGitPath(_T("versioned")));
900 selectList
.AddPath(CTGitPath(_T("assume-unchanged")));
901 selectList
.AddPath(CTGitPath(_T("skip-worktree")));
902 selectList
.AddPath(CTGitPath(_T("a/skip-worktree")));
903 EXPECT_TRUE(testList
.FillBasedOnIndexFlags(GIT_IDXENTRY_VALID
| GIT_IDXENTRY_SKIP_WORKTREE
, &selectList
) == 0);
904 EXPECT_EQ(3, testList
.GetCount());
905 EXPECT_STREQ(_T("a/skip-worktree"), testList
[0].GetGitPathString());
906 EXPECT_STREQ(_T("assume-unchanged"), testList
[1].GetGitPathString());
907 EXPECT_STREQ(_T("skip-worktree"), testList
[2].GetGitPathString());
910 selectList
.AddPath(CTGitPath(_T("a")));
911 EXPECT_TRUE(testList
.FillBasedOnIndexFlags(GIT_IDXENTRY_VALID
| GIT_IDXENTRY_SKIP_WORKTREE
, &selectList
) == 0);
912 EXPECT_EQ(2, testList
.GetCount());
913 EXPECT_STREQ(_T("a/assume-unchanged"), testList
[0].GetGitPathString());
914 EXPECT_STREQ(_T("a/skip-worktree"), testList
[1].GetGitPathString());
917 selectList
.AddPath(CTGitPath(_T("a")));
918 EXPECT_TRUE(testList
.FillBasedOnIndexFlags(GIT_IDXENTRY_VALID
, &selectList
) == 0);
919 EXPECT_EQ(1, testList
.GetCount());
920 EXPECT_STREQ(_T("a/assume-unchanged"), testList
[0].GetGitPathString());
923 TEST(CTGitPath
, ParserFromLsFile_Empty
)
925 CGitByteArray byteArray
;
926 CTGitPathList testList
;
927 EXPECT_EQ(0, testList
.ParserFromLsFile(byteArray
));
928 EXPECT_EQ(0, testList
.GetCount());
931 TEST(CTGitPath
, ParserFromLsFile_SingleFileConflict
)
933 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" };
934 CGitByteArray byteArray
;
935 byteArray
.append(git_ls_file_u_t_z_output
, sizeof(git_ls_file_u_t_z_output
));
936 CTGitPathList testList
;
937 EXPECT_EQ(0, testList
.ParserFromLsFile(byteArray
));
938 EXPECT_EQ(3, testList
.GetCount());
939 EXPECT_STREQ(_T("bla.txt"), testList
[0].GetGitPathString());
940 EXPECT_STREQ(_T("bla.txt"), testList
[1].GetGitPathString());
941 EXPECT_STREQ(_T("bla.txt"), testList
[2].GetGitPathString());
942 EXPECT_EQ(1, testList
[0].m_Stage
);
943 EXPECT_EQ(2, testList
[1].m_Stage
);
944 EXPECT_EQ(3, testList
[2].m_Stage
);
945 EXPECT_EQ(0, testList
[0].m_Action
);
946 EXPECT_EQ(0, testList
[1].m_Action
);
947 EXPECT_EQ(0, testList
[2].m_Action
);
950 TEST(CTGitPath
, ParserFromLsFile_DeletedFileConflict
)
952 // file added, modified on branch A, deleted on branch B, merge branch A on B (git status says: "deleted by us")
953 BYTE git_ls_file_u_t_z_output
[] = { "M 100644 24091f0add7afc47ac7cdc80ae4d3866b2ef588c 1 Neues Textdokument.txt\0M 100644 293b6f6293106b6ebb5d54ad482d7561b0f1c9ae 3 Neues Textdokument.txt\0" };
954 CGitByteArray byteArray
;
955 byteArray
.append(git_ls_file_u_t_z_output
, sizeof(git_ls_file_u_t_z_output
));
956 CTGitPathList testList
;
957 EXPECT_EQ(0, testList
.ParserFromLsFile(byteArray
));
958 EXPECT_EQ(2, testList
.GetCount());
959 EXPECT_STREQ(_T("Neues Textdokument.txt"), testList
[0].GetGitPathString());
960 EXPECT_STREQ(_T("Neues Textdokument.txt"), testList
[1].GetGitPathString());
961 EXPECT_EQ(1, testList
[0].m_Stage
);
962 EXPECT_EQ(3, testList
[1].m_Stage
);
963 EXPECT_EQ(0, testList
[0].m_Action
);
964 EXPECT_EQ(0, testList
[1].m_Action
);
967 TEST(CTGitPath
, ParserFromLsFile_MultipleFilesConflict
)
969 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" };
970 CGitByteArray byteArray
;
971 byteArray
.append(git_ls_file_u_t_z_output
, sizeof(git_ls_file_u_t_z_output
));
972 CTGitPathList testList
;
973 EXPECT_EQ(0, testList
.ParserFromLsFile(byteArray
));
974 EXPECT_EQ(3 * 3, testList
.GetCount()); // 3 files are conflicted with 3 stages
975 EXPECT_STREQ(_T("OSMtracker.sln"), testList
[0].GetGitPathString());
976 EXPECT_STREQ(_T("OSMtracker.sln"), testList
[1].GetGitPathString());
977 EXPECT_STREQ(_T("OSMtracker.sln"), testList
[2].GetGitPathString());
978 EXPECT_STREQ(_T("OSMtracker/frmMain.vb"), testList
[3].GetGitPathString());
979 EXPECT_STREQ(_T("OSMtracker/frmMain.vb"), testList
[4].GetGitPathString());
980 EXPECT_STREQ(_T("OSMtracker/frmMain.vb"), testList
[5].GetGitPathString());
981 EXPECT_STREQ(_T("OSMtracker/osmTileMap.vb"), testList
[6].GetGitPathString());
982 EXPECT_STREQ(_T("OSMtracker/osmTileMap.vb"), testList
[7].GetGitPathString());
983 EXPECT_STREQ(_T("OSMtracker/osmTileMap.vb"), testList
[8].GetGitPathString());
984 EXPECT_EQ(1, testList
[0].m_Stage
);
985 EXPECT_EQ(2, testList
[1].m_Stage
);
986 EXPECT_EQ(3, testList
[2].m_Stage
);
987 EXPECT_EQ(1, testList
[3].m_Stage
);
988 EXPECT_EQ(2, testList
[4].m_Stage
);
989 EXPECT_EQ(3, testList
[5].m_Stage
);
990 EXPECT_EQ(1, testList
[6].m_Stage
);
991 EXPECT_EQ(2, testList
[7].m_Stage
);
992 EXPECT_EQ(3, testList
[8].m_Stage
);
993 EXPECT_EQ(0, testList
[0].m_Action
);
994 EXPECT_EQ(0, testList
[1].m_Action
);
995 EXPECT_EQ(0, testList
[2].m_Action
);
996 EXPECT_EQ(0, testList
[3].m_Action
);
997 EXPECT_EQ(0, testList
[4].m_Action
);
998 EXPECT_EQ(0, testList
[5].m_Action
);
999 EXPECT_EQ(0, testList
[6].m_Action
);
1000 EXPECT_EQ(0, testList
[7].m_Action
);
1001 EXPECT_EQ(0, testList
[8].m_Action
);
1004 TEST(CTGitPath
, ParserFromLsFile_NormalRepo
)
1006 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" };
1007 CGitByteArray byteArray
;
1008 byteArray
.append(git_ls_file_u_t_z_output
, sizeof(git_ls_file_u_t_z_output
));
1009 CTGitPathList testList
;
1010 EXPECT_EQ(0, testList
.ParserFromLsFile(byteArray
));
1011 EXPECT_EQ(3, testList
.GetCount());
1012 EXPECT_STREQ(_T("README.md"), testList
[0].GetGitPathString());
1013 EXPECT_STREQ(_T("taskxml.xsd"), testList
[1].GetGitPathString());
1014 EXPECT_STREQ(_T("whitepaper.md"), testList
[2].GetGitPathString());
1015 EXPECT_EQ(0, testList
[0].m_Stage
);
1016 EXPECT_EQ(0, testList
[1].m_Stage
);
1017 EXPECT_EQ(0, testList
[2].m_Stage
);
1018 EXPECT_EQ(0, testList
[0].m_Action
);
1019 EXPECT_EQ(0, testList
[1].m_Action
);
1020 EXPECT_EQ(0, testList
[2].m_Action
);
1023 TEST(CTGitPath
, ParserFromLsFile_RepoWithSubmodule
)
1025 BYTE git_ls_file_u_t_z_output
[] = { "H 160000 d4eaf3c5d0994eb0112c17aa3c732022eb9fdf6b 0 ext/gtest\0" };
1026 CGitByteArray byteArray
;
1027 byteArray
.append(git_ls_file_u_t_z_output
, sizeof(git_ls_file_u_t_z_output
));
1028 CTGitPathList testList
;
1029 EXPECT_EQ(0, testList
.ParserFromLsFile(byteArray
));
1030 EXPECT_EQ(1, testList
.GetCount());
1031 EXPECT_STREQ(_T("ext/gtest"), testList
[0].GetGitPathString());
1032 EXPECT_EQ(0, testList
[0].m_Stage
);
1033 EXPECT_EQ(0, testList
[0].m_Action
);
1036 TEST(CTGitPath
, FillUnRev
)
1038 CAutoTempDir tmpDir
;
1040 CAutoRepository repo
= nullptr;
1041 ASSERT_TRUE(git_repository_init(repo
.GetPointer(), CUnicodeUtils::GetUTF8(tmpDir
.GetTempDir()), false) == 0);
1043 g_Git
.m_CurrentDir
= tmpDir
.GetTempDir();
1045 CTGitPathList testList
;
1046 EXPECT_EQ(0, testList
.FillUnRev(0));
1047 EXPECT_EQ(0, testList
.GetCount());
1049 EXPECT_EQ(0, testList
.FillUnRev(CTGitPath::LOGACTIONS_IGNORE
));
1050 EXPECT_EQ(0, testList
.GetCount());
1052 CString fileOne
= tmpDir
.GetTempDir() + L
"\\one";
1053 EXPECT_TRUE(CStringUtils::WriteStringToTextFile((LPCTSTR
)fileOne
, L
"something"));
1055 EXPECT_EQ(0, testList
.FillUnRev(0));
1056 EXPECT_EQ(1, testList
.GetCount());
1057 EXPECT_STREQ(L
"one", testList
[0].GetGitPathString());
1059 EXPECT_EQ(0, testList
.FillUnRev(CTGitPath::LOGACTIONS_IGNORE
));
1060 EXPECT_EQ(0, testList
.GetCount());
1062 CTGitPathList selectList
;
1063 selectList
.AddPath(CTGitPath(_T("one")));
1065 EXPECT_EQ(0, testList
.FillUnRev(0, &selectList
));
1066 EXPECT_EQ(1, testList
.GetCount());
1067 EXPECT_STREQ(L
"one", testList
[0].GetGitPathString());
1069 EXPECT_EQ(0, testList
.FillUnRev(CTGitPath::LOGACTIONS_IGNORE
, &selectList
));
1070 EXPECT_EQ(0, testList
.GetCount());
1072 CString gitIgnore
= tmpDir
.GetTempDir() + L
"\\.gitignore";
1073 EXPECT_TRUE(CStringUtils::WriteStringToTextFile((LPCTSTR
)gitIgnore
, L
""));
1075 EXPECT_EQ(0, testList
.FillUnRev(0));
1076 EXPECT_EQ(2, testList
.GetCount());
1077 EXPECT_STREQ(L
".gitignore", testList
[0].GetGitPathString());
1078 EXPECT_STREQ(L
"one", testList
[1].GetGitPathString());
1080 EXPECT_EQ(0, testList
.FillUnRev(CTGitPath::LOGACTIONS_IGNORE
));
1081 EXPECT_EQ(0, testList
.GetCount());
1083 EXPECT_EQ(0, testList
.FillUnRev(0, &selectList
));
1084 EXPECT_EQ(1, testList
.GetCount());
1085 EXPECT_STREQ(L
"one", testList
[0].GetGitPathString());
1087 EXPECT_EQ(0, testList
.FillUnRev(CTGitPath::LOGACTIONS_IGNORE
, &selectList
));
1088 EXPECT_EQ(0, testList
.GetCount());
1090 EXPECT_TRUE(CStringUtils::WriteStringToTextFile((LPCTSTR
)gitIgnore
, L
"/one"));
1092 EXPECT_EQ(0, testList
.FillUnRev(0));
1093 EXPECT_EQ(1, testList
.GetCount());
1094 EXPECT_STREQ(L
".gitignore", testList
[0].GetGitPathString());
1096 EXPECT_EQ(0, testList
.FillUnRev(CTGitPath::LOGACTIONS_IGNORE
));
1097 EXPECT_EQ(1, testList
.GetCount());
1098 EXPECT_STREQ(L
"one", testList
[0].GetGitPathString());
1100 EXPECT_EQ(0, testList
.FillUnRev(0, &selectList
));
1101 EXPECT_EQ(0, testList
.GetCount());
1103 EXPECT_EQ(0, testList
.FillUnRev(CTGitPath::LOGACTIONS_IGNORE
, &selectList
));
1104 EXPECT_EQ(1, testList
.GetCount());
1105 EXPECT_STREQ(L
"one", testList
[0].GetGitPathString());
1107 EXPECT_TRUE(CreateDirectory(tmpDir
.GetTempDir() + _T("\\subdir"), nullptr));
1109 selectList
.AddPath(CTGitPath(_T("subdir")));
1110 EXPECT_EQ(0, testList
.FillUnRev(0, &selectList
));
1111 EXPECT_EQ(0, testList
.GetCount());
1113 EXPECT_EQ(0, testList
.FillUnRev(CTGitPath::LOGACTIONS_IGNORE
, &selectList
));
1114 EXPECT_EQ(0, testList
.GetCount());
1116 fileOne
= tmpDir
.GetTempDir() + L
"\\subdir\\one";
1117 EXPECT_TRUE(CStringUtils::WriteStringToTextFile((LPCTSTR
)fileOne
, L
"something"));
1119 EXPECT_EQ(0, testList
.FillUnRev(0));
1120 EXPECT_EQ(2, testList
.GetCount());
1121 EXPECT_STREQ(L
".gitignore", testList
[0].GetGitPathString());
1122 EXPECT_STREQ(L
"subdir/one", testList
[1].GetGitPathString());
1124 EXPECT_EQ(0, testList
.FillUnRev(CTGitPath::LOGACTIONS_IGNORE
));
1125 EXPECT_EQ(1, testList
.GetCount());
1126 EXPECT_STREQ(L
"one", testList
[0].GetGitPathString());
1128 EXPECT_EQ(0, testList
.FillUnRev(0, &selectList
));
1129 EXPECT_EQ(1, testList
.GetCount());
1130 EXPECT_STREQ(L
"subdir/one", testList
[0].GetGitPathString());
1132 EXPECT_EQ(0, testList
.FillUnRev(CTGitPath::LOGACTIONS_IGNORE
, &selectList
));
1133 EXPECT_EQ(0, testList
.GetCount());
1135 EXPECT_TRUE(CStringUtils::WriteStringToTextFile((LPCTSTR
)gitIgnore
, L
"one"));
1137 EXPECT_EQ(0, testList
.FillUnRev(0));
1138 EXPECT_EQ(1, testList
.GetCount());
1139 EXPECT_STREQ(L
".gitignore", testList
[0].GetGitPathString());
1141 EXPECT_EQ(0, testList
.FillUnRev(CTGitPath::LOGACTIONS_IGNORE
));
1142 EXPECT_STREQ(L
"one", testList
[0].GetGitPathString());
1143 EXPECT_STREQ(L
"subdir/one", testList
[1].GetGitPathString());
1145 EXPECT_EQ(0, testList
.FillUnRev(CTGitPath::LOGACTIONS_IGNORE
, &selectList
));
1146 EXPECT_EQ(1, testList
.GetCount());
1147 EXPECT_STREQ(L
"subdir/one", testList
[0].GetGitPathString());