KiCad PCB EDA Suite
Loading...
Searching...
No Matches
git_push_handler.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2023 KiCad Developers, see AUTHORS.TXT for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/gpl-3.0.html
19 * or you may search the http://www.gnu.org website for the version 3 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include "git_push_handler.h"
26
27#include <iostream>
28
29GIT_PUSH_HANDLER::GIT_PUSH_HANDLER( git_repository* aRepo ) : KIGIT_COMMON( aRepo )
30{}
31
33{}
34
36{
37 PushResult result = PushResult::Success;
38
39 // Fetch updates from remote repository
40 git_remote* remote = nullptr;
41
42 if( git_remote_lookup( &remote, m_repo, "origin" ) != 0 )
43 {
44 AddErrorString( _( "Could not lookup remote" ) );
45 return PushResult::Error;
46 }
47
48 git_remote_callbacks remoteCallbacks = GIT_REMOTE_CALLBACKS_INIT;
49 remoteCallbacks.sideband_progress = progress_cb;
50 remoteCallbacks.transfer_progress = transfer_progress_cb;
51 remoteCallbacks.update_tips = update_cb;
52 remoteCallbacks.push_transfer_progress = push_transfer_progress_cb;
53 remoteCallbacks.payload = this;
54
55 if( git_remote_connect( remote, GIT_DIRECTION_PUSH, &remoteCallbacks, nullptr, nullptr ) )
56 {
57 git_remote_free( remote );
58 AddErrorString( _( "Could not connect to remote" ) );
59 return PushResult::Error;
60 }
61
62 git_push_options pushOptions = GIT_PUSH_OPTIONS_INIT;
63 pushOptions.callbacks = remoteCallbacks;
64
65 if( git_remote_push( remote, nullptr, &pushOptions ) )
66 {
67 git_remote_free( remote );
68 AddErrorString( _( "Could not push to remote" ) );
69 return PushResult::Error;
70 }
71
72 return result;
73}
74
75
76void GIT_PUSH_HANDLER::UpdateProgress( int aCurrent, int aTotal, const wxString& aMessage )
77{
78 ReportProgress( aCurrent, aTotal, aMessage );
79}
void ReportProgress(int aCurrent, int aTotal, const wxString &aMessage)
Definition: git_progress.h:45
GIT_PUSH_HANDLER(git_repository *aRepo)
PushResult PerformPush()
void UpdateProgress(int aCurrent, int aTotal, const wxString &aMessage) override
git_repository * m_repo
void AddErrorString(const wxString aErrorString)
#define _(s)
PushResult
int update_cb(const char *aRefname, const git_oid *aFirst, const git_oid *aSecond, void *aPayload)
int transfer_progress_cb(const git_transfer_progress *aStats, void *aPayload)
int push_transfer_progress_cb(unsigned int aCurrent, unsigned int aTotal, size_t aBytes, void *aPayload)
int progress_cb(const char *str, int len, void *data)