31#include <wx/bmpbuttn.h>
33#include <wx/checkbox.h>
62 git_config_entry* name_c =
nullptr;
63 git_config_entry* email_c =
nullptr;
65 git_config*
config =
nullptr;
67 if( git_config_open_default( &
config ) != 0 )
69 printf(
"Failed to open default Git config: %s\n", giterr_last()->message );
70 return std::make_pair(
name, email );
73 if( git_config_get_entry( &name_c,
config,
"user.name" ) != 0 )
75 printf(
"Failed to get user.name from Git config: %s\n", giterr_last()->message );
77 if( git_config_get_entry( &email_c,
config,
"user.email" ) != 0 )
79 printf(
"Failed to get user.email from Git config: %s\n", giterr_last()->message );
86 email = email_c->value;
88 git_config_entry_free( name_c );
89 git_config_entry_free( email_c );
92 return std::make_pair(
name, email );
98 std::vector<COMMON_SETTINGS::GIT_REPOSITORY>& repos = settings->
m_Git.
repositories;
102 for(
int row = 0; row <
m_grid->GetNumberRows(); row++ )
116 repos.push_back( repo );
130 git_remote_callbacks callbacks;
131 callbacks.version = GIT_REMOTE_CALLBACKS_VERSION;
139 callbacksPayload cb_data( { &repository,
true } );
141 callbacks.payload = &cb_data;
142 callbacks.credentials =
143 [](git_cred** out,
const char* url,
const char* username,
unsigned int allowed_types,
144 void* payload) ->
int
149 callbacksPayload* data =
static_cast<callbacksPayload*
>(payload);
151 data->success =
false;
153 if( allowed_types & GIT_CREDTYPE_USERNAME )
155 data->success =
true;
157 else if( data->repo->authType ==
"ssh" && ( allowed_types & GIT_CREDTYPE_SSH_KEY ) )
159 wxString sshKeyPath = data->repo->
ssh_path;
162 if( wxFileExists( sshKeyPath ) && wxFile::Access( sshKeyPath, wxFile::read ) )
163 data->success =
true;
165 else if( data->repo->authType ==
"password" )
167 data->success = ( allowed_types & GIT_CREDTYPE_USERPASS_PLAINTEXT );
174 wxString tempDirPath = wxFileName::CreateTempFileName(wxT(
"kigit_temp"));
176 if( !wxFileName::Mkdir( tempDirPath, wxS_DIR_DEFAULT ) )
178 git_libgit2_shutdown();
179 wxLogError(
"Failed to create temporary directory for Git repository (%s): %s", tempDirPath,
185 git_repository* repo =
nullptr;
186 int result = git_repository_init( &repo, tempDirPath.mb_str( wxConvUTF8 ), 0 );
190 git_repository_free(repo);
191 git_libgit2_shutdown();
192 wxRmdir(tempDirPath);
196 git_remote* remote =
nullptr;
197 result = git_remote_create_anonymous( &remote, repo, tempDirPath.mb_str( wxConvUTF8 ) );
201 git_remote_free(remote);
202 git_repository_free(repo);
203 git_libgit2_shutdown();
204 wxRmdir(tempDirPath);
210 git_remote_connect(remote, GIT_DIRECTION_FETCH, &callbacks,
nullptr,
nullptr);
212 git_remote_disconnect(remote);
213 git_remote_free(remote);
214 git_repository_free(repo);
216 git_libgit2_shutdown();
219 wxRmdir(tempDirPath);
221 return cb_data.success;
232 if( repo.
name.IsEmpty() || repo.
path.IsEmpty() )
235 int row =
m_grid->GetNumberRows();
262 m_author->SetValue( defaultAuthor.first );
287 if(
m_grid->GetNumberRows() <= 0 )
294 int row =
event.GetRow();
296 if( row < 0 || row >=
m_grid->GetNumberRows() )
309 if( type ==
"password" )
311 else if( type ==
"ssh" )
316 if( dialog.ShowModal() == wxID_OK )
346 if( dialog.ShowModal() == wxID_OK )
348 int row =
m_grid->GetNumberRows();
370 m_grid->MakeCellVisible( row, 0 );
377 wxGridEvent evt(
m_grid->GetId(), wxEVT_GRID_CELL_LEFT_DCLICK,
m_grid,
378 m_grid->GetGridCursorRow(),
m_grid->GetGridCursorCol() );
388 int curRow =
m_grid->GetGridCursorRow();
390 m_grid->DeleteRows( curRow );
392 curRow = std::max( 0, curRow - 1 );
393 m_grid->MakeCellVisible( curRow,
m_grid->GetGridCursorCol() );
394 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