OSDN Git Service

Add Git submodule update and fix ProgressDlg show Okay when command still running.
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / Commands / SubmoduleCommand.cpp
1 // TortoiseGit - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2008-2009 - TortoiseGit\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 "SubmoduleCommand.h"\r
21 \r
22 #include "MessageBox.h"\r
23 #include "RenameDlg.h"\r
24 #include "InputLogDlg.h"\r
25 #include "Git.h"\r
26 #include "DirFileEnum.h"\r
27 #include "ShellUpdater.h"\r
28 #include "SubmoduleAddDlg.h"\r
29 #include "ProgressDlg.h"\r
30 \r
31 bool SubmoduleAddCommand::Execute()\r
32 {\r
33         bool bRet = false;\r
34         CSubmoduleAddDlg dlg;\r
35         dlg.m_strPath = cmdLinePath.GetDirectory().GetWinPathString();\r
36         dlg.m_strProject = g_Git.m_CurrentDir;\r
37         if( dlg.DoModal() == IDOK )\r
38         {\r
39                 CString cmd;\r
40                 if(dlg.m_strPath.Left(g_Git.m_CurrentDir.GetLength()) == g_Git.m_CurrentDir)\r
41                         dlg.m_strPath = dlg.m_strPath.Right(dlg.m_strPath.GetLength()-g_Git.m_CurrentDir.GetLength()-1);\r
42                 \r
43                 CString branch;\r
44                 if(dlg.m_bBranch)\r
45                         branch.Format(_T(" -b %s "), dlg.m_strBranch);\r
46 \r
47                 dlg.m_strPath.Replace(_T('\\'),_T('/'));\r
48                 dlg.m_strRepos.Replace(_T('\\'),_T('/'));\r
49 \r
50                 cmd.Format(_T("git.exe submodule add %s -- \"%s\"  \"%s\""),\r
51                                                 branch,\r
52                                                 dlg.m_strRepos, dlg.m_strPath);\r
53 \r
54                 CProgressDlg progress;\r
55                 progress.m_GitCmd=cmd;\r
56                 progress.DoModal();\r
57 \r
58                 bRet = TRUE;\r
59         }\r
60         return bRet;\r
61 }\r
62 \r
63 bool SubmoduleUpdateCommand::Execute()\r
64 {\r
65         bool bRet = false;\r
66         CProgressDlg progress;\r
67         CString bkpath=parser.GetVal(_T("bkpath"));\r
68 \r
69         CString super=g_GitAdminDir.GetSuperProjectRoot( bkpath );\r
70         if(super.IsEmpty())\r
71         {\r
72                 CMessageBox::Show(NULL,_T("Can't found Super project"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
73                 //change current project root to super project\r
74                 return false;\r
75         }\r
76 \r
77         g_Git.m_CurrentDir=super;\r
78         \r
79         progress.m_Title.Format(_T("Submodule update - %s"),super);\r
80 \r
81         //progress.m_GitCmd.Format(_T("git.exe submodule update --init "));\r
82 \r
83         CString str;\r
84         for(int i=0;i<this->orgPathList.GetCount();i++)\r
85         {\r
86                 str.Format(_T("git.exe submodule update --init \"%s\""),((CTGitPath &)orgPathList[i]).GetSubPath(CTGitPath(super)).GetGitPathString());\r
87                 progress.m_GitCmdList.push_back(str);\r
88         }\r
89 \r
90         progress.DoModal();\r
91 \r
92         return !progress.m_GitStatus;\r
93 }\r