1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2015-2020, 2024 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "RepositoryFixtures.h"
22 #include "GitRevRefBrowser.h"
24 class GitRevRefBrowserCBasicGitWithTestRepoFixture
: public CBasicGitWithTestRepoFixture
28 class GitRevRefBrowserCBasicGitWithTestRepoBareFixture
: public CBasicGitWithTestRepoBareFixture
32 INSTANTIATE_TEST_SUITE_P(GitRevRefBrowser
, GitRevRefBrowserCBasicGitWithTestRepoFixture
, testing::Values(GIT_CLI
));
33 INSTANTIATE_TEST_SUITE_P(GitRevRefBrowser
, GitRevRefBrowserCBasicGitWithTestRepoBareFixture
, testing::Values(GIT_CLI
));
35 static void GetGitRevRefMap()
37 g_Git
.SetConfigValue(L
"branch.master.description", L
"test");
38 g_Git
.SetConfigValue(L
"branch.subdir/branch.description", L
"multi\nline");
40 MAP_REF_GITREVREFBROWSER refMap
;
42 EXPECT_EQ(0, GitRevRefBrowser::GetGitRevRefMap(refMap
, 0, err
));
43 EXPECT_STREQ(L
"", err
);
44 EXPECT_EQ(12U, refMap
.size());
46 GitRevRefBrowser rev
= refMap
[L
"refs/heads/master"];
47 EXPECT_STREQ(L
"7c3cbfe13a929d2291a574dca45e4fd2d2ac1aa6", rev
.m_CommitHash
.ToString());
48 EXPECT_STREQ(L
"Sven Strickroth", rev
.GetAuthorName());
49 EXPECT_STREQ(L
"2015-03-07 18:03:58", rev
.GetAuthorDate().FormatGmt(L
"%Y-%m-%d %H:%M:%S"));
50 EXPECT_STREQ(L
"Sven Strickroth", rev
.GetCommitterName());
51 EXPECT_STREQ(L
"2015-03-07 18:03:58", rev
.GetCommitterDate().FormatGmt(L
"%Y-%m-%d %H:%M:%S"));
52 EXPECT_STREQ(L
"Changed ASCII file", rev
.GetSubject());
53 EXPECT_STREQ(L
"refs/remotes/origin/master", rev
.m_UpstreamRef
);
54 EXPECT_STREQ(L
"test", rev
.m_Description
);
56 rev
= refMap
[L
"refs/heads/signed-commit"];
57 EXPECT_STREQ(L
"4c5c93d2a0b368bc4570d5ec02ab03b9c4334d44", rev
.m_CommitHash
.ToString());
58 EXPECT_STREQ(L
"Sven Strickroth", rev
.GetAuthorName());
59 EXPECT_STREQ(L
"2015-03-16 12:52:29", rev
.GetAuthorDate().FormatGmt(L
"%Y-%m-%d %H:%M:%S"));
60 EXPECT_STREQ(L
"Sven Strickroth", rev
.GetCommitterName());
61 EXPECT_STREQ(L
"2015-03-16 13:06:08", rev
.GetCommitterDate().FormatGmt(L
"%Y-%m-%d %H:%M:%S"));
62 EXPECT_STREQ(L
"Several actions", rev
.GetSubject());
63 EXPECT_STREQ(L
"", rev
.m_UpstreamRef
);
64 EXPECT_STREQ(L
"", rev
.m_Description
);
66 rev
= refMap
[L
"refs/tags/also-signed"];
67 EXPECT_STREQ(L
"e89cb722e0f9b2eb763bb059dc099ee6c502a6d8", rev
.m_CommitHash
.ToString());
68 EXPECT_STREQ(L
"Sven Strickroth", rev
.GetAuthorName());
69 EXPECT_STREQ(L
"2015-03-04 17:45:40", rev
.GetAuthorDate().FormatGmt(L
"%Y-%m-%d %H:%M:%S"));
70 EXPECT_STREQ(L
"Sven Strickroth", rev
.GetCommitterName());
71 EXPECT_STREQ(L
"2015-03-04 17:45:40", rev
.GetCommitterDate().FormatGmt(L
"%Y-%m-%d %H:%M:%S"));
72 EXPECT_STREQ(L
"Also signed", rev
.GetSubject());
73 EXPECT_STREQ(L
"", rev
.m_UpstreamRef
);
74 EXPECT_STREQ(L
"", rev
.m_Description
);
76 rev
= refMap
[L
"refs/heads/subdir/branch"];
77 EXPECT_STREQ(L
"31ff87c86e9f6d3853e438cb151043f30f09029a", rev
.m_CommitHash
.ToString());
78 EXPECT_STREQ(L
"Sven Strickroth", rev
.GetAuthorName());
79 EXPECT_STREQ(L
"2015-03-16 12:52:29", rev
.GetAuthorDate().FormatGmt(L
"%Y-%m-%d %H:%M:%S")); // used here, because author and commit time differ
80 EXPECT_STREQ(L
"a", rev
.GetCommitterName());
81 EXPECT_STREQ(L
"2017-07-29 15:05:49", rev
.GetCommitterDate().FormatGmt(L
"%Y-%m-%d %H:%M:%S")); // used here, because author and commit time differ
82 EXPECT_STREQ(L
"Several actions", rev
.GetSubject());
83 EXPECT_STREQ(L
"", rev
.m_UpstreamRef
);
84 EXPECT_STREQ(L
"multi\nline", rev
.m_Description
);
87 EXPECT_EQ(0, GitRevRefBrowser::GetGitRevRefMap(refMap
, 0, err
, [](const CString
& refName
) { return CStringUtils::StartsWith(refName
, L
"refs/heads/"); }));
88 EXPECT_STREQ(L
"", err
);
89 EXPECT_EQ(6U, refMap
.size());
90 EXPECT_TRUE(refMap
.find(L
"refs/heads/master") != refMap
.end());
91 for (auto it
= refMap
.cbegin(); it
!= refMap
.cend(); ++it
)
92 EXPECT_TRUE(CStringUtils::StartsWith(it
->first
, L
"refs/heads/"));
95 EXPECT_EQ(0, GitRevRefBrowser::GetGitRevRefMap(refMap
, 1, err
));
96 EXPECT_STREQ(L
"", err
);
97 EXPECT_EQ(6U, refMap
.size());
98 for (const auto& branch
: { L
"refs/heads/master", L
"refs/heads/master2", L
"refs/remotes/origin/master", L
"refs/tags/all-files-signed", L
"refs/tags/also-signed", L
"refs/tags/normal-tag" })
99 EXPECT_TRUE(refMap
.find(branch
) != refMap
.end());
102 EXPECT_EQ(0, GitRevRefBrowser::GetGitRevRefMap(refMap
, 2, err
));
103 EXPECT_STREQ(L
"", err
);
104 EXPECT_EQ(6U, refMap
.size());
105 EXPECT_TRUE(refMap
.find(L
"refs/heads/master") == refMap
.end());
106 for (const auto& branch
: { L
"refs/heads/forconflict", L
"refs/heads/signed-commit", L
"refs/heads/simple-conflict", L
"refs/heads/subdir/branch", L
"refs/notes/commits", L
"refs/stash" })
107 EXPECT_TRUE(refMap
.find(branch
) != refMap
.end());
110 TEST_P(GitRevRefBrowserCBasicGitWithTestRepoFixture
, GetGitRevRefMap
)
115 TEST_P(GitRevRefBrowserCBasicGitWithTestRepoBareFixture
, GetGitRevRefMap
)