Moved #include "git2.h" to stdafx.h
[TortoiseGit.git] / src / TortoiseProc / Commands / CloneCommand.cpp
blob2fa2f8903bcadf9b5dc05ee2b7d5a83450dd75ad
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 "UnicodeUtils.h"
31 #include "SysProgressDlg.h"
33 bool CloneCommand::Execute()
35 CCloneDlg dlg;
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)
43 CString recursiveStr;
44 if(dlg.m_bRecursive)
45 recursiveStr = _T("--recursive");
46 else
47 recursiveStr = _T("");
49 CString bareStr;
50 if(dlg.m_bBare)
51 bareStr = _T("--bare");
52 else
53 bareStr = _T("");
55 CString nocheckoutStr;
56 if (dlg.m_bNoCheckout)
57 nocheckoutStr = _T("--no-checkout");
59 CString branchStr;
60 if (dlg.m_bBranch)
61 branchStr = _T("--branch ") + dlg.m_strBranch;
63 if(dlg.m_bAutoloadPuttyKeyFile)
65 CAppUtils::LaunchPAgent(&dlg.m_strPuttyKeyFile);
68 CAppUtils::RemoveTrailSlash(dlg.m_Directory);
69 if (!dlg.m_bSVN)
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('@'));
81 if (atSign > 0)
83 CString path = url.Mid(atSign);
84 path.Replace(_T('\\'), _T('/'));
85 url = url.Mid(0, atSign) + path;
87 else
88 url.Replace( _T('\\'), _T('/'));
91 CString depth;
92 if (dlg.m_bDepth)
94 depth.Format(_T(" --depth %d"),dlg.m_nDepth);
97 g_Git.m_CurrentDir = this->orgCmdLinePath.GetWinPathString();
99 CString cmd;
100 CString progressarg;
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\""),
108 nocheckoutStr,
109 recursiveStr,
110 bareStr,
111 branchStr,
112 progressarg,
113 depth,
114 url,
115 dir);
117 // Handle Git SVN-clone
118 if(dlg.m_bSVN)
120 //g_Git.m_CurrentDir=dlg.m_Directory;
121 cmd.Format(_T("git.exe svn clone \"%s\" \"%s\""),
122 url,dlg.m_Directory);
124 if(dlg.m_bSVNTrunk)
125 cmd+=_T(" -T ")+dlg.m_strSVNTrunk;
127 if(dlg.m_bSVNBranch)
128 cmd+=_T(" -b ")+dlg.m_strSVNBranchs;
130 if(dlg.m_bSVNTags)
131 cmd+=_T(" -t ")+dlg.m_strSVNTags;
133 if(dlg.m_bSVNFrom)
135 CString str;
136 str.Format(_T("%d:HEAD"),dlg.m_nSVNFrom);
137 cmd+=_T(" -r ")+str;
140 if(dlg.m_bSVNUserName)
142 cmd+= _T(" --username ");
143 cmd+=dlg.m_strUserName;
146 else
148 if (g_Git.UsingLibGit2(CGit::GIT_CMD_CLONE))
150 CGitProgressDlg GitDlg;
151 CTGitPathList list;
152 list.AddPath(CTGitPath(dir));
153 GitDlg.SetCommand(CGitProgressDlg::GitProgress_Clone);
154 GitDlg.SetUrl(url);
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);
159 GitDlg.DoModal();
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);
177 return FALSE;
181 if(ret == IDOK)
182 return TRUE;
185 return FALSE;