make bisect work (initial commit)
[TortoiseGit.git] / src / TortoiseProc / Commands / IgnoreCommand.cpp
blobd4fcc93fb37320f5ffa1a391b1ed139e764d19ba
1 // TortoiseSVN - 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 "IgnoreCommand.h"
22 #include "MessageBox.h"
23 #include "PathUtils.h"
24 #include "AppUtils.h"
25 #include "ShellUpdater.h"
26 //#include "SVNProperties.h"
28 bool IgnoreCommand::Execute()
30 bool bmask=false;
32 if(parser.HasKey(_T("onlymask")))
34 bmask=true;
37 bool ret = CAppUtils::IgnoreFile(pathList,bmask);
39 if (parser.HasKey(_T("delete")))
41 int key;
43 CString format;
45 if(CMessageBox::Show(hwndExplorer, _T("Keep file locally?"), _T("TortoiseGit"), MB_ICONERROR|MB_YESNO) == IDYES)
47 format= _T("git.exe update-index --force-remove -- \"%s\"");
49 else
51 format=_T("git.exe rm -r -f -- \"%s\"");
54 CString output;
55 CString cmd;
56 int nPath;
57 for(nPath = 0; nPath < pathList.GetCount(); nPath++)
60 cmd.Format(format,pathList[nPath].GetGitPathString());
61 if(g_Git.Run(cmd,&output,CP_ACP))
63 key=CMessageBox::Show(hwndExplorer, output, _T("TortoiseGit"), MB_ICONERROR|MB_OKCANCEL);
64 if(key == IDCANCEL)
65 return FALSE;
70 output.Format(_T("%d files removed"),nPath);
72 CShellUpdater::Instance().AddPathsForUpdate(pathList);
74 CMessageBox::Show(hwndExplorer, output, _T("TortoiseGit"), MB_ICONINFORMATION|MB_OK);
77 CShellUpdater::Instance().AddPathsForUpdate(orgPathList);
78 CShellUpdater::Instance().Flush();
80 return ret;
81 #if 0
82 CString filelist;
83 BOOL err = FALSE;
84 for(int nPath = 0; nPath < pathList.GetCount(); nPath++)
86 CString name = CPathUtils::PathPatternEscape(pathList[nPath].GetFileOrDirectoryName());
87 if (parser.HasKey(_T("onlymask")))
89 name = _T("*")+pathList[nPath].GetFileExtension();
91 filelist += name + _T("\n");
92 CTSVNPath parentfolder = pathList[nPath].GetContainingDirectory();
93 SVNProperties props(parentfolder, SVNRev::REV_WC, false);
94 CStringA value;
95 for (int i=0; i<props.GetCount(); i++)
97 CString propname(props.GetItemName(i).c_str());
98 if (propname.CompareNoCase(_T("svn:ignore"))==0)
100 //treat values as normal text even if they're not
101 value = (char *)props.GetItemValue(i).c_str();
104 if (value.IsEmpty())
105 value = name;
106 else
108 // make sure we don't have duplicate entries
109 std::set<CStringA> ignoreItems;
110 ignoreItems.insert(CUnicodeUtils::GetUTF8(name));
111 CStringA token;
112 int curPos = 0;
113 token= value.Tokenize("\n",curPos);
114 while (token != _T(""))
116 token.Trim();
117 ignoreItems.insert(token);
118 token = value.Tokenize("\n", curPos);
120 value.Empty();
121 for (std::set<CStringA>::iterator it = ignoreItems.begin(); it != ignoreItems.end(); ++it)
123 value += *it;
124 value += "\n";
127 if (!props.Add(_T("svn:ignore"), (LPCSTR)value))
129 CString temp;
130 temp.Format(IDS_ERR_FAILEDIGNOREPROPERTY, (LPCTSTR)name);
131 temp += _T("\n");
132 temp += props.GetLastErrorMsg().c_str();
133 CMessageBox::Show(hwndExplorer, temp, _T("TortoiseGit"), MB_ICONERROR);
134 err = TRUE;
135 break;
138 if (err == FALSE)
140 CString temp;
141 temp.Format(IDS_PROC_IGNORESUCCESS, (LPCTSTR)filelist);
142 CMessageBox::Show(hwndExplorer, temp, _T("TortoiseGit"), MB_ICONINFORMATION);
143 return true;
145 #endif