Extend static functions in CAppUtils with a window handle parameter
[TortoiseGit.git] / src / TortoiseProc / Commands / RemoveCommand.cpp
blob9a88a8f4333e2c2ac5a81e817f28c8ba5ded32ff
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2013, 2015-2017 - TortoiseGit
4 // Copyright (C) 2007-2008 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 #include "RemoveCommand.h"
23 #include "MessageBox.h"
24 #include "Git.h"
25 #include "ShellUpdater.h"
27 bool RemoveCommand::Execute()
29 bool bRet = false;
30 // removing items from a working copy is done item-by-item so we
31 // have a chance to show a progress bar
33 // removing items from an URL in the repository requires that we
34 // ask the user for a log message.
35 #if 0
36 BOOL bForce = FALSE;
37 SVN svn;
38 if ((!pathList.IsEmpty())&&(SVN::PathIsURL(pathList[0])))
40 // Delete using URL's, not wc paths
41 svn.SetPromptApp(&theApp);
42 CInputLogDlg dlg;
43 CString sUUID;
44 svn.GetRepositoryRootAndUUID(pathList[0], sUUID);
45 dlg.SetUUID(sUUID);
46 CString sHint;
47 if (pathList.GetCount() == 1)
48 sHint.Format(IDS_INPUT_REMOVEONE, (LPCTSTR)pathList[0].GetSVNPathString());
49 else
50 sHint.Format(IDS_INPUT_REMOVEMORE, pathList.GetCount());
51 dlg.SetActionText(sHint);
52 if (dlg.DoModal()==IDOK)
54 if (!svn.Remove(pathList, TRUE, parser.HasKey(L"keep"), dlg.GetLogMessage()))
56 CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), L"TortoiseGit", MB_ICONERROR);
57 return FALSE;
59 return true;
61 return FALSE;
63 else
65 for (int nPath = 0; nPath < pathList.GetCount(); ++nPath)
67 CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": remove file %s\n", (LPCTSTR)pathList[nPath].GetUIPathString());
68 // even though SVN::Remove takes a list of paths to delete at once
69 // we delete each item individually so we can prompt the user
70 // if something goes wrong or unversioned/modified items are
71 // to be deleted
72 CTSVNPathList removePathList(pathList[nPath]);
73 if (bForce)
75 CTSVNPath delPath = removePathList[0];
76 delPath.Delete(true);
78 if (!svn.Remove(removePathList, bForce, parser.HasKey(L"keep")))
80 if ((svn.Err->apr_err == SVN_ERR_UNVERSIONED_RESOURCE) ||
81 (svn.Err->apr_err == SVN_ERR_CLIENT_MODIFIED))
83 CString msg, yes, no, yestoall;
84 if (pathList[nPath].IsDirectory())
85 msg.Format(IDS_PROC_REMOVEFORCEFOLDER, pathList[nPath].GetWinPath());
86 else
87 msg.Format(IDS_PROC_REMOVEFORCE, (LPCTSTR)svn.GetLastErrorMessage());
88 yes.LoadString(IDS_MSGBOX_YES);
89 no.LoadString(IDS_MSGBOX_NO);
90 yestoall.LoadString(IDS_PROC_YESTOALL);
91 UINT ret = CMessageBox::Show(hwndExplorer, msg, L"TortoiseGit", 2, IDI_ERROR, yes, no, yestoall);
92 if (ret == 3)
93 bForce = TRUE;
94 if ((ret == 1)||(ret==3))
96 CTSVNPath delPath = removePathList[0];
97 delPath.Delete(true);
98 if (!svn.Remove(removePathList, TRUE, parser.HasKey(L"keep")))
99 CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), L"TortoiseGit", MB_ICONERROR);
100 else
101 bRet = true;
104 else
105 CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), L"TortoiseGit", MB_ICONERROR);
109 if (bRet)
110 CShellUpdater::Instance().AddPathsForUpdate(pathList);
111 #endif
113 //we don't ask user about if keep local copy.
114 //because there are command "Delete(keep local copy)" at explore context menu
115 //int key = CMessageBox::Show(hwndExplorer, L"File will removed from version control\r\n Do you want to keep local copy", L"TortoiseGit", MB_ICONINFORMATION | MB_YESNOCANCEL);
116 //if(key == IDCANCEL)
118 CString format;
119 BOOL keepLocal = parser.HasKey(L"keep");
120 if (pathList.GetCount() > 1)
121 format.Format(keepLocal ? IDS_WARN_DELETE_MANY_FROM_INDEX : IDS_WARN_DELETE_MANY, pathList.GetCount());
122 else
123 format.Format(keepLocal ? IDS_WARN_DELETE_ONE_FROM_INDEX : IDS_WARN_REMOVE, (LPCTSTR)pathList[0].GetGitPathString());
124 if (CMessageBox::Show(hwndExplorer, format, L"TortoiseGit", 2, IDI_QUESTION, CString(MAKEINTRESOURCE(IDS_REMOVEBUTTON)), CString(MAKEINTRESOURCE(IDS_MSGBOX_ABORT))) == 2)
125 return false;
127 if (keepLocal)
128 format= L"git.exe rm -r -f --cached -- \"%s\"";
129 else
130 format = L"git.exe rm -r -f -- \"%s\"";
132 CString output;
133 CString cmd;
134 int nPath;
135 for (nPath = 0; nPath < pathList.GetCount(); ++nPath)
137 cmd.Format(format, (LPCTSTR)pathList[nPath].GetGitPathString());
138 if (g_Git.Run(cmd, &output, CP_UTF8))
140 if (CMessageBox::Show(hwndExplorer, output, L"TortoiseGit", 2, IDI_ERROR, CString(MAKEINTRESOURCE(IDS_IGNOREBUTTON)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON))) == 2)
141 return FALSE;
145 output.Format(IDS_PROC_FILESREMOVED, nPath);
147 CShellUpdater::Instance().AddPathsForUpdate(pathList);
149 CMessageBox::Show(hwndExplorer, output, L"TortoiseGit", MB_ICONINFORMATION | MB_OK);
151 CShellUpdater::Instance().Flush();
152 return bRet;