Use static method
[TortoiseGit.git] / src / TortoiseProc / Commands / CloneCommand.cpp
blobc404efd4cf1100729e6792a572b360f36401a5c4
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-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 "CloneCommand.h"
22 #include "GitProgressDlg.h"
23 #include "StringUtils.h"
24 #include "Hooks.h"
25 #include "MessageBox.h"
27 #include "CloneDlg.h"
28 #include "ProgressDlg.h"
29 #include "AppUtils.h"
30 #include "git2.h"
31 #include "UnicodeUtils.h"
32 #include "SysProgressDlg.h"
34 bool CloneCommand::Execute()
36 CCloneDlg dlg;
37 dlg.m_Directory=this->orgCmdLinePath.GetWinPathString();
39 if (parser.HasKey(_T("url")))
40 dlg.m_URL = parser.GetVal(_T("url"));
42 if(dlg.DoModal()==IDOK)
44 CString recursiveStr;
45 if(dlg.m_bRecursive)
46 recursiveStr = _T("--recursive");
47 else
48 recursiveStr = _T("");
50 CString bareStr;
51 if(dlg.m_bBare)
52 bareStr = _T("--bare");
53 else
54 bareStr = _T("");
56 CString nocheckoutStr;
57 if (dlg.m_bNoCheckout)
58 nocheckoutStr = _T("--no-checkout");
60 CString branchStr;
61 if (dlg.m_bBranch)
62 branchStr = _T("--branch ") + dlg.m_strBranch;
64 if(dlg.m_bAutoloadPuttyKeyFile)
66 CAppUtils::LaunchPAgent(&dlg.m_strPuttyKeyFile);
69 CAppUtils::RemoveTrailSlash(dlg.m_Directory);
70 if (!dlg.m_bSVN)
71 CAppUtils::RemoveTrailSlash(dlg.m_URL);
73 CString dir=dlg.m_Directory;
74 CString url=dlg.m_URL;
76 // is this a windows format UNC path, ie starts with \\?
77 if (url.Find(_T("\\\\")) == 0)
79 // yes, change all \ to /
80 // this should not be necessary but msysgit does not support the use \ here yet
81 int atSign = url.Find(_T('@'));
82 if (atSign > 0)
84 CString path = url.Mid(atSign);
85 path.Replace(_T('\\'), _T('/'));
86 url = url.Mid(0, atSign) + path;
88 else
89 url.Replace( _T('\\'), _T('/'));
92 CString depth;
93 if (dlg.m_bDepth)
95 depth.Format(_T(" --depth %d"),dlg.m_nDepth);
98 g_Git.m_CurrentDir = this->orgCmdLinePath.GetWinPathString();
100 CString cmd;
101 CString progressarg;
103 int ver = CAppUtils::GetMsysgitVersion();
105 if(ver >= 0x01070002) //above 1.7.0.2
106 progressarg = _T("--progress");
108 cmd.Format(_T("git.exe clone %s %s %s %s %s -v %s \"%s\" \"%s\""),
109 nocheckoutStr,
110 recursiveStr,
111 bareStr,
112 branchStr,
113 progressarg,
114 depth,
115 url,
116 dir);
118 // Handle Git SVN-clone
119 if(dlg.m_bSVN)
121 //g_Git.m_CurrentDir=dlg.m_Directory;
122 cmd.Format(_T("git.exe svn clone \"%s\" \"%s\""),
123 url,dlg.m_Directory);
125 if(dlg.m_bSVNTrunk)
126 cmd+=_T(" -T ")+dlg.m_strSVNTrunk;
128 if(dlg.m_bSVNBranch)
129 cmd+=_T(" -b ")+dlg.m_strSVNBranchs;
131 if(dlg.m_bSVNTags)
132 cmd+=_T(" -t ")+dlg.m_strSVNTags;
134 if(dlg.m_bSVNFrom)
136 CString str;
137 str.Format(_T("%d:HEAD"),dlg.m_nSVNFrom);
138 cmd+=_T(" -r ")+str;
141 if(dlg.m_bSVNUserName)
143 cmd+= _T(" --username ");
144 cmd+=dlg.m_strUserName;
147 else
149 if (g_Git.UsingLibGit2(CGit::GIT_CMD_CLONE))
151 CGitProgressDlg GitDlg;
152 CTGitPathList list;
153 list.AddPath(CTGitPath(dir));
154 GitDlg.SetCommand(CGitProgressDlg::GitProgress_Clone);
155 GitDlg.SetUrl(url);
156 GitDlg.SetPathList(list);
157 GitDlg.SetIsBare(!!dlg.m_bBare);
158 GitDlg.SetRefSpec(dlg.m_bBranch ? dlg.m_strBranch : CString());
159 GitDlg.SetNoCheckout(!!dlg.m_bNoCheckout);
160 GitDlg.DoModal();
161 return !GitDlg.DidErrorsOccur();
164 CProgressDlg progress;
165 progress.m_GitCmd=cmd;
166 INT_PTR ret = progress.DoModal();
168 if( progress.m_GitStatus == 0)
170 if(dlg.m_bAutoloadPuttyKeyFile)
172 g_Git.m_CurrentDir = dlg.m_Directory;
173 SetCurrentDirectory(g_Git.m_CurrentDir);
175 if(g_Git.SetConfigValue(_T("remote.origin.puttykeyfile"), dlg.m_strPuttyKeyFile, CONFIG_LOCAL, CP_UTF8, &dlg.m_Directory))
177 CMessageBox::Show(NULL,_T("Fail set config remote.origin.puttykeyfile"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
178 return FALSE;
182 if(ret == IDOK)
183 return TRUE;
186 return FALSE;