Fixed issue #4133: libgit2 returned: failed to parse revision specifier (ref ending...
[TortoiseGit.git] / src / TortoiseProc / ProgressCommands / FetchProgressCommand.cpp
blob72551f13b164efa06cfa638f3451c64be3cf2f9d
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2013-2017, 2024 - 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 "FetchProgressCommand.h"
21 #include "AppUtils.h"
23 bool FetchProgressCommand::Run(CGitProgressList* list, CString& sWindowTitle, int& /*m_itemCountTotal*/, int& /*m_itemCount*/)
25 if (!g_Git.UsingLibGit2(CGit::GIT_CMD_FETCH))
27 // should never run to here
28 ASSERT(0);
29 return false;
32 list->SetWindowTitle(IDS_PROGRS_TITLE_FETCH, g_Git.m_CurrentDir, sWindowTitle);
33 list->SetBackgroundImage(IDI_UPDATE_BKG);
34 list->ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_TITLE_FETCH)) + L' ' + m_url.GetGitPathString() + L' ' + m_RefSpec);
36 CStringA url = CUnicodeUtils::GetUTF8(m_url.GetGitPathString());
38 CSmartAnimation animate(list->m_pAnimate);
40 CAutoRepository repo(g_Git.GetGitRepository());
41 if (!repo)
43 list->ReportGitError();
44 return false;
47 CAutoRemote remote;
48 // first try with a named remote (e.g. "origin")
49 if (git_remote_lookup(remote.GetPointer(), repo, url) < 0)
51 // retry with repository located at a specific url
52 if (git_remote_create_anonymous(remote.GetPointer(), repo, url) < 0)
54 list->ReportGitError();
55 return false;
59 git_fetch_options fetchopts = GIT_FETCH_OPTIONS_INIT;
60 fetchopts.prune = m_Prune;
61 fetchopts.update_fetchhead = GIT_REMOTE_UPDATE_FETCHHEAD | GIT_REMOTE_UPDATE_REPORT_UNCHANGED;
62 fetchopts.download_tags = m_AutoTag;
63 git_remote_callbacks& callbacks = fetchopts.callbacks;
64 callbacks.update_tips = RemoteUpdatetipsCallback;
65 callbacks.sideband_progress = RemoteProgressCallback;
66 callbacks.transfer_progress = FetchCallback;
67 callbacks.completion = RemoteCompletionCallback;
68 callbacks.credentials = CAppUtils::Git2GetUserPassword;
69 callbacks.certificate_check = CAppUtils::Git2CertificateCheck;
70 CGitProgressList::Payload cbpayload = { list, repo };
71 callbacks.payload = &cbpayload;
73 if (!m_RefSpec.IsEmpty() && git_remote_add_fetch(repo, git_remote_name(remote), CUnicodeUtils::GetUTF8(m_RefSpec)))
74 goto error;
76 if (git_remote_fetch(remote, nullptr, &fetchopts, nullptr) < 0)
77 goto error;
79 // Not setting m_PostCmdCallback here, as clone is only called from AppUtils.cpp
81 return true;
83 error:
84 list->ReportGitError();
85 return false;