Fixed issue #406: Putty key can't save when clone.
[TortoiseGit.git] / src / TortoiseProc / Commands / CloneCommand.cpp
blob21305a947bc18216cd56c67daaa162b76425a9ab
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 if(dlg.m_bAutoloadPuttyKeyFile)
39 CAppUtils::LaunchPAgent(&dlg.m_strPuttyKeyFile);
42 CAppUtils::RemoveTrailSlash(dlg.m_Directory);
43 CAppUtils::RemoveTrailSlash(dlg.m_URL);
45 CString dir=dlg.m_Directory;
46 CString url=dlg.m_URL;
48 // is this a windows format UNC path, ie starts with \\
49 if (url.Find(_T("\\\\")) == 0)
51 // yes, change all \ to /
52 // this should not be necessary but msysgit does not support the use \ here yet
53 url.Replace( _T('\\'), _T('/'));
56 CString depth;
57 if (dlg.m_bDepth)
60 depth.Format(_T(" --depth %d"),dlg.m_nDepth);
63 CString cmd;
64 CString progressarg;
65 CString version;
66 cmd = _T("git.exe --version");
67 if(g_Git.Run(cmd, &version, CP_ACP))
69 CMessageBox::Show(NULL,_T("git have not installed"), _T("TortoiseGit"), MB_OK|MB_ICONERROR);
70 return false;
73 int start=0;
74 int ver;
76 CString str=version.Tokenize(_T("."),start);
77 int space = str.ReverseFind(_T(' '));
78 str=str.Mid(space+1,start);
79 ver = _ttol(str);
80 ver <<=16;
81 version = version.Mid(start);
82 start = 0;
83 str = version.Tokenize(_T("."),start);
84 ver |= _ttol(str)&0xFFFF;
86 if(ver >= 0x10007) //above 1.7.0.2
87 progressarg = _T("--progress");
90 cmd.Format(_T("git.exe clone %s -v %s \"%s\" \"%s\""),
91 progressarg,
92 depth,
93 url,
94 dir);
97 // Handle Git SVN-clone
98 if(dlg.m_bSVN)
101 //g_Git.m_CurrentDir=dlg.m_Directory;
102 cmd.Format(_T("git.exe svn clone \"%s\" \"%s\""),
103 url,dlg.m_Directory);
105 if(dlg.m_bSVNTrunk)
106 cmd+=_T(" -T ")+dlg.m_strSVNTrunk;
108 if(dlg.m_bSVNBranch)
109 cmd+=_T(" -b ")+dlg.m_strSVNBranchs;
111 if(dlg.m_bSVNTags)
112 cmd+=_T(" -t ")+dlg.m_strSVNTags;
114 if(dlg.m_bSVNFrom)
116 CString str;
117 str.Format(_T("%d:HEAD"),dlg.m_nSVNFrom);
118 cmd+=_T(" -r ")+str;
122 CProgressDlg progress;
123 progress.m_GitCmd=cmd;
124 int ret = progress.DoModal();
126 if( progress.m_GitStatus == 0)
128 if(dlg.m_bAutoloadPuttyKeyFile)
130 g_Git.m_CurrentDir = dlg.m_Directory;
131 CString cmd,out;
132 cmd.Format(_T("git.exe config remote.origin.puttykeyfile \"%s\""),dlg.m_strPuttyKeyFile);
133 if(g_Git.Run(cmd,&out,CP_ACP))
135 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
136 return FALSE;
142 if(ret == IDOK)
143 return TRUE;
146 return FALSE;