1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2013-2015 - 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 "CloneProgressCommand.h"
22 #include "../TGitCache/CacheInterface.h"
24 bool CloneProgressCommand::Run(CGitProgressList
* list
, CString
& sWindowTitle
, int& /*m_itemCountTotal*/, int& /*m_itemCount*/)
26 if (!g_Git
.UsingLibGit2(CGit::GIT_CMD_CLONE
))
28 // should never run to here
32 list
->SetWindowTitle(IDS_PROGRS_TITLE_CLONE
, m_url
.GetGitPathString(), sWindowTitle
);
33 list
->SetBackgroundImage(IDI_SWITCH_BKG
);
34 list
->ReportCmd(CString(MAKEINTRESOURCE(IDS_PROG_CLONE
)));
36 if (m_url
.IsEmpty() || m_targetPathList
.IsEmpty())
39 git_checkout_options checkout_opts
= GIT_CHECKOUT_OPTIONS_INIT
;
40 checkout_opts
.checkout_strategy
= m_bNoCheckout
? GIT_CHECKOUT_NONE
: GIT_CHECKOUT_SAFE
;
41 checkout_opts
.progress_cb
= CheckoutCallback
;
42 checkout_opts
.progress_payload
= list
;
44 git_clone_options cloneOpts
= GIT_CLONE_OPTIONS_INIT
;
45 git_remote_callbacks
& callbacks
= cloneOpts
.fetch_opts
.callbacks
;
46 callbacks
.update_tips
= RemoteUpdatetipsCallback
;
47 callbacks
.sideband_progress
= RemoteProgressCallback
;
48 callbacks
.completion
= RemoteCompletionCallback
;
49 callbacks
.transfer_progress
= FetchCallback
;
50 callbacks
.credentials
= CAppUtils::Git2GetUserPassword
;
51 callbacks
.certificate_check
= CAppUtils::Git2CertificateCheck
;
52 CGitProgressList::Payload cbpayload
= { list
};
53 callbacks
.payload
= &cbpayload
;
55 CSmartAnimation
animate(list
->m_pAnimate
);
56 cloneOpts
.bare
= m_bBare
;
57 cloneOpts
.repository_cb
= [](git_repository
** out
, const char* path
, int bare
, void* /*payload*/) -> int
59 git_repository_init_options init_options
= GIT_REPOSITORY_INIT_OPTIONS_INIT
;
60 init_options
.flags
= GIT_REPOSITORY_INIT_MKPATH
| GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE
;
61 init_options
.flags
|= bare
? GIT_REPOSITORY_INIT_BARE
: 0;
63 return git_repository_init_ext(out
, path
, &init_options
);
66 struct remote_cb_payload
68 const char* remoteName
;
71 cloneOpts
.remote_cb
= [](git_remote
** out
, git_repository
* repo
, const char* /*name*/, const char* url
, void* payload
) -> int
75 remote_cb_payload
* data
= (remote_cb_payload
*)payload
;
78 if ((error
= git_remote_create(origin
.GetPointer(), repo
, data
->remoteName
, url
)) < 0)
81 *out
= origin
.Detach();
84 remote_cb_payload remote_cb_payloadData
;
85 remote_cb_payloadData
.remoteName
= m_remote
.IsEmpty() ? "origin" : CUnicodeUtils::GetUTF8(m_remote
);
86 cloneOpts
.remote_cb_payload
= &remote_cb_payloadData
;
88 CStringA checkout_branch
= CUnicodeUtils::GetUTF8(m_RefSpec
);
89 if (!checkout_branch
.IsEmpty())
90 cloneOpts
.checkout_branch
= checkout_branch
;
91 cloneOpts
.checkout_opts
= checkout_opts
;
93 CBlockCacheForPath
block(m_targetPathList
[0].GetWinPathString());
94 CAutoRepository cloned_repo
;
95 if (git_clone(cloned_repo
.GetPointer(), CUnicodeUtils::GetUTF8(m_url
.GetGitPathString()), CUnicodeUtils::GetUTF8(m_targetPathList
[0].GetWinPathString()), &cloneOpts
) < 0)
97 list
->ReportGitError();
101 // Not setting m_PostCmdCallback here, as clone is only called from CloneCommand.cpp