OSDN Git Service

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