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;
49 git_remote_init_callbacks( &remoteCallbacks, GIT_REMOTE_CALLBACKS_VERSION );
50 remoteCallbacks.sideband_progress = progress_cb;
51 remoteCallbacks.transfer_progress = transfer_progress_cb;
52 remoteCallbacks.update_tips = update_cb;
53 remoteCallbacks.push_transfer_progress = push_transfer_progress_cb;
54 remoteCallbacks.payload = this;
55
56 if( git_remote_connect( remote, GIT_DIRECTION_PUSH, &remoteCallbacks, nullptr, nullptr ) )
57 {
58 git_remote_free( remote );
59 AddErrorString( wxString::Format( _( "Could not connect to remote: %s" ),
60 git_error_last()->message ) );
61 return PushResult::Error;
62 }
63
64 git_push_options pushOptions;
65 git_push_init_options( &pushOptions, GIT_PUSH_OPTIONS_VERSION );
66 pushOptions.callbacks = remoteCallbacks;
67
68 if( git_remote_push( remote, nullptr, &pushOptions ) )
69 {
70 git_remote_free( remote );
71 AddErrorString( wxString::Format( _( "Could not push to remote: %s" ),
72 git_error_last()->message ) );
73 return PushResult::Error;
74 }
75
76 return result;
77}
78
79
80void GIT_PUSH_HANDLER::UpdateProgress( int aCurrent, int aTotal, const wxString& aMessage )
81{
82 ReportProgress( aCurrent, aTotal, aMessage );
83}
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)