36#include <wx/filename.h>
54 static wxWindow* window =
nullptr;
112 const char* workdir = git_repository_workdir(
m_repo );
115 return wxString( workdir );
118 return wxEmptyString;
134 return wxEmptyString;
136 git_reference* head =
nullptr;
138 int retval = git_repository_head( &head,
m_repo );
140 if( retval && retval != GIT_EUNBORNBRANCH && retval != GIT_ENOTFOUND )
141 return wxEmptyString;
145 return wxEmptyString;
148 git_reference* branch;
150 if( git_reference_resolve( &branch, head ) )
152 wxLogTrace(
traceGit,
"Failed to resolve branch" );
153 return wxEmptyString;
157 const char* branchName =
"";
159 if( git_branch_name( &branchName, branch ) )
161 wxLogTrace(
traceGit,
"Failed to get branch name" );
162 return wxEmptyString;
165 return wxString( branchName );
173 if( !
m_repo || git_reference_name_to_id( &oid,
m_repo,
"HEAD" ) != GIT_OK )
174 return wxEmptyString;
176 return wxString::FromUTF8( git_oid_tostr_s( &oid ) );
225 std::function<
void()> aRetry )
231 std::lock_guard<std::mutex> lock( aCommon->m_credentialsMutex );
233 if( aCommon->secretReadLocked() )
236 remote = aCommon->m_remote;
237 username = aCommon->m_username;
240 auto finish = [weak = std::weak_ptr<KIGIT_COMMON>( aCommon ), aOwner, remote, username,
241 retry = std::move( aRetry )](
bool aFound,
const wxString& aSecret )
244 std::shared_ptr<KIGIT_COMMON> common = weak.lock();
246 if( !common || aOwner.expired() )
250 std::lock_guard<std::mutex> lock( common->m_credentialsMutex );
253 if( !common->m_secretFetched && common->m_remote == remote && common->m_username == username )
256 common->m_password = aSecret;
258 common->m_secretFetched =
true;
273 return wxEmptyString;
277 if( git_reference_name_to_id( &headOid,
m_repo,
"HEAD" ) != GIT_OK )
278 return wxEmptyString;
280 git_commit* commit =
nullptr;
282 if( git_commit_lookup( &commit,
m_repo, &headOid ) != GIT_OK )
283 return wxEmptyString;
286 const char*
message = git_commit_message( commit );
300 git_status_options statusOpts;
301 git_status_init_options( &statusOpts, GIT_STATUS_OPTIONS_VERSION );
302 statusOpts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
304 git_status_list* statusList =
nullptr;
306 if( git_status_list_new( &statusList,
m_repo, &statusOpts ) != GIT_OK )
314 return git_status_list_entrycount( statusList ) > 0;
322std::map<std::string, std::vector<wxString>> collectRefNames(
git_repository* aRepo )
324 std::map<std::string, std::vector<wxString>> names;
328 if( git_reference_name_to_id( &headOid, aRepo,
"HEAD" ) == GIT_OK )
329 names[git_oid_tostr_s( &headOid )].push_back( wxS(
"HEAD" ) );
331 git_reference_iterator* iter =
nullptr;
333 if( git_reference_iterator_new( &iter, aRepo ) != GIT_OK )
337 git_reference* ref =
nullptr;
340 while( git_reference_next( &ref, iter ) == GIT_OK )
344 if( !git_reference_is_branch( ref ) && !git_reference_is_remote( ref ) && !git_reference_is_tag( ref ) )
347 git_object* target =
nullptr;
349 if( git_reference_peel( &target, ref, GIT_OBJECT_COMMIT ) != GIT_OK )
354 std::string hash = git_oid_tostr_s( git_object_id( target ) );
362wxString shortHashOf(
const git_oid* aOid )
366 char shortHash[13] = { 0 };
367 git_oid_tostr( shortHash,
sizeof( shortHash ), aOid );
368 return wxString::FromUTF8( shortHash );
393 const char* gitDir = git_repository_path(
m_repo );
399 wxFileName fetchHead( wxString::FromUTF8( gitDir ), wxS(
"FETCH_HEAD" ) );
401 if( !fetchHead.FileExists() )
404 return fetchHead.GetModificationTime();
417 if( git_oid_fromstr( &oid, aId.utf8_string().c_str() ) != GIT_OK )
420 git_commit* commit =
nullptr;
422 if( git_commit_lookup( &commit,
m_repo, &oid ) != GIT_OK )
428 detail.when = wxDateTime(
static_cast<time_t
>( git_commit_time( commit ) ) );
434 if(
const char*
message = git_commit_message( commit ) )
442 if( raw.StartsWith( wxS(
"WIP on " ), &rest ) || raw.StartsWith( wxS(
"On " ), &rest ) )
444 int colon = rest.Find( wxS(
": " ) );
446 if( colon != wxNOT_FOUND )
448 detail.branch = rest.Left( colon );
449 detail.message = rest.Mid( colon + 2 );
455 git_commit* base =
nullptr;
457 if( git_commit_parent( &base, commit, 0 ) != GIT_OK )
461 detail.baseHash = shortHashOf( git_commit_id( base ) );
463 git_tree* baseTree =
nullptr;
464 git_tree* stashTree =
nullptr;
466 if( git_commit_tree( &baseTree, base ) != GIT_OK || git_commit_tree( &stashTree, commit ) != GIT_OK )
471 git_diff* diff =
nullptr;
473 if( git_diff_tree_to_tree( &diff,
m_repo, baseTree, stashTree,
nullptr ) == GIT_OK )
478 [&
detail](
const git_diff_delta& aDelta )
481 aDelta.new_file.path ? aDelta.new_file.path : aDelta.old_file.path;
482 detail.files.push_back( wxString::FromUTF8(
path ) );
486 if( git_commit_parentcount( commit ) > 2 )
488 git_commit* untracked =
nullptr;
490 if( git_commit_parent( &untracked, commit, 2 ) == GIT_OK )
493 git_tree* untrackedTree =
nullptr;
495 if( git_commit_tree( &untrackedTree, untracked ) == GIT_OK )
500 untrackedTree, GIT_TREEWALK_PRE,
501 [](
const char* aRoot,
const git_tree_entry* aEntry,
void* aPayload ) ->
int
503 if( git_tree_entry_type( aEntry ) == GIT_OBJECT_BLOB )
505 auto* files =
static_cast<std::vector<wxString>*
>( aPayload );
506 files->push_back( wxString::FromUTF8( aRoot )
507 + wxString::FromUTF8( git_tree_entry_name( aEntry ) ) );
528 git_object* headObj =
nullptr;
530 if( git_revparse_single( &headObj,
m_repo,
"HEAD^{tree}" ) == GIT_OK )
531 headTree.reset(
reinterpret_cast<git_tree*
>( headObj ) );
533 git_diff_options opts;
534 git_diff_options_init( &opts, GIT_DIFF_OPTIONS_VERSION );
535 opts.flags = GIT_DIFF_INCLUDE_UNTRACKED | GIT_DIFF_RECURSE_UNTRACKED_DIRS | GIT_DIFF_SHOW_UNTRACKED_CONTENT;
537 git_diff* diff =
nullptr;
539 if( git_diff_tree_to_workdir_with_index( &diff,
m_repo, headTree.get(), &opts ) != GIT_OK )
543 std::pair<int, int> total{ 0, 0 };
545 for(
size_t ii = 0; ii < git_diff_num_deltas( diff ); ++ii )
547 git_patch* patch =
nullptr;
549 if( git_patch_from_diff( &patch, diff, ii ) != GIT_OK )
553 const git_diff_delta*
delta = git_patch_get_delta( patch );
556 if( !
path || aPaths.count( wxString::FromUTF8(
path ) ) == 0 )
562 if( git_patch_line_stats(
nullptr, &added, &removed, patch ) == GIT_OK )
564 total.first +=
static_cast<int>( added );
565 total.second +=
static_cast<int>( removed );
578 std::vector<KIGIT_BRANCH_INFO> branches;
580 git_branch_iterator* branchIterator =
nullptr;
582 if( git_branch_iterator_new( &branchIterator,
m_repo, GIT_BRANCH_ALL ) )
584 wxLogTrace(
traceGit,
"Failed to get branch iterator" );
589 git_reference* branchReference =
nullptr;
590 git_branch_t branchType;
595 branchReference =
nullptr;
597 int rc = git_branch_next( &branchReference, &branchType, branchIterator );
599 if( rc == GIT_ITEROVER )
608 const char* branchName =
"";
612 if( git_reference_type( branchReference ) != GIT_REFERENCE_DIRECT )
615 if( git_branch_name( &branchName, branchReference ) )
617 wxLogTrace(
traceGit,
"Failed to get branch name in iter loop" );
621 const git_oid* commitId = git_reference_target( branchReference );
622 git_commit* commit =
nullptr;
624 if( !commitId || git_commit_lookup( &commit,
m_repo, commitId ) != GIT_OK )
626 wxLogTrace(
traceGit,
"Failed to get commit in iter loop" );
631 git_time_t commitTime = git_commit_time( commit );
635 info.isRemote = branchType == GIT_BRANCH_REMOTE;
636 info.isCurrent = !
info.isRemote && git_branch_is_head( branchReference ) == 1;
637 info.tipHash = shortHashOf( commitId );
639 info.when = wxDateTime(
static_cast<time_t
>( commitTime ) );
641 branches.push_back( std::move(
info ) );
656 git_reference* ref =
nullptr;
658 if( git_reference_dwim( &ref,
m_repo, aBranch.utf8_string().c_str() ) != GIT_OK )
662 git_object* target =
nullptr;
664 if( git_reference_peel( &target, ref, GIT_OBJECT_COMMIT ) != GIT_OK )
668 git_commit* commit =
reinterpret_cast<git_commit*
>( target );
672 detail.tipHash = shortHashOf( git_commit_id( commit ) );
673 detail.when = wxDateTime(
static_cast<time_t
>( git_commit_time( commit ) ) );
675 if(
const git_signature* author = git_commit_author( commit ) )
681 if(
const char*
message = git_commit_message( commit ) )
687 git_reference* upstream =
nullptr;
689 if( !git_reference_is_branch( ref ) || git_branch_upstream( &upstream, ref ) != GIT_OK )
693 const char* upstreamName =
"";
695 if( git_branch_name( &upstreamName, upstream ) == GIT_OK )
709 std::vector<wxString> projDirs;
715 if( git_reference_name_to_id( &oid,
m_repo,
"HEAD" ) != GIT_OK )
721 if( git_commit_lookup( &commit,
m_repo, &oid ) != GIT_OK )
729 if( git_commit_tree( &tree, commit ) != GIT_OK )
739 tree, GIT_TREEWALK_PRE,
740 [](
const char* root,
const git_tree_entry* entry,
void* payload )
742 std::vector<wxString>* prjs =
static_cast<std::vector<wxString>*
>( payload );
743 wxFileName root_fn( git_tree_entry_name( entry ) );
745 root_fn.SetPath( root );
747 if( git_tree_entry_type( entry ) == GIT_OBJECT_BLOB
748 && ( ( root_fn.GetExt() ==
"kicad_pro" ) || ( root_fn.GetExt() ==
"pro" ) ) )
750 prjs->push_back( root_fn.GetFullPath() );
757 std::sort( projDirs.begin(), projDirs.end(),
758 [](
const wxString& a,
const wxString& b )
760 int a_freq = a.Freq( wxFileName::GetPathSeparator() );
761 int b_freq = b.Freq( wxFileName::GetPathSeparator() );
763 if( a_freq == b_freq )
766 return a_freq < b_freq;
775 std::pair<std::set<wxString>, std::set<wxString>> modified_files;
778 return modified_files;
780 git_reference* head =
nullptr;
781 git_reference* remote_head =
nullptr;
783 if( git_repository_head( &head,
m_repo ) != GIT_OK )
785 wxLogTrace(
traceGit,
"Failed to get modified HEAD" );
786 return modified_files;
791 if( git_branch_upstream( &remote_head, head ) != GIT_OK )
796 wxLogTrace(
traceGit,
"Failed to get modified remote HEAD" );
797 return modified_files;
802 const git_oid* head_oid = git_reference_target( head );
803 const git_oid* remote_oid = git_reference_target( remote_head );
805 if( !head_oid || !remote_oid )
806 return modified_files;
808 auto load_tree = [
this](
const git_oid* aOid ) -> git_tree*
810 git_commit* commit =
nullptr;
812 if( git_commit_lookup( &commit,
m_repo, aOid ) != GIT_OK )
819 git_tree* tree =
nullptr;
821 if( git_commit_tree( &tree, commit ) != GIT_OK )
830 git_tree* head_tree = load_tree( head_oid );
833 git_tree* remote_tree = load_tree( remote_oid );
836 if( !head_tree || !remote_tree )
837 return modified_files;
846 if( git_merge_base( &base_oid,
m_repo, head_oid, remote_oid ) != GIT_OK )
849 return modified_files;
852 git_tree* base_tree = load_tree( &base_oid );
856 return modified_files;
858 auto collect_paths = [
this]( git_tree* aOldTree, git_tree* aNewTree, std::set<wxString>& aOut )
863 git_diff_options localOpts;
864 git_diff_init_options( &localOpts, GIT_DIFF_OPTIONS_VERSION );
866 git_diff* diff =
nullptr;
868 if( git_diff_tree_to_tree( &diff,
m_repo, aOldTree, aNewTree, &localOpts ) != GIT_OK )
875 [&aOut](
const git_diff_delta& aDelta )
877 if( aDelta.new_file.path )
878 aOut.insert( wxString::FromUTF8( aDelta.new_file.path ) );
880 if( aDelta.old_file.path )
881 aOut.insert( wxString::FromUTF8( aDelta.old_file.path ) );
884 git_diff_free( diff );
887 collect_paths( base_tree, head_tree, modified_files.first );
888 collect_paths( base_tree, remote_tree, modified_files.second );
894 std::set<wxString> actuallyDifferent;
895 collect_paths( head_tree, remote_tree, actuallyDifferent );
897 auto filterToDifferent = [&]( std::set<wxString>& aSet )
899 for(
auto it = aSet.begin(); it != aSet.end(); )
900 it = actuallyDifferent.count( *it ) ? std::next( it ) : aSet.erase( it );
903 filterToDifferent( modified_files.first );
904 filterToDifferent( modified_files.second );
906 return modified_files;
911 const git_reference* aBase )
const
913 if( !
m_repo || !aBranch || !aBase )
916 git_object* branchCommit =
nullptr;
918 if( git_reference_peel( &branchCommit, aBranch, GIT_OBJECT_COMMIT ) != GIT_OK )
922 git_object* baseCommit =
nullptr;
924 if( git_reference_peel( &baseCommit, aBase, GIT_OBJECT_COMMIT ) != GIT_OK )
931 git_object_id( baseCommit ) );
944 return status && status->HasLocalCommits();
950 return m_repo && git_repository_head_detached(
m_repo ) == 1;
959 git_config*
config =
nullptr;
961 if( git_repository_config( &
config,
m_repo ) != GIT_OK )
967 return git_config_get_bool( &rebase,
config,
"pull.rebase" ) == GIT_OK && rebase;
976 git_reference* head =
nullptr;
978 if( git_repository_head( &head,
m_repo ) != GIT_OK )
982 git_reference* upstream =
nullptr;
983 int result = git_branch_upstream( &upstream, head );
985 if(
result == GIT_ENOTFOUND )
992 std::optional<KIGIT_AHEAD_BEHIND> counts =
compareRefs( head, upstream );
1004 return std::nullopt;
1006 git_reference* branch =
nullptr;
1008 if( git_branch_lookup( &branch,
m_repo, aBranch.utf8_string().c_str(), GIT_BRANCH_LOCAL ) != GIT_OK )
1009 return std::nullopt;
1012 git_reference* head =
nullptr;
1014 if( git_repository_head( &head,
m_repo ) != GIT_OK )
1015 return std::nullopt;
1018 std::optional<KIGIT_AHEAD_BEHIND> counts =
compareRefs( branch, head );
1021 return std::nullopt;
1023 return counts->ahead;
1029 std::vector<wxString> messages;
1034 git_revwalk* walker =
nullptr;
1036 if( git_revwalk_new( &walker,
m_repo ) != GIT_OK )
1040 git_revwalk_sorting( walker, GIT_SORT_TIME | GIT_SORT_TOPOLOGICAL );
1042 if( git_revwalk_push_head( walker ) != GIT_OK )
1045 std::set<wxString> seen;
1048 while( messages.size() < aMax && git_revwalk_next( &oid, walker ) == GIT_OK )
1050 git_commit* commit =
nullptr;
1052 if( git_commit_lookup( &commit,
m_repo, &oid ) != GIT_OK )
1059 if( git_commit_parentcount( commit ) > 1 )
1062 if(
const char*
text = git_commit_message( commit ) )
1068 messages.push_back(
message );
1079std::string treeEntryIdAt( git_commit* aCommit,
const char* aPath )
1081 git_tree* tree =
nullptr;
1083 if( git_commit_tree( &tree, aCommit ) != GIT_OK )
1087 git_tree_entry* entry =
nullptr;
1089 if( git_tree_entry_bypath( &entry, tree, aPath ) != GIT_OK )
1094 return git_oid_tostr_s( git_tree_entry_id( entry ) );
1100bool commitTouchesPath( git_commit* aCommit,
const std::string& aPath )
1102 std::string after = treeEntryIdAt( aCommit, aPath.c_str() );
1105 if( git_commit_parentcount( aCommit ) > 0 )
1107 git_commit* parent =
nullptr;
1109 if( git_commit_parent( &parent, aCommit, 0 ) == GIT_OK )
1112 before = treeEntryIdAt( parent, aPath.c_str() );
1116 return after != before;
1124 std::vector<KIGIT_COMMIT_INFO> commits;
1130 git_revwalk* walker =
nullptr;
1132 if( git_revwalk_new( &walker,
m_repo ) != GIT_OK )
1139 git_revwalk_sorting( walker, GIT_SORT_TIME | GIT_SORT_TOPOLOGICAL );
1141 if( aFilter.
branch.IsEmpty() )
1143 git_revwalk_push_head( walker );
1144 git_revwalk_push_glob( walker,
"refs/heads/*" );
1145 git_revwalk_push_glob( walker,
"refs/remotes/*" );
1150 git_reference* ref =
nullptr;
1152 if( git_reference_dwim( &ref,
m_repo, aFilter.
branch.utf8_string().c_str() ) != GIT_OK )
1156 git_object* target =
nullptr;
1158 if( git_reference_peel( &target, ref, GIT_OBJECT_COMMIT ) != GIT_OK )
1162 git_revwalk_push( walker, git_object_id( target ) );
1165 std::map<std::string, std::vector<wxString>> refNames = collectRefNames(
m_repo );
1166 wxString search = aFilter.
search.Lower();
1167 std::string
path = aFilter.
path.utf8_string();
1170 while( commits.size() < aMax && git_revwalk_next( &oid, walker ) == GIT_OK )
1177 git_commit* commit =
nullptr;
1179 if( git_commit_lookup( &commit,
m_repo, &oid ) != GIT_OK )
1184 if( !
path.empty() && !commitTouchesPath( commit,
path ) )
1188 info.hash = shortHashOf( &oid );
1190 if(
const char* summary = git_commit_summary( commit ) )
1193 if(
const git_signature* author = git_commit_author( commit ) )
1199 info.when = wxDateTime(
static_cast<time_t
>( git_commit_time( commit ) ) );
1201 std::string fullHash = git_oid_tostr_s( &oid );
1203 auto matches = [&](
const wxString& aText )
1205 return aText.Lower().Contains( search );
1208 if( !search.IsEmpty() && !matches(
info.summary ) && !matches(
info.author ) && !matches(
info.email )
1209 && !matches( fullHash ) )
1214 auto named = refNames.find( fullHash );
1216 if( named != refNames.end() )
1217 info.refs = named->second;
1219 commits.push_back(
info );
1233 git_object* obj =
nullptr;
1235 if( git_revparse_single( &obj,
m_repo, aHash.utf8_string().c_str() ) != GIT_OK )
1240 if( git_object_type( obj ) != GIT_OBJECT_COMMIT )
1243 git_commit* commit =
reinterpret_cast<git_commit*
>( obj );
1244 const git_oid* oid = git_commit_id( commit );
1247 detail.hash = wxString::FromUTF8( git_oid_tostr_s( oid ) );
1248 detail.shortHash = shortHashOf( oid );
1250 if(
const char*
message = git_commit_message( commit ) )
1255 if(
const git_signature* author = git_commit_author( commit ) )
1261 detail.when = wxDateTime(
static_cast<time_t
>( git_commit_time( commit ) ) );
1263 for(
unsigned ii = 0; ii < git_commit_parentcount( commit ); ++ii )
1264 detail.parents.push_back( shortHashOf( git_commit_parent_id( commit, ii ) ) );
1266 std::map<std::string, std::vector<wxString>> refNames = collectRefNames(
m_repo );
1267 auto named = refNames.find( git_oid_tostr_s( oid ) );
1269 if( named != refNames.end() )
1270 detail.refs = named->second;
1272 git_tree* tree =
nullptr;
1274 if( git_commit_tree( &tree, commit ) != GIT_OK )
1282 if( git_commit_parentcount( commit ) > 0 )
1284 git_commit* parent =
nullptr;
1286 if( git_commit_parent( &parent, commit, 0 ) == GIT_OK )
1289 git_tree* raw =
nullptr;
1291 if( git_commit_tree( &raw, parent ) == GIT_OK )
1292 parentTree.reset( raw );
1296 git_diff* diff =
nullptr;
1298 if( git_diff_tree_to_tree( &diff,
m_repo, parentTree.get(), tree,
nullptr ) != GIT_OK )
1303 git_diff_find_options findOpts;
1304 git_diff_find_options_init( &findOpts, GIT_DIFF_FIND_OPTIONS_VERSION );
1305 findOpts.flags = GIT_DIFF_FIND_RENAMES | GIT_DIFF_FIND_COPIES;
1306 git_diff_find_similar( diff, &findOpts );
1308 for(
size_t ii = 0; ii < git_diff_num_deltas( diff ); ++ii )
1310 git_patch* patch =
nullptr;
1312 if( git_patch_from_diff( &patch, diff, ii ) != GIT_OK )
1316 const git_diff_delta*
delta = git_patch_get_delta( patch );
1319 file.
path = wxString::FromUTF8(
delta->new_file.path ?
delta->new_file.path :
delta->old_file.path );
1321 file.
binary = (
delta->flags & GIT_DIFF_FLAG_BINARY ) != 0;
1323 if(
delta->status == GIT_DELTA_RENAMED ||
delta->status == GIT_DELTA_COPIED )
1324 file.
oldPath = wxString::FromUTF8(
delta->old_file.path );
1329 if( git_patch_line_stats(
nullptr, &added, &removed, patch ) == GIT_OK )
1331 file.
added =
static_cast<int>( added );
1332 file.
removed =
static_cast<int>( removed );
1337 detail.files.push_back( file );
1349 std::vector<KIGIT_STASH_INFO>* out;
1353int collectStash(
size_t aIndex,
const char* aMessage,
const git_oid* aStashId,
void* aPayload )
1355 STASH_COLLECT* ctx =
static_cast<STASH_COLLECT*
>( aPayload );
1358 info.index = aIndex;
1361 char hash[GIT_OID_HEXSZ + 1] = { 0 };
1362 git_oid_tostr( hash,
sizeof( hash ), aStashId );
1363 info.id = wxString::FromUTF8( hash );
1365 git_commit* commit =
nullptr;
1367 if( git_commit_lookup( &commit, ctx->repo, aStashId ) == GIT_OK )
1370 info.when = wxDateTime(
static_cast<time_t
>( git_commit_time( commit ) ) );
1373 ctx->out->push_back(
info );
1381 std::vector<KIGIT_STASH_INFO> stashes;
1386 STASH_COLLECT ctx{
m_repo, &stashes };
1387 git_stash_foreach(
m_repo, collectStash, &ctx );
1395 std::vector<KIGIT_TAG_INFO> tags;
1400 git_strarray tagNames = {
nullptr, 0 };
1402 if( git_tag_list( &tagNames,
m_repo ) != GIT_OK )
1407 for(
size_t i = 0; i < tagNames.count; ++i )
1412 info.name = tagName;
1418 info.summary =
detail.message.BeforeFirst(
'\n' );
1422 tags.push_back(
info );
1426 std::stable_sort( tags.begin(), tags.end(),
1429 if( !a.when.IsValid() || !b.when.IsValid() )
1430 return a.when.IsValid();
1432 return a.when > b.when;
1441 std::vector<std::pair<wxString, wxString>> remotes;
1446 git_strarray names = {
nullptr, 0 };
1448 if( git_remote_list( &names,
m_repo ) != GIT_OK )
1453 for(
size_t i = 0; i < names.count; ++i )
1455 wxString
name = wxString::FromUTF8( names.strings[i] );
1456 git_remote* remote =
nullptr;
1458 if( git_remote_lookup( &remote,
m_repo, names.strings[i] ) != GIT_OK )
1463 const char* url = git_remote_url( remote );
1473 return m_repo && git_repository_head_unborn(
m_repo ) == 1;
1483 wxString ref = wxS(
"refs/heads/" ) + aName;
1485 return git_repository_set_head(
m_repo, ref.utf8_string().c_str() ) == GIT_OK;
1541 git_object* obj =
nullptr;
1542 wxString spec = wxS(
"refs/tags/" ) + aName;
1544 if( git_revparse_single( &obj,
m_repo, spec.utf8_string().c_str() ) != GIT_OK )
1551 git_object* peeled =
nullptr;
1553 if( git_object_peel( &peeled, obj, GIT_OBJECT_COMMIT ) != GIT_OK )
1557 git_commit* commit =
reinterpret_cast<git_commit*
>( peeled );
1561 detail.hash = shortHashOf( git_commit_id( commit ) );
1563 const char*
message =
nullptr;
1564 const git_signature* who =
nullptr;
1566 if( git_object_type( obj ) == GIT_OBJECT_TAG )
1568 git_tag* tag =
reinterpret_cast<git_tag*
>( obj );
1569 message = git_tag_message( tag );
1570 who = git_tag_tagger( tag );
1574 message = git_commit_message( commit );
1576 bool annotated = who !=
nullptr;
1579 who = git_commit_author( commit );
1590 detail.when = wxDateTime(
static_cast<time_t
>( annotated ? who->when.time : git_commit_time( commit ) ) );
1653 if( !
m_repo || aPath.IsEmpty() )
1656 git_index*
index =
nullptr;
1658 if( git_repository_index( &
index,
m_repo ) != GIT_OK )
1663 const git_index_entry* ancestor =
nullptr;
1664 const git_index_entry* ours =
nullptr;
1665 const git_index_entry* theirs =
nullptr;
1667 return git_index_conflict_get( &ancestor, &ours, &theirs,
index, aPath.utf8_string().c_str() ) == GIT_OK;
1673 return m_repo && git_repository_state(
m_repo ) != GIT_REPOSITORY_STATE_NONE;
1682 switch( git_repository_state(
m_repo ) )
1686 case GIT_REPOSITORY_STATE_REBASE:
1687 case GIT_REPOSITORY_STATE_REBASE_INTERACTIVE:
1688 case GIT_REPOSITORY_STATE_REBASE_MERGE:
1690 case GIT_REPOSITORY_STATE_CHERRYPICK:
1692 case GIT_REPOSITORY_STATE_REVERT:
1706 std::vector<KIGIT_CONFLICT_SIDES>& aConflicts, wxString& aError )
1713 const std::vector<std::pair<wxString, wxString>>& aResolvedFiles,
1729 [aOwner](
const auto& aEntry )
1731 return aEntry.first == aOwner;
1741 for(
const auto& [owner, callback] : listeners )
1745 [target = owner](
const auto& aEntry )
1747 return aEntry.first == target;
1766 [
this](
const char* aName ) ->
bool
1768 git_remote* remote =
nullptr;
1770 if( git_remote_lookup( &remote,
m_repo, aName ) != GIT_OK )
1775 const char* fetch_url = git_remote_url( remote );
1776 const char* push_url = git_remote_pushurl( remote );
1780 push_url = fetch_url;
1782 return fetch_url && push_url;
1787 if( checkRemote( preferred.c_str() ) )
1790 if( preferred !=
"origin" && checkRemote(
"origin" ) )
1793 git_strarray remotes = {
nullptr, 0 };
1795 if( git_remote_list( &remotes,
m_repo ) != GIT_OK )
1797 wxLogTrace(
traceGit,
"Failed to enumerate remotes for haspushpull" );
1803 for(
size_t ii = 0; ii < remotes.count; ++ii )
1805 if( checkRemote( remotes.strings[ii] ) )
1817 if( remoteName.IsEmpty() )
1818 remoteName = wxS(
"origin" );
1826 git_remote* remote =
nullptr;
1828 if( !
m_repo || git_remote_lookup( &remote,
m_repo, aRemoteName.utf8_string().c_str() ) != GIT_OK )
1829 return wxEmptyString;
1832 const char* url = git_remote_pushurl( remote ) ? git_remote_pushurl( remote ) : git_remote_url( remote );
1834 return url ? wxString::FromUTF8( url ) : wxString();
1841 git_strarray remotes = {
nullptr, 0 };
1843 if( git_remote_list( &remotes,
m_repo ) == GIT_OK )
1848 if( remotes.count == 1 )
1850 retval = remotes.strings[0];
1854 for(
size_t ii = 0; ii < remotes.count; ++ii )
1856 if( strcmp( remotes.strings[ii],
"origin" ) == 0 )
1858 retval = remotes.strings[ii];
1864 git_strarray_dispose( &remotes );
1873 git_remote* remote =
nullptr;
1875 if( git_remote_lookup( &remote,
m_repo,
"origin" ) == GIT_OK )
1877 retval = git_remote_name( remote );
1878 git_remote_free( remote );
1882 wxLogTrace(
traceGit,
"Failed to get remote name from default remote: %s",
1894 return wxEmptyString;
1898 git_reference* head =
nullptr;
1899 git_reference* upstream =
nullptr;
1902 if( git_repository_head( &head,
m_repo ) != GIT_OK )
1910 if( git_branch_upstream( &upstream, head ) != GIT_OK )
1917 git_buf remote_name = GIT_BUF_INIT_CONST(
nullptr, 0 );
1919 if( git_branch_remote_name( &remote_name,
m_repo, git_reference_name( upstream ) ) == GIT_OK )
1921 retval = remote_name.ptr;
1922 git_buf_dispose( &remote_name );
1927 "Failed to get remote name from upstream branch: %s",
1939 if( aKey.IsEmpty() )
1972 return wxEmptyString;
2013 if( !aEntered.
sshKey.IsEmpty() )
2037 const auto deadline = std::chrono::steady_clock::now() + aWait;
2041 while( !lock.try_lock() && std::chrono::steady_clock::now() < deadline )
2042 std::this_thread::sleep_for( std::chrono::milliseconds( 20 ) );
2063 [&](
const wxString& aKey )
2065 return KIGIT::IsSameSSHKey( aKey, remembered );
2111 return wxEmptyString;
2118 return wxEmptyString;
2122 if(
const char* workdir = git_repository_workdir(
m_repo ) )
2123 return wxString::FromUTF8( workdir );
2125 if(
const char*
path = git_repository_path(
m_repo ) )
2126 return wxString::FromUTF8(
path );
2128 return wxEmptyString;
2156 git_remote* remote =
nullptr;
2158 if( git_remote_lookup( &remote,
m_repo, remote_name.ToStdString().c_str() ) == GIT_OK )
2161 if(
const char* remoteUrl = git_remote_url( remote ) )
2162 url = wxString::FromUTF8( remoteUrl );
2164 git_remote_free( remote );
2174 bool keysStale =
false;
2246 size_t protoSep = aUrl.find(
"://" );
2248 if( protoSep == wxString::npos )
2249 return wxString::npos;
2251 size_t hostStart = protoSep + 3;
2252 size_t pathStart = aUrl.find_first_of(
"/?#", hostStart );
2253 size_t searchEnd = ( pathStart == wxString::npos ) ? aUrl.length() : pathStart;
2255 if( searchEnd <= hostStart )
2256 return wxString::npos;
2258 size_t at = aUrl.rfind(
'@', searchEnd - 1 );
2260 return ( at != wxString::npos && at >= hostStart ) ? at : wxString::npos;
2266 const git_error* error = git_error_last();
2268 if( error ==
nullptr )
2269 return wxString(
"No error" );
2282 if(
const git_error* error = git_error_last() )
2284 info.klass = error->klass;
2285 info.message = wxString::FromUTF8( error->message ? error->message :
"" );
2295 const std::string
text = aText.utf8_string();
2298 for(
size_t ii = 0; ii <
text.size(); ++ii )
2300 if(
text[ii] ==
'%' && ii + 2 <
text.size() && isxdigit( (
unsigned char)
text[ii + 1] )
2301 && isxdigit( (
unsigned char)
text[ii + 2] ) )
2303 decoded +=
static_cast<char>( std::stoi(
text.substr( ii + 1, 2 ),
nullptr, 16 ) );
2324 if( aPort.IsEmpty() )
2327 if( !aPort.ToLong( &port ) || port <= 0 || port > 65535 )
2330 return static_cast<int>( port );
2334static bool isScpIpv6(
const wxString& aText,
size_t aBracket )
2338 for(
size_t ii = aBracket + 1; ii < aText.length(); ++ii )
2340 wxUniChar c = aText[ii];
2348 if( c !=
':' && !wxIsxdigit( c ) )
2358 for(
size_t ii = aStart; ii < aText.length(); ++ii )
2360 if( aText[ii] ==
'@' )
2363 if( aText[ii] ==
':' )
2372static bool parseScpAddress(
const wxString& aURL, wxString& aUser, wxString& aHost, wxString& aPort )
2389 size_t user = 0, userLen = 0, host = 0, hostLen = 0, port = 0, portLen = 0;
2391 bool havePath =
false;
2393 for(
size_t ii = 0; ii < aURL.length() && !havePath; ++ii )
2395 wxUniChar c = aURL[ii];
2400 if( c ==
'@' || c ==
':' )
2410 else if( bracket++ > 1 )
2431 userLen = ii - user;
2438 state = c ==
'[' ? IPV6 : HOST;
2445 hostLen = ii - host;
2446 state = bracket ? PORT_START : PATH_START;
2450 if( bracket-- == 0 )
2453 hostLen = ii - host;
2476 hostLen = ii - host;
2477 state = bracket ? PORT_START : PATH_START;
2488 if( bracket-- == 0 )
2491 portLen = ii - port;
2504 case PATH_START: havePath =
true;
break;
2508 if( !havePath || hostLen == 0 )
2511 aUser = aURL.Mid( user, userLen );
2512 aHost = aURL.Mid( host, hostLen );
2513 aPort = aURL.Mid( port, portLen );
2516 if( aHost.StartsWith(
"[" ) && aHost.EndsWith(
"]" ) )
2517 aHost = aHost.Mid( 1, aHost.length() - 2 );
2528 size_t schemeEnd = aURL.find(
"://" );
2529 size_t hostStart = 0;
2532 if( schemeEnd != wxString::npos )
2534 wxString scheme = aURL.Left( schemeEnd ).Lower();
2536 if( scheme ==
"https" || scheme ==
"http" )
2538 else if( scheme ==
"ssh" || scheme ==
"ssh+git" || scheme ==
"git+ssh" )
2543 hostStart = schemeEnd + 3;
2544 hostEnd = aURL.find_first_of(
"/?#", hostStart );
2547 if( at != wxString::npos )
2549 wxString credentials = aURL.Mid( hostStart, at - hostStart );
2550 size_t colon = credentials.find(
':' );
2551 wxString user = credentials.Left( colon );
2554 if( colon != wxString::npos )
2557 wxString userPrefix;
2560 userPrefix = user +
"@";
2562 result.url = aURL.Left( hostStart ) + userPrefix + aURL.Mid( at + 1 );
2569 if( aURL.length() >= 2 && wxIsalpha( aURL[0] ) && aURL[1] ==
':' )
2572 hostEnd = aURL.find(
':' );
2573 size_t bracket = aURL.find(
'[' );
2575 if( bracket != wxString::npos && bracket < hostEnd )
2577 size_t endBracket = aURL.find(
']', bracket );
2579 if( endBracket != wxString::npos )
2580 hostEnd = aURL.find(
':', endBracket + 1 );
2583 size_t slash = aURL.find_first_of(
"/\\" );
2585 if( hostEnd == wxString::npos || hostEnd == 0 || ( slash != wxString::npos && slash < hostEnd ) )
2600 wxString host = aURL.Mid( hostStart, hostEnd == wxString::npos ? wxString::npos : hostEnd - hostStart );
2603 if( host.StartsWith(
"[" ) )
2605 result.hostname = host.AfterFirst(
'[' ).BeforeFirst(
']' );
2606 port = host.AfterFirst(
']' ).AfterFirst(
':' );
2610 result.hostname = host.BeforeFirst(
':' );
2611 port = host.AfterFirst(
':' );
2651 const git_oid* aOID,
unsigned int aIsMerge,
void* aPayload )
2654 git_oid_cpy( (git_oid*) aPayload, aOID );
2665 wxArrayString lines = wxSplit( aKeyText,
'\n',
'\0' );
2667 if( lines.IsEmpty() || !lines[0].Contains( wxS(
"PRIVATE KEY" ) ) )
2670 if( lines[0].Contains( wxS(
"ENCRYPTED" ) ) )
2674 for(
size_t ii = 1; ii < lines.GetCount(); ++ii )
2676 if( lines[ii].Trim().IsEmpty() )
2679 if( lines[ii].StartsWith( wxS(
"Proc-Type:" ) ) && lines[ii].Contains( wxS(
"ENCRYPTED" ) ) )
2683 if( !lines[0].Contains( wxS(
"OPENSSH PRIVATE KEY" ) ) )
2689 for(
size_t ii = 1; ii < lines.GetCount(); ++ii )
2691 if( lines[ii].StartsWith( wxS(
"-----" ) ) )
2697 wxMemoryBuffer raw = wxBase64Decode( body, wxBase64DecodeMode_SkipWS );
2699 const char magic[] =
"openssh-key-v1";
2700 const size_t magicLen =
sizeof( magic );
2701 const unsigned char* data =
static_cast<const unsigned char*
>( raw.GetData() );
2703 if( raw.GetDataLen() < magicLen + 4 || std::memcmp( data, magic, magicLen ) != 0 )
2707 (
static_cast<uint32_t
>( data[magicLen] ) << 24 ) | (
static_cast<uint32_t
>( data[magicLen + 1] ) << 16 )
2708 | (
static_cast<uint32_t
>( data[magicLen + 2] ) << 8 ) |
static_cast<uint32_t
>( data[magicLen + 3] );
2710 if( nameLen == 0 || raw.GetDataLen() < magicLen + 4 + nameLen )
2713 std::string cipher(
reinterpret_cast<const char*
>( data + magicLen + 4 ), nameLen );
2715 return cipher !=
"none";
2722 if( aKey.IsEmpty() || !wxFileName::IsFileReadable( aKey ) )
2725 wxFFile file( aKey, wxS(
"rb" ) );
2734 git_config*
config =
nullptr;
2736 if( ( aRepo ? git_repository_config( &
config, aRepo ) : git_config_open_default( &
config ) ) != 0 )
2737 return wxEmptyString;
2740 git_config_entry* entry =
nullptr;
2742 if( git_config_get_entry( &entry,
config,
"core.sshCommand" ) != 0 )
2743 return wxEmptyString;
2746 return wxString::FromUTF8( entry->value );
2755 git_object* obj =
nullptr;
2756 std::string refStr( aRef.ToUTF8() );
2758 if( git_revparse_single( &obj, aRepo, refStr.c_str() ) != 0 )
2760 wxLogTrace(
traceGit,
"git_revparse_single failed for ref '%s': %s",
2766 git_tree* tree =
nullptr;
2768 if( git_object_peel(
reinterpret_cast<git_object**
>( &tree ), obj, GIT_OBJECT_TREE ) != 0 )
2770 wxLogTrace(
traceGit,
"git_object_peel to tree failed for '%s': %s",
2781 std::vector<wxString> refs;
2786 auto resolves = [&](
const wxString& aRef )
2791 auto add = [&](
const wxString& aRef )
2793 if( resolves( aRef ) && std::find( refs.begin(), refs.end(), aRef ) == refs.end() )
2794 refs.push_back( aRef );
2799 git_reference* head =
nullptr;
2801 if( git_repository_head( &head, aRepo ) == 0 )
2805 if( git_reference_is_branch( head ) )
2807 current = wxString::FromUTF8( git_reference_shorthand( head ) );
2809 git_reference* tracking =
nullptr;
2811 if( git_branch_upstream( &tracking, head ) == 0 )
2814 upstream = wxString::FromUTF8( git_reference_shorthand( tracking ) );
2819 const wxString
main = wxS(
"main" );
2820 const wxString master = wxS(
"master" );
2822 for(
const wxString& base : {
main, master, upstream } )
2824 if( base != current && resolves( base ) )
2826 refs.push_back( base );
2831 add( current.IsEmpty() ? wxString( wxS(
"HEAD" ) ) : current );
2835 add( wxS(
"HEAD" ) );
2842 const std::function<
void(
const git_diff_delta& )>& aCallback )
2847 std::size_t numDeltas = git_diff_num_deltas( aDiff );
2849 for( std::size_t ii = 0; ii < numDeltas; ++ii )
2851 const git_diff_delta*
delta = git_diff_get_delta( aDiff, ii );
2856 aCallback( *
delta );
2863 if( aName.IsEmpty() )
2864 return _(
"Enter a name for the branch." );
2868 if( aName.Contains( wxS(
" " ) ) )
2869 return _(
"A branch name cannot contain spaces." );
2871 if( aName.StartsWith( wxS(
"-" ) ) )
2872 return _(
"A branch name cannot start with a dash." );
2874 if( aName.Contains( wxS(
".." ) ) )
2875 return _(
"A branch name cannot contain two dots in a row." );
2877 if( aName.EndsWith( wxS(
"/" ) ) )
2878 return _(
"A branch name cannot end with a slash." );
2882#if LIBGIT2_VER_MAJOR > 1 || ( LIBGIT2_VER_MAJOR == 1 && LIBGIT2_VER_MINOR >= 5 )
2883 valid = git_branch_name_is_valid( &valid, aName.utf8_string().c_str() ) == GIT_OK && valid;
2885 std::string refName =
"refs/heads/" + aName.utf8_string();
2886 valid = aName != wxS(
"HEAD" ) && git_reference_is_valid_name( refName.c_str() );
2890 return wxString::Format(
_(
"'%s' is not a valid branch name." ), aName );
2892 return wxEmptyString;
2898 if( !aText || !*aText )
2901 wxString
decoded = wxString::FromUTF8( aText );
2906 return wxString( aText, wxConvISO8859_1 );
2912 return _(
"Another git operation is in progress. Try again in a moment." );
2919 message.Replace( wxS(
"\r\n" ), wxS(
"\n" ) );
2920 message.Trim(
true ).Trim(
false );
2922 wxString description = aDescription;
2923 description.Replace( wxS(
"\r\n" ), wxS(
"\n" ) );
2924 description.Trim(
true ).Trim(
false );
2926 if( !description.IsEmpty() )
2927 message << wxS(
"\n\n" ) << description;
2929 if( !aSignOff.IsEmpty() )
2931 wxString trailer = wxS(
"Signed-off-by: " ) + aSignOff;
2932 bool signedOff =
false;
2935 for( wxString line : wxSplit(
message,
'\n' ) )
2937 if( line.Trim() == trailer )
2942 message << wxS(
"\n\n" ) << trailer;
2952 message.Replace( wxS(
"\r\n" ), wxS(
"\n" ) );
2953 message.Trim(
true ).Trim(
false );
2955 aSummary =
message.BeforeFirst(
'\n' );
2956 aDescription =
message.AfterFirst(
'\n' );
2957 aDescription.Trim(
false );
virtual RestoreResult RestoreVersion(KIGIT_COMMON &aCommon, const wxString &aCommitHash, KIGIT_ERROR_MESSAGE &aError)=0
virtual bool CreateTag(git_repository *aRepo, const wxString &aName, const wxString &aMessage)=0
virtual bool CheckoutTag(git_repository *aRepo, const wxString &aName)=0
virtual int CreateBranch(git_repository *aRepo, const wxString &aBranchName, const wxString &aFrom)=0
virtual bool DeleteTag(git_repository *aRepo, const wxString &aName)=0
virtual bool SetRemoteUrl(git_repository *aRepo, const wxString &aName, const wxString &aUrl)=0
virtual bool AbandonOperation(git_repository *aRepo, wxString &aError)=0
Drop a merge, rebase, cherry-pick or revert left in progress and return to the last commit.
virtual bool GetMergeConflicts(git_repository *aRepo, const wxString &aStageDir, wxString &aHeadOid, wxString &aTheirsOid, std::vector< KIGIT_CONFLICT_SIDES > &aConflicts, wxString &aError)=0
virtual bool DeleteBranch(git_repository *aRepo, const wxString &aBranchName)=0
virtual bool AddRemote(git_repository *aRepo, const wxString &aName, const wxString &aUrl)=0
virtual bool StashPop(git_repository *aRepo, size_t aIndex)=0
virtual MergeCommitResult CreateMergedCommit(git_repository *aRepo, const wxString &aExpectedHeadOid, const wxString &aTheirsOid, const std::vector< std::pair< wxString, wxString > > &aResolvedFiles, KIGIT_ERROR_MESSAGE &aError)=0
virtual bool StashApply(git_repository *aRepo, size_t aIndex)=0
virtual bool SetUserConfig(git_repository *aRepo, const wxString &aName, const wxString &aEmail)=0
virtual bool IsPathInHead(git_repository *aRepo, const wxString &aPath)=0
virtual bool DiscardChanges(git_repository *aRepo, const std::vector< wxString > &aPaths, wxString &aError)=0
virtual bool StashSave(git_repository *aRepo, const wxString &aMessage)=0
virtual bool StashDrop(git_repository *aRepo, size_t aIndex)=0
virtual bool RemoveRemote(git_repository *aRepo, const wxString &aName)=0
static std::optional< wxString > ProjectPrefix(const wxString &aWorkDir, const wxString &aProjectPath)
The project's folder inside the repository, ending in a slash.
std::mutex m_gitActionMutex
void FollowRewrittenUrl(const wxString &aRawUrl)
Bind the session to a URL that url.insteadOf rewrote, keeping the username, password and key entered ...
static bool DeferForSecret(const std::shared_ptr< KIGIT_COMMON > &aCommon, const std::weak_ptr< bool > &aOwner, std::function< void()> aRetry)
Read the remote's secret from the keyring on the UI thread without blocking it, so an unlock prompt c...
void updateConnectionType()
std::pair< int, int > GetWorkingTreeLineStats(const std::set< wxString > &aPaths) const
wxString GetAcceptedSSHKey() const
The encrypted key the server last accepted for this remote, so the credential prompt asks for the rig...
void ResetNextKey()
Start the next attempt from the first key, with the key that last connected to the current remote mov...
std::shared_ptr< std::atomic< bool > > CANCEL_TOKEN
One token per operation.
GIT_CONN_TYPE GetConnType() const
std::vector< KIGIT_COMMIT_INFO > GetRecentCommits(size_t aMax=50, const KIGIT_HISTORY_FILTER &aFilter={}) const
bool HasUncommittedTrackedChanges(bool *aReadOk=nullptr) const
void SyncRemoteUrl(const wxString &aRawUrl)
Bind the session to the URL a transfer is about to connect to.
CANCEL_TOKEN ActiveCancelToken() const
bool StashPop(size_t aIndex)
std::optional< wxString > GetProjectPrefix() const
Project folder relative to the repository, with a trailing slash.
void SetConnType(GIT_CONN_TYPE aConnType)
For a remote whose address names no transport, the user picks one in the prompt.
wxString GetRemote() const
wxString GetLastCommitMessage() const
std::mutex m_credentialsMutex
Serializes the credential fields between the UI thread and the authentication callback's worker threa...
wxString GetCurrentBranchName() const
wxString GetGitRootDirectory() const
bool IsOperationInProgress() const
True while a merge, rebase, cherry-pick or revert is in progress, which refuses commits.
KIGIT_TAG_DETAIL GetTagDetail(const wxString &aName) const
wxString GetSSHKey() const
The key the project was set up with, even when its file is gone, otherwise the first key offered.
void SetSSHKey(const wxString &aSSHKey)
bool IsPullRebaseConfigured() const
True when the repository is set to rebase rather than merge when getting changes.
KIGIT_COMMIT_DETAIL GetCommitDetail(const wxString &aHash) const
bool CheckoutTag(const wxString &aName)
wxString remoteNameWithoutUpstream() const
Remote to use when HEAD names no upstream, empty when several remotes leave it ambiguous.
wxString m_publicKeysHost
bool DeleteTag(const wxString &aName)
std::vector< wxString > GetProjectDirs()
Return a vector of project files in the repository.
wxString GetRemoteNameOrDefault() const
Returns GetRemotename() when non-empty, otherwise "origin".
static KIGIT_ERROR_INFO GetLastGitErrorInfo(int aCode)
The error libgit2 holds for a call that returned aCode.
wxString m_acceptedSSHKey
git_repository * GetRepo() const
KIGIT_COMMON(git_repository *aRepo, const wxString &aProjectPath=wxEmptyString)
aProjectPath is the absolute project directory.
CREDENTIAL_IDENTITY GetCredentialIdentity() const
void NotifyRefreshListeners()
wxString GetPushUrl(const wxString &aRemoteName) const
The address a push to aRemoteName connects to, its push URL or else its URL. Empty without one.
std::vector< wxString > GetRecentCommitMessages(size_t aMax) const
wxString GetProjectDir() const
Return the path set by SetProjectDir(), or the repository's working directory.
bool RemoveRemote(const wxString &aName)
std::optional< size_t > GetUnmergedCommitCount(const wxString &aBranch) const
Commits in aBranch that HEAD does not contain. No value when either cannot be read.
bool CreateBranch(const wxString &aName, const wxString &aFrom=wxEmptyString)
wxString GetNextPublicKey()
By value, so the caller never holds a pointer into the vector.
bool AddRemote(const wxString &aName, const wxString &aUrl)
int SSHPortFor(const wxString &aHost) const
The SSH port the session's remote names for aHost, 22 when it names none, or -1 when the remote is on...
bool GetMergeConflicts(const wxString &aStageDir, wxString &aHeadOid, wxString &aTheirsOid, std::vector< KIGIT_CONFLICT_SIDES > &aConflicts, wxString &aError)
Recompute the merge in memory and extract each conflicted file's three versions into aStageDir,...
void AddRefreshListener(void *aOwner, std::function< void()> aCallback)
std::vector< KIGIT_STASH_INFO > GetStashes() const
std::unique_lock< std::mutex > TryLockActionFor(std::chrono::milliseconds aWait)
TryLockAction that keeps trying for aWait before giving up.
bool StartUnbornBranch(const wxString &aName)
Point HEAD at a branch that does not exist yet, so the first commit creates it.
std::pair< std::set< wxString >, std::set< wxString > > GetDifferentFiles() const
Return a pair of sets of files that differ locally from the remote repository The first set is files ...
bool IsHeadUnborn() const
True while the repository has no commits, so HEAD names a branch that does not exist yet.
bool ApplyPromptedCredentials(const CREDENTIAL_IDENTITY &aFor, const PROMPTED_CREDENTIALS &aEntered)
Apply what the prompt collected, unless the session has moved to another remote since aFor was taken.
std::vector< std::pair< void *, std::function< void()> > > m_refreshListeners
std::vector< wxString > m_publicKeys
bool IsShuttingDown() const
Background timers ask this before starting work of their own.
KIGIT_BRANCH_DETAIL GetBranchDetail(const wxString &aBranch) const
wxString GetHeadCommitId() const
Full commit ID at HEAD, or empty for an unborn or missing HEAD.
bool HasPushAndPullRemote() const
bool StashApply(size_t aIndex)
bool DiscardChanges(const std::vector< wxString > &aPaths, wxString &aError)
Put the given working directory relative paths back to their committed state.
void rebuildPublicKeysUnlocked()
Rebuild m_publicKeys as the project key, when offerable, then the key that last connected to m_remote...
bool SetUserConfig(const wxString &aName, const wxString &aEmail)
void updateConnectionTypeUnlocked()
Body of updateConnectionType, for callers that already hold m_credentialsMutex.
bool IsPathInHead(const wxString &aPath)
True when the working directory relative path exists in the HEAD commit's tree.
std::optional< KIGIT_UPSTREAM_STATUS > UpstreamStatus() const
The current branch against its upstream.
KIGIT_STASH_DETAIL GetStashDetail(const wxString &aId) const
std::vector< std::pair< wxString, wxString > > GetRemotes() const
Returns every remote as a (name, URL) pair.
static wxString GetLastGitError()
libgit2's last message, without credentials from any URL it quotes, so it is safe to show or trace.
bool CreateTag(const wxString &aName, const wxString &aMessage=wxEmptyString)
MergeCommitResult CreateMergedCommit(const wxString &aExpectedHeadOid, const wxString &aTheirsOid, const std::vector< std::pair< wxString, wxString > > &aResolvedFiles, KIGIT_ERROR_MESSAGE &aError)
Redo the merge with each conflicted path replaced by its resolved file, then commit and check out.
bool AbandonOperation(wxString &aError)
Drop that operation and return to the last commit. The caller holds the action lock.
void UpdateCurrentBranchInfo()
wxString GetFirstOfferedSSHKey() const
The key the next attempt will try first, for the credential prompt to show.
void RemoveRefreshListener(void *aOwner)
bool StashDrop(size_t aIndex)
bool HasLocalCommits() const
True when HEAD has commits its upstream does not, or has no upstream yet.
std::vector< wxString > m_discoveredKeys
void RememberWorkingSSHKey(const KIGIT_AUTH_ATTEMPT &aAttempt)
Remember the key that connected for aAttempt, so the next connection offers it first.
bool StashSave(const wxString &aMessage)
Set the uncommitted tracked changes aside as a new stash, as git stash push would.
wxDateTime GetLastFetchTime() const
static REMOTE_URL ParseRemoteURL(const wxString &aURL)
wxString GetPassword()
The secret for the remote, read without ever prompting, so it is safe on a transfer worker.
GitOperation OperationInProgress() const
Which operation that is, so the panel can name it.
std::optional< KIGIT_AHEAD_BEHIND > compareRefs(const git_reference *aBranch, const git_reference *aBase) const
Count commits unique to aBranch and aBase. No value if the history cannot be read.
RestoreResult RestoreVersion(const wxString &aCommitHash, KIGIT_ERROR_MESSAGE &aError)
Restore the project as it was at aCommitHash, recorded as a new commit on top of the current head.
void SetAcceptedSSHKey(const wxString &aKey)
std::vector< KIGIT_TAG_INFO > GetTags() const
std::vector< KIGIT_BRANCH_INFO > GetBranches() const
Local and remote branches with their tip commits.
bool DeleteBranch(const wxString &aName)
bool IsPathConflicted(const wxString &aPath) const
True while aPath is one of the files a merge or rebase stopped on.
wxString GetRemotename() const
bool IsHeadDetached() const
True when HEAD points at a commit rather than a branch, as after checking out a tag.
bool SetRemoteUrl(const wxString &aName, const wxString &aUrl)
GIT_BACKEND * GetGitBackend()
const wxChar *const traceGit
Flag to enable Git debugging output.
@ USER
The main config directory (e.g. ~/.config/kicad/)
int fetchhead_foreach_cb(const char *, const char *, const git_oid *aOID, unsigned int aIsMerge, void *aPayload)
static size_t findUserinfoAt(const wxString &aUrl)
static bool scpHasUser(const wxString &aText, size_t aStart)
static bool isScpIpv6(const wxString &aText, size_t aBracket)
static int parsePort(const wxString &aPort)
static bool parseScpAddress(const wxString &aURL, wxString &aUser, wxString &aHost, wxString &aPort)
static wxString decodePercent(const wxString &aText)
bool IsPrivateKeyFileEncrypted(const wxString &aKey)
IsPrivateKeyEncrypted for the key file aKey. A file that cannot be read is reported as unencrypted.
std::unique_ptr< git_tree, decltype([](git_tree *aTree) { git_tree_free(aTree); })> GitTreePtr
A unique pointer for git_tree objects with automatic cleanup.
APIEXPORT wxString StripEmbeddedUserinfo(const wxString &aText)
Remove the user and password from every URL quoted in a message, since the remote's can carry a passw...
bool IsPrivateKeyEncrypted(const wxString &aKeyText)
Report whether an SSH private key is protected by a passphrase.
void SplitCommitMessage(const wxString &aMessage, wxString &aSummary, wxString &aDescription)
Split a commit message into its first line and the description after the first blank line.
APIEXPORT bool IsOfferableSSHKey(const wxString &aKey)
Whether aKey can be offered to a server.
wxString BranchNameError(const wxString &aName)
Empty when aName is a branch name git would accept, otherwise why it would not, in the words to show ...
git_tree * ResolveRefToTree(git_repository *aRepo, const wxString &aRef)
Resolve a string ref (branch name, short OID, full OID, tag) to its tree.
std::unique_ptr< git_revwalk, decltype([](git_revwalk *aWalker) { git_revwalk_free(aWalker); })> GitRevWalkPtr
A unique pointer for git_revwalk objects with automatic cleanup.
wxString BusyMessage()
What every caller says when it finds the session already busy.
std::unique_ptr< git_commit, decltype([](git_commit *aCommit) { git_commit_free(aCommit); })> GitCommitPtr
A unique pointer for git_commit objects with automatic cleanup.
void CollectDiffDeltas(git_diff *aDiff, const std::function< void(const git_diff_delta &)> &aCallback)
Walk every delta in a computed diff, invoking aCallback once per delta.
wxString ConfiguredSSHCommand(git_repository *aRepo)
git's core.sshCommand for aRepo, or from the user's git config when aRepo is null....
APIEXPORT wxString RememberedSSHKey(const wxString &aRemote)
The key that last connected to aRemote, or empty.
std::unique_ptr< git_status_list, decltype([](git_status_list *aList) { git_status_list_free(aList); })> GitStatusListPtr
A unique pointer for git_status_list 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.
std::unique_ptr< git_patch, decltype([](git_patch *aPatch) { git_patch_free(aPatch); })> GitPatchPtr
A unique pointer for git_patch objects with automatic cleanup.
APIEXPORT std::vector< wxString > DefaultSSHKeyCandidates(const wxString &aHomeDir, const wxString &aHost, const wxString &aSSHCommand=wxEmptyString)
Private keys to offer aHost, best first.
std::unique_ptr< git_reference, decltype([](git_reference *aRef) { git_reference_free(aRef); })> GitReferencePtr
A unique pointer for git_reference objects with automatic cleanup.
wxString ComposeCommitMessage(const wxString &aSummary, const wxString &aDescription, const wxString &aSignOff)
Join a summary line, an optional description and an optional sign-off into one commit message.
std::unique_ptr< git_strarray, decltype([](git_strarray *aArray) { git_strarray_free(aArray); })> GitStrArrayPtr
A unique pointer for git_strarray objects with automatic cleanup.
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.
APIEXPORT wxString HomeDir()
The user's home folder, where ssh looks for its config and default keys: the first candidate with a ....
std::unique_ptr< git_reference_iterator, decltype([](git_reference_iterator *aIter) { git_reference_iterator_free(aIter); })> GitReferenceIteratorPtr
A unique pointer for git_reference_iterator objects with automatic cleanup.
APIEXPORT wxWindow *& ActiveAdvancedGitWindow()
The advanced git window, or null when none is open.
APIEXPORT void RememberSSHKey(const wxString &aRemote, const wxString &aKey)
Remember aKey as the key that connected to aRemote. Safe to call from any thread.
std::unique_ptr< git_tree_entry, decltype([](git_tree_entry *aEntry) { git_tree_entry_free(aEntry); })> GitTreeEntryPtr
A unique pointer for git_tree_entry objects with automatic cleanup.
wxString DecodeRepoText(const char *aText)
Decode text that came out of a repository.
std::vector< wxString > CompareBranchRefs(git_repository *aRepo)
Refs to offer when comparing branches, base first and head second.
APIEXPORT bool IsSameSSHKey(const wxString &aKey, const wxString &aOther)
Whether two key paths name the same file.
std::unique_ptr< git_branch_iterator, decltype([](git_branch_iterator *aIter) { git_branch_iterator_free(aIter); })> GitBranchIteratorPtr
A unique pointer for git_branch_iterator objects with automatic cleanup.
std::unique_ptr< git_index, decltype([](git_index *aIndex) { git_index_free(aIndex); })> GitIndexPtr
A unique pointer for git_index objects with automatic cleanup.
std::unique_ptr< git_diff, decltype([](git_diff *aDiff) { git_diff_free(aDiff); })> GitDiffPtr
A unique pointer for git_diff objects with automatic cleanup.
std::unique_ptr< git_object, decltype([](git_object *aObject) { git_object_free(aObject); })> GitObjectPtr
A unique pointer for git_object objects with automatic cleanup.
std::unique_ptr< git_remote, decltype([](git_remote *aRemote) { git_remote_free(aRemote); })> GitRemotePtr
A unique pointer for git_remote objects with automatic cleanup.
size_t behind
Commits only in the second reference.
size_t ahead
Commits only in the first reference.
What the credential callback handed out during one operation, kept to explain a rejection.
KIGIT_COMMON::GIT_CONN_TYPE connType
std::vector< wxString > keysTried
Key files offered, in order.
wxString oldPath
For a rename or copy, where the file came from.
KIGIT::FILE_CHANGE_STATUS status
The remote the credential prompt was opened for.
What the credential prompt collected.
std::optional< wxString > username
A transport address with any embedded credentials extracted.
int port
0 when the address names none.
wxString url
Keeps the SSH username, scheme and port, but never a password.
What libgit2 reported for a failed call, read before anything else can replace it.
A summary the user can act on, with the raw text that explains it kept apart for the details.
wxString search
Keep only commits whose summary, author or hash contains this.
wxString path
Keep only commits that changed this file or folder, relative to the root.
wxString branch
One branch, local or remote, or empty for every branch and HEAD.
Where the current branch stands against its upstream.
static std::string decoded(const std::string &aBase64)
wxString result
Test unit parsing edge cases and error handling.
wxLogTrace helper definitions.