OSDN Git Service

Fixed issue #155: Fix SVN Rebase sets upstream as remotes/trunk
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / Commands / UnIgnoreCommand.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 "UnIgnoreCommand.h"\r
21 \r
22 #include "MessageBox.h"\r
23 #include "PathUtils.h"\r
24 #include "SVNProperties.h"\r
25 \r
26 bool UnIgnoreCommand::Execute()\r
27 {\r
28         CString filelist;\r
29         BOOL err = FALSE;\r
30         for(int nPath = 0; nPath < pathList.GetCount(); nPath++)\r
31         {\r
32                 CString name = CPathUtils::PathPatternEscape(pathList[nPath].GetFileOrDirectoryName());\r
33                 if (parser.HasKey(_T("onlymask")))\r
34                 {\r
35                         name = _T("*")+pathList[nPath].GetFileExtension();\r
36                 }\r
37                 filelist += name + _T("\n");\r
38                 CTSVNPath parentfolder = pathList[nPath].GetContainingDirectory();\r
39                 SVNProperties props(parentfolder, SVNRev::REV_WC, false);\r
40                 CStringA value;\r
41                 for (int i=0; i<props.GetCount(); i++)\r
42                 {\r
43                         CString propname(props.GetItemName(i).c_str());\r
44                         if (propname.CompareNoCase(_T("svn:ignore"))==0)\r
45                         {\r
46                                 //treat values as normal text even if they're not\r
47                                 value = (char *)props.GetItemValue(i).c_str();\r
48                                 break;\r
49                         }\r
50                 }\r
51                 value = value.Trim("\n\r");\r
52                 value += "\n";\r
53                 value.Remove('\r');\r
54                 value.Replace("\n\n", "\n");\r
55 \r
56                 // Delete all occurrences of 'name'\r
57                 // "\n" is temporarily prepended to make the algorithm easier\r
58                 value = "\n" + value;\r
59                 value.Replace("\n" + CUnicodeUtils::GetUTF8(name) + "\n", "\n");\r
60                 value = value.Mid(1);\r
61 \r
62                 CStringA sTrimmedvalue = value;\r
63                 sTrimmedvalue.Trim();\r
64                 if (sTrimmedvalue.IsEmpty())\r
65                 {\r
66                         if (!props.Remove(_T("svn:ignore")))\r
67                         {\r
68                                 CString temp;\r
69                                 temp.Format(IDS_ERR_FAILEDUNIGNOREPROPERTY, (LPCTSTR)name);\r
70                                 CMessageBox::Show(hwndExplorer, temp, _T("TortoiseSVN"), MB_ICONERROR);\r
71                                 err = TRUE;\r
72                                 break;\r
73                         }\r
74                 }\r
75                 else\r
76                 {\r
77                         if (!props.Add(_T("svn:ignore"), (LPCSTR)value))\r
78                         {\r
79                                 CString temp;\r
80                                 temp.Format(IDS_ERR_FAILEDUNIGNOREPROPERTY, (LPCTSTR)name);\r
81                                 CMessageBox::Show(hwndExplorer, temp, _T("TortoiseSVN"), MB_ICONERROR);\r
82                                 err = TRUE;\r
83                                 break;\r
84                         }\r
85                 }\r
86         }\r
87         if (err == FALSE)\r
88         {\r
89                 CString temp;\r
90                 temp.Format(IDS_PROC_UNIGNORESUCCESS, (LPCTSTR)filelist);\r
91                 CMessageBox::Show(hwndExplorer, temp, _T("TortoiseSVN"), MB_ICONINFORMATION);\r
92                 return true;\r
93         }\r
94         return false;\r
95 }\r