31#include <wx/bmpbuttn.h>
33#include <wx/checkbox.h>
63 git_config_entry* name_c =
nullptr;
64 git_config_entry* email_c =
nullptr;
66 git_config*
config =
nullptr;
68 if( git_config_open_default( &
config ) != 0 )
70 printf(
"Failed to open default Git config: %s\n", giterr_last()->message );
71 return std::make_pair(
name, email );
74 if( git_config_get_entry( &name_c,
config,
"user.name" ) != 0 )
76 printf(
"Failed to get user.name from Git config: %s\n", giterr_last()->message );
78 if( git_config_get_entry( &email_c,
config,
"user.email" ) != 0 )
80 printf(
"Failed to get user.email from Git config: %s\n", giterr_last()->message );
87 email = email_c->value;
89 git_config_entry_free( name_c );
90 git_config_entry_free( email_c );
93 return std::make_pair(
name, email );
99 std::vector<COMMON_SETTINGS::GIT_REPOSITORY>& repos = settings->
m_Git.
repositories;
103 for(
int row = 0; row <
m_grid->GetNumberRows(); row++ )
117 repos.push_back( repo );
131 git_remote_callbacks callbacks;
132 callbacks.version = GIT_REMOTE_CALLBACKS_VERSION;
140 callbacksPayload cb_data( { &repository,
true } );
142 callbacks.payload = &cb_data;
143 callbacks.credentials =
144 [](git_cred** out,
const char* url,
const char* username,
unsigned int allowed_types,
145 void* payload) ->
int
150 callbacksPayload* data =
static_cast<callbacksPayload*
>(payload);
152 data->success =
false;
154 if( allowed_types & GIT_CREDTYPE_USERNAME )
156 data->success =
true;
158 else if( data->repo->authType ==
"ssh" && ( allowed_types & GIT_CREDTYPE_SSH_KEY ) )
160 wxString sshKeyPath = data->repo->
ssh_path;
163 if( wxFileExists( sshKeyPath ) && wxFile::Access( sshKeyPath, wxFile::read ) )
164 data->success =
true;
166 else if( data->repo->authType ==
"password" )
168 data->success = ( allowed_types & GIT_CREDTYPE_USERPASS_PLAINTEXT );
175 wxString tempDirPath = wxFileName::CreateTempFileName(wxT(
"kigit_temp"));
177 if( !wxFileName::Mkdir( tempDirPath, wxS_DIR_DEFAULT ) )
179 git_libgit2_shutdown();
180 wxLogError(
"Failed to create temporary directory for Git repository (%s): %s", tempDirPath,
186 git_repository* repo =
nullptr;
187 int result = git_repository_init( &repo, tempDirPath.mb_str( wxConvUTF8 ), 0 );
191 git_repository_free(repo);
192 git_libgit2_shutdown();
193 wxRmdir(tempDirPath);
197 git_remote* remote =
nullptr;
198 result = git_remote_create_anonymous( &remote, repo, tempDirPath.mb_str( wxConvUTF8 ) );
202 git_remote_free(remote);
203 git_repository_free(repo);
204 git_libgit2_shutdown();
205 wxRmdir(tempDirPath);
211 git_remote_connect(remote, GIT_DIRECTION_FETCH, &callbacks,
nullptr,
nullptr);
213 git_remote_disconnect(remote);
214 git_remote_free(remote);
215 git_repository_free(repo);
217 git_libgit2_shutdown();
220 wxRmdir(tempDirPath);
222 return cb_data.success;
233 if( repo.
name.IsEmpty() || repo.
path.IsEmpty() )
236 int row =
m_grid->GetNumberRows();
263 m_author->SetValue( defaultAuthor.first );
288 if(
m_grid->GetNumberRows() <= 0 )
295 int row =
event.GetRow();
297 if( row < 0 || row >=
m_grid->GetNumberRows() )
310 if( type ==
"password" )
312 else if( type ==
"ssh" )
349 int row =
m_grid->GetNumberRows();
371 m_grid->MakeCellVisible( row, 0 );
378 wxGridEvent evt(
m_grid->GetId(), wxEVT_GRID_CELL_LEFT_DCLICK,
m_grid,
379 m_grid->GetGridCursorRow(),
m_grid->GetGridCursorCol() );
389 int curRow =
m_grid->GetGridCursorRow();
391 m_grid->DeleteRows( curRow );
393 curRow = std::max( 0, curRow - 1 );
394 m_grid->MakeCellVisible( curRow,
m_grid->GetGridCursorCol() );
395 m_grid->SetGridCursor( curRow,
m_grid->GetGridCursorCol() );
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
void SetRepoType(KIGIT_COMMON::GIT_CONN_TYPE aType)
void SetRepoSSHPath(const wxString &aPath)
KIGIT_COMMON::GIT_CONN_TYPE GetRepoType() const
void SetRepoName(const wxString &aName)
void SetPassword(const wxString &aPassword)
wxString GetRepoSSHPath() const
wxString GetRepoURL() const
void SetRepoURL(const wxString &aURL)
wxString GetUsername() const
wxString GetRepoName() const
void SetUsername(const wxString &aUsername)
wxString GetPassword() const
Class PANEL_GIT_REPOS_BASE.
STD_BITMAP_BUTTON * m_btnAddRepo
wxStaticText * m_authorLabel
STD_BITMAP_BUTTON * m_btnEditRepo
wxStaticText * m_authorEmailLabel
STD_BITMAP_BUTTON * m_btnDelete
wxTextCtrl * m_authorEmail
PANEL_GIT_REPOS(wxWindow *parent)
~PANEL_GIT_REPOS() override
void onGridDClick(wxGridEvent &event) override
void onEditClick(wxCommandEvent &event) override
void onDefaultClick(wxCommandEvent &event) override
void onAddClick(wxCommandEvent &event) override
void ResetPanel() override
Reset the contents of this panel.
bool TransferDataToWindow() override
bool TransferDataFromWindow() override
void onDeleteClick(wxCommandEvent &event) override
virtual COMMON_SETTINGS * GetCommonSettings() const
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
static bool testRepositoryConnection(COMMON_SETTINGS::GIT_REPOSITORY &repository)
static std::pair< wxString, wxString > getDefaultAuthorAndEmail()
PGM_BASE & Pgm()
The global Program "get" accessor.
std::vector< GIT_REPOSITORY > repositories