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.
20 #include "CloneCommand.h"
22 #include "GitProgressDlg.h"
23 #include "StringUtils.h"
25 #include "MessageBox.h"
28 #include "ProgressDlg.h"
30 #include "UnicodeUtils.h"
31 #include "SysProgressDlg.h"
33 bool CloneCommand::Execute()
36 dlg
.m_Directory
=this->orgCmdLinePath
.GetWinPathString();
38 if (parser
.HasKey(_T("url")))
39 dlg
.m_URL
= parser
.GetVal(_T("url"));
41 if(dlg
.DoModal()==IDOK
)
45 recursiveStr
= _T("--recursive");
47 recursiveStr
= _T("");
51 bareStr
= _T("--bare");
55 CString nocheckoutStr
;
56 if (dlg
.m_bNoCheckout
)
57 nocheckoutStr
= _T("--no-checkout");
61 branchStr
= _T("--branch ") + dlg
.m_strBranch
;
63 if(dlg
.m_bAutoloadPuttyKeyFile
)
65 CAppUtils::LaunchPAgent(&dlg
.m_strPuttyKeyFile
);
68 CAppUtils::RemoveTrailSlash(dlg
.m_Directory
);
70 CAppUtils::RemoveTrailSlash(dlg
.m_URL
);
72 CString dir
=dlg
.m_Directory
;
73 CString url
=dlg
.m_URL
;
75 // is this a windows format UNC path, ie starts with \\?
76 if (url
.Find(_T("\\\\")) == 0)
78 // yes, change all \ to /
79 // this should not be necessary but msysgit does not support the use \ here yet
80 int atSign
= url
.Find(_T('@'));
83 CString path
= url
.Mid(atSign
);
84 path
.Replace(_T('\\'), _T('/'));
85 url
= url
.Mid(0, atSign
) + path
;
88 url
.Replace( _T('\\'), _T('/'));
94 depth
.Format(_T(" --depth %d"),dlg
.m_nDepth
);
97 g_Git
.m_CurrentDir
= this->orgCmdLinePath
.GetWinPathString();
102 int ver
= CAppUtils::GetMsysgitVersion();
104 if(ver
>= 0x01070002) //above 1.7.0.2
105 progressarg
= _T("--progress");
107 cmd
.Format(_T("git.exe clone %s %s %s %s %s -v %s \"%s\" \"%s\""),
117 // Handle Git SVN-clone
120 //g_Git.m_CurrentDir=dlg.m_Directory;
121 cmd
.Format(_T("git.exe svn clone \"%s\" \"%s\""),
122 url
,dlg
.m_Directory
);
125 cmd
+=_T(" -T ")+dlg
.m_strSVNTrunk
;
128 cmd
+=_T(" -b ")+dlg
.m_strSVNBranchs
;
131 cmd
+=_T(" -t ")+dlg
.m_strSVNTags
;
136 str
.Format(_T("%d:HEAD"),dlg
.m_nSVNFrom
);
140 if(dlg
.m_bSVNUserName
)
142 cmd
+= _T(" --username ");
143 cmd
+=dlg
.m_strUserName
;
148 if (g_Git
.UsingLibGit2(CGit::GIT_CMD_CLONE
))
150 CGitProgressDlg GitDlg
;
152 list
.AddPath(CTGitPath(dir
));
153 GitDlg
.SetCommand(CGitProgressDlg::GitProgress_Clone
);
155 GitDlg
.SetPathList(list
);
156 GitDlg
.SetIsBare(!!dlg
.m_bBare
);
157 GitDlg
.SetRefSpec(dlg
.m_bBranch
? dlg
.m_strBranch
: CString());
158 GitDlg
.SetNoCheckout(!!dlg
.m_bNoCheckout
);
160 return !GitDlg
.DidErrorsOccur();
163 CProgressDlg progress
;
164 progress
.m_GitCmd
=cmd
;
165 INT_PTR ret
= progress
.DoModal();
167 if( progress
.m_GitStatus
== 0)
169 if(dlg
.m_bAutoloadPuttyKeyFile
)
171 g_Git
.m_CurrentDir
= dlg
.m_Directory
;
172 SetCurrentDirectory(g_Git
.m_CurrentDir
);
174 if(g_Git
.SetConfigValue(_T("remote.origin.puttykeyfile"), dlg
.m_strPuttyKeyFile
, CONFIG_LOCAL
, CP_UTF8
, &dlg
.m_Directory
))
176 CMessageBox::Show(NULL
,_T("Fail set config remote.origin.puttykeyfile"),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);