Correct Handle case when patch file is not in repository path.
[TortoiseGit.git] / src / TortoiseProc / Commands / CleanupCommand.cpp
blob89324fa3816dee7c35ab3e2133aaeba4a0bf0f51
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.
19 #include "StdAfx.h"
20 #include "CleanupCommand.h"
22 #include "MessageBox.h"
23 #include "ProgressDlg.h"
24 #include "Git.h"
25 //#include "GitGlobal.h"
26 #include "GitAdminDir.h"
27 #include "DirFileEnum.h"
28 #include "ShellUpdater.h"
30 bool CleanupCommand::Execute()
32 bool bRet = false;
33 CString temp;
34 temp.Format(_T("Are you sure clean all untracked files"));
35 if(CMessageBox::Show(NULL,temp,_T("TortoiseGit"),MB_YESNO)==IDYES)
37 CProgressDlg progress;
38 progress.m_GitCmd.Format(_T("git clean -d -x -f "));
39 if(progress.DoModal()==IDOK)
40 return TRUE;
42 #if 0
43 CProgressDlg progress;
44 progress.SetTitle(IDS_PROC_CLEANUP);
45 progress.SetAnimation(IDR_CLEANUPANI);
46 progress.SetShowProgressBar(false);
47 progress.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_CLEANUP_INFO1)));
48 progress.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROC_CLEANUP_INFO2)));
49 progress.ShowModeless(hwndExplorer);
51 CString strSuccessfullPaths, strFailedPaths;
52 for (int i=0; i<pathList.GetCount(); ++i)
54 SVN svn;
55 if (!svn.CleanUp(pathList[i]))
57 strFailedPaths += _T("- ") + pathList[i].GetWinPathString() + _T("\n");
58 strFailedPaths += svn.GetLastErrorMessage() + _T("\n\n");
60 else
62 strSuccessfullPaths += _T("- ") + pathList[i].GetWinPathString() + _T("\n");
64 // after the cleanup has finished, crawl the path downwards and send a change
65 // notification for every directory to the shell. This will update the
66 // overlays in the left tree view of the explorer.
67 CDirFileEnum crawler(pathList[i].GetWinPathString());
68 CString sPath;
69 bool bDir = false;
70 CTSVNPathList updateList;
71 while (crawler.NextFile(sPath, &bDir))
73 if ((bDir) && (!g_SVNAdminDir.IsAdminDirPath(sPath)))
75 updateList.AddPath(CTSVNPath(sPath));
78 updateList.AddPath(pathList[i]);
79 CShellUpdater::Instance().AddPathsForUpdate(updateList);
80 CShellUpdater::Instance().Flush();
81 updateList.SortByPathname(true);
82 for (INT_PTR i=0; i<updateList.GetCount(); ++i)
84 SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, updateList[i].GetWinPath(), NULL);
85 ATLTRACE(_T("notify change for path %s\n"), updateList[i].GetWinPath());
89 progress.Stop();
91 CString strMessage;
92 if ( !strSuccessfullPaths.IsEmpty() )
94 CString tmp;
95 tmp.Format(IDS_PROC_CLEANUPFINISHED, (LPCTSTR)strSuccessfullPaths);
96 strMessage += tmp;
97 bRet = true;
99 if ( !strFailedPaths.IsEmpty() )
101 if (!strMessage.IsEmpty())
102 strMessage += _T("\n");
103 CString tmp;
104 tmp.Format(IDS_PROC_CLEANUPFINISHED_FAILED, (LPCTSTR)strFailedPaths);
105 strMessage += tmp;
106 bRet = false;
108 CMessageBox::Show(hwndExplorer, strMessage, _T("TortoiseSVN"), MB_OK | (strFailedPaths.IsEmpty()?MB_ICONINFORMATION:MB_ICONERROR));
109 #endif
110 CShellUpdater::Instance().Flush();
111 return bRet;