Added force option to Submodule Update dialog
[TortoiseGit.git] / src / TortoiseProc / Commands / SubmoduleCommand.cpp
blob26bafff99c34b1210b29190caa464033a42c7669
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2009,2012 - 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 dlg.m_strPath.Replace(_T('\\'),_T('/'));
49 dlg.m_strRepos.Replace(_T('\\'),_T('/'));
51 cmd.Format(_T("git.exe submodule add %s -- \"%s\" \"%s\""),
52 branch,
53 dlg.m_strRepos, dlg.m_strPath);
55 CProgressDlg progress;
56 progress.m_GitCmd=cmd;
57 progress.DoModal();
59 bRet = TRUE;
61 return bRet;
64 bool SubmoduleUpdateCommand::Execute()
66 CString bkpath;
67 if (parser.HasKey(_T("bkpath")))
68 bkpath = parser.GetVal(_T("bkpath"));
69 else
71 bkpath = this->orgPathList[0].GetWinPathString();
72 int start = bkpath.ReverseFind(_T('\\'));
73 if (start >= 0)
74 bkpath = bkpath.Left(start);
77 CString super = g_GitAdminDir.GetSuperProjectRoot(bkpath);
78 if (super.IsEmpty())
80 CMessageBox::Show(NULL,IDS_ERR_NOTFOUND_SUPER_PRJECT,IDS_APPNAME,MB_OK|MB_ICONERROR);
81 //change current project root to super project
82 return false;
85 CSubmoduleUpdateDlg submoduleUpdateDlg;
86 if (submoduleUpdateDlg.DoModal() != IDOK)
87 return false;
89 CProgressDlg progress;
91 g_Git.m_CurrentDir = super;
93 CString params;
94 if (submoduleUpdateDlg.m_bInit)
95 params = _T(" --init");
96 if (submoduleUpdateDlg.m_bRecursive)
97 params += _T(" --recursive");
98 if (submoduleUpdateDlg.m_bForce)
99 params += _T(" --force");
101 for (int i = 0; i < this->orgPathList.GetCount(); i++)
103 if (orgPathList[i].IsDirectory())
105 CString str;
106 str.Format(_T("git.exe submodule update%s \"%s\""), params, ((CTGitPath &)orgPathList[i]).GetSubPath(CTGitPath(super)).GetGitPathString());
107 progress.m_GitCmdList.push_back(str);
111 progress.DoModal();
113 return !progress.m_GitStatus;
116 bool SubmoduleCommand::Execute(CString cmd, CString arg)
118 CProgressDlg progress;
119 CString bkpath;
121 if(parser.HasKey(_T("bkpath")))
123 bkpath=parser.GetVal(_T("bkpath"));
125 else
127 bkpath=this->orgPathList[0].GetWinPathString();
128 int start = bkpath.ReverseFind(_T('\\'));
129 if( start >= 0 )
130 bkpath=bkpath.Left(start);
133 CString super=g_GitAdminDir.GetSuperProjectRoot( bkpath );
134 if(super.IsEmpty())
136 CMessageBox::Show(NULL,IDS_ERR_NOTFOUND_SUPER_PRJECT,IDS_APPNAME,MB_OK|MB_ICONERROR);
137 //change current project root to super project
138 return false;
141 g_Git.m_CurrentDir=super;
143 progress.m_Title.Format(_T("Submodule %s"),cmd);
145 //progress.m_GitCmd.Format(_T("git.exe submodule update --init "));
147 CString str;
148 for(int i=0;i<this->orgPathList.GetCount();i++)
150 if(orgPathList[i].IsDirectory())
152 str.Format(_T("git.exe submodule %s %s \"%s\""),cmd,arg, ((CTGitPath &)orgPathList[i]).GetSubPath(CTGitPath(super)).GetGitPathString());
153 progress.m_GitCmdList.push_back(str);
157 progress.DoModal();
159 return !progress.m_GitStatus;