OSDN Git Service

d0aa4bd7cd902c29a793c166cc93c07200e0d4f1
[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 SubmoduleCommand::Execute(CString cmd,  CString arg)\r
64 {\r
65         bool bRet = false;\r
66         CProgressDlg progress;\r
67         CString bkpath;\r
68 \r
69         if(parser.HasKey(_T("bkpath")))\r
70         {\r
71                 bkpath=parser.GetVal(_T("bkpath"));\r
72         }\r
73         else\r
74         {\r
75                 bkpath=this->orgPathList[0].GetWinPathString();\r
76                 bkpath=bkpath.Left(bkpath.ReverseFind(_T('\\')));\r
77         }\r
78 \r
79         CString super=g_GitAdminDir.GetSuperProjectRoot( bkpath );\r
80         if(super.IsEmpty())\r
81         {\r
82                 CMessageBox::Show(NULL,_T("Can't found Super project"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
83                 //change current project root to super project\r
84                 return false;\r
85         }\r
86 \r
87         g_Git.m_CurrentDir=super;\r
88         \r
89         progress.m_Title.Format(_T("Submodule %s - %s"),cmd,super);\r
90 \r
91         //progress.m_GitCmd.Format(_T("git.exe submodule update --init "));\r
92 \r
93         CString str;\r
94         for(int i=0;i<this->orgPathList.GetCount();i++)\r
95         {\r
96                 if(orgPathList[i].IsDirectory())\r
97                 {\r
98                         str.Format(_T("git.exe submodule %s %s \"%s\""),cmd,arg, ((CTGitPath &)orgPathList[i]).GetSubPath(CTGitPath(super)).GetGitPathString());\r
99                         progress.m_GitCmdList.push_back(str);\r
100                 }\r
101         }\r
102 \r
103         progress.DoModal();\r
104 \r
105         return !progress.m_GitStatus;\r
106 }\r