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 "CleanupCommand.h"
22 #include "MessageBox.h"
23 #include "ProgressDlg.h"
25 //#include "GitGlobal.h"
26 #include "GitAdminDir.h"
27 #include "DirFileEnum.h"
28 #include "ShellUpdater.h"
29 #include "CleanTypeDlg.h"
31 bool CleanupCommand::Execute()
36 if( dlg
.DoModal() == IDOK
)
38 CProgressDlg progress
;
40 cmd
.Format(_T("git clean "));
43 switch(dlg
.m_CleanType
)
56 for(int i
=0;i
<this->pathList
.GetCount();i
++)
59 if(this->pathList
[i
].IsDirectory())
60 path
= pathList
[i
].GetGitPathString();
62 path
= pathList
[i
].GetContainingDirectory().GetGitPathString();
64 progress
.m_GitCmdList
.push_back(cmd
+ _T(" \"") + path
+ _T("\""));
67 if(progress
.DoModal()==IDOK
)
71 CProgressDlg progress
;
72 progress
.SetTitle(IDS_PROC_CLEANUP
);
73 progress
.SetAnimation(IDR_CLEANUPANI
);
74 progress
.SetShowProgressBar(false);
75 progress
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_CLEANUP_INFO1
)));
76 progress
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROC_CLEANUP_INFO2
)));
77 progress
.ShowModeless(hwndExplorer
);
79 CString strSuccessfullPaths
, strFailedPaths
;
80 for (int i
=0; i
<pathList
.GetCount(); ++i
)
83 if (!svn
.CleanUp(pathList
[i
]))
85 strFailedPaths
+= _T("- ") + pathList
[i
].GetWinPathString() + _T("\n");
86 strFailedPaths
+= svn
.GetLastErrorMessage() + _T("\n\n");
90 strSuccessfullPaths
+= _T("- ") + pathList
[i
].GetWinPathString() + _T("\n");
92 // after the cleanup has finished, crawl the path downwards and send a change
93 // notification for every directory to the shell. This will update the
94 // overlays in the left tree view of the explorer.
95 CDirFileEnum
crawler(pathList
[i
].GetWinPathString());
98 CTSVNPathList updateList
;
99 while (crawler
.NextFile(sPath
, &bDir
))
101 if ((bDir
) && (!g_SVNAdminDir
.IsAdminDirPath(sPath
)))
103 updateList
.AddPath(CTSVNPath(sPath
));
106 updateList
.AddPath(pathList
[i
]);
107 CShellUpdater::Instance().AddPathsForUpdate(updateList
);
108 CShellUpdater::Instance().Flush();
109 updateList
.SortByPathname(true);
110 for (INT_PTR i
=0; i
<updateList
.GetCount(); ++i
)
112 SHChangeNotify(SHCNE_UPDATEITEM
, SHCNF_PATH
, updateList
[i
].GetWinPath(), NULL
);
113 ATLTRACE(_T("notify change for path %s\n"), updateList
[i
].GetWinPath());
120 if ( !strSuccessfullPaths
.IsEmpty() )
123 tmp
.Format(IDS_PROC_CLEANUPFINISHED
, (LPCTSTR
)strSuccessfullPaths
);
127 if ( !strFailedPaths
.IsEmpty() )
129 if (!strMessage
.IsEmpty())
130 strMessage
+= _T("\n");
132 tmp
.Format(IDS_PROC_CLEANUPFINISHED_FAILED
, (LPCTSTR
)strFailedPaths
);
136 CMessageBox::Show(hwndExplorer
, strMessage
, _T("TortoiseGit"), MB_OK
| (strFailedPaths
.IsEmpty()?MB_ICONINFORMATION
:MB_ICONERROR
));
138 CShellUpdater::Instance().Flush();