From 470d011871b3450fc0ecc334a7b10a5c0174db3b Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Fri, 24 Dec 2021 12:26:57 +0100 Subject: [PATCH] Adjust test cases to latest Git 2.34 changes Signed-off-by: Sven Strickroth --- src/Git/TGitPath.cpp | 2 ++ src/Git/TGitPath.h | 5 +++++ test/UnitTests/GitTest.cpp | 44 +++++++++++++++++++++++++++++++------ test/UnitTests/RepositoryFixtures.h | 5 ++++- 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/Git/TGitPath.cpp b/src/Git/TGitPath.cpp index dfe56b3da..62f76fbdb 100644 --- a/src/Git/TGitPath.cpp +++ b/src/Git/TGitPath.cpp @@ -1283,6 +1283,8 @@ int CTGitPathList::ParserFromLog(BYTE_VECTOR &log, bool parseDeletes /*false*/) // reset submodule/folder status if a staged entry is not a folder if (p.IsDirectory() && ((modeold && !(modeold & S_IFDIR)) || (modenew && !(modenew & S_IFDIR)))) p.UnsetDirectoryStatus(); + else if (!p.IsDirectory() && (modenew && (modenew & S_IFDIR))) + p.SetDirectoryStatus(); if(merged) p.m_Action |= CTGitPath::LOGACTIONS_MERGED; diff --git a/src/Git/TGitPath.h b/src/Git/TGitPath.h index 4e710bafe..343ec744d 100644 --- a/src/Git/TGitPath.h +++ b/src/Git/TGitPath.h @@ -295,6 +295,11 @@ public: * Used while diffing commits where a submodule changed to a file */ void UnsetDirectoryStatus() { m_bIsDirectory = false; } + /** + * Marks a path as a directory by setting the cached IsDirectory status + * Used while diffing commits where a file changed to a submodule + */ + void SetDirectoryStatus() { m_bIsDirectory = true; } private: /** diff --git a/test/UnitTests/GitTest.cpp b/test/UnitTests/GitTest.cpp index 12e498c6e..925e75cf3 100644 --- a/test/UnitTests/GitTest.cpp +++ b/test/UnitTests/GitTest.cpp @@ -2763,8 +2763,15 @@ TEST_P(CBasicGitWithSubmoduleRepositoryFixture, GetWorkingTreeChanges_Submodules EXPECT_EQ(0, m_Git.GetWorkingTreeChanges(list, false, nullptr)); ASSERT_EQ(1, list.GetCount()); EXPECT_STREQ(L"something", list[0].GetGitPathString()); - EXPECT_EQ(CTGitPath::LOGACTIONS_UNMERGED | CTGitPath::LOGACTIONS_MISSING, list[0].m_Action); - EXPECT_FALSE(list[0].IsDirectory()); // neither file nor directory is in filesystem + if (m_Git.ms_LastMsysGitVersion < ConvertVersionToInt(2, 34, 0)) { + EXPECT_EQ(CTGitPath::LOGACTIONS_UNMERGED | CTGitPath::LOGACTIONS_MISSING, list[0].m_Action); + EXPECT_FALSE(list[0].IsDirectory()); // neither file nor directory is in filesystem + } + else + { + EXPECT_EQ(CTGitPath::LOGACTIONS_UNMERGED | CTGitPath::LOGACTIONS_ADDED, list[0].m_Action); + EXPECT_TRUE(list[0].IsDirectory()); // now a directory is in filesystem + } // test for merge conflict submodule/file (local submodule, remote file) output.Empty(); @@ -2776,19 +2783,31 @@ TEST_P(CBasicGitWithSubmoduleRepositoryFixture, GetWorkingTreeChanges_Submodules EXPECT_EQ(1, m_Git.Run(L"git.exe merge file", &output, CP_UTF8)); EXPECT_STRNE(L"", output); EXPECT_EQ(0, m_Git.GetWorkingTreeChanges(list, false, nullptr)); - ASSERT_EQ(1, list.GetCount()); + if (m_Git.ms_LastMsysGitVersion < ConvertVersionToInt(2, 34, 0)) + ASSERT_EQ(1, list.GetCount()); + else + ASSERT_EQ(2, list.GetCount()); EXPECT_STREQ(L"something", list[0].GetGitPathString()); - if (m_Git.ms_bCygwinGit || m_Git.ms_bMsys2Git) + if (m_Git.ms_LastMsysGitVersion < ConvertVersionToInt(2, 34, 0) && (m_Git.ms_bCygwinGit || m_Git.ms_bMsys2Git)) { EXPECT_TRUE(output.Find(L"error: failed to create path") > 0); EXPECT_EQ(CTGitPath::LOGACTIONS_UNMERGED, list[0].m_Action); EXPECT_TRUE(list[0].IsDirectory()); // folder is in filesystem } - else + else if (m_Git.ms_LastMsysGitVersion < ConvertVersionToInt(2, 34, 0)) { EXPECT_EQ(CTGitPath::LOGACTIONS_UNMERGED | CTGitPath::LOGACTIONS_MODIFIED, list[0].m_Action); EXPECT_FALSE(list[0].IsDirectory()); // file is in filesystem } + else + { + EXPECT_STREQ(L"something", list[0].GetGitPathString()); + EXPECT_EQ(CTGitPath::LOGACTIONS_UNMERGED, list[0].m_Action); + EXPECT_TRUE(list[0].IsDirectory()); // directory is in filesystem + EXPECT_STREQ(L"something~file", list[1].GetGitPathString()); + EXPECT_EQ(CTGitPath::LOGACTIONS_UNMERGED | CTGitPath::LOGACTIONS_ADDED, list[1].m_Action); + EXPECT_FALSE(list[1].IsDirectory()); // alternative file is in filesystem + } // test for merge conflict submodule/file (remote submodule, local file) output.Empty(); @@ -2800,10 +2819,21 @@ TEST_P(CBasicGitWithSubmoduleRepositoryFixture, GetWorkingTreeChanges_Submodules EXPECT_EQ(1, m_Git.Run(L"git.exe merge branch1", &output, CP_UTF8)); EXPECT_STRNE(L"", output); EXPECT_EQ(0, m_Git.GetWorkingTreeChanges(list, false, nullptr)); - ASSERT_EQ(1, list.GetCount()); + if (m_Git.ms_LastMsysGitVersion < ConvertVersionToInt(2, 34, 0)) + ASSERT_EQ(1, list.GetCount()); + else + ASSERT_EQ(2, list.GetCount()); EXPECT_STREQ(L"something", list[0].GetGitPathString()); EXPECT_EQ(CTGitPath::LOGACTIONS_UNMERGED | CTGitPath::LOGACTIONS_MODIFIED, list[0].m_Action); - EXPECT_FALSE(list[0].IsDirectory()); // file is in filesystem + if (m_Git.ms_LastMsysGitVersion < ConvertVersionToInt(2, 34, 0)) + EXPECT_FALSE(list[0].IsDirectory()); // file is in filesystem + else + { + EXPECT_TRUE(list[0].IsDirectory()); // directory is in filesystem + EXPECT_STREQ(L"something~HEAD", list[1].GetGitPathString()); + EXPECT_EQ(CTGitPath::LOGACTIONS_UNMERGED | CTGitPath::LOGACTIONS_ADDED, list[1].m_Action); + EXPECT_FALSE(list[1].IsDirectory()); // alternative file is in filesystem + } // test for simple merge conflict DeleteFile(submoduleDir); diff --git a/test/UnitTests/RepositoryFixtures.h b/test/UnitTests/RepositoryFixtures.h index 3b9801f08..99ccb5a5d 100644 --- a/test/UnitTests/RepositoryFixtures.h +++ b/test/UnitTests/RepositoryFixtures.h @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2015-2018 - TortoiseGit +// Copyright (C) 2015-2018, 2021 - TortoiseGit // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -90,6 +90,9 @@ protected: g_Git.m_IsUseLibGit2_mask = m_Git.m_IsUseLibGit2_mask; // libgit relies on CWD being set to working tree SetCurrentDirectory(m_Git.m_CurrentDir); + + if (CGit::ms_LastMsysGitVersion == 0) + CGit::ms_LastMsysGitVersion = max(0, m_Git.GetGitVersion(nullptr, nullptr)); } virtual void TearDown() override -- 2.11.4.GIT