From 953c16b4be688ae0f93cd56a8ae6d6f07aa3180e Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Mon, 6 Feb 2017 23:56:19 +0100 Subject: [PATCH] Fixed issue #2911: Doing Add on repository root fails with libgit2 returned invalid path" Signed-off-by: Sven Strickroth --- src/Changelog.txt | 1 + src/Git/TGitPath.cpp | 6 +++-- test/UnitTests/TGitPathTest.cpp | 41 +++++++++++++++++++++++++++++--- test/UnitTests/UnitTests.vcxproj | 2 ++ test/UnitTests/UnitTests.vcxproj.filters | 9 +++++++ 5 files changed, 54 insertions(+), 5 deletions(-) diff --git a/src/Changelog.txt b/src/Changelog.txt index bc9acc963..aea0a8298 100644 --- a/src/Changelog.txt +++ b/src/Changelog.txt @@ -3,6 +3,7 @@ Released: unreleased == Bug Fixes == * Fixed issue #2909: Commit window unclosable after clicking "No" and "do not ask again" + * Fixed issue #2911: Doing Add on repository root fails with libgit2 returned invalid path" = Release 2.4.0 = Released: 2017-01-31 diff --git a/src/Git/TGitPath.cpp b/src/Git/TGitPath.cpp index 8b0559a87..220d637b0 100644 --- a/src/Git/TGitPath.cpp +++ b/src/Git/TGitPath.cpp @@ -328,14 +328,16 @@ void CTGitPath::UpdateAttributes() const { EnsureBackslashPathSet(); WIN32_FILE_ATTRIBUTE_DATA attribs; - if (m_sBackslashPath.GetLength() >= 248) + if (m_sBackslashPath.IsEmpty()) + m_sLongBackslashPath = L"."; + else if (m_sBackslashPath.GetLength() >= 248) { if (!PathIsRelative(m_sBackslashPath)) m_sLongBackslashPath = L"\\\\?\\" + m_sBackslashPath; else m_sLongBackslashPath = L"\\\\?\\" + g_Git.CombinePath(m_sBackslashPath); } - if(GetFileAttributesEx(m_sBackslashPath.GetLength() >= 248 ? m_sLongBackslashPath : m_sBackslashPath, GetFileExInfoStandard, &attribs)) + if (GetFileAttributesEx(m_sBackslashPath.IsEmpty() || m_sBackslashPath.GetLength() >= 248 ? m_sLongBackslashPath : m_sBackslashPath, GetFileExInfoStandard, &attribs)) { m_bIsDirectory = !!(attribs.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); // don't cast directly to an __int64: diff --git a/test/UnitTests/TGitPathTest.cpp b/test/UnitTests/TGitPathTest.cpp index 3c73c0392..78ac73cbe 100644 --- a/test/UnitTests/TGitPathTest.cpp +++ b/test/UnitTests/TGitPathTest.cpp @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2015-2016 - TortoiseGit +// Copyright (C) 2015-2017 - TortoiseGit // Copyright (C) 2003-2008 - TortoiseSVN // This program is free software; you can redistribute it and/or @@ -22,8 +22,8 @@ #include "TGitPath.h" #include "Git.h" #include "StringUtils.h" - -extern CGit g_Git; +#include "PreserveChdir.h" +#include "AutoTempDir.h" TEST(CTGitPath, GetDirectoryTest) { @@ -1730,3 +1730,38 @@ TEST(CTGitPath, SetDirectory_DiskAccess) pathDir3.UnsetDirectoryStatus(); EXPECT_FALSE(pathDir3.IsDirectory()); } + +TEST(CTGitPath, AreAllPathsFiles) +{ + CTGitPathList list; + EXPECT_TRUE(list.AreAllPathsFiles()); + + list.AddPath(CTGitPath(L"C:\\Windows\\explorer.exe")); + EXPECT_TRUE(list.AreAllPathsFiles()); + + list.AddPath(CTGitPath(L"C:\\Windows")); + EXPECT_FALSE(list.AreAllPathsFiles()); + + list.Clear(); + EXPECT_TRUE(list.AreAllPathsFiles()); + + // now test relative paths + PreserveChdir chdir; + CAutoTempDir tmp; + SetCurrentDirectory(tmp.GetTempDir()); + + EXPECT_TRUE(CStringUtils::WriteStringToTextFile(tmp.GetTempDir() + L"\\file1", L"something")); + list.AddPath(CTGitPath(L"file1")); + EXPECT_TRUE(list.AreAllPathsFiles()); + + EXPECT_TRUE(CreateDirectory(tmp.GetTempDir() + L"\\dir", nullptr)); + list.AddPath(CTGitPath(L"dir")); + EXPECT_FALSE(list.AreAllPathsFiles()); + + list.Clear(); + list.AddPath(CTGitPath()); // equivalent of "." + EXPECT_FALSE(list.AreAllPathsFiles()); + + list.AddPath(CTGitPath(L"file1")); + EXPECT_FALSE(list.AreAllPathsFiles()); +} diff --git a/test/UnitTests/UnitTests.vcxproj b/test/UnitTests/UnitTests.vcxproj index 48fa98e71..b3af7f48b 100644 --- a/test/UnitTests/UnitTests.vcxproj +++ b/test/UnitTests/UnitTests.vcxproj @@ -83,6 +83,7 @@ + @@ -125,6 +126,7 @@ + diff --git a/test/UnitTests/UnitTests.vcxproj.filters b/test/UnitTests/UnitTests.vcxproj.filters index 079bc8ecf..323dc0bfb 100644 --- a/test/UnitTests/UnitTests.vcxproj.filters +++ b/test/UnitTests/UnitTests.vcxproj.filters @@ -21,6 +21,9 @@ {6bdce77d-3a9a-458f-8e18-65f43a40657c} + + {3afc6978-ab69-4a83-8199-c978ef2284e9} + @@ -155,6 +158,9 @@ Utils + + TortoiseShell + @@ -331,5 +337,8 @@ Utils + + TortoiseShell + \ No newline at end of file -- 2.11.4.GIT