1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2009,2012-2013 - TortoiseGit
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.
20 #include "SubmoduleCommand.h"
22 #include "MessageBox.h"
23 #include "RenameDlg.h"
24 #include "InputLogDlg.h"
26 #include "DirFileEnum.h"
27 #include "ShellUpdater.h"
28 #include "SubmoduleAddDlg.h"
29 #include "SubmoduleUpdateDlg.h"
30 #include "ProgressDlg.h"
32 bool SubmoduleAddCommand::Execute()
36 dlg
.m_strPath
= cmdLinePath
.GetDirectory().GetWinPathString();
37 dlg
.m_strProject
= g_Git
.m_CurrentDir
;
38 if( dlg
.DoModal() == IDOK
)
41 if(dlg
.m_strPath
.Left(g_Git
.m_CurrentDir
.GetLength()) == g_Git
.m_CurrentDir
)
42 dlg
.m_strPath
= dlg
.m_strPath
.Right(dlg
.m_strPath
.GetLength()-g_Git
.m_CurrentDir
.GetLength()-1);
46 branch
.Format(_T(" -b %s "), dlg
.m_strBranch
);
50 force
= _T("--force");
52 dlg
.m_strPath
.Replace(_T('\\'),_T('/'));
53 dlg
.m_strRepos
.Replace(_T('\\'),_T('/'));
55 cmd
.Format(_T("git.exe submodule add %s %s -- \"%s\" \"%s\""),
57 dlg
.m_strRepos
, dlg
.m_strPath
);
59 CProgressDlg progress
;
60 progress
.m_GitCmd
=cmd
;
68 bool SubmoduleUpdateCommand::Execute()
71 if (parser
.HasKey(_T("bkpath")))
72 bkpath
= parser
.GetVal(_T("bkpath"));
75 bkpath
= this->orgPathList
[0].GetWinPathString();
76 int start
= bkpath
.ReverseFind(_T('\\'));
78 bkpath
= bkpath
.Left(start
);
81 CString super
= g_GitAdminDir
.GetSuperProjectRoot(bkpath
);
84 CMessageBox::Show(NULL
,IDS_ERR_NOTFOUND_SUPER_PRJECT
,IDS_APPNAME
,MB_OK
|MB_ICONERROR
);
85 //change current project root to super project
89 CSubmoduleUpdateDlg submoduleUpdateDlg
;
90 if (submoduleUpdateDlg
.DoModal() != IDOK
)
93 CProgressDlg progress
;
95 g_Git
.m_CurrentDir
= super
;
98 if (submoduleUpdateDlg
.m_bInit
)
99 params
= _T(" --init");
100 if (submoduleUpdateDlg
.m_bRecursive
)
101 params
+= _T(" --recursive");
102 if (submoduleUpdateDlg
.m_bForce
)
103 params
+= _T(" --force");
104 if (submoduleUpdateDlg
.m_bNoFetch
)
105 params
+= _T(" --no-fetch");
106 if (submoduleUpdateDlg
.m_bMerge
)
107 params
+= _T(" --merge");
108 if (submoduleUpdateDlg
.m_bRebase
)
109 params
+= _T(" --rebase");
111 for (int i
= 0; i
< this->orgPathList
.GetCount(); i
++)
113 if (orgPathList
[i
].IsDirectory())
116 str
.Format(_T("git.exe submodule update%s \"%s\""), params
, ((CTGitPath
&)orgPathList
[i
]).GetSubPath(CTGitPath(super
)).GetGitPathString());
117 progress
.m_GitCmdList
.push_back(str
);
123 return !progress
.m_GitStatus
;
126 bool SubmoduleCommand::Execute(CString cmd
, CString arg
)
128 CProgressDlg progress
;
131 if(parser
.HasKey(_T("bkpath")))
133 bkpath
=parser
.GetVal(_T("bkpath"));
137 bkpath
=this->orgPathList
[0].GetWinPathString();
138 int start
= bkpath
.ReverseFind(_T('\\'));
140 bkpath
=bkpath
.Left(start
);
143 CString super
=g_GitAdminDir
.GetSuperProjectRoot( bkpath
);
146 CMessageBox::Show(NULL
,IDS_ERR_NOTFOUND_SUPER_PRJECT
,IDS_APPNAME
,MB_OK
|MB_ICONERROR
);
147 //change current project root to super project
151 g_Git
.m_CurrentDir
=super
;
153 progress
.m_Title
.Format(_T("Submodule %s"),cmd
);
155 //progress.m_GitCmd.Format(_T("git.exe submodule update --init "));
158 for(int i
=0;i
<this->orgPathList
.GetCount();i
++)
160 if(orgPathList
[i
].IsDirectory())
162 str
.Format(_T("git.exe submodule %s %s \"%s\""),cmd
,arg
, ((CTGitPath
&)orgPathList
[i
]).GetSubPath(CTGitPath(super
)).GetGitPathString());
163 progress
.m_GitCmdList
.push_back(str
);
169 return !progress
.m_GitStatus
;