Browse References Dialog: Allow to filter for merged and unmerged branches
[TortoiseGit.git] / test / UnitTests / GitRevRefBrowseTest.cpp
blob3b5a39c3cec6d8290fe764ffc6da77fce188b804
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2015-2016 - 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.
20 #include "stdafx.h"
21 #include "RepositoryFixtures.h"
22 #include "GitRevRefBrowser.h"
24 class GitRevRefBrowserCBasicGitWithTestRepoFixture : public CBasicGitWithTestRepoFixture
28 class GitRevRefBrowserCBasicGitWithTestRepoBareFixture : public CBasicGitWithTestRepoBareFixture
32 INSTANTIATE_TEST_CASE_P(GitRevRefBrowser, GitRevRefBrowserCBasicGitWithTestRepoFixture, testing::Values(GIT_CLI));
33 INSTANTIATE_TEST_CASE_P(GitRevRefBrowser, GitRevRefBrowserCBasicGitWithTestRepoBareFixture, testing::Values(GIT_CLI));
35 static void GetGitRevRefMap()
37 g_Git.SetConfigValue(_T("branch.master.description"), _T("test"));
38 g_Git.SetConfigValue(_T("branch.subdir/branch.description"), _T("multi\nline"));
40 MAP_REF_GITREVREFBROWSER refMap;
41 CString err;
42 EXPECT_EQ(0, GitRevRefBrowser::GetGitRevRefMap(refMap, 0, err));
43 EXPECT_TRUE(err.IsEmpty());
44 EXPECT_EQ(11, refMap.size());
46 GitRevRefBrowser rev = refMap[L"refs/heads/master"];
47 EXPECT_STREQ(_T("7c3cbfe13a929d2291a574dca45e4fd2d2ac1aa6"), rev.m_CommitHash.ToString());
48 EXPECT_STREQ(_T("Sven Strickroth"), rev.GetAuthorName());
49 EXPECT_STREQ(_T("2015-03-07 18:03:58"), rev.GetAuthorDate().FormatGmt(L"%Y-%m-%d %H:%M:%S"));
50 EXPECT_STREQ(_T("Changed ASCII file"), rev.GetSubject());
51 EXPECT_STREQ(_T("refs/remotes/origin/master"), rev.m_UpstreamRef);
52 EXPECT_STREQ(_T("test"), rev.m_Description);
54 rev = refMap[L"refs/heads/subdir/branch"];
55 EXPECT_STREQ(_T("4c5c93d2a0b368bc4570d5ec02ab03b9c4334d44"), rev.m_CommitHash.ToString());
56 EXPECT_STREQ(_T("Sven Strickroth"), rev.GetAuthorName());
57 EXPECT_STREQ(_T("2015-03-16 12:52:29"), rev.GetAuthorDate().FormatGmt(L"%Y-%m-%d %H:%M:%S"));
58 EXPECT_STREQ(_T("Several actions"), rev.GetSubject());
59 EXPECT_STREQ(_T(""), rev.m_UpstreamRef);
60 EXPECT_STREQ(_T("multi\nline"), rev.m_Description);
62 rev = refMap[L"refs/tags/also-signed"];
63 EXPECT_STREQ(_T("e89cb722e0f9b2eb763bb059dc099ee6c502a6d8"), rev.m_CommitHash.ToString());
64 EXPECT_STREQ(_T(""), rev.GetAuthorName());
65 EXPECT_TRUE(rev.GetAuthorDate() == 0);
66 EXPECT_STREQ(_T("Also signed"), rev.GetSubject());
67 EXPECT_STREQ(_T(""), rev.m_UpstreamRef);
68 EXPECT_STREQ(_T(""), rev.m_Description);
70 refMap.clear();
71 EXPECT_EQ(0, GitRevRefBrowser::GetGitRevRefMap(refMap, 0, err, [](const CString& refName) { return wcsncmp(refName, L"refs/heads/", 11) == 0; }));
72 EXPECT_TRUE(err.IsEmpty());
73 EXPECT_EQ(5, refMap.size());
74 EXPECT_TRUE(refMap.find(L"refs/heads/master") != refMap.end());
75 for (auto it = refMap.cbegin(); it != refMap.cend(); ++it)
76 EXPECT_TRUE(CStringUtils::StartsWith(it->first, L"refs/heads/"));
78 refMap.clear();
79 EXPECT_EQ(0, GitRevRefBrowser::GetGitRevRefMap(refMap, 1, err));
80 EXPECT_TRUE(err.IsEmpty());
81 EXPECT_EQ(6, refMap.size());
82 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" })
83 EXPECT_TRUE(refMap.find(branch) != refMap.end());
85 refMap.clear();
86 EXPECT_EQ(0, GitRevRefBrowser::GetGitRevRefMap(refMap, 2, err));
87 EXPECT_TRUE(err.IsEmpty());
88 EXPECT_EQ(5, refMap.size());
89 EXPECT_TRUE(refMap.find(L"refs/heads/master") == refMap.end());
90 for (const auto& branch : { L"refs/heads/forconflict", L"refs/heads/simple-conflict", L"refs/heads/subdir/branch", L"refs/notes/commits", L"refs/stash" })
91 EXPECT_TRUE(refMap.find(branch) != refMap.end());
94 TEST_P(GitRevRefBrowserCBasicGitWithTestRepoFixture, GetGitRevRefMap)
96 GetGitRevRefMap();
99 TEST_P(GitRevRefBrowserCBasicGitWithTestRepoBareFixture, GetGitRevRefMap)
101 GetGitRevRefMap();