OSDN Git Service

Fix Issue 22 Error deleting file from context menu if filename contains spaces
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / Commands / RemoveCommand.cpp
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2007-2008 - TortoiseSVN\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 #include "StdAfx.h"\r
20 #include "RemoveCommand.h"\r
21 \r
22 #include "MessageBox.h"\r
23 //#include "ProgressDlg.h"\r
24 #include "Git.h"\r
25 #include "InputLogDlg.h"\r
26 #include "ShellUpdater.h"\r
27 \r
28 bool RemoveCommand::Execute()\r
29 {\r
30         bool bRet = false;\r
31         // removing items from a working copy is done item-by-item so we\r
32         // have a chance to show a progress bar\r
33         //\r
34         // removing items from an URL in the repository requires that we\r
35         // ask the user for a log message.\r
36 #if 0\r
37         BOOL bForce = FALSE;\r
38         SVN svn;\r
39         if ((pathList.GetCount())&&(SVN::PathIsURL(pathList[0])))\r
40         {\r
41                 // Delete using URL's, not wc paths\r
42                 svn.SetPromptApp(&theApp);\r
43                 CInputLogDlg dlg;\r
44                 CString sUUID;\r
45                 svn.GetRepositoryRootAndUUID(pathList[0], sUUID);\r
46                 dlg.SetUUID(sUUID);\r
47                 CString sHint;\r
48                 if (pathList.GetCount() == 1)\r
49                         sHint.Format(IDS_INPUT_REMOVEONE, (LPCTSTR)pathList[0].GetSVNPathString());\r
50                 else\r
51                         sHint.Format(IDS_INPUT_REMOVEMORE, pathList.GetCount());\r
52                 dlg.SetActionText(sHint);\r
53                 if (dlg.DoModal()==IDOK)\r
54                 {\r
55                         if (!svn.Remove(pathList, TRUE, parser.HasKey(_T("keep")), dlg.GetLogMessage()))\r
56                         {\r
57                                 CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);\r
58                                 return FALSE;\r
59                         }\r
60                         return true;\r
61                 }\r
62                 return FALSE;\r
63         }\r
64         else\r
65         {\r
66                 for(int nPath = 0; nPath < pathList.GetCount(); nPath++)\r
67                 {\r
68                         TRACE(_T("remove file %s\n"), (LPCTSTR)pathList[nPath].GetUIPathString());\r
69                         // even though SVN::Remove takes a list of paths to delete at once\r
70                         // we delete each item individually so we can prompt the user\r
71                         // if something goes wrong or unversioned/modified items are\r
72                         // to be deleted\r
73                         CTSVNPathList removePathList(pathList[nPath]);\r
74                         if (bForce)\r
75                         {\r
76                                 CTSVNPath delPath = removePathList[0];\r
77                                 delPath.Delete(true);\r
78                         }\r
79                         if (!svn.Remove(removePathList, bForce, parser.HasKey(_T("keep"))))\r
80                         {\r
81                                 if ((svn.Err->apr_err == SVN_ERR_UNVERSIONED_RESOURCE) ||\r
82                                         (svn.Err->apr_err == SVN_ERR_CLIENT_MODIFIED))\r
83                                 {\r
84                                         CString msg, yes, no, yestoall;\r
85                                         if (pathList[nPath].IsDirectory())\r
86                                         {\r
87                                                 msg.Format(IDS_PROC_REMOVEFORCEFOLDER, pathList[nPath].GetWinPath());\r
88                                         }\r
89                                         else\r
90                                         {\r
91                                                 msg.Format(IDS_PROC_REMOVEFORCE, (LPCTSTR)svn.GetLastErrorMessage());\r
92                                         }\r
93                                         yes.LoadString(IDS_MSGBOX_YES);\r
94                                         no.LoadString(IDS_MSGBOX_NO);\r
95                                         yestoall.LoadString(IDS_PROC_YESTOALL);\r
96                                         UINT ret = CMessageBox::Show(hwndExplorer, msg, _T("TortoiseSVN"), 2, IDI_ERROR, yes, no, yestoall);\r
97                                         if (ret == 3)\r
98                                                 bForce = TRUE;\r
99                                         if ((ret == 1)||(ret==3))\r
100                                         {\r
101                                                 CTSVNPath delPath = removePathList[0];\r
102                                                 delPath.Delete(true);\r
103                                                 if (!svn.Remove(removePathList, TRUE, parser.HasKey(_T("keep"))))\r
104                                                 {\r
105                                                         CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);\r
106                                                 }\r
107                                                 else\r
108                                                         bRet = true;\r
109                                         }\r
110                                 }\r
111                                 else\r
112                                         CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);\r
113                         }\r
114                 }\r
115         }\r
116         if (bRet)\r
117                 CShellUpdater::Instance().AddPathsForUpdate(pathList);\r
118 #endif\r
119         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);\r
120         if(key == IDCANCEL)\r
121                 return FALSE;\r
122 \r
123         CString format;\r
124         if(key == IDNO)\r
125                 format=_T("git.exe rm -r -f \"%s\"");\r
126 \r
127         if(key == IDYES)\r
128                 format= _T("git.exe update-index --force-remove -- \"%s\"");\r
129 \r
130         CString output;\r
131         CString cmd;\r
132         int nPath;\r
133         for(nPath = 0; nPath < pathList.GetCount(); nPath++)\r
134         {\r
135 \r
136                 cmd.Format(format,pathList[nPath].GetGitPathString());\r
137                 if(g_Git.Run(cmd,&output,CP_OEMCP))\r
138                 {\r
139                         key=CMessageBox::Show(hwndExplorer, output, _T("TortoiseGit"), MB_ICONERROR|MB_OKCANCEL);\r
140                         if(key == IDCANCEL)\r
141                                 return FALSE;\r
142 \r
143                 }\r
144         }\r
145 \r
146         output.Format(_T("%d files removed"),nPath);\r
147         \r
148         CMessageBox::Show(hwndExplorer, output, _T("TortoiseGit"), MB_ICONINFORMATION|MB_OK);\r
149 \r
150         return bRet;\r
151 }\r