SyncDlg: Make check if local branch fast-fowards to remote branch work again
[TortoiseGit.git] / src / TortoiseProc / Commands / CleanupCommand.cpp
blobcaa4b0030a4b1b3500ae6a7dbdf5a03826a1bab7
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.
20 #include "StdAfx.h"
21 #include "CleanupCommand.h"
23 #include "MessageBox.h"
24 #include "ProgressDlg.h"
25 #include "Git.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()
34 bool bRet = false;
36 CCleanTypeDlg dlg;
37 if( dlg.DoModal() == IDOK)
39 CString cmd;
40 cmd.Format(_T("git clean -n"));
41 if(dlg.m_bDir)
42 cmd += _T(" -d ");
43 switch(dlg.m_CleanType)
45 case 0:
46 cmd += _T(" -fx");
47 break;
48 case 1:
49 cmd += _T(" -f");
50 break;
51 case 2:
52 cmd += _T(" -fX");
53 break;
56 CString cmdout, cmdouterr;
57 if (g_Git.Run(cmd, &cmdout, &cmdouterr, CP_UTF8)) {
58 MessageBox(NULL, cmdouterr, _T("TortoiseGit"), MB_ICONERROR);
59 return FALSE;
62 int pos = 0;
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);
74 #if 0
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)
86 SVN svn;
87 if (!svn.CleanUp(pathList[i]))
89 strFailedPaths += _T("- ") + pathList[i].GetWinPathString() + _T("\n");
90 strFailedPaths += svn.GetLastErrorMessage() + _T("\n\n");
92 else
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());
100 CString sPath;
101 bool bDir = false;
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());
121 progress.Stop();
123 CString strMessage;
124 if ( !strSuccessfullPaths.IsEmpty() )
126 CString tmp;
127 tmp.Format(IDS_PROC_CLEANUPFINISHED, (LPCTSTR)strSuccessfullPaths);
128 strMessage += tmp;
129 bRet = true;
131 if ( !strFailedPaths.IsEmpty() )
133 if (!strMessage.IsEmpty())
134 strMessage += _T("\n");
135 CString tmp;
136 tmp.Format(IDS_PROC_CLEANUPFINISHED_FAILED, (LPCTSTR)strFailedPaths);
137 strMessage += tmp;
138 bRet = false;
140 CMessageBox::Show(hwndExplorer, strMessage, _T("TortoiseGit"), MB_OK | (strFailedPaths.IsEmpty()?MB_ICONINFORMATION:MB_ICONERROR));
141 #endif
142 CShellUpdater::Instance().Flush();
143 return bRet;