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.
20 #include "RemoveCommand.h"
22 #include "MessageBox.h"
23 //#include "ProgressDlg.h"
25 #include "InputLogDlg.h"
26 #include "ShellUpdater.h"
28 bool RemoveCommand::Execute()
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.
39 if ((pathList
.GetCount())&&(SVN::PathIsURL(pathList
[0])))
41 // Delete using URL's, not wc paths
42 svn
.SetPromptApp(&theApp
);
45 svn
.GetRepositoryRootAndUUID(pathList
[0], sUUID
);
48 if (pathList
.GetCount() == 1)
49 sHint
.Format(IDS_INPUT_REMOVEONE
, (LPCTSTR
)pathList
[0].GetSVNPathString());
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
);
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
73 CTSVNPathList
removePathList(pathList
[nPath
]);
76 CTSVNPath delPath
= removePathList
[0];
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());
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
);
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
);
112 CMessageBox::Show(hwndExplorer
, svn
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
117 CShellUpdater::Instance().AddPathsForUpdate(pathList
);
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)
126 CString format
, keepLocal
;
127 if(parser
.HasKey(_T("keep")))
128 keepLocal
= _T(" from the index");
129 if (pathList
.GetCount() > 1)
130 format
.Format(_T("Do you really want to remove the %d selected files/directories%s?"), pathList
.GetCount(), keepLocal
);
132 format
.Format(_T("Do you really want to remove \"%s\"%s?"), pathList
[0].GetGitPathString(), keepLocal
);
133 if (CMessageBox::Show(hwndExplorer
, format
, _T("TortoiseGit"), 2, IDI_QUESTION
, _T("&Remove"), _T("&Abort")) == 2) {
137 if(parser
.HasKey(_T("keep")))
139 format
= _T("git.exe update-index --force-remove -- \"%s\"");
143 format
=_T("git.exe rm -r -f -- \"%s\"");
149 for (nPath
= 0; nPath
< pathList
.GetCount(); ++nPath
)
151 cmd
.Format(format
,pathList
[nPath
].GetGitPathString());
152 if (g_Git
.Run(cmd
, &output
, CP_UTF8
))
154 key
=CMessageBox::Show(hwndExplorer
, output
, _T("TortoiseGit"), MB_ICONERROR
|MB_OKCANCEL
);
160 output
.Format(IDS_PROC_FILESREMOVED
, nPath
);
162 CShellUpdater::Instance().AddPathsForUpdate(pathList
);
164 CMessageBox::Show(hwndExplorer
, output
, _T("TortoiseGit"), MB_ICONINFORMATION
|MB_OK
);
166 CShellUpdater::Instance().Flush();