From 8f797f97d359357d77743ca74dec3c134748b8dc Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Sat, 18 Jul 2020 12:34:55 +0200 Subject: [PATCH] Implement very simple multi-project pull/fetch/push Signed-off-by: Sven Strickroth --- src/Changelog.txt | 1 + src/TortoiseProc/Commands/FetchCommand.cpp | 20 +++++++++++++++++++- src/TortoiseProc/Commands/PullCommand.cpp | 22 ++++++++++++++++++++-- src/TortoiseShell/ContextMenu.cpp | 15 +++++++++------ src/TortoiseShell/MenuInfo.cpp | 8 ++++---- src/TortoiseShell/ShellExt.h | 6 +++--- 6 files changed, 56 insertions(+), 16 deletions(-) diff --git a/src/Changelog.txt b/src/Changelog.txt index 6eee22b36..da4e6cc11 100644 --- a/src/Changelog.txt +++ b/src/Changelog.txt @@ -27,6 +27,7 @@ Released: unreleased * Fixed issue #3282: Prefs and Docs - UDiff should have a link back to Diff Viewer section * Update TortoiseGitPlink to PuTTY Plink 0.74 * Update libgit2 to 1.0 + * Implement very simple multi-project pull/fetch/push = Release 2.10.0.2 = Released: 2020-03-24 diff --git a/src/TortoiseProc/Commands/FetchCommand.cpp b/src/TortoiseProc/Commands/FetchCommand.cpp index 2b16b7c5a..cba6ac920 100644 --- a/src/TortoiseProc/Commands/FetchCommand.cpp +++ b/src/TortoiseProc/Commands/FetchCommand.cpp @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2008-2013, 2015-2016, 2018-2019 - TortoiseGit +// Copyright (C) 2008-2013, 2015-2016, 2018-2020 - TortoiseGit // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -30,5 +30,23 @@ bool FetchCommand::Execute() return false; } + if (orgPathList.GetCount() > 1) + { + bool retVal = true; + for (int i = 0; i < orgPathList.GetCount(); ++i) + { + auto item = orgPathList[i]; + if (!item.IsWCRoot() || !GitAdminDir::IsBareRepo(item.GetWinPathString())) + { + retVal = false; + continue; + } + g_Git.m_CurrentDir = item.GetWinPathString(); + SetCurrentDirectory(g_Git.m_CurrentDir); + retVal &= CAppUtils::Fetch(GetExplorerHWND(), parser.GetVal(L"remote")); + } + return retVal; + } + return CAppUtils::Fetch(GetExplorerHWND(), parser.GetVal(L"remote")); } diff --git a/src/TortoiseProc/Commands/PullCommand.cpp b/src/TortoiseProc/Commands/PullCommand.cpp index 87aacd917..1180f699c 100644 --- a/src/TortoiseProc/Commands/PullCommand.cpp +++ b/src/TortoiseProc/Commands/PullCommand.cpp @@ -1,6 +1,6 @@ -// TortoiseGit - a Windows shell extension for easy version control +// TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2008-2013, 2015, 2018 - TortoiseGit +// Copyright (C) 2008-2013, 2015, 2018, 2020 - TortoiseGit // Copyright (C) 2007-2008 - TortoiseSVN // This program is free software; you can redistribute it and/or @@ -31,5 +31,23 @@ bool PullCommand::Execute() return false; } + if (orgPathList.GetCount() > 1) + { + bool retVal = true; + for (int i = 0; i < orgPathList.GetCount(); ++i) + { + auto item = orgPathList[i]; + if (!item.IsWCRoot() || !GitAdminDir::IsBareRepo(item.GetWinPathString())) + { + retVal = false; + continue; + } + g_Git.m_CurrentDir = item.GetWinPathString(); + SetCurrentDirectory(g_Git.m_CurrentDir); + retVal &= CAppUtils::Pull(GetExplorerHWND(), false); + } + return retVal; + } + return CAppUtils::Pull(GetExplorerHWND(), false); } diff --git a/src/TortoiseShell/ContextMenu.cpp b/src/TortoiseShell/ContextMenu.cpp index f9b9b5655..7e2898150 100644 --- a/src/TortoiseShell/ContextMenu.cpp +++ b/src/TortoiseShell/ContextMenu.cpp @@ -701,7 +701,7 @@ bool CShellExt::WriteClipboardPathsToTempFile(std::wstring& tempfile) return true; } -std::wstring CShellExt::WriteFileListToTempFile() +std::wstring CShellExt::WriteFileListToTempFile(bool bFoldersOnly = false) { //write all selected files and paths to a temporary file //for TortoiseGitProc.exe to read out again. @@ -735,6 +735,9 @@ std::wstring CShellExt::WriteFileListToTempFile() for (const auto& file_ : files_) { + if (bFoldersOnly && !PathIsDirectory(file_.c_str())) + continue; + ::WriteFile(file, file_.c_str(), static_cast(file_.size()) * sizeof(TCHAR), &written, 0); ::WriteFile(file, L"\n", 2, &written, 0); } @@ -1130,9 +1133,9 @@ void CShellExt::AddPathCommand(tstring& gitCmd, LPCTSTR command, bool bFilesAllo gitCmd += L'"'; } -void CShellExt::AddPathFileCommand(tstring& gitCmd, LPCTSTR command) +void CShellExt::AddPathFileCommand(tstring& gitCmd, LPCTSTR command, bool bFoldersOnly = false) { - tstring tempfile = WriteFileListToTempFile(); + tstring tempfile = WriteFileListToTempFile(bFoldersOnly); gitCmd += command; gitCmd += L" /pathfile:\""; gitCmd += tempfile; @@ -1572,10 +1575,10 @@ STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi) AddPathCommand(gitCmd, L"clone", false); break; case ShellMenuPull: - AddPathCommand(gitCmd, L"pull", false); + AddPathFileCommand(gitCmd, L"pull", true); break; case ShellMenuPush: - AddPathCommand(gitCmd, L"push", false); + AddPathFileCommand(gitCmd, L"push", true); break; case ShellMenuBranch: AddPathCommand(gitCmd, L"branch", false); @@ -1593,7 +1596,7 @@ STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi) AddPathFileDropCommand(gitCmd, L"importpatch"); break; case ShellMenuFetch: - AddPathCommand(gitCmd, L"fetch", false); + AddPathFileCommand(gitCmd, L"fetch", true); break; default: diff --git a/src/TortoiseShell/MenuInfo.cpp b/src/TortoiseShell/MenuInfo.cpp index 29a566233..3ef784f44 100644 --- a/src/TortoiseShell/MenuInfo.cpp +++ b/src/TortoiseShell/MenuInfo.cpp @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2008-2016, 2018-2019 - TortoiseGit +// Copyright (C) 2008-2016, 2018-2020 - TortoiseGit // Copyright (C) 2003-2008 - TortoiseSVN // This program is free software; you can redistribute it and/or @@ -30,13 +30,13 @@ MenuInfo menuInfo[] = {ITEMIS_FOLDER, ITEMIS_INGIT|ITEMIS_FOLDERINGIT|ITEMIS_BAREREPO}, {ITEMIS_FOLDER|ITEMIS_IGNORED, 0}, {ITEMIS_FOLDER|ITEMIS_EXTENDED, 0}, {0, 0} }, { ShellMenuPull, MENUPULL, IDI_PULL, IDS_MENUPULL, IDS_MENUDESCPULL, - {ITEMIS_FOLDERINGIT|ITEMIS_ONLYONE, ITEMIS_BISECT|ITEMIS_MERGEACTIVE}, {0, 0}, {0, 0}, {0, 0} }, + {ITEMIS_FOLDERINGIT|ITEMIS_ONLYONE, ITEMIS_BISECT|ITEMIS_MERGEACTIVE}, {ITEMIS_WCROOT, ITEMIS_BISECT|ITEMIS_MERGEACTIVE}, {0, 0}, {0, 0} }, { ShellMenuFetch, MENUFETCH, IDI_UPDATE, IDS_MENUFETCH, IDS_MENUDESCFETCH, - {ITEMIS_FOLDERINGIT|ITEMIS_ONLYONE, 0}, {ITEMIS_BAREREPO, 0}, {0, 0}, {0, 0} }, + {ITEMIS_FOLDERINGIT|ITEMIS_ONLYONE, 0}, {ITEMIS_BAREREPO, 0}, {ITEMIS_WCROOT, 0}, {0, 0} }, { ShellMenuPush, MENUPUSH, IDI_PUSH, IDS_MENUPUSH, IDS_MENUDESCPUSH, - {ITEMIS_FOLDERINGIT|ITEMIS_ONLYONE, 0}, {ITEMIS_BAREREPO, 0}, {0, 0}, {0, 0} }, + {ITEMIS_FOLDERINGIT|ITEMIS_ONLYONE, 0}, {ITEMIS_BAREREPO, 0}, {ITEMIS_WCROOT, 0}, {0, 0} }, { ShellMenuSync, MENUSYNC, IDI_RELOCATE, IDS_MENUSYNC, IDS_MENUDESCSYNC, {ITEMIS_FOLDERINGIT|ITEMIS_ONLYONE, ITEMIS_BISECT|ITEMIS_MERGEACTIVE}, {0, 0}, {0, 0}, {0, 0} }, diff --git a/src/TortoiseShell/ShellExt.h b/src/TortoiseShell/ShellExt.h index 02c41a3c9..f08ad9350 100644 --- a/src/TortoiseShell/ShellExt.h +++ b/src/TortoiseShell/ShellExt.h @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2018-2019 - TortoiseGit +// Copyright (C) 2018-2020 - TortoiseGit // Copyright (C) 2003-2012, 2014 - TortoiseSVN // This program is free software; you can redistribute it and/or @@ -99,14 +99,14 @@ protected: private: void InsertGitMenu(BOOL istop, HMENU menu, UINT pos, UINT_PTR id, UINT stringid, UINT icon, UINT idCmdFirst, GitCommands com, UINT uFlags); bool InsertIgnoreSubmenus(UINT &idCmd, UINT idCmdFirst, HMENU hMenu, HMENU subMenu, UINT &indexMenu, int &indexSubMenu, unsigned __int64 topmenu, bool bShowIcons, UINT uFlags); - std::wstring WriteFileListToTempFile(); + std::wstring WriteFileListToTempFile(bool bFoldersOnly); bool WriteClipboardPathsToTempFile(std::wstring& tempfile); LPCTSTR GetMenuTextFromResource(int id); bool ShouldInsertItem(const MenuInfo& pair) const; bool ShouldEnableMenu(const YesNoPair& pair) const; void TweakMenu(HMENU menu); void AddPathCommand(tstring& gitCmd, LPCTSTR command, bool bFilesAllowed); - void AddPathFileCommand(tstring& gitCmd, LPCTSTR command); + void AddPathFileCommand(tstring& gitCmd, LPCTSTR command, bool bFoldersOnly); void AddPathFileDropCommand(tstring& gitCmd, LPCTSTR command); STDMETHODIMP QueryDropContext(UINT uFlags, UINT idCmdFirst, HMENU hMenu, UINT &indexMenu); bool IsIllegalFolder(const std::wstring& folder, int* cslidarray); -- 2.11.4.GIT