1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2009,2012-2015 - 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"
33 bool SubmoduleAddCommand::Execute()
37 dlg
.m_strPath
= cmdLinePath
.GetDirectory().GetWinPathString();
38 dlg
.m_strProject
= g_Git
.m_CurrentDir
;
39 if( dlg
.DoModal() == IDOK
)
41 if (dlg
.m_bAutoloadPuttyKeyFile
)
42 CAppUtils::LaunchPAgent(&dlg
.m_strPuttyKeyFile
);
45 if(dlg
.m_strPath
.Left(g_Git
.m_CurrentDir
.GetLength()) == g_Git
.m_CurrentDir
)
46 dlg
.m_strPath
= dlg
.m_strPath
.Right(dlg
.m_strPath
.GetLength()-g_Git
.m_CurrentDir
.GetLength()-1);
50 branch
.Format(_T(" -b %s "), dlg
.m_strBranch
);
54 force
= _T("--force");
56 dlg
.m_strPath
.Replace(_T('\\'),_T('/'));
57 dlg
.m_strRepos
.Replace(_T('\\'),_T('/'));
59 cmd
.Format(_T("git.exe submodule add %s %s -- \"%s\" \"%s\""),
61 dlg
.m_strRepos
, dlg
.m_strPath
);
63 CProgressDlg progress
;
64 progress
.m_GitCmd
=cmd
;
67 if (progress
.m_GitStatus
== 0)
69 if (dlg
.m_bAutoloadPuttyKeyFile
)
71 SetCurrentDirectory(g_Git
.m_CurrentDir
);
73 dlg
.m_strPath
.Replace(_T('/'), _T('\\'));
74 subgit
.m_CurrentDir
= PathIsRelative(dlg
.m_strPath
) ? g_Git
.CombinePath(dlg
.m_strPath
) : dlg
.m_strPath
;
76 if (subgit
.SetConfigValue(_T("remote.origin.puttykeyfile"), dlg
.m_strPuttyKeyFile
, CONFIG_LOCAL
))
78 CMessageBox::Show(NULL
, _T("Fail set config remote.origin.puttykeyfile"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
89 bool SubmoduleUpdateCommand::Execute()
92 if (parser
.HasKey(_T("bkpath")))
93 bkpath
= parser
.GetVal(_T("bkpath"));
96 bkpath
= this->orgPathList
[0].GetWinPathString();
97 int start
= bkpath
.ReverseFind(_T('\\'));
99 bkpath
= bkpath
.Left(start
);
102 CString super
= GitAdminDir::GetSuperProjectRoot(bkpath
);
105 CMessageBox::Show(NULL
,IDS_ERR_NOTFOUND_SUPER_PRJECT
,IDS_APPNAME
,MB_OK
|MB_ICONERROR
);
106 //change current project root to super project
110 STRING_VECTOR pathFilterList
;
111 for (int i
= 0; i
< orgPathList
.GetCount(); i
++)
113 if (orgPathList
[i
].IsDirectory())
115 CString path
= ((CTGitPath
&)orgPathList
[i
]).GetSubPath(CTGitPath(super
)).GetGitPathString();
117 pathFilterList
.push_back(path
);
121 CSubmoduleUpdateDlg submoduleUpdateDlg
;
122 submoduleUpdateDlg
.m_PathFilterList
= pathFilterList
;
123 if (parser
.HasKey(_T("selectedpath")))
125 CString selectedPath
= parser
.GetVal(_T("selectedpath"));
126 selectedPath
.Replace(_T('\\'), _T('/'));
127 submoduleUpdateDlg
.m_PathList
.push_back(selectedPath
);
129 if (submoduleUpdateDlg
.DoModal() != IDOK
)
132 CProgressDlg progress
;
134 g_Git
.m_CurrentDir
= super
;
137 if (submoduleUpdateDlg
.m_bInit
)
138 params
= _T(" --init");
139 if (submoduleUpdateDlg
.m_bRecursive
)
140 params
+= _T(" --recursive");
141 if (submoduleUpdateDlg
.m_bForce
)
142 params
+= _T(" --force");
143 if (submoduleUpdateDlg
.m_bNoFetch
)
144 params
+= _T(" --no-fetch");
145 if (submoduleUpdateDlg
.m_bMerge
)
146 params
+= _T(" --merge");
147 if (submoduleUpdateDlg
.m_bRebase
)
148 params
+= _T(" --rebase");
149 if (submoduleUpdateDlg
.m_bRemote
)
150 params
+= _T(" --remote");
152 for (size_t i
= 0; i
< submoduleUpdateDlg
.m_PathList
.size(); ++i
)
155 str
.Format(_T("git.exe submodule update%s -- \"%s\""), params
, submoduleUpdateDlg
.m_PathList
[i
]);
156 progress
.m_GitCmdList
.push_back(str
);
161 return !progress
.m_GitStatus
;
164 bool SubmoduleCommand::Execute(CString cmd
, CString arg
)
166 CProgressDlg progress
;
169 if(parser
.HasKey(_T("bkpath")))
171 bkpath
=parser
.GetVal(_T("bkpath"));
175 bkpath
=this->orgPathList
[0].GetWinPathString();
176 int start
= bkpath
.ReverseFind(_T('\\'));
178 bkpath
=bkpath
.Left(start
);
181 CString super
= GitAdminDir::GetSuperProjectRoot(bkpath
);
184 CMessageBox::Show(NULL
,IDS_ERR_NOTFOUND_SUPER_PRJECT
,IDS_APPNAME
,MB_OK
|MB_ICONERROR
);
185 //change current project root to super project
189 g_Git
.m_CurrentDir
=super
;
191 //progress.m_GitCmd.Format(_T("git.exe submodule update --init "));
194 for (int i
= 0; i
< this->orgPathList
.GetCount(); ++i
)
196 if(orgPathList
[i
].IsDirectory())
198 str
.Format(_T("git.exe submodule %s %s -- \"%s\""),cmd
,arg
, ((CTGitPath
&)orgPathList
[i
]).GetSubPath(CTGitPath(super
)).GetGitPathString());
199 progress
.m_GitCmdList
.push_back(str
);
205 return !progress
.m_GitStatus
;