Can specify specific paths of submodules to update
[TortoiseGit.git] / src / TortoiseProc / Commands / SubmoduleCommand.cpp
blob21adc2801564777c2af6b286761e539c05e6b9e7
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.
19 #include "stdafx.h"
20 #include "SubmoduleCommand.h"
22 #include "MessageBox.h"
23 #include "RenameDlg.h"
24 #include "InputLogDlg.h"
25 #include "Git.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()
34 bool bRet = false;
35 CSubmoduleAddDlg dlg;
36 dlg.m_strPath = cmdLinePath.GetDirectory().GetWinPathString();
37 dlg.m_strProject = g_Git.m_CurrentDir;
38 if( dlg.DoModal() == IDOK )
40 CString cmd;
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);
44 CString branch;
45 if(dlg.m_bBranch)
46 branch.Format(_T(" -b %s "), dlg.m_strBranch);
48 CString force;
49 if (dlg.m_bForce)
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\""),
56 branch, force,
57 dlg.m_strRepos, dlg.m_strPath);
59 CProgressDlg progress;
60 progress.m_GitCmd=cmd;
61 progress.DoModal();
63 bRet = TRUE;
65 return bRet;
68 bool SubmoduleUpdateCommand::Execute()
70 CString bkpath;
71 if (parser.HasKey(_T("bkpath")))
72 bkpath = parser.GetVal(_T("bkpath"));
73 else
75 bkpath = this->orgPathList[0].GetWinPathString();
76 int start = bkpath.ReverseFind(_T('\\'));
77 if (start >= 0)
78 bkpath = bkpath.Left(start);
81 CString super = g_GitAdminDir.GetSuperProjectRoot(bkpath);
82 if (super.IsEmpty())
84 CMessageBox::Show(NULL,IDS_ERR_NOTFOUND_SUPER_PRJECT,IDS_APPNAME,MB_OK|MB_ICONERROR);
85 //change current project root to super project
86 return false;
89 STRING_VECTOR pathFilterList;
90 for (size_t i = 0; i < orgPathList.GetCount(); i++)
92 if (orgPathList[i].IsDirectory())
94 CString path = ((CTGitPath &)orgPathList[i]).GetSubPath(CTGitPath(super)).GetGitPathString();
95 if (!path.IsEmpty())
96 pathFilterList.push_back(path);
100 CSubmoduleUpdateDlg submoduleUpdateDlg;
101 submoduleUpdateDlg.m_PathFilterList = pathFilterList;
102 if (submoduleUpdateDlg.DoModal() != IDOK)
103 return false;
105 CProgressDlg progress;
107 g_Git.m_CurrentDir = super;
109 CString params;
110 if (submoduleUpdateDlg.m_bInit)
111 params = _T(" --init");
112 if (submoduleUpdateDlg.m_bRecursive)
113 params += _T(" --recursive");
114 if (submoduleUpdateDlg.m_bForce)
115 params += _T(" --force");
116 if (submoduleUpdateDlg.m_bNoFetch)
117 params += _T(" --no-fetch");
118 if (submoduleUpdateDlg.m_bMerge)
119 params += _T(" --merge");
120 if (submoduleUpdateDlg.m_bRebase)
121 params += _T(" --rebase");
123 for (size_t i = 0; i < submoduleUpdateDlg.m_PathList.size(); ++i)
125 CString str;
126 str.Format(_T("git.exe submodule update%s \"%s\""), params, submoduleUpdateDlg.m_PathList[i]);
127 progress.m_GitCmdList.push_back(str);
130 progress.DoModal();
132 return !progress.m_GitStatus;
135 bool SubmoduleCommand::Execute(CString cmd, CString arg)
137 CProgressDlg progress;
138 CString bkpath;
140 if(parser.HasKey(_T("bkpath")))
142 bkpath=parser.GetVal(_T("bkpath"));
144 else
146 bkpath=this->orgPathList[0].GetWinPathString();
147 int start = bkpath.ReverseFind(_T('\\'));
148 if( start >= 0 )
149 bkpath=bkpath.Left(start);
152 CString super=g_GitAdminDir.GetSuperProjectRoot( bkpath );
153 if(super.IsEmpty())
155 CMessageBox::Show(NULL,IDS_ERR_NOTFOUND_SUPER_PRJECT,IDS_APPNAME,MB_OK|MB_ICONERROR);
156 //change current project root to super project
157 return false;
160 g_Git.m_CurrentDir=super;
162 progress.m_Title.Format(_T("Submodule %s"),cmd);
164 //progress.m_GitCmd.Format(_T("git.exe submodule update --init "));
166 CString str;
167 for (int i = 0; i < this->orgPathList.GetCount(); ++i)
169 if(orgPathList[i].IsDirectory())
171 str.Format(_T("git.exe submodule %s %s \"%s\""),cmd,arg, ((CTGitPath &)orgPathList[i]).GetSubPath(CTGitPath(super)).GetGitPathString());
172 progress.m_GitCmdList.push_back(str);
176 progress.DoModal();
178 return !progress.m_GitStatus;