Enable security checks and features
[TortoiseGit.git] / src / TortoiseProc / Commands / CloneCommand.cpp
blob8e09dd24674b1d75fbb96cd4a41021f3917cb114
1 // TortoiseSVN - a Windows shell extension for easy version control
3 // Copyright (C) 2007-2008 - TortoiseSVN
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 "SVNProgressDlg.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"
31 bool CloneCommand::Execute()
33 CCloneDlg dlg;
34 dlg.m_Directory=this->orgCmdLinePath.GetWinPathString();
35 if(dlg.DoModal()==IDOK)
37 CString BareStr;
38 if(dlg.m_bBare)
39 BareStr = _T("--bare");
40 else
41 BareStr = _T("");
43 if(dlg.m_bAutoloadPuttyKeyFile)
45 CAppUtils::LaunchPAgent(&dlg.m_strPuttyKeyFile);
48 CAppUtils::RemoveTrailSlash(dlg.m_Directory);
49 CAppUtils::RemoveTrailSlash(dlg.m_URL);
51 CString dir=dlg.m_Directory;
52 CString url=dlg.m_URL;
54 // is this a windows format UNC path, ie starts with \\
55 if (url.Find(_T("\\\\")) == 0)
57 // yes, change all \ to /
58 // this should not be necessary but msysgit does not support the use \ here yet
59 url.Replace( _T('\\'), _T('/'));
62 CString depth;
63 if (dlg.m_bDepth)
66 depth.Format(_T(" --depth %d"),dlg.m_nDepth);
69 CString cmd;
70 CString progressarg;
72 int ver = CAppUtils::GetMsysgitVersion();
74 if(ver >= 0x01070002) //above 1.7.0.2
75 progressarg = _T("--progress");
78 cmd.Format(_T("git.exe clone %s %s -v %s \"%s\" \"%s\""),
79 BareStr,
80 progressarg,
81 depth,
82 url,
83 dir);
86 // Handle Git SVN-clone
87 if(dlg.m_bSVN)
90 //g_Git.m_CurrentDir=dlg.m_Directory;
91 cmd.Format(_T("git.exe svn clone \"%s\" \"%s\""),
92 url,dlg.m_Directory);
94 if(dlg.m_bSVNTrunk)
95 cmd+=_T(" -T ")+dlg.m_strSVNTrunk;
97 if(dlg.m_bSVNBranch)
98 cmd+=_T(" -b ")+dlg.m_strSVNBranchs;
100 if(dlg.m_bSVNTags)
101 cmd+=_T(" -t ")+dlg.m_strSVNTags;
103 if(dlg.m_bSVNFrom)
105 CString str;
106 str.Format(_T("%d:HEAD"),dlg.m_nSVNFrom);
107 cmd+=_T(" -r ")+str;
110 if(dlg.m_bSVNUserName)
112 cmd+= _T(" --username ");
113 cmd+=dlg.m_strUserName;
116 CProgressDlg progress;
117 progress.m_GitCmd=cmd;
118 int ret = progress.DoModal();
120 if( progress.m_GitStatus == 0)
122 if(dlg.m_bAutoloadPuttyKeyFile)
124 g_Git.m_CurrentDir = dlg.m_Directory;
126 if(g_Git.SetConfigValue(_T("remote.origin.puttykeyfile"),dlg.m_strPuttyKeyFile, CONFIG_LOCAL,CP_ACP,&dlg.m_Directory))
128 CMessageBox::Show(NULL,_T("Fail set config remote.origin.puttykeyfile"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
129 return FALSE;
135 if(ret == IDOK)
136 return TRUE;
139 return FALSE;