Optimized error message options for failed removal of files
[TortoiseGit.git] / src / TortoiseProc / Commands / RemoveCommand.cpp
blobcf7368b82a79221af14071e5a7cb14109c6d2a1f
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2007-2008 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "stdafx.h"
20 #include "RemoveCommand.h"
22 #include "MessageBox.h"
23 //#include "ProgressDlg.h"
24 #include "Git.h"
25 #include "InputLogDlg.h"
26 #include "ShellUpdater.h"
28 bool RemoveCommand::Execute()
30 bool bRet = false;
31 // removing items from a working copy is done item-by-item so we
32 // have a chance to show a progress bar
34 // removing items from an URL in the repository requires that we
35 // ask the user for a log message.
36 #if 0
37 BOOL bForce = FALSE;
38 SVN svn;
39 if ((pathList.GetCount())&&(SVN::PathIsURL(pathList[0])))
41 // Delete using URL's, not wc paths
42 svn.SetPromptApp(&theApp);
43 CInputLogDlg dlg;
44 CString sUUID;
45 svn.GetRepositoryRootAndUUID(pathList[0], sUUID);
46 dlg.SetUUID(sUUID);
47 CString sHint;
48 if (pathList.GetCount() == 1)
49 sHint.Format(IDS_INPUT_REMOVEONE, (LPCTSTR)pathList[0].GetSVNPathString());
50 else
51 sHint.Format(IDS_INPUT_REMOVEMORE, pathList.GetCount());
52 dlg.SetActionText(sHint);
53 if (dlg.DoModal()==IDOK)
55 if (!svn.Remove(pathList, TRUE, parser.HasKey(_T("keep")), dlg.GetLogMessage()))
57 CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
58 return FALSE;
60 return true;
62 return FALSE;
64 else
66 for (int nPath = 0; nPath < pathList.GetCount(); ++nPath)
68 TRACE(_T("remove file %s\n"), (LPCTSTR)pathList[nPath].GetUIPathString());
69 // even though SVN::Remove takes a list of paths to delete at once
70 // we delete each item individually so we can prompt the user
71 // if something goes wrong or unversioned/modified items are
72 // to be deleted
73 CTSVNPathList removePathList(pathList[nPath]);
74 if (bForce)
76 CTSVNPath delPath = removePathList[0];
77 delPath.Delete(true);
79 if (!svn.Remove(removePathList, bForce, parser.HasKey(_T("keep"))))
81 if ((svn.Err->apr_err == SVN_ERR_UNVERSIONED_RESOURCE) ||
82 (svn.Err->apr_err == SVN_ERR_CLIENT_MODIFIED))
84 CString msg, yes, no, yestoall;
85 if (pathList[nPath].IsDirectory())
87 msg.Format(IDS_PROC_REMOVEFORCEFOLDER, pathList[nPath].GetWinPath());
89 else
91 msg.Format(IDS_PROC_REMOVEFORCE, (LPCTSTR)svn.GetLastErrorMessage());
93 yes.LoadString(IDS_MSGBOX_YES);
94 no.LoadString(IDS_MSGBOX_NO);
95 yestoall.LoadString(IDS_PROC_YESTOALL);
96 UINT ret = CMessageBox::Show(hwndExplorer, msg, _T("TortoiseGit"), 2, IDI_ERROR, yes, no, yestoall);
97 if (ret == 3)
98 bForce = TRUE;
99 if ((ret == 1)||(ret==3))
101 CTSVNPath delPath = removePathList[0];
102 delPath.Delete(true);
103 if (!svn.Remove(removePathList, TRUE, parser.HasKey(_T("keep"))))
105 CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
107 else
108 bRet = true;
111 else
112 CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
116 if (bRet)
117 CShellUpdater::Instance().AddPathsForUpdate(pathList);
118 #endif
120 //we don't ask user about if keep local copy.
121 //because there are command "Delete(keep local copy)" at explore context menu
122 //int key=CMessageBox::Show(hwndExplorer, _T("File will removed from version control\r\n Do you want to keep local copy"), _T("TortoiseGit"), MB_ICONINFORMATION|MB_YESNOCANCEL);
123 //if(key == IDCANCEL)
125 CString format, keepLocal;
126 if(parser.HasKey(_T("keep")))
127 keepLocal = _T(" from the index");
128 if (pathList.GetCount() > 1)
129 format.Format(_T("Do you really want to remove the %d selected files/directories%s?"), pathList.GetCount(), keepLocal);
130 else
131 format.Format(_T("Do you really want to remove \"%s\"%s?"), pathList[0].GetGitPathString(), keepLocal);
132 if (CMessageBox::Show(hwndExplorer, format, _T("TortoiseGit"), 2, IDI_QUESTION, _T("&Remove"), _T("&Abort")) == 2) {
133 return false;
136 if(parser.HasKey(_T("keep")))
138 format= _T("git.exe rm -r -f --cached -- \"%s\"");
140 else
142 format=_T("git.exe rm -r -f -- \"%s\"");
145 CString output;
146 CString cmd;
147 int nPath;
148 for (nPath = 0; nPath < pathList.GetCount(); ++nPath)
150 cmd.Format(format,pathList[nPath].GetGitPathString());
151 if (g_Git.Run(cmd, &output, CP_UTF8))
153 if (CMessageBox::Show(hwndExplorer, output, _T("TortoiseGit"), 2, IDI_ERROR, CString(MAKEINTRESOURCE(IDS_IGNOREBUTTON)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON))) == 2)
154 return FALSE;
158 output.Format(IDS_PROC_FILESREMOVED, nPath);
160 CShellUpdater::Instance().AddPathsForUpdate(pathList);
162 CMessageBox::Show(hwndExplorer, output, _T("TortoiseGit"), MB_ICONINFORMATION|MB_OK);
164 CShellUpdater::Instance().Flush();
165 return bRet;