40#include <wx/filename.h>
67#if ( LIBGIT2_VER_MAJOR > 1 ) || ( LIBGIT2_VER_MAJOR == 1 && LIBGIT2_VER_MINOR >= 7 )
68 constexpr int connectTimeoutMs = 10000;
69 constexpr int transferTimeoutMs = 30000;
71 if( git_libgit2_opts( GIT_OPT_SET_SERVER_CONNECT_TIMEOUT, connectTimeoutMs ) != GIT_OK
72 || git_libgit2_opts( GIT_OPT_SET_SERVER_TIMEOUT, transferTimeoutMs ) != GIT_OK )
74 wxLogTrace(
traceGit,
"LIBGIT_BACKEND::Init(): could not set server timeouts: %s",
90 constexpr auto kOrphanJoinTimeout = std::chrono::seconds( 5 );
95 wxLogTrace(
traceGit,
"LIBGIT_BACKEND::Shutdown(): %zu orphan git thread(s) did not finish within %lld ms; "
96 "skipping libgit2 shutdown",
97 stuck,
static_cast<long long>( kOrphanJoinTimeout.count() ) );
107 git_libgit2_shutdown();
113#if ( LIBGIT2_VER_MAJOR >= 1 ) || ( LIBGIT2_VER_MINOR >= 99 )
114 int major = 0, minor = 0, rev = 0;
115 return git_libgit2_version( &major, &minor, &rev ) == GIT_OK;
126 if( aRc == GIT_ENOTFOUND )
127 return {
_(
"Set your name and email before committing (gear menu > Set Author...)." ), wxEmptyString };
135 if( aRc == GIT_ENOTFOUND )
137 aHandler->
AddError( wxString::Format(
_(
"There is no remote named '%s'. Add it on the Remotes page of the "
138 "Advanced Git window." ),
144 aHandler->
AddError( wxString::Format(
_(
"Could not read the remote '%s'." ), aRemoteName ),
152 std::unique_lock<std::mutex> lock = aHandler->
GetActionLock();
154 if( !lock.owns_lock() )
156 wxLogTrace(
traceGit,
"GIT_CLONE_HANDLER::PerformClone() could not lock" );
168 if( !clonePath.DirExists() )
170 if( !clonePath.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
172 aHandler->
AddErrorString( wxString::Format(
_(
"Could not create directory '%s'" ),
210 const std::set<std::string>& aSelected )
212 std::map<std::string, SELECTED_STATE>
result;
214 for(
const std::string&
path : aSelected )
218 if(
const git_index_entry* entry = git_index_get_bypath( aIndex,
path.c_str(), 0 ) )
221 state.
id = entry->id;
222 state.
mode = entry->mode;
234 std::map<std::string, SELECTED_STATE>
result;
235 size_t count = git_index_entrycount( aIndex );
237 for(
size_t ii = 0; ii < count; ii++ )
239 if(
const git_index_entry* entry = git_index_get_byindex( aIndex, ii ) )
243 state.
id = entry->id;
244 state.
mode = entry->mode;
245 result[entry->path] = state;
256 const char* indexPath = git_index_path( aRepoIndex );
261 git_index* fresh =
nullptr;
263 if( git_index_open( &fresh, indexPath ) != GIT_OK )
266 int rc = git_index_read( fresh, 1 );
269 if( rc != GIT_OK && rc != GIT_ENOTFOUND )
271 git_index_free( fresh );
280 std::map<std::string, SELECTED_STATE>& aOut )
293static bool wholeStateOnDisk( git_index* aRepoIndex, std::map<std::string, SELECTED_STATE>& aOut )
323 git_index_read(
index, 1 );
332 const char* workdir = git_repository_workdir( aRepo );
334 for(
const wxString& file : aFiles )
338 bool onDisk = workdir
339 && wxFileName::Exists( wxString::FromUTF8( workdir ) + file,
340 wxFILE_EXISTS_ANY | wxFILE_EXISTS_NO_FOLLOW );
343 std::string
path = file.utf8_string();
346 onDisk ? git_index_add_bypath( aIndex,
path.c_str() ) : git_index_remove_bypath( aIndex,
path.c_str() );
360 bool hasHeadNow = git_reference_name_to_id( &headNow, aRepo,
"HEAD" ) == GIT_OK;
362 return hasHeadNow != aHadHead || ( hasHeadNow && !git_oid_equal( &headNow, &aHeadAtStart ) );
368 const std::map<std::string, SELECTED_STATE>& aAtStart )
370 std::map<std::string, SELECTED_STATE> now;
377static bool indexChangedSince( git_index* aIndex,
const std::map<std::string, SELECTED_STATE>& aAtStart )
379 std::map<std::string, SELECTED_STATE> now;
395 const std::set<std::string>& aSelected )
397 for(
int attempt = 0; attempt < 3; attempt++ )
399 if( git_index_read( aIndex, 1 ) != 0 )
402 std::map<std::string, SELECTED_STATE> readState =
readWholeState( aIndex );
404 for(
const std::string&
path : aSelected )
405 git_index_remove_bypath( aIndex,
path.c_str() );
409 git_index_entry entry = staged.entry;
410 entry.path = staged.path.c_str();
412 if( git_index_add( aIndex, &entry ) != 0 )
416 std::map<std::string, SELECTED_STATE> diskState;
421 if( diskState != readState )
424 if( git_index_write( aIndex ) == 0 )
437 if( git_index_has_conflicts( aIndex ) )
439 aError =
_(
"This project has conflicts that are not resolved yet. Finish or abort the merge "
440 "with git, then commit here." );
446 switch( git_repository_state( aRepo ) )
448 case GIT_REPOSITORY_STATE_NONE:
return false;
449 case GIT_REPOSITORY_STATE_MERGE: operation =
_(
"merge" );
break;
450 case GIT_REPOSITORY_STATE_REVERT:
451 case GIT_REPOSITORY_STATE_REVERT_SEQUENCE: operation =
_(
"revert" );
break;
452 case GIT_REPOSITORY_STATE_CHERRYPICK:
453 case GIT_REPOSITORY_STATE_CHERRYPICK_SEQUENCE: operation =
_(
"cherry-pick" );
break;
454 case GIT_REPOSITORY_STATE_BISECT: operation =
_(
"bisect" );
break;
455 default: operation =
_(
"rebase" );
break;
458 aError = wxString::Format(
_(
"This project is in the middle of a %s. Finish or abort it with git, "
459 "then commit here." ),
484 if( git_repository_index( &
index, aRepo ) != 0 )
493 git_index_read(
index, 1 );
495 wxString blockedError;
499 aError = { blockedError, wxEmptyString };
503 for(
const wxString& file : aFiles )
530 if(
const git_index_entry* entry = git_index_get_bypath(
index,
path.c_str(), 0 ) )
536 if( git_index_write_tree( &treeId,
index ) != 0 )
542 git_tree* tree =
nullptr;
544 if( git_tree_lookup( &tree, aRepo, &treeId ) != 0 )
550 aTreeOut.reset( tree );
555 aError = {
_(
"The branch moved while this was running, so nothing was "
556 "committed. Review the changes and try again." ),
564 aError = {
_(
"The staged files changed outside KiCad while this ran. Nothing "
565 "was committed. Review the changes and try again." ),
576 const wxString& aMessage,
const wxString& aAuthorName,
577 const wxString& aAuthorEmail )
587 if( !staging.
Begin( repo, aFiles, stagingError ) )
596 if( git_repository_head_unborn( repo ) == 0 )
598 git_reference* headRef =
nullptr;
600 if( git_repository_head( &headRef, repo ) != 0 )
602 aHandler->
AddGitError(
_(
"Could not read the current commit." ) );
607 git_tree* headTree =
nullptr;
609 if( git_reference_peel( (git_object**) &headTree, headRef, GIT_OBJECT_TREE ) != 0 )
611 aHandler->
AddGitError(
_(
"Could not read the current commit." ) );
617 if( git_index_read_tree(
index, headTree ) != 0 )
619 aHandler->
AddGitError(
_(
"Could not prepare the commit." ) );
623 else if( git_index_clear(
index ) != 0 )
625 aHandler->
AddGitError(
_(
"Could not prepare the commit." ) );
631 if( !staging.
BuildTree( repo, aFiles, treePtr, stagingError ) )
637 git_tree* tree = treePtr.get();
639 git_commit* parent =
nullptr;
641 if( git_repository_head_unborn( repo ) == 0 )
643 git_reference* headRef =
nullptr;
645 if( git_repository_head( &headRef, repo ) != 0 )
647 aHandler->
AddGitError(
_(
"Could not read the current commit." ) );
653 if( git_reference_peel( (git_object**) &parent, headRef, GIT_OBJECT_COMMIT ) != 0 )
655 aHandler->
AddGitError(
_(
"Could not read the current commit." ) );
662 git_signature* author =
nullptr;
664 if( git_signature_now( &author, aAuthorName.utf8_string().c_str(), aAuthorEmail.utf8_string().c_str() ) != 0 )
666 aHandler->
AddGitError(
_(
"Could not record the commit author." ) );
672 size_t parentsCount = parent ? 1 : 0;
674#if( LIBGIT2_VER_MAJOR == 1 && LIBGIT2_VER_MINOR == 8 \
675 && ( LIBGIT2_VER_REVISION < 2 || LIBGIT2_VER_REVISION == 3 ) )
676 git_commit*
const parents[1] = { parent };
677 git_commit**
const parentsPtr = parent ? parents :
nullptr;
679 const git_commit* parents[1] = { parent };
680 const git_commit** parentsPtr = parent ? parents :
nullptr;
683 if( git_commit_create( &oid, repo,
"HEAD", author, author,
nullptr, aMessage.utf8_string().c_str(), tree,
684 parentsCount, parentsPtr )
687 aHandler->
AddGitError(
_(
"Could not create the commit." ) );
695 git_index_read(
index, 1 );
696 aHandler->
AddErrorString(
_(
"The commit was created, but the list of staged files was left "
697 "alone, because the staged files changed outside KiCad while "
706 aHandler->
AddErrorString(
_(
"The commit was created, but the list of staged files was left "
707 "alone, because another program kept changing it." ) );
713 aHandler->
AddGitError(
_(
"The commit was created, but the list of staged files could not be updated." ) );
724 const wxString& aMessage,
const wxString& aAuthorName,
725 const wxString& aAuthorEmail )
732 if( git_repository_head_unborn( repo ) != 0 )
734 aHandler->
AddErrorString(
_(
"Cannot amend: the branch has no commits yet." ) );
738 git_reference* headRef =
nullptr;
740 if( git_repository_head( &headRef, repo ) != 0 )
742 aHandler->
AddGitError(
_(
"Could not read the current commit." ) );
747 git_commit* headCommit =
nullptr;
749 if( git_reference_peel( (git_object**) &headCommit, headRef, GIT_OBJECT_COMMIT ) != 0 )
751 aHandler->
AddGitError(
_(
"Could not read the current commit." ) );
759 if( !staging.
Begin( repo, aFiles, stagingError ) )
768 git_tree* headTree =
nullptr;
770 if( git_commit_tree( &headTree, headCommit ) != 0 )
772 aHandler->
AddGitError(
_(
"Could not read the current commit." ) );
778 if( git_index_read_tree(
index, headTree ) != 0 )
780 aHandler->
AddGitError(
_(
"Could not prepare the commit." ) );
786 if( !staging.
BuildTree( repo, aFiles, treePtr, stagingError ) )
792 git_tree* tree = treePtr.get();
794 git_signature* author =
nullptr;
796 if( git_signature_now( &author, aAuthorName.utf8_string().c_str(), aAuthorEmail.utf8_string().c_str() ) != 0 )
798 aHandler->
AddGitError(
_(
"Could not record the commit author." ) );
805 if( git_commit_amend( &oid, headCommit,
"HEAD", author, author,
nullptr, aMessage.utf8_string().c_str(), tree )
808 aHandler->
AddGitError(
_(
"Could not amend the commit." ) );
816 git_index_read(
index, 1 );
817 aHandler->
AddErrorString(
_(
"The commit was amended, but the list of staged files was left "
818 "alone, because the staged files changed outside KiCad while "
827 aHandler->
AddErrorString(
_(
"The commit was amended, but the list of staged files was left "
828 "alone, because another program kept changing it." ) );
834 aHandler->
AddGitError(
_(
"The commit was amended, but the list of staged files could not be updated." ) );
848 git_reference_iterator* rawIter =
nullptr;
850 if(
int rc = git_reference_iterator_glob_new( &rawIter, aRepo,
"refs/remotes/*" ); rc != GIT_OK )
854 std::vector<git_oid> tips;
855 std::vector<wxString> names;
856 git_reference* rawRef =
nullptr;
859 while( ( rc = git_reference_next( &rawRef, iter.get() ) ) == GIT_OK )
864 if( git_reference_type( ref.get() ) == GIT_REFERENCE_SYMBOLIC )
867 git_object* rawTip =
nullptr;
869 if(
int peel = git_reference_peel( &rawTip, ref.get(), GIT_OBJECT_COMMIT ); peel != GIT_OK )
873 tips.push_back( *git_object_id( tip.get() ) );
874 names.push_back( wxString::FromUTF8( git_reference_shorthand( ref.get() ) ) );
877 if( rc != GIT_ITEROVER )
883#if LIBGIT2_VER_MAJOR > 1 || ( LIBGIT2_VER_MAJOR == 1 && LIBGIT2_VER_MINOR >= 5 )
884 int reachable = git_graph_reachable_from_any( aRepo, &aCommit, tips.data(), tips.size() );
890 for(
size_t ii = 0; ii < tips.size(); ++ii )
892 reachable = git_graph_reachable_from_any( aRepo, &aCommit, &tips[ii], 1 );
899 aRemoteRef = names[ii];
906 for(
size_t ii = 0; ii < tips.size(); ++ii )
909 git_oid_equal( &aCommit, &tips[ii] ) ? 1 : git_graph_descendant_of( aRepo, &tips[ii], &aCommit );
916 aRemoteRef = names[ii];
927 const git_oid& aExpectedHead, wxString& aMessage )
934 git_reference* rawHead =
nullptr;
936 if( git_reference_lookup( &rawHead, repo,
"HEAD" ) != GIT_OK )
938 aHandler->
AddGitError(
_(
"Could not read the current commit." ) );
943 const char* branchName = git_reference_symbolic_target( head.get() );
946 if( !branchName || aExpectedBranch.IsEmpty() || wxString::FromUTF8( branchName ) != aExpectedBranch )
949 git_reference* rawBranch =
nullptr;
950 int lookup = git_reference_lookup( &rawBranch, repo, branchName );
952 if( lookup == GIT_ENOTFOUND )
955 if( lookup != GIT_OK )
957 aHandler->
AddGitError(
_(
"Could not read the current commit." ) );
962 const git_oid* tip = git_reference_target( branch.get() );
964 if( !tip || !git_oid_equal( tip, &aExpectedHead ) )
969 aHandler->
AddErrorString(
_(
"Finish or abandon the current Git operation before undoing a commit." ) );
973 git_commit* rawCommit =
nullptr;
975 if( git_commit_lookup( &rawCommit, repo, &aExpectedHead ) != GIT_OK )
977 aHandler->
AddGitError(
_(
"Could not read the current commit." ) );
986 aHandler->
AddGitError(
_(
"Could not check whether the commit was already sent to a remote." ) );
996 if( git_commit_parentcount( commit.get() ) == 0 )
999 git_transaction* rawTransaction =
nullptr;
1000 moved = git_transaction_new( &rawTransaction, repo );
1002 std::unique_ptr<git_transaction,
decltype( &git_transaction_free )> transaction( rawTransaction,
1003 git_transaction_free );
1006 if(
moved == GIT_OK )
1007 moved = git_transaction_lock_ref( transaction.get(), branchName );
1009 if(
moved == GIT_OK )
1010 moved = git_reference_name_to_id( ¤t, repo, branchName );
1012 if(
moved == GIT_OK && !git_oid_equal( ¤t, &aExpectedHead ) )
1013 moved = GIT_EMODIFIED;
1015 if(
moved == GIT_OK )
1016 moved = git_transaction_remove( transaction.get(), branchName );
1018 if(
moved == GIT_OK )
1019 moved = git_transaction_commit( transaction.get() );
1023 git_reference* rawMoved =
nullptr;
1024 moved = git_reference_create_matching( &rawMoved, repo, branchName, git_commit_parent_id( commit.get(), 0 ), 1,
1025 &aExpectedHead,
"undo: moving to parent" );
1026 git_reference_free( rawMoved );
1029 if(
moved == GIT_EMODIFIED )
1032 if(
moved != GIT_OK )
1034 aHandler->
AddGitError(
_(
"Could not undo the commit." ) );
1038 aMessage = wxString::FromUTF8( git_commit_message( commit.get() ) );
1046 std::unique_lock<std::mutex> lock = aHandler->
GetActionLock();
1048 if( !lock.owns_lock() )
1050 wxLogTrace(
traceGit,
"GIT_PUSH_HANDLER::PerformPush: Could not lock mutex" );
1061 const wxString targetChanged =
_(
"The branch or its last commit changed while the push was waiting. "
1062 "Review the changes and try again." );
1064 auto matchesExpectedTarget = [aHandler]( git_reference* aHead )
1069 if( !aHead || !git_reference_is_branch( aHead ) )
1072 const git_oid* oid = git_reference_target( aHead );
1073 wxString branch = wxString::FromUTF8( git_reference_shorthand( aHead ) );
1074 wxString commit = oid ? wxString::FromUTF8( git_oid_tostr_s( oid ) ) : wxString();
1082 git_reference* expectedHead =
nullptr;
1083 git_repository_head( &expectedHead, aHandler->
GetRepo() );
1086 if( !matchesExpectedTarget( expectedHead ) )
1094 std::string remoteNameUtf8 = remoteName.utf8_string();
1095 git_remote* remote =
nullptr;
1097 if(
int rc = git_remote_lookup( &remote, aHandler->
GetRepo(), remoteNameUtf8.c_str() ); rc != GIT_OK )
1106 const char* pushUrl = git_remote_pushurl( remote ) ? git_remote_pushurl( remote ) : git_remote_url( remote );
1111 aHandler->
AddErrorString(
_(
"The remote changed while the push was waiting. Review it and try again." ) );
1126 bool refused =
false;
1128 auto refuse = [&](
const wxString& aMessage )
1136 auto connected = [&]() -> wxString
1138 git_reference* head =
nullptr;
1140 if( git_repository_head( &head, aHandler->
GetRepo() ) != 0 )
1141 return refuse(
_(
"Could not get the repository head." ) );
1143 headPtr.reset( head );
1147 if( !git_reference_is_branch( head ) )
1149 return refuse(
_(
"This project is showing an old snapshot rather than a branch, so there "
1150 "is nothing to push. Go back to a branch first." ) );
1153 if( !matchesExpectedTarget( head ) )
1154 return refuse( targetChanged );
1158 return wxString::Format( wxS(
"%s%s:%s" ), aForce ? wxS(
"+" ) : wxS(
"" ),
1159 wxString::FromUTF8( git_oid_tostr_s( git_reference_target( head ) ) ),
1160 wxString::FromUTF8( git_reference_name( head ) ) );
1163 if(
int pushResult = transport.
Push( connected ) )
1175 git_reference* upstreamRef =
nullptr;
1176 int rc = git_branch_upstream( &upstreamRef, headPtr.get() );
1178 if( rc == GIT_ENOTFOUND )
1180 wxString upstreamName = wxString::Format(
"%s/%s", remoteName, git_reference_shorthand( headPtr.get() ) );
1181 git_branch_set_upstream( headPtr.get(), upstreamName.utf8_string().c_str() );
1183 else if( rc == GIT_OK )
1195 std::map<wxString, FileStatus> fileStatusMap;
1199 return fileStatusMap;
1201 git_status_options status_options;
1202 git_status_init_options( &status_options, GIT_STATUS_OPTIONS_VERSION );
1203 status_options.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
1204 status_options.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
1209 status_options.flags |= GIT_STATUS_OPT_INCLUDE_UNMODIFIED;
1211 std::string pathspec_str;
1212 std::vector<const char*> pathspec_ptrs;
1214 if( !aPathspec.IsEmpty() )
1216 pathspec_str = aPathspec.utf8_string();
1217 pathspec_ptrs.push_back( pathspec_str.c_str() );
1219 status_options.pathspec.strings =
const_cast<char**
>( pathspec_ptrs.data() );
1220 status_options.pathspec.count = pathspec_ptrs.size();
1224 status_options.flags |= GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH;
1227 git_status_list* status_list =
nullptr;
1229 if( git_status_list_new( &status_list, repo, &status_options ) != GIT_OK )
1232 return fileStatusMap;
1237 size_t count = git_status_list_entrycount( status_list );
1240 for(
size_t ii = 0; ii < count; ++ii )
1242 const git_status_entry* entry = git_status_byindex( status_list, ii );
1243 std::string
path( entry->head_to_index ? entry->head_to_index->old_file.path
1244 : entry->index_to_workdir->old_file.path );
1246 wxString absPath = repoWorkDir +
path;
1247 fileStatusMap[absPath] =
FileStatus{ absPath,
1249 static_cast<unsigned int>( entry->status ) };
1252 return fileStatusMap;
1261 return wxEmptyString;
1263 git_reference* currentBranchReference =
nullptr;
1264 int rc = git_repository_head( ¤tBranchReference, repo );
1267 if( currentBranchReference )
1269 return git_reference_shorthand( currentBranchReference );
1271 else if( rc == GIT_EUNBORNBRANCH )
1273 return wxEmptyString;
1278 return wxEmptyString;
1284 const std::set<wxString>& aLocalChanges,
1285 const std::set<wxString>& aRemoteChanges,
1286 std::map<wxString, FileStatus>& aFileStatus )
1295 for(
auto& [absPath, fileStatus] : aFileStatus )
1297 wxString relativePath = absPath;
1298 if( relativePath.StartsWith( repoWorkDir ) )
1300 relativePath = relativePath.Mid( repoWorkDir.length() );
1303 relativePath.Replace( wxS(
"\\" ), wxS(
"/" ) );
1307 std::string relativePathStd = relativePath.ToStdString();
1311 if( aLocalChanges.count( relativePathStd ) )
1313 else if( aRemoteChanges.count( relativePathStd ) )
1333 git_config*
config =
nullptr;
1335 if( git_repository_config( &
config, repo ) != GIT_OK )
1343 git_config_entry* entry =
nullptr;
1344 int result = git_config_get_entry( &entry,
config, aKey.utf8_string().c_str() );
1347 if(
result != GIT_OK || entry ==
nullptr )
1349 wxLogTrace(
traceGit,
"Config key '%s' not found", aKey );
1353 aValue = wxString( entry->value );
1361 int error = git_repository_open( &repo, aPath.utf8_string().c_str() );
1365 git_repository_free( repo );
1372 return error == GIT_EOWNER;
1385 git_reference* head =
nullptr;
1388 if( git_repository_head_unborn( aRepo ) != 1 || git_reference_lookup( &head, aRepo,
"HEAD" ) != GIT_OK )
1393 if(
const char* target = git_reference_symbolic_target( head ) )
1394 wxString::FromUTF8( target ).StartsWith( wxS(
"refs/heads/" ), &
name );
1403 git_config*
config =
nullptr;
1404 git_config* local =
nullptr;
1406 if( branch.IsEmpty() || git_repository_config( &
config, aRepo ) != GIT_OK )
1411 if( git_config_open_level( &local,
config, GIT_CONFIG_LEVEL_LOCAL ) != GIT_OK )
1429 if( git_repository_init( &repo, aPath.utf8_string().c_str(), 0 ) != GIT_OK )
1432 git_repository_free( repo );
1434 aHandler->
AddError( wxString::Format(
_(
"Could not set up version control in %s." ), aPath ),
1443 aHandler->
AddGitError( wxString::Format(
_(
"Could not set up version control in %s." ), aPath ) );
1447 wxLogTrace(
traceGit,
"Successfully initialized Git repository at %s", aPath );
1454 if( aConfig.
url.IsEmpty() )
1461 aHandler->
AddErrorString(
_(
"No repository available to set up remote" ) );
1466 git_remote* remote =
nullptr;
1469 if( git_remote_lookup( &remote, repo,
"origin" ) == GIT_OK )
1472 error = git_remote_set_url( repo,
"origin", parsed.
url.utf8_str() );
1476 error = git_remote_create_with_fetchspec( &remote, repo,
"origin", parsed.
url.utf8_str(),
1477 "+refs/heads/*:refs/remotes/origin/*" );
1481 if( error != GIT_OK )
1486 context.
url = parsed.
url;
1502 wxLogTrace(
traceGit,
"Successfully set up remote origin" );
1510 if( git_reference_lookup( aReference, repo, aBranchName.utf8_string().c_str() ) == GIT_OK )
1513 return git_reference_dwim( aReference, repo, aBranchName.utf8_string().c_str() );
1527 git_reference* branchRef =
nullptr;
1531 if( rc == GIT_ENOTFOUND )
1533 aHandler->
AddError( wxString::Format(
_(
"The branch '%s' no longer exists." ), aBranchName ),
1538 aHandler->
AddError( wxString::Format(
_(
"Could not open the branch '%s'." ), aBranchName ),
1548 if( git_reference_is_remote( branchRef ) )
1550 aHandler->
AddErrorString( wxString::Format(
_(
"'%s' is a branch on the remote, so the project "
1551 "cannot be switched to it. Make a local branch from "
1557 const char* branchRefName = git_reference_name( branchRef );
1558 git_object* branchObj =
nullptr;
1560 if( git_revparse_single( &branchObj, repo, aBranchName.utf8_string().c_str() ) != GIT_OK )
1562 aHandler->
AddError( wxString::Format(
_(
"Could not open the branch '%s'." ), aBranchName ),
1570 git_checkout_options checkoutOpts;
1571 git_checkout_init_options( &checkoutOpts, GIT_CHECKOUT_OPTIONS_VERSION );
1572 checkoutOpts.checkout_strategy = GIT_CHECKOUT_SAFE;
1574 std::vector<wxString> conflictPaths;
1576 checkoutOpts.notify_flags = GIT_CHECKOUT_NOTIFY_CONFLICT;
1577 checkoutOpts.notify_payload = &conflictPaths;
1578 checkoutOpts.notify_cb = []( git_checkout_notify_t aWhy,
const char* aPath,
const git_diff_file*,
1579 const git_diff_file*,
const git_diff_file*,
void* aPayload ) ->
int
1581 if( aWhy == GIT_CHECKOUT_NOTIFY_CONFLICT && aPath )
1582 static_cast<std::vector<wxString>*
>( aPayload )->push_back( wxString::FromUTF8( aPath ) );
1587 if(
int rc = git_checkout_tree( repo, branchObj, &checkoutOpts ) )
1590 if( rc == GIT_ECONFLICT )
1593 bool anyUntracked =
false;
1594 size_t shown = std::min<size_t>( conflictPaths.size(), 10 );
1596 for(
size_t i = 0; i < shown; i++ )
1600 anyUntracked |= !tracked;
1601 wxString tag = tracked ? wxString() : wxS(
" " ) +
_(
"(never committed)" );
1603 fileList << conflictPaths[i] << tag << wxS(
"\n" );
1606 if( conflictPaths.size() > shown )
1607 fileList << wxString::Format(
_(
"and %zu more\n" ), conflictPaths.size() - shown );
1609 wxString advice = anyUntracked ?
_(
"Commit or stash your changes first. Files that were never "
1610 "committed are not included in a stash, so commit or discard "
1611 "those from the Version Control panel." )
1612 :
_(
"Commit or stash your changes first." );
1614 aHandler->
AddErrorString( wxString::Format(
_(
"Switching to branch '%s' would overwrite:\n\n"
1616 aBranchName, fileList, advice ) );
1620 aHandler->
AddError( wxString::Format(
_(
"Could not switch to the branch '%s'." ), aBranchName ),
1625 if( git_repository_set_head( repo, branchRefName ) != GIT_OK )
1627 aHandler->
AddError( wxString::Format(
_(
"Could not switch to the branch '%s'." ), aBranchName ),
1632 wxLogTrace(
traceGit,
"Successfully switched to branch '%s'", aBranchName );
1642 const std::vector<wxString>& aRemoteBranches )
1644 git_config*
config =
nullptr;
1645 git_config* local =
nullptr;
1647 if( git_repository_config( &
config, aRepo ) != GIT_OK )
1652 if( git_config_open_level( &local,
config, GIT_CONFIG_LEVEL_LOCAL ) != GIT_OK )
1665 git_branch_iterator* iterator =
nullptr;
1666 git_reference* ref =
nullptr;
1669 if( git_branch_iterator_new( &iterator, aRepo, GIT_BRANCH_LOCAL ) != GIT_OK )
1673 const int rc = git_branch_next( &ref, &type, iterator );
1676 if( rc != GIT_OK && rc != GIT_ITEROVER )
1679 git_reflog* reflog =
nullptr;
1681 if( git_reflog_read( &reflog, aRepo,
"HEAD" ) != GIT_OK )
1684 std::unique_ptr<git_reflog,
decltype( &git_reflog_free )> reflogPtr( reflog, git_reflog_free );
1687 if( rc == GIT_OK || git_reflog_entrycount( reflog ) != 0 || localName.IsEmpty()
1688 || localName != wxString::FromUTF8( marked.ptr ) )
1695 if( aRemoteBranches.empty() )
1699 if( aRemoteBranches.size() != 1 || aRemoteBranches.front() == localName )
1705 const wxString branch = aRemoteBranches.front();
1706 const wxString section = wxS(
"branch." ) + branch;
1707 git_transaction* transaction =
nullptr;
1709 if( git_config_lock( &transaction, local ) != GIT_OK )
1712 std::unique_ptr<git_transaction,
decltype( &git_transaction_free )> transactionPtr( transaction,
1713 git_transaction_free );
1716 if( git_config_set_string( local, ( section + wxS(
".remote" ) ).utf8_str(), aRemoteName.utf8_str() ) != GIT_OK
1717 || git_config_set_string( local, ( section + wxS(
".merge" ) ).utf8_str(),
1718 ( wxS(
"refs/heads/" ) + branch ).utf8_str() )
1720 || git_transaction_commit( transaction ) != GIT_OK
1721 || git_repository_set_head( aRepo, ( wxS(
"refs/heads/" ) + branch ).utf8_str() ) != GIT_OK )
1723 wxLogTrace(
traceGit,
"adoptRemoteBranch: could not move %s to %s: %s", localName, branch,
1729 wxLogTrace(
traceGit,
"adoptRemoteBranch: first commit goes to %s instead of %s", branch, localName );
1738 std::unique_lock<std::mutex> lock;
1744 if( !lock.owns_lock() )
1746 wxLogTrace(
traceGit,
"GIT_PULL_HANDLER::PerformFetch() - Could not lock mutex" );
1753 std::optional<KIGIT_COMMON::OPERATION_GUARD> operation;
1763 std::string remoteNameUtf8 = remoteName.utf8_string();
1764 git_remote* remote =
nullptr;
1766 if(
int rc = git_remote_lookup( &remote, aHandler->
GetRepo(), remoteNameUtf8.c_str() ); rc != GIT_OK )
1768 wxLogTrace(
traceGit,
"GIT_PULL_HANDLER::PerformFetch() - Failed to lookup remote '%s'", remoteName );
1776 if(
const char* url = git_remote_url( remote ) )
1787 std::vector<wxString> remoteBranches;
1789 if( transport.
Fetch( &remoteBranches ) )
1795 if( aRemoteHasBranches )
1796 *aRemoteHasBranches = !remoteBranches.empty();
1800 aHandler->
AddGitError( wxString::Format(
_(
"Fetched from '%s', but could not switch the new repository "
1801 "to the remote's branch." ),
1806 wxLogTrace(
traceGit,
"GIT_PULL_HANDLER::PerformFetch() - Fetch completed successfully" );
1813 return fetchRemote( aHandler, aSkipLock,
nullptr );
1819 const std::vector<std::string>& aPaths );
1825 git_index*
index =
nullptr;
1827 if( git_repository_index( &
index, aRepo ) == GIT_OK )
1830 git_index_read(
index, 1 );
1846 std::vector<std::string> paths;
1848 git_status_options statusOpts;
1849 git_status_init_options( &statusOpts, GIT_STATUS_OPTIONS_VERSION );
1850 statusOpts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
1852 git_status_list* statusList =
nullptr;
1854 if( git_status_list_new( &statusList, aRepo, &statusOpts ) != GIT_OK )
1859 for(
size_t ii = 0; ii < git_status_list_entrycount( statusList ); ii++ )
1861 const git_status_entry* entry = git_status_byindex( statusList, ii );
1863 if( entry->head_to_index && entry->head_to_index->new_file.path )
1864 paths.emplace_back( entry->head_to_index->new_file.path );
1865 else if( entry->index_to_workdir && entry->index_to_workdir->new_file.path )
1866 paths.emplace_back( entry->index_to_workdir->new_file.path );
1877 git_status_options statusOpts;
1878 git_status_init_options( &statusOpts, GIT_STATUS_OPTIONS_VERSION );
1879 statusOpts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
1881 git_status_list* statusList =
nullptr;
1883 if( git_status_list_new( &statusList, aRepo, &statusOpts ) != GIT_OK )
1894 std::vector<wxString>& aCollisions )
1896 git_status_options statusOpts;
1897 git_status_init_options( &statusOpts, GIT_STATUS_OPTIONS_VERSION );
1898 statusOpts.show = GIT_STATUS_SHOW_WORKDIR_ONLY;
1899 statusOpts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
1901 git_status_list* statusList =
nullptr;
1904 if( git_status_list_new( &statusList, aRepo, &statusOpts ) != GIT_OK )
1908 size_t count = git_status_list_entrycount( statusList );
1910 for(
size_t ii = 0; ii < count; ++ii )
1912 const git_status_entry* entry = git_status_byindex( statusList, ii );
1914 if( !( entry->status & GIT_STATUS_WT_NEW ) || !entry->index_to_workdir )
1917 const char*
path = entry->index_to_workdir->new_file.path;
1918 git_tree_entry* treeEntry =
nullptr;
1920 if(
path && git_tree_entry_bypath( &treeEntry, aIncomingTree,
path ) == GIT_OK )
1923 aCollisions.push_back( wxString::FromUTF8(
path ) );
1935 for(
const wxString&
path : aPaths )
1936 listed += wxS(
"\n " ) +
path;
1938 return wxString::Format(
_(
"Getting changes would overwrite files that were never committed:%s\n\n"
1939 "Commit or discard them first." ),
1948 git_reference* symbolic =
nullptr;
1949 std::string branchRefName;
1951 if( git_reference_lookup( &symbolic, repo,
"HEAD" ) == GIT_OK )
1955 if(
const char* target = git_reference_symbolic_target( symbolic ) )
1956 branchRefName = target;
1959 if( branchRefName.empty() )
1961 aHandler->
AddErrorString(
_(
"Could not get the repository head." ) );
1965 git_commit* commit =
nullptr;
1967 if( git_commit_lookup( &commit, repo, &aRemoteOid ) != GIT_OK )
1969 aHandler->
AddGitError(
_(
"Could not read the fetched commit." ) );
1974 git_tree* tree =
nullptr;
1976 if( git_commit_tree( &tree, commit ) != GIT_OK )
1978 aHandler->
AddGitError(
_(
"Could not read the fetched commit." ) );
1983 std::vector<wxString> collisions;
1987 aHandler->
AddErrorString(
_(
"Could not read the status of the project files, so getting changes was "
1988 "stopped. Files that were never committed could have been overwritten." ) );
1992 if( !collisions.empty() )
2000 git_reference* branchRef =
nullptr;
2002 wxString shorthand = wxString::FromUTF8( branchRefName );
2003 shorthand.StartsWith( wxS(
"refs/heads/" ), &shorthand );
2005 if( git_reference_create( &branchRef, repo, branchRefName.c_str(), &aRemoteOid, 0,
"pull: adopt remote history" )
2008 aHandler->
AddError( wxString::Format(
_(
"Could not create the branch '%s'." ), shorthand ),
2015 git_checkout_options checkoutOpts;
2016 git_checkout_options_init( &checkoutOpts, GIT_CHECKOUT_OPTIONS_VERSION );
2017 checkoutOpts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_RECREATE_MISSING;
2019 if( git_checkout_tree( repo,
reinterpret_cast<git_object*
>( tree ), &checkoutOpts ) != GIT_OK )
2022 bool restored = git_reference_delete( branchRef ) == GIT_OK;
2026 aHandler->
AddError( restored ?
_(
"Could not check out the remote branch, so nothing was changed." )
2027 :
_(
"Could not check out the remote branch, and the project may be partly "
2034 git_branch_set_upstream( branchRef, upstream.utf8_string().c_str() );
2043 std::unique_lock<std::mutex> lock = aHandler->
GetActionLock();
2045 if( !lock.owns_lock() )
2047 wxLogTrace(
traceGit,
"GIT_PULL_HANDLER::PerformPull() - Could not lock mutex" );
2058 bool remoteHasBranches =
true;
2060 if( !
fetchRemote( aHandler,
true, &remoteHasBranches ) )
2063 git_oid pull_merge_oid = {};
2067 aHandler->
AddGitError(
_(
"Could not read the fetched changes." ) );
2074#if ( LIBGIT2_VER_MAJOR >= 1 ) || ( LIBGIT2_VER_MINOR >= 99 )
2075 if( git_oid_is_zero( &pull_merge_oid ) )
2077 if( git_oid_iszero( &pull_merge_oid ) )
2080 git_reference* head_ref =
nullptr;
2081 wxString branch_shorthand;
2083 if( git_repository_head( &head_ref, aHandler->
GetRepo() ) == GIT_OK )
2085 if( git_reference_is_branch( head_ref ) )
2086 branch_shorthand = wxString::FromUTF8( git_reference_shorthand( head_ref ) );
2088 else if( git_repository_head_unborn( aHandler->
GetRepo() ) == 1 )
2091 git_reference* symbolic =
nullptr;
2093 if( git_reference_lookup( &symbolic, aHandler->
GetRepo(),
"HEAD" ) == GIT_OK )
2097 if(
const char* target = git_reference_symbolic_target( symbolic ) )
2098 wxString::FromUTF8( target ).StartsWith( wxS(
"refs/heads/" ), &branch_shorthand );
2104 if( !branch_shorthand.IsEmpty() )
2107 wxString remoteRefName = wxString::Format(
"refs/remotes/%s/%s", remoteName, branch_shorthand );
2109 if( git_reference_name_to_id( &pull_merge_oid, aHandler->
GetRepo(), remoteRefName.utf8_string().c_str() )
2113 wxString upstream = wxString::Format(
"%s/%s", remoteName, branch_shorthand );
2114 git_branch_set_upstream( head_ref, upstream.utf8_string().c_str() );
2119#if ( LIBGIT2_VER_MAJOR >= 1 ) || ( LIBGIT2_VER_MINOR >= 99 )
2120 if( git_oid_is_zero( &pull_merge_oid ) )
2122 if( git_oid_iszero( &pull_merge_oid ) )
2126 if( !remoteHasBranches )
2129 aHandler->
AddErrorString(
_(
"Nothing to pull: the remote has no branch matching the current local "
2144 _(
"The changes being fetched keep '%s' in Git LFS, which KiCad cannot read or write. "
2145 "Use git on the command line for this repository." ),
2151 git_annotated_commit* fetchhead_commit;
2153 if( git_annotated_commit_lookup( &fetchhead_commit, aHandler->
GetRepo(), &pull_merge_oid ) )
2155 aHandler->
AddGitError(
_(
"Could not read the fetched commit." ) );
2160 const git_annotated_commit* merge_commits[] = { fetchhead_commit };
2161 git_merge_analysis_t merge_analysis;
2162 git_merge_preference_t merge_preference = GIT_MERGE_PREFERENCE_NONE;
2164 if( git_merge_analysis( &merge_analysis, &merge_preference, aHandler->
GetRepo(), merge_commits, 1 ) )
2166 aHandler->
AddGitError(
_(
"Could not compare the fetched changes with this branch." ) );
2170 if( merge_analysis & GIT_MERGE_ANALYSIS_UNBORN )
2173 if( merge_analysis & GIT_MERGE_ANALYSIS_UP_TO_DATE )
2175 wxLogTrace(
traceGit,
"GIT_PULL_HANDLER::PerformPull() - Repository is up to date" );
2176 git_repository_state_cleanup( aHandler->
GetRepo() );
2180 if( merge_analysis & GIT_MERGE_ANALYSIS_FASTFORWARD )
2182 wxLogTrace(
traceGit,
"GIT_PULL_HANDLER::PerformPull() - Fast-forward merge" );
2186 if( merge_analysis & GIT_MERGE_ANALYSIS_NORMAL )
2188 wxLogTrace(
traceGit,
"GIT_PULL_HANDLER::PerformPull() - Normal merge" );
2190 git_config*
config =
nullptr;
2192 if( git_repository_config( &
config, aHandler->
GetRepo() ) != GIT_OK )
2194 wxLogTrace(
traceGit,
"GIT_PULL_HANDLER::PerformPull() - Failed to get repository config" );
2195 aHandler->
AddGitError(
_(
"Could not read the repository settings." ) );
2201 int rebase_value = 0;
2202 int ret = git_config_get_bool( &rebase_value,
config,
"pull.rebase" );
2204 if( ret == GIT_OK && rebase_value )
2206 wxLogTrace(
traceGit,
"GIT_PULL_HANDLER::PerformPull() - Using rebase based on config" );
2210 wxLogTrace(
traceGit,
"GIT_PULL_HANDLER::PerformPull() - Using merge based on config" );
2214 wxLogTrace(
traceGit,
"GIT_PULL_HANDLER::PerformPull() - Merge needs resolution" );
2221 git_reference* rawRef =
nullptr;
2223 if( git_repository_head( &rawRef, aHandler->
GetRepo() ) )
2225 aHandler->
AddErrorString(
_(
"Could not get the repository head." ) );
2231 git_oid updatedRefOid;
2232 const char* branch_shorthand = git_reference_shorthand( rawRef );
2234 wxString remoteBranchName;
2238 git_reference* upstreamRef =
nullptr;
2240 if( git_branch_upstream( &upstreamRef, rawRef ) == GIT_OK )
2243 remoteBranchName = wxString::FromUTF8( git_reference_name( upstreamRef ) );
2247 remoteBranchName = wxString::Format(
"refs/remotes/%s/%s", remote_name, branch_shorthand );
2250 if(
int rc = git_reference_name_to_id( &updatedRefOid, aHandler->
GetRepo(), remoteBranchName.c_str() );
2253 wxString shownName = remoteBranchName;
2254 shownName.StartsWith( wxS(
"refs/remotes/" ), &shownName );
2256 aHandler->
AddError( wxString::Format( rc == GIT_ENOTFOUND ?
_(
"Could not find the remote branch '%s'." )
2257 :
_(
"Could not read the remote branch '%s'." ),
2263 git_commit* targetCommit =
nullptr;
2265 if( git_commit_lookup( &targetCommit, aHandler->
GetRepo(), &updatedRefOid ) != GIT_OK )
2267 aHandler->
AddGitError(
_(
"Could not read the fetched commit." ) );
2273 git_tree* targetTree =
nullptr;
2275 if( git_commit_tree( &targetTree, targetCommit ) != GIT_OK )
2277 aHandler->
AddGitError(
_(
"Could not read the fetched commit." ) );
2288 aHandler->
AddGitError(
_(
"Could not read the status of the project files, so getting changes was stopped." ) );
2294 aHandler->
AddErrorString(
_(
"There are changes that are not committed yet, and getting changes would "
2295 "run over them. Commit them first." ) );
2299 std::vector<wxString> collisions;
2303 aHandler->
AddErrorString(
_(
"Could not read the status of the project files, so getting changes was "
2304 "stopped. Files that were never committed could have been overwritten." ) );
2308 if( !collisions.empty() )
2314 git_checkout_options checkoutOptions;
2315 git_checkout_init_options( &checkoutOptions, GIT_CHECKOUT_OPTIONS_VERSION );
2317 []( git_checkout_notify_t why,
const char*
path,
const git_diff_file* baseline,
2318 const git_diff_file* target,
const git_diff_file* workdir,
void* payload ) ->
int
2322 case GIT_CHECKOUT_NOTIFY_CONFLICT:
2325 case GIT_CHECKOUT_NOTIFY_DIRTY:
2328 case GIT_CHECKOUT_NOTIFY_UPDATED:
2331 case GIT_CHECKOUT_NOTIFY_UNTRACKED:
2334 case GIT_CHECKOUT_NOTIFY_IGNORED:
2344 checkoutOptions.checkout_strategy = GIT_CHECKOUT_SAFE;
2345 checkoutOptions.notify_flags = GIT_CHECKOUT_NOTIFY_ALL;
2346 checkoutOptions.notify_cb = notify_cb;
2349 git_commit* previousCommit =
nullptr;
2351 if( git_reference_peel( (git_object**) &previousCommit, rawRef, GIT_OBJECT_COMMIT ) != GIT_OK )
2353 aHandler->
AddErrorString(
_(
"Could not read the current commit." ) );
2359 if( git_checkout_tree( aHandler->
GetRepo(),
reinterpret_cast<git_object*
>( targetTree ),
2360 &checkoutOptions ) != GIT_OK )
2367 aHandler->
AddError( restored ?
_(
"Could not update the project files, so nothing was changed." )
2368 :
_(
"Could not update the project files, and they may be partly changed." ),
2373 git_reference* updatedRef =
nullptr;
2375 if( git_reference_set_target( &updatedRef, rawRef, &updatedRefOid,
nullptr ) != GIT_OK )
2383 aHandler->
AddError( restored ?
_(
"Could not move the branch, so nothing was changed." )
2384 :
_(
"Could not move the branch, and the project files may be left at the "
2385 "incoming version while the branch is not." ),
2392 if( git_repository_state_cleanup( aHandler->
GetRepo() ) != GIT_OK )
2395 wxLogTrace(
traceGit,
"handleFastForward: state cleanup failed after a completed fast-forward: %s",
2408 git_status_options opts;
2409 git_status_init_options( &opts, GIT_STATUS_OPTIONS_VERSION );
2412 opts.show = GIT_STATUS_SHOW_WORKDIR_ONLY;
2413 opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED;
2415 git_status_list* status_list =
nullptr;
2417 if( git_status_list_new( &status_list, aRepo, &opts ) != GIT_OK )
2424 size_t count = git_status_list_entrycount( status_list );
2427 for(
size_t ii = 0; ii < count; ++ii )
2429 const git_status_entry* entry = git_status_byindex( status_list, ii );
2432 if( entry->status & ( GIT_STATUS_WT_MODIFIED | GIT_STATUS_WT_DELETED | GIT_STATUS_WT_TYPECHANGE ) )
2441 size_t aMergeHeadsCount )
2446 aHandler->
AddErrorString(
_(
"Cannot merge: you have unstaged changes. Please commit or stash them "
2447 "before pulling." ) );
2455 git_signature* probe =
nullptr;
2457 if(
int rc = git_signature_default( &probe, repo ); rc != GIT_OK )
2468 git_commit* theirs =
nullptr;
2470 if( git_commit_lookup( &theirs, repo, git_annotated_commit_id( aMergeHeads[0] ) ) == GIT_OK )
2473 git_tree* theirsTree =
nullptr;
2475 if( git_commit_tree( &theirsTree, theirs ) == GIT_OK )
2478 std::vector<wxString> collisions;
2482 aHandler->
AddErrorString(
_(
"Could not read the status of the project files, so getting "
2483 "changes was stopped. Files that were never committed could "
2484 "have been overwritten." ) );
2488 if( !collisions.empty() )
2497 if( git_merge( repo, aMergeHeads, aMergeHeadsCount,
nullptr,
nullptr ) )
2499 aHandler->
AddGitError(
_(
"Could not merge the fetched changes." ) );
2503 git_index*
index =
nullptr;
2505 if( git_repository_index( &
index, repo ) != GIT_OK )
2507 aHandler->
AddErrorString(
_(
"Could not read repository index after merge." ) );
2513 if( git_index_has_conflicts(
index ) )
2516 git_object* head_obj =
nullptr;
2518 if( git_revparse_single( &head_obj, repo,
"HEAD" ) == GIT_OK )
2521 git_reset( repo, head_obj, GIT_RESET_HARD,
nullptr );
2524 git_repository_state_cleanup( repo );
2530 git_tree* tree =
nullptr;
2531 git_reference* head_ref =
nullptr;
2533 git_commit* head_commit =
nullptr;
2534 git_commit* merge_commit =
nullptr;
2535 git_signature* signature =
nullptr;
2538 auto undoMerge = [&]()
2540 git_object* headObj =
nullptr;
2542 if( git_revparse_single( &headObj, repo,
"HEAD" ) == GIT_OK )
2545 git_reset( repo, headObj, GIT_RESET_HARD,
nullptr );
2548 git_repository_state_cleanup( repo );
2551 if( git_index_write_tree( &tree_oid,
index ) != GIT_OK || git_tree_lookup( &tree, repo, &tree_oid ) != GIT_OK )
2560 if( git_repository_head( &head_ref, repo ) != GIT_OK )
2562 aHandler->
AddErrorString(
_(
"Could not get the repository head." ) );
2569 if( git_reference_name_to_id( &head_oid, repo,
"HEAD" ) != GIT_OK
2570 || git_commit_lookup( &head_commit, repo, &head_oid ) != GIT_OK
2571 || git_commit_lookup( &merge_commit, repo, git_annotated_commit_id( aMergeHeads[0] ) ) != GIT_OK )
2573 aHandler->
AddErrorString(
_(
"Could not look up the commits to merge." ) );
2581 if(
int rc = git_signature_default( &signature, repo ); rc != GIT_OK )
2591 const git_commit* parents[] = { head_commit, merge_commit };
2592 wxString
message = wxString::Format(
_(
"Merge remote-tracking branch into %s" ),
2593 git_reference_shorthand( head_ref ) );
2594 git_oid merge_commit_oid;
2596 if( git_commit_create( &merge_commit_oid, repo,
"HEAD", signature, signature,
nullptr,
2597 message.utf8_string().c_str(), tree, 2, parents ) != GIT_OK )
2599 aHandler->
AddGitError(
_(
"Could not create the merge commit." ) );
2604 git_repository_state_cleanup( repo );
2611 git_signature* signature =
nullptr;
2613 if(
int rc = git_signature_default( &signature, aRepo ); rc != GIT_OK )
2621 git_rebase_options rebase_opts;
2622 git_rebase_init_options( &rebase_opts, GIT_REBASE_OPTIONS_VERSION );
2623 git_rebase* rebase =
nullptr;
2625 if( git_rebase_init( &rebase, aRepo,
nullptr, aOnto,
nullptr, &rebase_opts ) != GIT_OK )
2627 aHandler->
AddGitError(
_(
"Could not start the rebase." ) );
2632 git_rebase_operation* op =
nullptr;
2633 int nextResult = GIT_OK;
2635 while( ( nextResult = git_rebase_next( &op, rebase ) ) == GIT_OK )
2638 int commitResult = git_rebase_commit( &commit_oid, rebase,
nullptr, signature,
nullptr,
nullptr );
2641 if( commitResult == GIT_EAPPLIED )
2644 if( commitResult != GIT_OK )
2647 git_rebase_abort( rebase );
2649 if( commitResult == GIT_EUNMERGED )
2651 aHandler->
AddErrorString(
_(
"The rebase ran into conflicts. This is best resolved from a "
2652 "git command line." ) );
2656 aHandler->
AddError(
_(
"Could not rebase your commits onto the fetched changes." ), gitError );
2661 if( nextResult != GIT_ITEROVER )
2664 git_rebase_abort( rebase );
2665 aHandler->
AddError(
_(
"Could not rebase your commits onto the fetched changes." ), gitError );
2669 if( git_rebase_finish( rebase, signature ) != GIT_OK )
2672 git_rebase_abort( rebase );
2673 aHandler->
AddError(
_(
"Could not finish the rebase." ), gitError );
2682 size_t aMergeHeadsCount )
2687 aHandler->
AddErrorString(
_(
"Cannot pull with rebase: you have unstaged changes. Please commit or stash "
2688 "them before pulling." ) );
2702 if(
int rc = git_repository_open_ext( &repo, aFilename, 0,
nullptr ); rc != GIT_OK )
2708 if( rc == GIT_EOWNER && aError )
2712 if( git_repository_discover( &gitDir, aFilename, 0,
nullptr ) == GIT_OK )
2716 wxString::FromUTF8( gitDir.ptr ) );
2725 *aTrustCommand =
refusal.trustCommand;
2740 std::string start = aFrom.IsEmpty() ? std::string(
"HEAD" ) : aFrom.utf8_string();
2741 git_object* startObj =
nullptr;
2743 if(
int error = git_revparse_single( &startObj, aRepo, start.c_str() ); error != GIT_OK )
2750 git_object* peeled =
nullptr;
2752 if(
int error = git_object_peel( &peeled, startObj, GIT_OBJECT_COMMIT ); error != GIT_OK )
2759 git_commit* commit =
reinterpret_cast<git_commit*
>( peeled );
2760 git_reference* branchRef =
nullptr;
2762 std::string
name = aBranchName.utf8_string();
2764 if(
int error = git_branch_create( &branchRef, aRepo,
name.c_str(), commit, 0 ); error != GIT_OK )
2770 git_reference_free( branchRef );
2777 if( !aRepo || aBranchName.IsEmpty() )
2780 git_reference* branch =
nullptr;
2782 if( git_branch_lookup( &branch, aRepo, aBranchName.utf8_string().c_str(), GIT_BRANCH_LOCAL ) != GIT_OK )
2786 return git_branch_delete( branch ) == GIT_OK;
2795 git_signature* signature =
nullptr;
2797 if( git_signature_default( &signature, aRepo ) != GIT_OK )
2804 git_index*
index =
nullptr;
2806 if( git_repository_index( &
index, aRepo ) != GIT_OK )
2811 if( git_index_read(
index,
true ) != GIT_OK || git_index_write(
index ) != GIT_OK )
2814 std::string
message = aMessage.utf8_string();
2817 return git_stash_save( &stashOid, aRepo, signature,
message.empty() ?
nullptr :
message.c_str(), GIT_STASH_DEFAULT )
2824 const std::vector<std::string>& aPaths );
2836 git_error_set_str( GIT_ERROR_STASH,
_(
"Commit or discard the current changes first, so the stash has "
2837 "a clean version to apply to." )
2845 if( git_reference_name_to_id( &headOid, aRepo,
"HEAD" ) != GIT_OK )
2848 git_commit* headCommit =
nullptr;
2850 if( git_commit_lookup( &headCommit, aRepo, &headOid ) != GIT_OK )
2855 if( git_stash_apply( aRepo, aIndex,
nullptr ) != GIT_OK )
2860 git_index*
index =
nullptr;
2861 bool conflicted = git_repository_index( &
index, aRepo ) != GIT_OK || git_index_has_conflicts(
index );
2868 git_error_set_str( GIT_ERROR_STASH,
_(
"The stash does not fit on top of the current version of the "
2869 "files, so nothing was changed. Restore the version it was made "
2870 "on from History, then apply it there." )
2894 return aRepo && git_stash_drop( aRepo, aIndex ) == GIT_OK;
2900 if( !aRepo || aName.IsEmpty() )
2903 git_object* target =
nullptr;
2905 if( git_revparse_single( &target, aRepo,
"HEAD" ) != GIT_OK )
2911 if( aMessage.IsEmpty() )
2912 return git_tag_create_lightweight( &oid, aRepo, aName.utf8_string().c_str(), target, 0 ) == GIT_OK;
2915 git_signature* tagger =
nullptr;
2917 if( git_signature_default( &tagger, aRepo ) != GIT_OK )
2921 std::string
name = aName.utf8_string();
2922 std::string
message = aMessage.utf8_string();
2924 return git_tag_create( &oid, aRepo,
name.c_str(), target, tagger,
message.c_str(), 0 ) == GIT_OK;
2930 if( !aRepo || aName.IsEmpty() )
2933 return git_tag_delete( aRepo, aName.utf8_string().c_str() ) == GIT_OK;
2939 if( !aRepo || aName.IsEmpty() )
2942 git_object* target =
nullptr;
2943 wxString spec = aName + wxT(
"^{commit}" );
2945 if( git_revparse_single( &target, aRepo, spec.utf8_string().c_str() ) != GIT_OK )
2950 git_checkout_options opts;
2951 git_checkout_options_init( &opts, GIT_CHECKOUT_OPTIONS_VERSION );
2952 opts.checkout_strategy = GIT_CHECKOUT_SAFE;
2954 if( git_checkout_tree( aRepo, target, &opts ) != GIT_OK )
2957 return git_repository_set_head_detached( aRepo, git_object_id( target ) ) == GIT_OK;
2963 if( !aRepo || aName.IsEmpty() )
2966 git_remote* remote =
nullptr;
2968 if( git_remote_create( &remote, aRepo, aName.utf8_string().c_str(), aUrl.utf8_string().c_str() ) != GIT_OK )
2978 if( !aRepo || aName.IsEmpty() )
2981 return git_remote_set_url( aRepo, aName.utf8_string().c_str(), aUrl.utf8_string().c_str() ) == GIT_OK;
2987 if( !aRepo || aName.IsEmpty() )
2990 return git_remote_delete( aRepo, aName.utf8_string().c_str() ) == GIT_OK;
2999 git_config*
config =
nullptr;
3001 if( git_repository_config( &
config, aRepo ) != GIT_OK )
3006 bool ok = git_config_set_string(
config,
"user.name", aName.utf8_string().c_str() ) == GIT_OK;
3007 ok = ok && git_config_set_string(
config,
"user.email", aEmail.utf8_string().c_str() ) == GIT_OK;
3016bool writeConflictSide(
git_repository* aRepo,
const git_index_entry* aEntry,
const wxString& aDest )
3020 if( !out.Create( aDest,
true, wxS_IRUSR | wxS_IWUSR ) )
3026 git_blob* blob =
nullptr;
3028 if( git_blob_lookup( &blob, aRepo, &aEntry->id ) != GIT_OK )
3033 const void* raw = git_blob_rawcontent( blob );
3034 git_off_t size = git_blob_rawsize( blob );
3036 return out.Write( raw,
static_cast<size_t>( size ) ) ==
static_cast<size_t>( size );
3046 if( git_reference_name_to_id( &oursOid, aRepo,
"HEAD" ) != GIT_OK )
3048 aError =
_(
"Could not get the repository head." );
3054 if( !aPinnedTheirsOid.IsEmpty() )
3057 if( git_oid_fromstr( &theirsOid, aPinnedTheirsOid.utf8_string().c_str() ) != GIT_OK )
3059 aError =
_(
"Could not find the fetched remote commit." );
3065 git_object* fetchHead =
nullptr;
3067 if( git_revparse_single( &fetchHead, aRepo,
"FETCH_HEAD" ) != GIT_OK )
3069 aError =
_(
"Could not find the fetched remote commit." );
3074 theirsOid = *git_object_id( fetchHead );
3077 git_commit* ours =
nullptr;
3079 if( git_commit_lookup( &ours, aRepo, &oursOid ) != GIT_OK )
3081 aError =
_(
"Could not look up the commits to merge." );
3085 aOursOut.reset( ours );
3087 git_commit* theirs =
nullptr;
3089 if( git_commit_lookup( &theirs, aRepo, &theirsOid ) != GIT_OK )
3091 aError =
_(
"Could not look up the commits to merge." );
3095 aTheirsOut.reset( theirs );
3097 git_tree* oursTree =
nullptr;
3099 if( git_commit_tree( &oursTree, ours ) != GIT_OK )
3101 aError =
_(
"Could not read the commit trees." );
3106 git_tree* theirsTree =
nullptr;
3108 if( git_commit_tree( &theirsTree, theirs ) != GIT_OK )
3110 aError =
_(
"Could not read the commit trees." );
3120 if( git_merge_base( &baseOid, aRepo, &oursOid, &theirsOid ) == GIT_OK )
3122 git_commit* baseCommit =
nullptr;
3124 if( git_commit_lookup( &baseCommit, aRepo, &baseOid ) == GIT_OK )
3127 git_tree* baseTree =
nullptr;
3129 if( git_commit_tree( &baseTree, baseCommit ) == GIT_OK )
3130 baseTreePtr.reset( baseTree );
3134 git_merge_options mergeOpts;
3135 git_index* mergedIndex =
nullptr;
3137 git_merge_options_init( &mergeOpts, GIT_MERGE_OPTIONS_VERSION );
3139 if( git_merge_trees( &mergedIndex, aRepo, baseTreePtr.get(), oursTree, theirsTree, &mergeOpts ) != GIT_OK )
3145 aIndexOut.reset( mergedIndex );
3155 if( aPaths.empty() )
3158 git_tree* tree =
nullptr;
3160 if( git_commit_tree( &tree, aCommit ) != GIT_OK )
3164 std::vector<char*> pathSpec;
3167 for(
const std::string&
path : aPaths )
3168 pathSpec.push_back(
const_cast<char*
>(
path.c_str() ) );
3170 git_checkout_options checkoutOpts;
3171 git_checkout_init_options( &checkoutOpts, GIT_CHECKOUT_OPTIONS_VERSION );
3172 checkoutOpts.checkout_strategy = GIT_CHECKOUT_FORCE | GIT_CHECKOUT_REMOVE_UNTRACKED;
3173 checkoutOpts.paths.strings = pathSpec.data();
3174 checkoutOpts.paths.count = pathSpec.size();
3176 return git_checkout_tree( aRepo,
reinterpret_cast<git_object*
>( tree ), &checkoutOpts ) == GIT_OK;
3181static bool treeHolds( git_tree* aTree,
const char* aPath,
const git_oid& aOnDisk )
3183 git_tree_entry* entry =
nullptr;
3185 if( git_tree_entry_bypath( &entry, aTree, aPath ) != GIT_OK )
3190 return git_oid_equal( &aOnDisk, git_tree_entry_id( entry ) );
3197 const char* workdir = git_repository_workdir( aRepo );
3203 if( !wxFileName::Exists( wxString::FromUTF8( workdir ) + wxString::FromUTF8( aPath ) ) )
3209 if( git_repository_hashfile( &onDisk, aRepo, aPath, GIT_OBJECT_BLOB,
nullptr ) != GIT_OK )
3212 return treeHolds( aWrittenTree, aPath, onDisk ) ||
treeHolds( aPreviousTree, aPath, onDisk );
3220 git_tree* previousTree =
nullptr;
3222 if( git_commit_tree( &previousTree, aHeadCommit ) != GIT_OK )
3227 git_diff* diff =
nullptr;
3229 if( git_diff_tree_to_tree( &diff, aRepo, previousTree, aWrittenTree,
nullptr ) != GIT_OK )
3234 std::set<std::string> touched;
3236 for(
size_t ii = 0; ii < git_diff_num_deltas( diff ); ii++ )
3238 const git_diff_delta*
delta = git_diff_get_delta( diff, ii );
3241 for(
const char*
path : {
delta->old_file.path,
delta->new_file.path } )
3244 touched.emplace(
path );
3248 std::vector<std::string> restorable;
3249 bool leftBehind =
false;
3251 for(
const std::string&
path : touched )
3254 restorable.push_back(
path );
3259 if( restorable.empty() )
3279 git_reference* aHeadRef, git_commit* aRollbackCommit,
3280 const char* aReflogLabel, wxString& aGitError )
3282 git_checkout_options checkoutOpts;
3283 git_checkout_options_init( &checkoutOpts, GIT_CHECKOUT_OPTIONS_VERSION );
3284 checkoutOpts.checkout_strategy = GIT_CHECKOUT_FORCE;
3286 if( git_checkout_tree( aRepo,
reinterpret_cast<git_object*
>( aTree ), &checkoutOpts ) != GIT_OK )
3297 git_reference* updatedRef =
nullptr;
3299 if( git_reference_set_target( &updatedRef, aHeadRef, &aCommitOid, aReflogLabel ) != GIT_OK )
3323 aError.
details =
_(
"The project has no git repository." );
3329 if( !projectPrefix )
3331 aError.
details =
_(
"Could not work out which folder this project occupies in the repository, "
3332 "so nothing was restored." );
3336 git_object* targetObj =
nullptr;
3338 if( git_revparse_single( &targetObj, repo, aCommitHash.utf8_string().c_str() ) != GIT_OK )
3340 aError.
details =
_(
"Could not find that version." );
3345 git_commit* targetCommit =
nullptr;
3347 if( git_object_type( targetObj ) != GIT_OBJECT_COMMIT
3348 || git_commit_lookup( &targetCommit, repo, git_object_id( targetObj ) ) != GIT_OK )
3350 aError.
details =
_(
"Could not find that version." );
3355 git_tree* targetTree =
nullptr;
3357 if( git_commit_tree( &targetTree, targetCommit ) != GIT_OK )
3359 aError.
details =
_(
"Could not read that version's contents." );
3365 git_reference* headRef =
nullptr;
3367 if( git_repository_head( &headRef, repo ) != GIT_OK )
3369 aError.
details =
_(
"Could not get the repository head." );
3374 git_commit* headCommit =
nullptr;
3376 if( git_reference_peel( (git_object**) &headCommit, headRef, GIT_OBJECT_COMMIT ) != GIT_OK )
3378 aError.
details =
_(
"Could not get the repository head." );
3383 git_tree* headTree =
nullptr;
3385 if( git_commit_tree( &headTree, headCommit ) != GIT_OK )
3387 aError.
details =
_(
"Could not get the repository head." );
3395 git_tree* effectiveTree = targetTree;
3397 if( !projectPrefix->IsEmpty() )
3400 std::string prefixUtf8( projectPrefix->BeforeLast(
'/' ).utf8_string() );
3401 git_tree_entry* subtreeEntry =
nullptr;
3403 if( git_tree_entry_bypath( &subtreeEntry, targetTree, prefixUtf8.c_str() ) != GIT_OK )
3405 aError.
details =
_(
"That version does not contain this project's folder." );
3411 if( git_tree_entry_type( subtreeEntry ) != GIT_OBJECT_TREE )
3413 aError.
details =
_(
"That version does not contain this project's folder." );
3417 git_tree_update update;
3418 update.action = GIT_TREE_UPDATE_UPSERT;
3419 update.id = *git_tree_entry_id( subtreeEntry );
3420 update.filemode = GIT_FILEMODE_TREE;
3421 update.path = prefixUtf8.c_str();
3423 git_oid combinedOid;
3425 if( git_tree_create_updated( &combinedOid, repo, headTree, 1, &update ) != GIT_OK )
3427 aError.
details = wxString::Format(
_(
"Could not build the restored content: %s" ),
3434 if( git_tree_lookup( &
combined, repo, &combinedOid ) != GIT_OK )
3436 aError.
details =
_(
"Could not build the restored content." );
3440 effectiveTreePtr.reset(
combined );
3447 git_status_options statusOpts;
3448 git_status_init_options( &statusOpts, GIT_STATUS_OPTIONS_VERSION );
3449 statusOpts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
3450 statusOpts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
3452 git_status_list* statusList =
nullptr;
3454 if( git_status_list_new( &statusList, repo, &statusOpts ) != GIT_OK )
3456 aError.
details =
_(
"Could not read the repository status." );
3462 size_t count = git_status_list_entrycount( statusList );
3464 for(
size_t ii = 0; ii < count && !dirty; ++ii )
3466 const git_status_entry* entry = git_status_byindex( statusList, ii );
3468 if( entry->status == GIT_STATUS_WT_NEW )
3470 const char*
path = entry->index_to_workdir ? entry->index_to_workdir->new_file.path :
nullptr;
3474 git_tree_entry* treeEntry =
nullptr;
3476 if( git_tree_entry_bypath( &treeEntry, effectiveTree,
path ) == GIT_OK )
3493 if( git_oid_equal( git_commit_tree_id( headCommit ), git_tree_id( effectiveTree ) ) )
3496 git_signature* signature =
nullptr;
3498 if(
int rc = git_signature_default( &signature, repo ); rc != GIT_OK )
3506 char shortHash[13] = { 0 };
3507 git_oid_tostr( shortHash,
sizeof( shortHash ), git_commit_id( targetCommit ) );
3511 const git_commit* parents[] = { headCommit };
3512 wxString
message = wxString::Format(
_(
"Restore version %s" ), shortHash );
3513 git_oid restoreCommitOid;
3515 if( git_commit_create( &restoreCommitOid, repo,
nullptr, signature, signature,
nullptr,
3516 message.utf8_string().c_str(), effectiveTree, 1, parents )
3526 switch(
publishPreparedCommit( repo, effectiveTree, restoreCommitOid, headRef, headCommit,
"restore", gitError ) )
3532 wxString::Format(
_(
"Could not update the working files, so nothing was changed: %s" ), gitError );
3536 aError.
details = wxString::Format(
_(
"Could not update the working files, and they may be partially "
3543 wxString::Format(
_(
"Could not record the restore commit, so nothing was changed: %s" ), gitError );
3547 aError.
details = wxString::Format(
_(
"Could not record the restore commit, and the working files may "
3548 "have been changed: %s" ),
3561 aError =
_(
"The project has no git repository." );
3565 if( aPaths.empty() )
3568 std::vector<std::string> pathStorage;
3569 std::vector<char*> pathPtrs;
3570 std::vector<wxString> neverCommitted;
3572 for(
const wxString&
path : aPaths )
3575 pathStorage.push_back(
path.utf8_string() );
3577 neverCommitted.push_back(
path );
3581 if( !neverCommitted.empty() )
3583 git_index*
index =
nullptr;
3585 if( git_repository_index( &
index, aRepo ) != GIT_OK )
3593 for(
const wxString&
path : neverCommitted )
3594 git_index_remove_bypath(
index,
path.utf8_string().c_str() );
3596 if( git_index_write(
index ) != GIT_OK )
3603 if( pathStorage.empty() )
3606 for( std::string&
path : pathStorage )
3607 pathPtrs.push_back(
path.data() );
3609 git_checkout_options opts;
3610 git_checkout_init_options( &opts, GIT_CHECKOUT_OPTIONS_VERSION );
3614 opts.checkout_strategy = GIT_CHECKOUT_FORCE | GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH;
3615 opts.paths.strings = pathPtrs.data();
3616 opts.paths.count = pathPtrs.size();
3618 if( git_checkout_head( aRepo, &opts ) != GIT_OK )
3635 if( git_reference_name_to_id( &headOid, aRepo,
"HEAD" ) != GIT_OK )
3638 git_commit* headCommit =
nullptr;
3640 if( git_commit_lookup( &headCommit, aRepo, &headOid ) != GIT_OK )
3644 git_tree* headTree =
nullptr;
3646 if( git_commit_tree( &headTree, headCommit ) != GIT_OK )
3650 git_tree_entry* entry =
nullptr;
3652 if( git_tree_entry_bypath( &entry, headTree, aPath.utf8_string().c_str() ) != GIT_OK )
3665 aError =
_(
"The project has no git repository." );
3671 const wxString rebaseIsAnotherProgram =
3672 _(
"This rebase was started by another program, and only that program can finish or abort it." );
3674 switch( git_repository_state( aRepo ) )
3676 case GIT_REPOSITORY_STATE_NONE:
return true;
3678 case GIT_REPOSITORY_STATE_REBASE_MERGE:
3679 case GIT_REPOSITORY_STATE_REBASE_INTERACTIVE:
3683 git_rebase* rebase =
nullptr;
3685 if( git_rebase_open( &rebase, aRepo,
nullptr ) != GIT_OK )
3687 aError = rebaseIsAnotherProgram;
3693 if( git_rebase_abort( rebase ) != GIT_OK )
3695 aError = rebaseIsAnotherProgram;
3702 case GIT_REPOSITORY_STATE_BISECT:
3705 aError =
_(
"This project is in the middle of a search through its history, started by another "
3706 "program. Only that program can end the search and bring the project back." );
3709 case GIT_REPOSITORY_STATE_REBASE:
3710 case GIT_REPOSITORY_STATE_APPLY_MAILBOX:
3711 case GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE:
3712 aError = rebaseIsAnotherProgram;
3718 git_object* head =
nullptr;
3720 if( git_revparse_single( &head, aRepo,
"HEAD" ) != GIT_OK )
3727 git_tree* headTree =
nullptr;
3729 if( git_object_peel(
reinterpret_cast<git_object**
>( &headTree ), head, GIT_OBJECT_TREE ) != GIT_OK )
3736 git_index*
index =
nullptr;
3738 if( git_repository_index( &
index, aRepo ) != GIT_OK )
3749 std::set<std::string> touched;
3752 git_index_conflict_iterator* conflicts =
nullptr;
3754 if( git_index_conflict_iterator_new( &conflicts,
index ) == GIT_OK )
3756 const git_index_entry* ancestor =
nullptr;
3757 const git_index_entry* ours =
nullptr;
3758 const git_index_entry* theirs =
nullptr;
3760 while( git_index_conflict_next( &ancestor, &ours, &theirs, conflicts ) == GIT_OK )
3762 for(
const git_index_entry* entry : { ancestor, ours, theirs } )
3764 if( entry && entry->path )
3765 touched.insert( entry->path );
3769 git_index_conflict_iterator_free( conflicts );
3772 git_diff* diff =
nullptr;
3774 if( git_diff_tree_to_index( &diff, aRepo, headTree,
index,
nullptr ) != GIT_OK )
3783 [&touched](
const git_diff_delta& aDelta )
3785 if( aDelta.old_file.path )
3786 touched.insert( aDelta.old_file.path );
3788 if( aDelta.new_file.path )
3789 touched.insert( aDelta.new_file.path );
3792 if( !touched.empty() )
3794 std::vector<char*> paths;
3796 for(
const std::string&
path : touched )
3797 paths.push_back(
const_cast<char*
>(
path.c_str() ) );
3799 git_checkout_options checkoutOpts;
3800 git_checkout_options_init( &checkoutOpts, GIT_CHECKOUT_OPTIONS_VERSION );
3801 checkoutOpts.checkout_strategy = GIT_CHECKOUT_FORCE;
3802 checkoutOpts.paths.strings = paths.data();
3803 checkoutOpts.paths.count = paths.size();
3805 if( git_checkout_head( aRepo, &checkoutOpts ) != GIT_OK )
3812 if( git_repository_state_cleanup( aRepo ) != GIT_OK )
3823 wxString& aTheirsOid, std::vector<KIGIT_CONFLICT_SIDES>& aConflicts,
3830 aError =
_(
"The project has no git repository." );
3838 if( !remergeInMemory( aRepo, wxEmptyString, mergedIndex, ours, theirs, aError ) )
3842 char theirsStr[GIT_OID_HEXSZ + 1] = { 0 };
3843 git_oid_tostr( theirsStr,
sizeof( theirsStr ), git_commit_id( theirs.get() ) );
3844 aTheirsOid = wxString::FromUTF8( theirsStr );
3847 if( !git_index_has_conflicts( mergedIndex.get() ) )
3849 aError =
_(
"The merge has no conflicts." );
3853 if( !wxFileName::Mkdir( aStageDir, 0700, wxPATH_MKDIR_FULL ) )
3855 aError =
_(
"Could not create a temporary directory." );
3859 char oidStr[GIT_OID_HEXSZ + 1] = { 0 };
3860 git_oid_tostr( oidStr,
sizeof( oidStr ), git_commit_id( ours.get() ) );
3861 aHeadOid = wxString::FromUTF8( oidStr );
3863 git_index_conflict_iterator* iter =
nullptr;
3865 if( git_index_conflict_iterator_new( &iter, mergedIndex.get() ) != GIT_OK )
3867 aError =
_(
"Could not list the merge conflicts." );
3873 const git_index_entry* ancestor =
nullptr;
3874 const git_index_entry* mine =
nullptr;
3875 const git_index_entry* remote =
nullptr;
3876 const wxString sep = wxFileName::GetPathSeparator();
3879 while( git_index_conflict_next( &ancestor, &mine, &remote, iter ) == GIT_OK )
3881 const git_index_entry* named = mine ? mine : ( remote ? remote : ancestor );
3887 sides.
path = wxString::FromUTF8( named->path );
3889 sides.
hasOurs = mine !=
nullptr;
3892 wxString base = wxFileName( sides.
path ).GetFullName();
3893 sides.
ancestorFile = aStageDir + sep + wxString::Format( wxS(
"c%d_base_%s" ), n, base );
3894 sides.
oursFile = aStageDir + sep + wxString::Format( wxS(
"c%d_mine_%s" ), n, base );
3895 sides.
theirsFile = aStageDir + sep + wxString::Format( wxS(
"c%d_remote_%s" ), n, base );
3898 if( !writeConflictSide( aRepo, ancestor, sides.
ancestorFile )
3899 || !writeConflictSide( aRepo, mine, sides.
oursFile )
3900 || !writeConflictSide( aRepo, remote, sides.
theirsFile ) )
3902 aError =
_(
"Could not extract the conflicting file versions." );
3906 aConflicts.push_back( sides );
3909 return !aConflicts.empty();
3914 const wxString& aTheirsOid,
3915 const std::vector<std::pair<wxString, wxString>>& aResolvedFiles,
3920 aError.
details =
_(
"The project has no git repository." );
3928 git_status_options statusOpts;
3929 git_status_init_options( &statusOpts, GIT_STATUS_OPTIONS_VERSION );
3930 statusOpts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
3932 git_status_list* statusList =
nullptr;
3934 if( git_status_list_new( &statusList, aRepo, &statusOpts ) != GIT_OK )
3936 aError.
details =
_(
"Could not read the repository status." );
3942 if( git_status_list_entrycount( statusList ) > 0 )
3944 aError.
details =
_(
"Files changed while the conflicts were being resolved, and finishing the "
3945 "merge would overwrite those changes. Get changes again to redo the merge "
3946 "with the current files." );
3955 if( !remergeInMemory( aRepo, aTheirsOid, mergedIndex, ours, theirs, aError.
details ) )
3958 char oidStr[GIT_OID_HEXSZ + 1] = { 0 };
3959 git_oid_tostr( oidStr,
sizeof( oidStr ), git_commit_id( ours.get() ) );
3962 if( aExpectedHeadOid != wxString::FromUTF8( oidStr ) )
3964 aError.
details =
_(
"The repository changed while resolving. Get changes again." );
3968 for(
const auto& [
path, resolvedFile] : aResolvedFiles )
3970 std::string pathUtf8(
path.utf8_string() );
3971 const git_index_entry* mine =
nullptr;
3972 const git_index_entry* remote =
nullptr;
3973 const git_index_entry* ancestor =
nullptr;
3975 git_index_conflict_get( &ancestor, &mine, &remote, mergedIndex.get(), pathUtf8.c_str() );
3978 if( resolvedFile.IsEmpty() )
3980 if( git_index_conflict_remove( mergedIndex.get(), pathUtf8.c_str() ) != GIT_OK )
3982 aError.
details = wxString::Format(
_(
"Could not mark '%s' as resolved." ),
path );
3989 std::ifstream in( resolvedFile.fn_str(), std::ios::binary );
3993 aError.
details = wxString::Format(
_(
"Could not read the resolved file for '%s'." ),
path );
3997 std::string
bytes( ( std::istreambuf_iterator<char>( in ) ), std::istreambuf_iterator<char>() );
4000 git_writestream* stream =
nullptr;
4003 bool stored = git_blob_create_from_stream( &stream, aRepo, pathUtf8.c_str() ) == GIT_OK;
4005 if( stored && stream->write( stream,
bytes.data(),
bytes.size() ) != GIT_OK )
4007 stream->free( stream );
4011 if( !stored || git_blob_create_from_stream_commit( &blobOid, stream ) != GIT_OK )
4013 aError.
details = wxString::Format(
_(
"Could not store the resolved file for '%s'." ),
path );
4017 git_index_entry entry;
4018 memset( &entry, 0,
sizeof( entry ) );
4019 entry.path = pathUtf8.c_str();
4021 entry.mode = mine ? mine->mode : ( remote ? remote->mode : GIT_FILEMODE_BLOB );
4023 if( git_index_conflict_remove( mergedIndex.get(), pathUtf8.c_str() ) != GIT_OK
4024 || git_index_add( mergedIndex.get(), &entry ) != GIT_OK )
4026 aError.
details = wxString::Format(
_(
"Could not mark '%s' as resolved." ),
path );
4031 if( git_index_has_conflicts( mergedIndex.get() ) )
4033 aError.
details =
_(
"Not every conflict was resolved." );
4039 if( git_index_write_tree_to( &treeOid, mergedIndex.get(), aRepo ) != GIT_OK )
4041 aError.
details =
_(
"Could not write the merge result." );
4045 git_tree* tree =
nullptr;
4047 if( git_tree_lookup( &tree, aRepo, &treeOid ) != GIT_OK )
4049 aError.
details =
_(
"Could not write the merge result." );
4055 git_signature* signature =
nullptr;
4057 if(
int rc = git_signature_default( &signature, aRepo ); rc != GIT_OK )
4065 git_reference* headRef =
nullptr;
4067 if( git_repository_head( &headRef, aRepo ) != GIT_OK )
4069 aError.
details =
_(
"Could not get the repository head." );
4075 const git_commit* parents[] = { ours.get(), theirs.get() };
4077 wxString::Format(
_(
"Merge remote-tracking branch into %s" ), git_reference_shorthand( headRef ) );
4078 git_oid mergeCommitOid;
4081 if( git_commit_create( &mergeCommitOid, aRepo,
nullptr, signature, signature,
nullptr,
4082 message.utf8_string().c_str(), tree, 2, parents )
4092 switch(
publishPreparedCommit( aRepo, tree, mergeCommitOid, headRef, ours.get(),
"merge", gitError ) )
4098 wxString::Format(
_(
"Could not update the working files, so nothing was changed: %s" ), gitError );
4102 aError.
details = wxString::Format(
_(
"Could not update the working files, and they may be partially "
4109 wxString::Format(
_(
"Could not record the merge commit, so nothing was changed: %s" ), gitError );
4113 aError.
details = wxString::Format(
_(
"Could not record the merge commit, and the working files may "
4114 "have been changed: %s" ),
4128 git_repository_free( aRepo );
4134 wxFileName gitDir( aProjectPath, wxEmptyString );
4135 gitDir.AppendDir(
".git" );
4137 if( gitDir.DirExists() )
4146 wxLogTrace(
traceGit,
"Failed to remove .git directory: %s", errors );
4152 wxLogTrace(
traceGit,
"Successfully removed VCS from project" );
KIGIT_ORPHAN_REGISTRY m_orphanRegistry
wxString GetClonePath() const
bool MatchesExpectedDestination(const wxString &aRemoteName, const wxString &aPushUrl) const
True without an expectation, or when both values match the confirmed destination.
bool MatchesExpectedTarget(const wxString &aBranch, const wxString &aHeadOid) const
True without an expectation, or when both values match the captured target.
bool HasExpectedDestination() const
bool HasExpectedTarget() const
KIGIT_COMMON::GIT_STATUS ConvertStatus(unsigned int aGitStatus)
Convert git status flags to KIGIT_COMMON::GIT_STATUS.
static bool ProjectUsesGitLfs(const KIGIT_COMMON &aCommon, wxString *aExample=nullptr, const git_oid *aCommit=nullptr)
Whether any committed file in the project's folder goes through Git LFS.
const KIGIT_ERROR_INFO & Error() const
libgit2's error for the last call that failed, read before anything else could replace it
int Fetch(std::vector< wxString > *aBranches=nullptr)
Fetch as git fetch would. aBranches, when given, receives the branches the remote advertised.
int Clone(const wxString &aUrl, const wxString &aPath, git_repository **aRepo)
Clone aUrl into aPath. The new repository is returned in aRepo for the caller to free.
int Push(const std::function< wxString()> &aConnected)
Connect, then push the refspec aConnected answers, so the caller can check what it pushes after a con...
Publishes a token for as long as its operation runs.
The project's git session.
void SyncRemoteUrl(const wxString &aRawUrl)
Bind the session to the URL a transfer is about to connect to.
std::optional< wxString > GetProjectPrefix() const
Project folder relative to the repository, with a trailing slash.
wxString GetRemote() const
bool IsOperationInProgress() const
True while a merge, rebase, cherry-pick or revert is in progress, which refuses commits.
void SetSSHKey(const wxString &aSSHKey)
void SetUsername(const wxString &aUsername)
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.
git_repository * GetRepo() const
static wxString GetLastGitError()
libgit2's last message, without credentials from any URL it quotes, so it is safe to show or trace.
static REMOTE_URL ParseRemoteURL(const wxString &aURL)
void SetPassword(const wxString &aPassword)
void SetRemote(const wxString &aRemote)
void SetRepo(git_repository *aRepo)
void AddErrorString(const wxString aErrorString)
void AddError(const wxString &aSummary, const wxString &aDetails)
A summary the user can act on, with the raw text that explains it kept apart for the details.
void AddGitError(const wxString &aSummary)
Queue the summary with libgit2's last error as its details.
wxString GetProjectDir() const
Get the project directory path, preserving symlinks if set.
KIGIT_FAILURE_REPORT ReportTransferFailure(const KIGIT_ERROR_INFO &aError, KIGIT_OPERATION aOperation, const wxString &aRemoteName)
Classify a failed libgit2 transfer call and queue its summary and details.
git_repository * GetRepo() const
Get a pointer to the git repository.
const KIGIT_COMMON::CANCEL_TOKEN & CancelToken() const
bool IsThisOperationCancelled() const
std::unique_lock< std::mutex > GetActionLock() const
KIGIT_COMMON * GetCommon() const
Get the common object.
wxString GetRemotename() const
Get the remote name.
bool DiscardChanges(git_repository *aRepo, const std::vector< wxString > &aPaths, wxString &aError) override
bool AddRemote(git_repository *aRepo, const wxString &aName, const wxString &aUrl) override
bool SetRemoteUrl(git_repository *aRepo, const wxString &aName, const wxString &aUrl) override
PullResult handleMerge(GIT_PULL_HANDLER *aHandler, const git_annotated_commit **aMergeHeads, size_t aMergeHeadsCount)
bool PerformFetch(GIT_PULL_HANDLER *aHandler, bool aSkipLock) override
static bool hasUnstagedChanges(git_repository *aRepo)
bool Clone(GIT_CLONE_HANDLER *aHandler) override
PullResult handleRebase(GIT_PULL_HANDLER *aHandler, const git_annotated_commit **aMergeHeads, size_t aMergeHeadsCount)
RestoreResult RestoreVersion(KIGIT_COMMON &aCommon, const wxString &aCommitHash, KIGIT_ERROR_MESSAGE &aError) override
bool CheckoutTag(git_repository *aRepo, const wxString &aName) override
bool RemoveVCS(git_repository *&aRepo, const wxString &aProjectPath, bool aRemoveGitDir, wxString *aErrors) override
UndoCommitResult UndoLastCommit(GIT_COMMIT_HANDLER *aHandler, const wxString &aExpectedBranch, const git_oid &aExpectedHead, wxString &aMessage) override
Move aExpectedBranch back to the parent of aExpectedHead, leaving the index and working files as they...
BranchResult SwitchToBranch(GIT_BRANCH_HANDLER *aHandler, const wxString &aBranchName) override
PullResult handleFastForward(GIT_PULL_HANDLER *aHandler)
CommitResult Commit(GIT_COMMIT_HANDLER *aHandler, const std::vector< wxString > &aFiles, const wxString &aMessage, const wxString &aAuthorName, const wxString &aAuthorEmail) override
bool StashSave(git_repository *aRepo, const wxString &aMessage) override
bool IsPathInHead(git_repository *aRepo, const wxString &aPath) override
git_repository * GetRepositoryForFile(const char *aFilename, wxString *aError, wxString *aTrustCommand) override
aError receives why git refused to open the repository, and aTrustCommand the command that trusts it ...
bool DeleteTag(git_repository *aRepo, const wxString &aName) override
bool StashPop(git_repository *aRepo, size_t aIndex) override
void UpdateRemoteStatus(GIT_STATUS_HANDLER *aHandler, const std::set< wxString > &aLocalChanges, const std::set< wxString > &aRemoteChanges, std::map< wxString, FileStatus > &aFileStatus) override
wxString GetCurrentBranchName(GIT_STATUS_HANDLER *aHandler) override
bool GetConfigString(GIT_CONFIG_HANDLER *aHandler, const wxString &aKey, wxString &aValue) override
bool DeleteBranch(git_repository *aRepo, const wxString &aBranchName) override
bool SetupRemote(GIT_INIT_HANDLER *aHandler, const RemoteConfig &aConfig) override
MergeCommitResult CreateMergedCommit(git_repository *aRepo, const wxString &aExpectedHeadOid, const wxString &aTheirsOid, const std::vector< std::pair< wxString, wxString > > &aResolvedFiles, KIGIT_ERROR_MESSAGE &aError) override
bool IsRepository(GIT_INIT_HANDLER *aHandler, const wxString &aPath) override
int CreateBranch(git_repository *aRepo, const wxString &aBranchName, const wxString &aFrom) override
bool IsLibraryAvailable() override
std::map< wxString, FileStatus > GetFileStatus(GIT_STATUS_HANDLER *aHandler, const wxString &aPathspec, bool aChangedOnly) override
bool StashApply(git_repository *aRepo, size_t aIndex) override
PushResult Push(GIT_PUSH_HANDLER *aHandler, bool aForce=false) override
wxString GetWorkingDirectory(GIT_STATUS_HANDLER *aHandler) override
CommitResult Amend(GIT_COMMIT_HANDLER *aHandler, const std::vector< wxString > &aFiles, const wxString &aMessage, const wxString &aAuthorName, const wxString &aAuthorEmail) override
bool GetMergeConflicts(git_repository *aRepo, const wxString &aStageDir, wxString &aHeadOid, wxString &aTheirsOid, std::vector< KIGIT_CONFLICT_SIDES > &aConflicts, wxString &aError) override
InitResult InitializeRepository(GIT_INIT_HANDLER *aHandler, const wxString &aPath) override
bool SetUserConfig(git_repository *aRepo, const wxString &aName, const wxString &aEmail) override
bool CreateTag(git_repository *aRepo, const wxString &aName, const wxString &aMessage) override
bool StashDrop(git_repository *aRepo, size_t aIndex) override
PullResult PerformPull(GIT_PULL_HANDLER *aHandler) override
bool RemoveRemote(git_repository *aRepo, const wxString &aName) override
bool AbandonOperation(git_repository *aRepo, wxString &aError) override
Drop a merge, rebase, cherry-pick or revert left in progress and return to the last commit.
static wxString GetUserCachePath()
Gets the stock (install) 3d viewer plugins path.
bool RmDirRecursive(const wxString &aFileName, wxString *aErrors)
Remove the directory aDirName and all its contents including subdirectories and their files.
@ SuccessIndexStale
Committed, but the staged list was left as another program had it. Never retry on this.
@ TargetChanged
The branch or its last commit is no longer the one the caller saw.
@ Published
A remote-tracking branch already holds the commit, so taking it back would rewrite shared history.
static KIGIT::PROMPT_ANSWER refusal(const wxWeakRef< wxWindow > &aParent, bool aHadParent)
@ Busy
Another git operation held the action lock, so nothing was pushed.
const wxChar *const traceGit
Flag to enable Git debugging output.
int fetchhead_foreach_cb(const char *, const char *, const git_oid *aOID, unsigned int aIsMerge, void *aPayload)
@ AlreadyCurrent
The chosen version's content matches the current head.
@ Restored
A new commit carrying the old version's content was created.
@ Error
The restore failed. See the error string.
@ Dirty
Uncommitted changes exist, and restoring would overwrite them.
The one place a fetch, push, clone or connection check reaches a remote.
static bool indexChangedSince(git_index *aIndex, const std::map< std::string, SELECTED_STATE > &aAtStart)
static void refreshCachedIndex(git_repository *aRepo)
static int lookup_branch_reference(git_repository *repo, const wxString &aBranchName, git_reference **aReference)
static bool rollbackWorkingTree(git_repository *aRepo, git_commit *aHeadCommit, git_tree *aWrittenTree)
static std::map< std::string, SELECTED_STATE > readSelectedState(git_index *aIndex, const std::set< std::string > &aSelected)
static bool fetchRemote(GIT_PULL_HANDLER *aHandler, bool aSkipLock, bool *aRemoteHasBranches)
static bool safeToRestore(git_repository *aRepo, const char *aPath, git_tree *aPreviousTree, git_tree *aWrittenTree)
static bool untrackedFilesOverwrittenBy(git_repository *aRepo, git_tree *aIncomingTree, std::vector< wxString > &aCollisions)
static bool branchMovedSince(git_repository *aRepo, const git_oid &aHeadAtStart, bool aHadHead)
static PUBLISH_RESULT publishPreparedCommit(git_repository *aRepo, git_tree *aTree, const git_oid &aCommitOid, git_reference *aHeadRef, git_commit *aRollbackCommit, const char *aReflogLabel, wxString &aGitError)
@ CHECKOUT_FAILED_PARTIAL
@ RECORD_FAILED_ROLLED_BACK
@ CHECKOUT_FAILED_ROLLED_BACK
static bool applyStashOntoCleanTree(git_repository *aRepo, size_t aIndex)
static int reachableFromRemote(git_repository *aRepo, const git_oid &aCommit, wxString &aRemoteRef)
static PullResult rebaseOnto(GIT_PULL_HANDLER *aHandler, git_repository *aRepo, const git_annotated_commit *aOnto)
static bool refuseWhileOperationInProgress(git_repository *aRepo, git_index *aIndex, wxString &aError)
static PullResult adoptRemoteHistory(GIT_PULL_HANDLER *aHandler, const git_oid &aRemoteOid)
static TREE_STATE trackedTreeState(git_repository *aRepo)
static git_index * openIndexOnDisk(git_index *aRepoIndex)
static wxString describeUntrackedCollisions(const std::vector< wxString > &aPaths)
static bool selectedPathsRestaged(git_index *aIndex, const std::set< std::string > &aSelected, const std::map< std::string, SELECTED_STATE > &aAtStart)
static bool treeHolds(git_tree *aTree, const char *aPath, const git_oid &aOnDisk)
static bool wholeStateOnDisk(git_index *aRepoIndex, std::map< std::string, SELECTED_STATE > &aOut)
static std::vector< std::string > changedPaths(git_repository *aRepo)
static bool selectedStateOnDisk(git_index *aRepoIndex, const std::set< std::string > &aSelected, std::map< std::string, SELECTED_STATE > &aOut)
static void reportRemoteLookupFailure(KIGIT_ERRORS *aHandler, int aRc, const wxString &aRemoteName)
static bool restorePathsFromCommit(git_repository *aRepo, git_commit *aCommit, const std::vector< std::string > &aPaths)
static const char ADOPT_REMOTE_BRANCH_KEY[]
static wxString unbornBranchName(git_repository *aRepo)
static std::map< std::string, SELECTED_STATE > readWholeState(git_index *aIndex)
static REPUBLISH_RESULT republishIndex(git_index *aIndex, const std::vector< STAGED_ENTRY > &aCommitted, const std::set< std::string > &aSelected)
static KIGIT_ERROR_MESSAGE describeSignatureFailure(int aRc)
static bool adoptRemoteBranch(git_repository *aRepo, const wxString &aRemoteName, const std::vector< wxString > &aRemoteBranches)
static bool markForRemoteBranchAdoption(git_repository *aRepo)
static bool applySelectedPaths(git_repository *aRepo, git_index *aIndex, const std::vector< wxString > &aFiles)
std::unique_ptr< git_tree, decltype([](git_tree *aTree) { git_tree_free(aTree); })> GitTreePtr
A unique pointer for git_tree 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.
std::unique_ptr< git_buf, decltype([](git_buf *aBuf) { git_buf_free(aBuf); })> GitBufPtr
A unique pointer for git_buf objects with automatic cleanup.
std::unique_ptr< git_index_conflict_iterator, decltype([](git_index_conflict_iterator *aIterator) { git_index_conflict_iterator_free(aIterator); })> GitIndexConflictIteratorPtr
A unique pointer for git_index_conflict_iterator 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.
std::unique_ptr< git_annotated_commit, decltype([](git_annotated_commit *aCommit) { git_annotated_commit_free(aCommit); })> GitAnnotatedCommitPtr
A unique pointer for git_annotated_commit objects with automatic cleanup.
APIEXPORT KIGIT_OWNERSHIP_REFUSAL DescribeOwnershipRefusal(const wxString &aStartDir, const wxString &aGitDir)
The message for a repository git refuses to open because another user owns it.
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.
APIEXPORT void SetDerivedPublicKeyFolder(const wxString &aDir)
Keep public key files written by EnsurePublicKeyFile in aDir.
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_reference, decltype([](git_reference *aRef) { git_reference_free(aRef); })> GitReferencePtr
A unique pointer for git_reference 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.
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 void SetRememberedSSHKeyStore(const wxString &aPath)
Keep remembered keys in aPath.
APIEXPORT KIGIT_FAILURE_REPORT DescribeGitFailure(const KIGIT_ERROR_INFO &aError, const KIGIT_AUTH_ATTEMPT &aAuth, const KIGIT_FAILURE_CONTEXT &aContext)
Turn a failed transfer into a message the user can act on.
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.
std::unique_ptr< git_blob, decltype([](git_blob *aBlob) { git_blob_free(aBlob); })> GitBlobPtr
A unique pointer for git_blob objects with automatic cleanup.
std::unique_ptr< git_signature, decltype([](git_signature *aSignature) { git_signature_free(aSignature); })> GitSignaturePtr
A unique pointer for git_signature objects with automatic cleanup.
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_rebase, decltype([](git_rebase *aRebase) { git_rebase_free(aRebase); })> GitRebasePtr
A unique pointer for git_rebase 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.
SCRATCH_INDEX_GUARD scratchGuard
std::map< std::string, SELECTED_STATE > indexAtStart
std::map< std::string, SELECTED_STATE > selectedAtStart
bool BuildTree(git_repository *aRepo, const std::vector< wxString > &aFiles, KIGIT::GitTreePtr &aTreeOut, KIGIT_ERROR_MESSAGE &aError)
Stage the chosen files over whatever the index already holds and write the tree they make.
bool Begin(git_repository *aRepo, const std::vector< wxString > &aFiles, KIGIT_ERROR_MESSAGE &aError)
Read the index, record what it holds and take it over. False leaves the reason in aError.
std::set< std::string > selectedPaths
std::vector< STAGED_ENTRY > committedEntries
KIGIT::GitIndexPtr indexPtr
A transport address with any embedded credentials extracted.
wxString url
Keeps the SSH username, scheme and port, but never a password.
wxString theirsFile
Extracted remote version, an empty file when absent.
wxString ancestorFile
Extracted common-ancestor version, an empty file when absent.
wxString oursFile
Extracted local version, an empty file when absent.
bool hasOurs
False when the local side deleted the file.
wxString path
Repository-relative path of the conflicted file.
bool hasTheirs
False when the remote side deleted the file.
bool hasAncestor
False when the file did not exist in the common ancestor.
A summary the user can act on, with the raw text that explains it kept apart for the details.
What the failed operation was doing, as far as the message needs it.
KIGIT_OPERATION operation
wxString url
The address connected to. Messages show only its host and its stripped form.
wxString remoteName
Empty when the operation has no named remote, as for a clone.
wxString summary
What happened and what to do next, in the user's terms. Never raw text.
wxString details
The raw error, the server's text and the address without its password.
Why git will not open a repository another user owns, and the command that trusts it.
bool operator==(const SELECTED_STATE &aOther) const
bool operator!=(const SELECTED_STATE &aOther) const
static std::vector< uint8_t > bytes(const std::string &aText)
wxString result
Test unit parsing edge cases and error handling.
wxLogTrace helper definitions.