1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2009, 2012-2016, 2018 - 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"
24 #include "ShellUpdater.h"
25 #include "SubmoduleAddDlg.h"
26 #include "SubmoduleUpdateDlg.h"
27 #include "ProgressDlg.h"
30 bool SubmoduleAddCommand::Execute()
34 dlg
.m_strPath
= cmdLinePath
.GetDirectory().GetWinPathString();
35 dlg
.m_strProject
= g_Git
.m_CurrentDir
;
36 if( dlg
.DoModal() == IDOK
)
38 if (dlg
.m_bAutoloadPuttyKeyFile
)
39 CAppUtils::LaunchPAgent(hwndExplorer
, &dlg
.m_strPuttyKeyFile
);
42 if (CStringUtils::StartsWith(dlg
.m_strPath
, g_Git
.m_CurrentDir
))
43 dlg
.m_strPath
= dlg
.m_strPath
.Right(dlg
.m_strPath
.GetLength()-g_Git
.m_CurrentDir
.GetLength()-1);
47 branch
.Format(L
" -b %s ", (LPCTSTR
)dlg
.m_strBranch
);
53 dlg
.m_strPath
.Replace(L
'\\', L
'/');
54 dlg
.m_strRepos
.Replace(L
'\\', L
'/');
56 cmd
.Format(L
"git.exe submodule add %s %s -- \"%s\" \"%s\"",
57 (LPCTSTR
)branch
, (LPCTSTR
)force
,
58 (LPCTSTR
)dlg
.m_strRepos
, (LPCTSTR
)dlg
.m_strPath
);
60 CProgressDlg progress
;
61 progress
.m_GitCmd
=cmd
;
64 if (progress
.m_GitStatus
== 0)
66 if (dlg
.m_bAutoloadPuttyKeyFile
)
68 SetCurrentDirectory(g_Git
.m_CurrentDir
);
70 dlg
.m_strPath
.Replace(L
'/', L
'\\');
71 subgit
.m_CurrentDir
= PathIsRelative(dlg
.m_strPath
) ? g_Git
.CombinePath(dlg
.m_strPath
) : dlg
.m_strPath
;
73 if (subgit
.SetConfigValue(L
"remote.origin.puttykeyfile", dlg
.m_strPuttyKeyFile
, CONFIG_LOCAL
))
75 CMessageBox::Show(hwndExplorer
, L
"Fail set config remote.origin.puttykeyfile", L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
86 bool SubmoduleUpdateCommand::Execute()
89 if (parser
.HasKey(L
"bkpath"))
90 bkpath
= parser
.GetVal(L
"bkpath");
93 bkpath
= this->orgPathList
[0].GetWinPathString();
94 int start
= bkpath
.ReverseFind(L
'\\');
96 bkpath
= bkpath
.Left(start
);
99 CString super
= GitAdminDir::GetSuperProjectRoot(bkpath
);
102 CMessageBox::Show(hwndExplorer
, IDS_ERR_NOTFOUND_SUPER_PRJECT
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
103 //change current project root to super project
107 STRING_VECTOR pathFilterList
;
108 for (int i
= 0; i
< orgPathList
.GetCount(); i
++)
110 if (orgPathList
[i
].IsDirectory())
112 CString path
= ((CTGitPath
&)orgPathList
[i
]).GetSubPath(CTGitPath(super
)).GetGitPathString();
114 pathFilterList
.push_back(path
);
118 CSubmoduleUpdateDlg submoduleUpdateDlg
;
119 submoduleUpdateDlg
.m_PathFilterList
= pathFilterList
;
120 if (parser
.HasKey(L
"selectedpath"))
122 CString selectedPath
= parser
.GetVal(L
"selectedpath");
123 selectedPath
.Replace(L
'\\', L
'/');
124 submoduleUpdateDlg
.m_PathList
.push_back(selectedPath
);
126 if (submoduleUpdateDlg
.DoModal() != IDOK
)
129 CProgressDlg progress
;
131 g_Git
.m_CurrentDir
= super
;
134 if (submoduleUpdateDlg
.m_bInit
)
136 if (submoduleUpdateDlg
.m_bRecursive
)
137 params
+= L
" --recursive";
138 if (submoduleUpdateDlg
.m_bForce
)
139 params
+= L
" --force";
140 if (submoduleUpdateDlg
.m_bNoFetch
)
141 params
+= L
" --no-fetch";
142 if (submoduleUpdateDlg
.m_bMerge
)
143 params
+= L
" --merge";
144 if (submoduleUpdateDlg
.m_bRebase
)
145 params
+= L
" --rebase";
146 if (submoduleUpdateDlg
.m_bRemote
)
147 params
+= L
" --remote";
148 if (CAppUtils::IsGitVersionNewerOrEqual(hWndExplorer
, 2, 11))
149 params
+= L
" --progress";
151 for (size_t i
= 0; i
< submoduleUpdateDlg
.m_PathList
.size(); ++i
)
154 str
.Format(L
"git.exe submodule update%s -- \"%s\"", (LPCTSTR
)params
, (LPCTSTR
)submoduleUpdateDlg
.m_PathList
[i
]);
155 progress
.m_GitCmdList
.push_back(str
);
158 progress
.m_PostCmdCallback
= [&](DWORD status
, PostCmdList
& postCmdList
)
163 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
164 if (gitPath
.IsBisectActive())
166 postCmdList
.emplace_back(IDI_THUMB_UP
, IDS_MENUBISECTGOOD
, [] { CAppUtils::RunTortoiseGitProc(L
"/command:bisect /good"); });
167 postCmdList
.emplace_back(IDI_THUMB_DOWN
, IDS_MENUBISECTBAD
, [] { CAppUtils::RunTortoiseGitProc(L
"/command:bisect /bad"); });
168 postCmdList
.emplace_back(IDI_BISECT
, IDS_MENUBISECTSKIP
, [] { CAppUtils::RunTortoiseGitProc(L
"/command:bisect /skip"); });
169 postCmdList
.emplace_back(IDI_BISECT_RESET
, IDS_MENUBISECTRESET
, [] { CAppUtils::RunTortoiseGitProc(L
"/command:bisect /reset"); });
175 return !progress
.m_GitStatus
;
178 bool SubmoduleCommand::Execute(CString cmd
, CString arg
)
180 CProgressDlg progress
;
183 if (parser
.HasKey(L
"bkpath"))
184 bkpath
=parser
.GetVal(L
"bkpath");
187 bkpath
=this->orgPathList
[0].GetWinPathString();
188 int start
= bkpath
.ReverseFind(L
'\\');
190 bkpath
=bkpath
.Left(start
);
193 CString super
= GitAdminDir::GetSuperProjectRoot(bkpath
);
196 CMessageBox::Show(hwndExplorer
, IDS_ERR_NOTFOUND_SUPER_PRJECT
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
197 //change current project root to super project
201 g_Git
.m_CurrentDir
=super
;
203 //progress.m_GitCmd.Format(L"git.exe submodule update --init ");
206 for (int i
= 0; i
< this->orgPathList
.GetCount(); ++i
)
208 if(orgPathList
[i
].IsDirectory())
210 str
.Format(L
"git.exe submodule %s %s -- \"%s\"", (LPCTSTR
)cmd
, (LPCTSTR
)arg
, (LPCTSTR
)((CTGitPath
&)orgPathList
[i
]).GetSubPath(CTGitPath(super
)).GetGitPathString());
211 progress
.m_GitCmdList
.push_back(str
);
217 return !progress
.m_GitStatus
;