From f011f9274712335d07890e559d1e0f71d55ba9f9 Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Sat, 2 Nov 2013 15:12:11 +0100 Subject: [PATCH] Handle submodules Signed-off-by: Sven Strickroth --- Languages/Tortoise.pot | 10 ++++++++ src/Resources/TortoiseProcENG.rc | 7 ++++++ src/TortoiseProc/Commands/DropCopyAddCommand.cpp | 32 ++++++++++++++++++++++-- src/TortoiseProc/resource.h | 2 ++ 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/Languages/Tortoise.pot b/Languages/Tortoise.pot index 89a4563f1..5a2bc4777 100644 --- a/Languages/Tortoise.pot +++ b/Languages/Tortoise.pot @@ -9827,6 +9827,16 @@ msgstr "" msgid "[Unassigned]" msgstr "" +#. Resource IDs: (93) +#, c-format +msgid "\"%s\" contains a git repository. It will not work as a submodule out of the box.\nDo you want to delete the .git-entry and add all files to the top repository or keep it as a separate repository in a subdirectory?" +msgstr "" + +#. Resource IDs: (92) +#, c-format +msgid "\"%s\" contains a git submodule. It is likely that this doesn't work any more on the destination after copying.\nDo you want to delete the .git-entry and add all files to the top repository or ignore this possible issue and keep it?" +msgstr "" + #. Resource IDs: (72) #, c-format msgid "\"%s\" is invalid." diff --git a/src/Resources/TortoiseProcENG.rc b/src/Resources/TortoiseProcENG.rc index 02dbfe587..a2a0d3ccd 100644 --- a/src/Resources/TortoiseProcENG.rc +++ b/src/Resources/TortoiseProcENG.rc @@ -4286,6 +4286,13 @@ BEGIN IDS_PROC_OVERWRITEEXPORT_KEEP "Keep" IDS_WARN_RENAMEREQUIRED "New name must not be empty or the same as the original name!" IDS_RENAME_INFO "Rename ""%s"":" + IDS_PROC_COPY_SUBMODULE """%s"" contains a git submodule. It is likely that this doesn't work any more on the destination after copying.\nDo you want to delete the .git-entry and add all files to the top repository or ignore this possible issue and keep it?" +END + +STRINGTABLE +BEGIN + IDS_PROC_COPY_REPOSITORY + """%s"" contains a git repository. It will not work as a submodule out of the box.\nDo you want to delete the .git-entry and add all files to the top repository or keep it as a separate repository in a subdirectory?" END #endif // English (U.S.) resources diff --git a/src/TortoiseProc/Commands/DropCopyAddCommand.cpp b/src/TortoiseProc/Commands/DropCopyAddCommand.cpp index 02bd4583a..52646c286 100644 --- a/src/TortoiseProc/Commands/DropCopyAddCommand.cpp +++ b/src/TortoiseProc/Commands/DropCopyAddCommand.cpp @@ -92,12 +92,40 @@ bool DropCopyAddCommand::Execute() fileop.fFlags = FOF_NO_CONNECTED_ELEMENTS | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_NOCONFIRMMKDIR | FOF_NOCOPYSECURITYATTRIBS | FOF_SILENT; if (!SHFileOperation(&fileop)) { - // add all copied files + // add all copied files WITH special handling for repos/submodules (folders which include a .git entry) CDirFileEnum finder(droppath + L"\\" + name); bool isDir = true; CString filepath; - while (finder.NextFile(filepath, &isDir)) + CString lastRepo; + bool isRepo = false; + while (finder.NextFile(filepath, &isDir, !isRepo)) // don't recurse into .git directories { + if (!lastRepo.IsEmpty()) + { + if (filepath.Find(lastRepo) == 0) + continue; + else + lastRepo.Empty(); + } + isRepo = filepath.Find(L"\\" + g_GitAdminDir.GetAdminDirName()) >= 0; + if (isRepo) + { + lastRepo = filepath.Mid(0, filepath.GetLength() - g_GitAdminDir.GetAdminDirName().GetLength()); + CString msg; + if (!isDir) + msg.Format(IDS_PROC_COPY_SUBMODULE, lastRepo); + else + msg.Format(IDS_PROC_COPY_REPOSITORY, lastRepo); + int ret = CMessageBox::Show(hwndExplorer, msg, _T("TortoiseGit"), 1, IDI_QUESTION, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON)), CString(MAKEINTRESOURCE(IDS_IGNOREBUTTON)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON))); + if (ret == 3) + return FALSE; + if (ret == 1) + { + CTGitPath(filepath).Delete(false); + lastRepo.Empty(); + } + continue; + } if (!isDir) copiedFiles.AddPath(CTGitPath(filepath.Mid(worktreePathLen + 1))); //add the new filepath } diff --git a/src/TortoiseProc/resource.h b/src/TortoiseProc/resource.h index d5de61c0b..b5b3e0a52 100644 --- a/src/TortoiseProc/resource.h +++ b/src/TortoiseProc/resource.h @@ -982,7 +982,9 @@ #define IDS_RENAME_INFO 1470 #define IDC_BUGTRAQCOPYBUTTON 1471 #define IDC_GIT_USERESINGNINGKEY 1471 +#define IDS_PROC_COPY_SUBMODULE 1471 #define IDC_BUGTRAQWCPATHLABEL 1472 +#define IDS_PROC_COPY_REPOSITORY 1472 #define IDC_BUGTRAQPATH 1473 #define IDC_BUGTRAQBROWSE 1474 #define IDC_BUGTRAQPROVIDERLABEL 1475 -- 2.11.4.GIT