1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009,2011-2012 - TortoiseGit
4 // Copyright (C) 2007-2008 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "CleanupCommand.h"
23 #include "MessageBox.h"
24 #include "ProgressDlg.h"
26 //#include "GitGlobal.h"
27 #include "GitAdminDir.h"
28 #include "DirFileEnum.h"
29 #include "ShellUpdater.h"
30 #include "CleanTypeDlg.h"
32 bool CleanupCommand::Execute()
37 if( dlg
.DoModal() == IDOK
)
40 cmd
.Format(_T("git clean -n"));
43 switch(dlg
.m_CleanType
)
56 CString cmdout
, cmdouterr
;
57 if (g_Git
.Run(cmd
, &cmdout
, &cmdouterr
, CP_UTF8
)) {
58 MessageBox(NULL
, cmdouterr
, _T("TortoiseGit"), MB_ICONERROR
);
63 CString token
= cmdout
.Tokenize(_T("\n"), pos
);
64 CTGitPathList delList
;
65 while (!token
.IsEmpty())
67 if (token
.Mid(0, 13) == _T("Would remove "))
68 delList
.AddPath(CTGitPath(token
.Mid(13).TrimRight()));
70 token
= cmdout
.Tokenize(_T("\n"), pos
);
72 delList
.DeleteAllFiles(true, false);
75 CProgressDlg progress
;
76 progress
.SetTitle(IDS_PROC_CLEANUP
);
77 progress
.SetAnimation(IDR_CLEANUPANI
);
78 progress
.SetShowProgressBar(false);
79 progress
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_CLEANUP_INFO1
)));
80 progress
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROC_CLEANUP_INFO2
)));
81 progress
.ShowModeless(hwndExplorer
);
83 CString strSuccessfullPaths
, strFailedPaths
;
84 for (int i
=0; i
<pathList
.GetCount(); ++i
)
87 if (!svn
.CleanUp(pathList
[i
]))
89 strFailedPaths
+= _T("- ") + pathList
[i
].GetWinPathString() + _T("\n");
90 strFailedPaths
+= svn
.GetLastErrorMessage() + _T("\n\n");
94 strSuccessfullPaths
+= _T("- ") + pathList
[i
].GetWinPathString() + _T("\n");
96 // after the cleanup has finished, crawl the path downwards and send a change
97 // notification for every directory to the shell. This will update the
98 // overlays in the left tree view of the explorer.
99 CDirFileEnum
crawler(pathList
[i
].GetWinPathString());
102 CTSVNPathList updateList
;
103 while (crawler
.NextFile(sPath
, &bDir
))
105 if ((bDir
) && (!g_SVNAdminDir
.IsAdminDirPath(sPath
)))
107 updateList
.AddPath(CTSVNPath(sPath
));
110 updateList
.AddPath(pathList
[i
]);
111 CShellUpdater::Instance().AddPathsForUpdate(updateList
);
112 CShellUpdater::Instance().Flush();
113 updateList
.SortByPathname(true);
114 for (INT_PTR i
=0; i
<updateList
.GetCount(); ++i
)
116 SHChangeNotify(SHCNE_UPDATEITEM
, SHCNF_PATH
, updateList
[i
].GetWinPath(), NULL
);
117 ATLTRACE(_T("notify change for path %s\n"), updateList
[i
].GetWinPath());
124 if ( !strSuccessfullPaths
.IsEmpty() )
127 tmp
.Format(IDS_PROC_CLEANUPFINISHED
, (LPCTSTR
)strSuccessfullPaths
);
131 if ( !strFailedPaths
.IsEmpty() )
133 if (!strMessage
.IsEmpty())
134 strMessage
+= _T("\n");
136 tmp
.Format(IDS_PROC_CLEANUPFINISHED_FAILED
, (LPCTSTR
)strFailedPaths
);
140 CMessageBox::Show(hwndExplorer
, strMessage
, _T("TortoiseGit"), MB_OK
| (strFailedPaths
.IsEmpty()?MB_ICONINFORMATION
:MB_ICONERROR
));
142 CShellUpdater::Instance().Flush();