c404efd4cf1100729e6792a572b360f36401a5c4
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"
31 #include "UnicodeUtils.h"
32 #include "SysProgressDlg.h"
34 bool CloneCommand::Execute()
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
)
46 recursiveStr
= _T("--recursive");
48 recursiveStr
= _T("");
52 bareStr
= _T("--bare");
56 CString nocheckoutStr
;
57 if (dlg
.m_bNoCheckout
)
58 nocheckoutStr
= _T("--no-checkout");
62 branchStr
= _T("--branch ") + dlg
.m_strBranch
;
64 if(dlg
.m_bAutoloadPuttyKeyFile
)
66 CAppUtils::LaunchPAgent(&dlg
.m_strPuttyKeyFile
);
69 CAppUtils::RemoveTrailSlash(dlg
.m_Directory
);
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('@'));
84 CString path
= url
.Mid(atSign
);
85 path
.Replace(_T('\\'), _T('/'));
86 url
= url
.Mid(0, atSign
) + path
;
89 url
.Replace( _T('\\'), _T('/'));
95 depth
.Format(_T(" --depth %d"),dlg
.m_nDepth
);
98 g_Git
.m_CurrentDir
= this->orgCmdLinePath
.GetWinPathString();
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\""),
118 // Handle Git SVN-clone
121 //g_Git.m_CurrentDir=dlg.m_Directory;
122 cmd
.Format(_T("git.exe svn clone \"%s\" \"%s\""),
123 url
,dlg
.m_Directory
);
126 cmd
+=_T(" -T ")+dlg
.m_strSVNTrunk
;
129 cmd
+=_T(" -b ")+dlg
.m_strSVNBranchs
;
132 cmd
+=_T(" -t ")+dlg
.m_strSVNTags
;
137 str
.Format(_T("%d:HEAD"),dlg
.m_nSVNFrom
);
141 if(dlg
.m_bSVNUserName
)
143 cmd
+= _T(" --username ");
144 cmd
+=dlg
.m_strUserName
;
149 if (g_Git
.UsingLibGit2(CGit::GIT_CMD_CLONE
))
151 CGitProgressDlg GitDlg
;
153 list
.AddPath(CTGitPath(dir
));
154 GitDlg
.SetCommand(CGitProgressDlg::GitProgress_Clone
);
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
);
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
);