From 617a1a33a551cf4cb4423258d43667669dd1c301 Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Tue, 28 Jul 2015 02:01:30 +0200 Subject: [PATCH] Allow to restore added or modified files from index if those are missing in working tree Signed-off-by: Sven Strickroth --- Languages/Tortoise.pot | 6 +++++- src/Git/GitStatusListCtrl.cpp | 23 +++++++++++++++++++---- src/Resources/TortoiseProcENG.rc | 3 ++- src/TortoiseProc/resource.h | 1 + 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/Languages/Tortoise.pot b/Languages/Tortoise.pot index 728fcf66f..97d6c906a 100644 --- a/Languages/Tortoise.pot +++ b/Languages/Tortoise.pot @@ -7392,6 +7392,10 @@ msgstr "" msgid "R&eset" msgstr "" +#. Resource IDs: (1582) +msgid "R&estore this file from index" +msgstr "" + #. Resource IDs: (20021) msgid "R&evert to this revision" msgstr "" @@ -9670,7 +9674,7 @@ msgstr "" #. Resource IDs: (1410) #, c-format -msgid "TortoiseGit detected that the file \"%s\" does not exist, but is staged as \"Added\".\nThe commit dialog cannot handle this.\n\nDo you want to remove it from the index?" +msgid "TortoiseGit detected that the file \"%s\" does not exist, but is staged as \"Added\" or \"Modified\".\nThe commit dialog cannot handle this.\n\nDo you want to restore or remove it from the index?" msgstr "" #. Resource IDs: (1560) diff --git a/src/Git/GitStatusListCtrl.cpp b/src/Git/GitStatusListCtrl.cpp index 07f7632c9..4edce0e3c 100644 --- a/src/Git/GitStatusListCtrl.cpp +++ b/src/Git/GitStatusListCtrl.cpp @@ -3943,29 +3943,44 @@ int CGitStatusListCtrl::UpdateFileList(CTGitPathList *list) BOOL bDeleteChecked = FALSE; int deleteFromIndex = 0; + bool needsRefresh = false; for (int i = 0; i < m_StatusFileList.GetCount(); ++i) { CTGitPath * gitpatch=(CTGitPath*)&m_StatusFileList[i]; gitpatch->m_Checked = TRUE; - if ((gitpatch->m_Action & (CTGitPath::LOGACTIONS_ADDED | CTGitPath::LOGACTIONS_REPLACED)) && !gitpatch->Exists()) + if ((gitpatch->m_Action & (CTGitPath::LOGACTIONS_ADDED | CTGitPath::LOGACTIONS_REPLACED | CTGitPath::LOGACTIONS_MODIFIED)) && !gitpatch->Exists()) { if (!bDeleteChecked) { CString message; message.Format(IDS_ASK_REMOVE_FROM_INDEX, gitpatch->GetWinPath()); - deleteFromIndex = CMessageBox::ShowCheck(m_hWnd, message, _T("TortoiseGit"), 1, IDI_EXCLAMATION, CString(MAKEINTRESOURCE(IDS_REMOVE_FROM_INDEX)), CString(MAKEINTRESOURCE(IDS_IGNOREBUTTON)), NULL, NULL, CString(MAKEINTRESOURCE(IDS_DO_SAME_FOR_REST)), &bDeleteChecked); + deleteFromIndex = CMessageBox::ShowCheck(m_hWnd, message, _T("TortoiseGit"), 1, IDI_EXCLAMATION, CString(MAKEINTRESOURCE(IDS_RESTORE_FROM_INDEX)), CString(MAKEINTRESOURCE(IDS_REMOVE_FROM_INDEX)), CString(MAKEINTRESOURCE(IDS_IGNOREBUTTON)), NULL, CString(MAKEINTRESOURCE(IDS_DO_SAME_FOR_REST)), &bDeleteChecked); } if (deleteFromIndex == 1) { - g_Git.Run(_T("git.exe rm -f --cache -- \"") + gitpatch->GetWinPathString() + _T("\""), nullptr, CP_UTF8); - continue; + CString err; + if (g_Git.Run(_T("git.exe checkout -- \"") + gitpatch->GetWinPathString() + _T("\""), &err, CP_UTF8)) + MessageBox(_T("Restoring from index failed:\n") + err, _T("TortoiseGit"), MB_ICONERROR); + else + needsRefresh = true; + } + else if (deleteFromIndex == 2) + { + CString err; + if (g_Git.Run(_T("git.exe rm -f --cache -- \"") + gitpatch->GetWinPathString() + _T("\""), &err, CP_UTF8)) + MessageBox(_T("Removing from index failed:\n") + err, _T("TortoiseGit"), MB_ICONERROR); + else + needsRefresh = true; } } m_arStatusArray.push_back((CTGitPath*)&m_StatusFileList[i]); } + if (needsRefresh) + MessageBox(_T("Due to changes to the index, please refresh the dialog (e.g., by pressing F5)."), _T("TortoiseGit"), MB_ICONINFORMATION); + return 0; } diff --git a/src/Resources/TortoiseProcENG.rc b/src/Resources/TortoiseProcENG.rc index 516dc22ff..7b458ab34 100644 --- a/src/Resources/TortoiseProcENG.rc +++ b/src/Resources/TortoiseProcENG.rc @@ -3498,7 +3498,7 @@ BEGIN IDS_DAEMON_SECURITY_WARN "While running daemon, all data of this repository is exposed without authentication and/or encryption." IDS_ASK_REMOVE_FROM_INDEX - "TortoiseGit detected that the file ""%s"" does not exist, but is staged as ""Added"".\nThe commit dialog cannot handle this.\n\nDo you want to remove it from the index?" + "TortoiseGit detected that the file ""%s"" does not exist, but is staged as ""Added"" or ""Modified"".\nThe commit dialog cannot handle this.\n\nDo you want to restore or remove it from the index?" IDS_REMOVE_FROM_INDEX "&Remove this file from index" IDS_DO_SAME_FOR_REST "&Do the same for the rest" IDS_PROGRS_TITLE_RESET "Reset" @@ -4682,6 +4682,7 @@ BEGIN IDS_REBASE_BRANCH_FF "The fetched branch fast-forwards upon the current branch.\n\nMerge or open the rebase dialog anyway?" IDS_MERGEBUTTON "&Merge" IDS_REBASEBUTTON "&Rebase" + IDS_RESTORE_FROM_INDEX "R&estore this file from index" END #endif // English (U.S.) resources diff --git a/src/TortoiseProc/resource.h b/src/TortoiseProc/resource.h index 00c74379b..184bcaaad 100644 --- a/src/TortoiseProc/resource.h +++ b/src/TortoiseProc/resource.h @@ -1215,6 +1215,7 @@ #define IDC_COMBOBOXEX_PATH 1582 #define IDC_SENDMAIL_GROUP 1582 #define IDC_UUID32 1582 +#define IDS_RESTORE_FROM_INDEX 1582 #define IDC_REP_BROWSE 1583 #define IDC_SEND_ADDRESS 1583 #define IDC_UUIDLABEL64 1583 -- 2.11.4.GIT