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.
20 #include "IgnoreCommand.h"
22 #include "MessageBox.h"
23 #include "PathUtils.h"
25 #include "ShellUpdater.h"
26 //#include "SVNProperties.h"
28 bool IgnoreCommand::Execute()
32 if(parser
.HasKey(_T("onlymask")))
37 bool ret
= CAppUtils::IgnoreFile(pathList
,bmask
);
39 if (parser
.HasKey(_T("delete")))
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\"");
51 format
=_T("git.exe rm -r -f -- \"%s\"");
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
);
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();
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);
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();
108 // make sure we don't have duplicate entries
109 std::set
<CStringA
> ignoreItems
;
110 ignoreItems
.insert(CUnicodeUtils::GetUTF8(name
));
113 token
= value
.Tokenize("\n",curPos
);
114 while (token
!= _T(""))
117 ignoreItems
.insert(token
);
118 token
= value
.Tokenize("\n", curPos
);
121 for (std::set
<CStringA
>::iterator it
= ignoreItems
.begin(); it
!= ignoreItems
.end(); ++it
)
127 if (!props
.Add(_T("svn:ignore"), (LPCSTR
)value
))
130 temp
.Format(IDS_ERR_FAILEDIGNOREPROPERTY
, (LPCTSTR
)name
);
132 temp
+= props
.GetLastErrorMsg().c_str();
133 CMessageBox::Show(hwndExplorer
, temp
, _T("TortoiseGit"), MB_ICONERROR
);
141 temp
.Format(IDS_PROC_IGNORESUCCESS
, (LPCTSTR
)filelist
);
142 CMessageBox::Show(hwndExplorer
, temp
, _T("TortoiseGit"), MB_ICONINFORMATION
);