KiCad PCB EDA Suite
Loading...
Searching...
No Matches
git_config_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_config_handler.h"
27#include <pgm_base.h>
29#include <trace_helpers.h>
30#include <wx/log.h>
31
33{}
34
36{}
37
39{
40 GitUserConfig userConfig;
41
42 // Try to get from git config first
43 userConfig.hasName = GetConfigString( "user.name", userConfig.authorName );
44 userConfig.hasEmail = GetConfigString( "user.email", userConfig.authorEmail );
45
46 // Fall back to common settings if not found in git config
47 if( !userConfig.hasName )
48 {
50 }
51
52 if( !userConfig.hasEmail )
53 {
55 }
56
57 return userConfig;
58}
59
61{
62 git_repository* repo = GetRepo();
63
64 if( !repo )
65 return wxEmptyString;
66
67 const char* workdir = git_repository_workdir( repo );
68
69 if( !workdir )
70 return wxEmptyString;
71
72 return wxString( workdir );
73}
74
75bool GIT_CONFIG_HANDLER::GetConfigString( const wxString& aKey, wxString& aValue )
76{
77 git_repository* repo = GetRepo();
78
79 if( !repo )
80 return false;
81
82 git_config* config = nullptr;
83
84 if( git_repository_config( &config, repo ) != GIT_OK )
85 {
86 wxLogTrace( traceGit, "Failed to get repository config: %s", KIGIT_COMMON::GetLastGitError() );
87 return false;
88 }
89
90 KIGIT::GitConfigPtr configPtr( config );
91
92 git_config_entry* entry = nullptr;
93 int result = git_config_get_entry( &entry, config, aKey.mb_str() );
94 KIGIT::GitConfigEntryPtr entryPtr( entry );
95
96 if( result != GIT_OK || entry == nullptr )
97 {
98 wxLogTrace( traceGit, "Config key '%s' not found", aKey );
99 return false;
100 }
101
102 aValue = wxString( entry->value );
103 return true;
104}
105
106void GIT_CONFIG_HANDLER::UpdateProgress( int aCurrent, int aTotal, const wxString& aMessage )
107{
108 ReportProgress( aCurrent, aTotal, aMessage );
109}
GitUserConfig GetUserConfig()
Get user configuration (name and email) from git config Falls back to common settings if not found in...
GIT_CONFIG_HANDLER(KIGIT_COMMON *aCommon)
void UpdateProgress(int aCurrent, int aTotal, const wxString &aMessage) override
wxString GetWorkingDirectory()
Get the repository working directory path.
bool GetConfigString(const wxString &aKey, wxString &aValue)
Get a string value from git config.
void ReportProgress(int aCurrent, int aTotal, const wxString &aMessage)
Definition: git_progress.h:45
static wxString GetLastGitError()
git_repository * GetRepo() const
Get a pointer to the git repository.
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:565
const wxChar *const traceGit
Flag to enable Git debugging output.
std::unique_ptr< git_config_entry, decltype([](git_config_entry *aEntry) { git_config_entry_free(aEntry) GitConfigEntryPtr
A unique pointer for git_config_entry objects with automatic cleanup.
std::unique_ptr< git_config, decltype([](git_config *aConfig) { git_config_free(aConfig) GitConfigPtr
A unique pointer for git_config objects with automatic cleanup.
PGM_BASE & Pgm()
The global program "get" accessor.
Definition: pgm_base.cpp:902
see class PGM_BASE
wxLogTrace helper definitions.