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 The 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
30{}
31
32
34{}
35
36
38{
39 PushResult result = PushResult::Success;
40
41 // Fetch updates from remote repository
42 git_remote* remote = nullptr;
43
44 if( git_remote_lookup( &remote, m_repo, "origin" ) != 0 )
45 {
46 AddErrorString( _( "Could not lookup remote" ) );
47 return PushResult::Error;
48 }
49
50 git_remote_callbacks remoteCallbacks;
51 git_remote_init_callbacks( &remoteCallbacks, GIT_REMOTE_CALLBACKS_VERSION );
52 remoteCallbacks.sideband_progress = progress_cb;
53 remoteCallbacks.transfer_progress = transfer_progress_cb;
54 remoteCallbacks.update_tips = update_cb;
55 remoteCallbacks.push_transfer_progress = push_transfer_progress_cb;
56 remoteCallbacks.credentials = credentials_cb;
57 remoteCallbacks.payload = this;
58
59 m_testedTypes = 0;
61
62 if( git_remote_connect( remote, GIT_DIRECTION_PUSH, &remoteCallbacks, nullptr, nullptr ) )
63 {
64 AddErrorString( wxString::Format( _( "Could not connect to remote: %s" ),
65 git_error_last()->message ) );
66 git_remote_free( remote );
67 return PushResult::Error;
68 }
69
70 git_push_options pushOptions;
71 git_push_init_options( &pushOptions, GIT_PUSH_OPTIONS_VERSION );
72 pushOptions.callbacks = remoteCallbacks;
73
74 // Get the current HEAD reference
75 git_reference* head = nullptr;
76
77 if( git_repository_head( &head, m_repo ) != 0 )
78 {
79 AddErrorString( _( "Could not get repository head" ) );
80 git_remote_free( remote );
81 return PushResult::Error;
82 }
83
84 // Create refspec for current branch
85 const char* refs[1];
86 refs[0] = git_reference_name( head );
87 const git_strarray refspecs = { (char**) refs, 1 };
88
89 git_reference_free(head);
90 if( git_remote_push( remote, &refspecs, &pushOptions ) )
91 {
92 AddErrorString( wxString::Format( _( "Could not push to remote: %s" ),
93 git_error_last()->message ) );
94 git_remote_disconnect( remote );
95 git_remote_free( remote );
96 return PushResult::Error;
97 }
98
99 git_remote_disconnect( remote );
100 git_remote_free( remote );
101
102 return result;
103}
104
105
106void GIT_PUSH_HANDLER::UpdateProgress( int aCurrent, int aTotal, const wxString& aMessage )
107{
108 ReportProgress( aCurrent, aTotal, aMessage );
109}
void ReportProgress(int aCurrent, int aTotal, const wxString &aMessage)
Definition: git_progress.h:45
GIT_PUSH_HANDLER(KIGIT_COMMON *aRepo)
PushResult PerformPush()
void UpdateProgress(int aCurrent, int aTotal, const wxString &aMessage) override
git_repository * m_repo
unsigned m_testedTypes
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 credentials_cb(git_cred **aOut, const char *aUrl, const char *aUsername, unsigned int aAllowedTypes, 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)