64#include <wx/filename.h>
65#include <wx/filesys.h>
66#include <wx/textfile.h>
98 git_repository_open( &repo,
m_repoPath.ToUTF8().data() );
105 const wxString& aMessage )
114 const std::string& aContent,
const char* aMessage )
118 git_commit* parentCommit =
nullptr;
122 BOOST_REQUIRE_EQUAL( git_blob_create_from_buffer( &blobOid, aRepo, aContent.data(), aContent.size() ), GIT_OK );
124 git_tree* parentTree =
nullptr;
127 git_treebuilder* builder =
nullptr;
130 git_treebuilder_insert(
nullptr, builder, aFile.ToUTF8().data(), &blobOid, GIT_FILEMODE_BLOB ),
135 git_treebuilder_free( builder );
136 git_tree_free( parentTree );
138 git_tree* tree =
nullptr;
141 git_signature* sig =
nullptr;
144 const git_commit* parents[1] = { parentCommit };
146 git_commit_create( &
result, aRepo,
nullptr, sig, sig,
nullptr, aMessage, tree, 1, parents ), GIT_OK );
148 git_signature_free( sig );
149 git_tree_free( tree );
150 git_commit_free( parentCommit );
157 char hex[GIT_OID_HEXSZ + 1] = { 0 };
158 git_oid_tostr( hex,
sizeof( hex ), &aOid );
160 wxString fetchHead =
repoPath() + wxFileName::GetPathSeparator() + wxT(
".git" )
161 + wxFileName::GetPathSeparator() + wxT(
"FETCH_HEAD" );
162 std::ofstream f( fetchHead.ToStdString() );
163 f << hex <<
"\t\tbranch 'master' of test\n";
169 git_remote* remote =
nullptr;
170 int rc = git_remote_create( &remote, aRepo,
"origin",
m_remotePath.ToUTF8().data() );
173 git_remote_free( remote );
183 git_config* cfg =
nullptr;
185 if( git_repository_config( &cfg, aRepo ) != 0 )
188 wxString remoteKey = wxString::Format(
"branch.%s.remote", aBranch );
189 wxString mergeKey = wxString::Format(
"branch.%s.merge", aBranch );
191 git_config_delete_entry( cfg, remoteKey.ToUTF8().data() );
192 git_config_delete_entry( cfg, mergeKey.ToUTF8().data() );
194 git_config_free( cfg );
202 git_config* cfg =
nullptr;
204 if( git_repository_config( &cfg, aRepo ) != 0 )
207 wxString remoteKey = wxString::Format(
"branch.%s.remote", aBranch );
208 wxString mergeKey = wxString::Format(
"branch.%s.merge", aBranch );
209 wxString mergeVal = wxString::Format(
"refs/heads/%s", aBranch );
211 git_config_set_string( cfg, remoteKey.ToUTF8().data(),
"origin" );
212 git_config_set_string( cfg, mergeKey.ToUTF8().data(), mergeVal.ToUTF8().data() );
213 git_config_free( cfg );
221 git_config* cfg =
nullptr;
223 if( git_repository_config( &cfg, aRepo ) != 0 )
224 return wxEmptyString;
226 git_buf buf = {
nullptr, 0, 0 };
229 if( git_config_get_string_buf( &buf, cfg, aKey.ToUTF8().data() ) == 0 && buf.ptr )
230 result = wxString::FromUTF8( buf.ptr );
232 git_buf_dispose( &buf );
233 git_config_free( cfg );
241 const wxString
path =
tempBase() + wxS(
"/global-ignore" );
242 git_config* rawConfig =
nullptr;
255 git_config* cfg =
nullptr;
260 createCommit( repo.get(), wxT(
"file.txt" ), wxT(
"initial\n" ), wxT(
"Initial commit" ) );
267 git_clone_options opts;
268 git_clone_init_options( &opts, GIT_CLONE_OPTIONS_VERSION );
275 git_repository_free( bare );
297 BOOST_TEST_REQUIRE( ready() );
300 BOOST_TEST_REQUIRE( repo );
313 for(
const char*
name : {
"refs/heads/aaa",
"refs/heads/zzz" } )
315 git_reference* ref =
nullptr;
317 git_reference_free( ref );
324 std::vector<std::string> names;
331 auto cb = [](
const char* aName,
const char*,
const git_oid*,
unsigned int aIsMerge,
void* aPayload ) ->
int
333 MARKED* m =
static_cast<MARKED*
>( aPayload );
337 m->names.push_back( std::string( aName ? aName :
"" ) );
351 BOOST_REQUIRE( clearUpstreamConfig( repo, wxT(
"master" ) ) );
356 MARKED marked = collect( repo );
369 MARKED marked = collect( repo );
382 BOOST_TEST_REQUIRE( ready() );
385 BOOST_TEST_REQUIRE( repo );
397 BOOST_REQUIRE_EQUAL( git_reference_name_to_id( &base, bare,
"refs/heads/master" ), GIT_OK );
399 git_oid attrs = createDetachedCommit( bare, base, wxT(
".gitattributes" ),
"*.kicad_pcb filter=lfs -text\n",
400 "Track boards with LFS" );
403 createDetachedCommit( bare, attrs, wxT(
"board.kicad_pcb" ),
404 "version https://git-lfs.github.com/spec/v1\n"
405 "oid sha256:0000000000000000000000000000000000000000000000000000000000000000\n"
409 git_reference* ref =
nullptr;
410 BOOST_REQUIRE_EQUAL( git_reference_create( &ref, bare,
"refs/heads/master", &board, 1,
nullptr ), GIT_OK );
411 git_reference_free( ref );
420 "the pull should refuse a commit that brings Git LFS in" );
423 BOOST_CHECK_MESSAGE( error.Upper().Contains( wxS(
"LFS" ) ),
424 "the refusal should name Git LFS, got: " + error.ToStdString() );
427 BOOST_CHECK( !wxFileName::FileExists( repoPath() + wxFileName::GetPathSeparator() + wxT(
"board.kicad_pcb" ) ) );
435 BOOST_TEST_REQUIRE( ready() );
438 BOOST_TEST_REQUIRE( repo );
443 git_oid local = createCommit( repo, wxT(
"pushed.txt" ), wxT(
"new\n" ), wxT(
"Push me" ) );
444 wxString refspec = wxString::FromUTF8( git_oid_tostr_s( &local ) ) + wxS(
":refs/heads/master" );
446 git_remote* remote =
nullptr;
455 BOOST_CHECK_MESSAGE( transport.
Push(
458 handler.CancelThisOperation();
462 "a cancelled push should stop at its next progress tick" );
469 BOOST_REQUIRE_EQUAL( git_reference_name_to_id( &remoteHead, bare,
"refs/heads/master" ), GIT_OK );
470 BOOST_CHECK( !git_oid_equal( &remoteHead, &local ) );
476 const wxString
project = wxT(
"/repo/proj/" );
493 wxT(
"/repo/proj" ) ) );
497 wxT(
"C:\\repo\\proj\\" ) ) );
499 wxT(
"C:\\repo\\proj\\" ) ) );
511 BOOST_TEST_REQUIRE( ready() );
514 BOOST_TEST_REQUIRE( repo );
517 git_oid c1 = createCommit( repo, wxT(
"file.txt" ), wxT(
"edited\n" ), wxT(
"Edit file" ) );
520 git_reference* trackingRef =
nullptr;
521 git_reference_create( &trackingRef, repo,
"refs/remotes/origin/master", &c1, 1,
nullptr );
524 git_reference_free( trackingRef );
527 setUpstreamConfig( repo, wxT(
"master" ) );
530 git_reference* headRef =
nullptr;
531 git_repository_head( &headRef, repo );
533 git_commit* headCommit =
nullptr;
534 git_reference_peel( (git_object**) &headCommit, headRef, GIT_OBJECT_COMMIT );
536 git_tree* tree =
nullptr;
537 git_commit_tree( &tree, headCommit );
539 git_signature* sig =
nullptr;
543 int rc = git_commit_amend( &amendedOid, headCommit,
"HEAD", sig, sig,
nullptr,
"Edit file (message-only amend)",
545 BOOST_TEST_REQUIRE( rc == 0 );
547 git_tree_free( tree );
548 git_commit_free( headCommit );
549 git_reference_free( headRef );
550 git_signature_free( sig );
558 BOOST_CHECK_MESSAGE( ahead.empty(),
"Message-only amend should not report any AHEAD files; got "
559 + std::to_string( ahead.size() ) );
560 BOOST_CHECK_MESSAGE( behind.empty(),
"Message-only amend should not report any BEHIND files; got "
561 + std::to_string( behind.size() ) );
563 git_repository_free( repo );
570 BOOST_TEST_REQUIRE( ready() );
573 BOOST_TEST_REQUIRE( repo );
575 git_oid c1 = createCommit( repo, wxT(
"file.txt" ), wxT(
"edited\n" ), wxT(
"Edit file" ) );
577 git_reference* trackingRef =
nullptr;
578 git_reference_create( &trackingRef, repo,
"refs/remotes/origin/master", &c1, 1,
nullptr );
581 git_reference_free( trackingRef );
584 setUpstreamConfig( repo, wxT(
"master" ) );
588 createCommit( repo, wxT(
"file.txt" ), wxT(
"edited again\n" ), wxT(
"Re-edit file" ) );
593 BOOST_CHECK_MESSAGE( ahead.count( wxT(
"file.txt" ) ) == 1,
594 "AHEAD should contain file.txt when content differs from upstream" );
596 git_repository_free( repo );
603 BOOST_TEST_REQUIRE( ready() );
606 BOOST_TEST_REQUIRE( repo );
609 clearUpstreamConfig( repo, wxT(
"master" ) );
619 "Pull without upstream config should succeed via fallback; got "
620 + std::to_string(
static_cast<int>(
result ) ) +
", err='"
624 BOOST_CHECK_EQUAL( readConfig( repo, wxT(
"branch.master.remote" ) ), wxString(
"origin" ) );
625 BOOST_CHECK_EQUAL( readConfig( repo, wxT(
"branch.master.merge" ) ), wxString(
"refs/heads/master" ) );
627 git_repository_free( repo );
637 BOOST_TEST_REQUIRE( ready() );
640 BOOST_TEST_REQUIRE( repo );
643 setUpstreamConfig( repo, wxT(
"master" ) );
645 git_object* initial =
nullptr;
646 BOOST_TEST_REQUIRE( git_revparse_single( &initial, repo,
"HEAD" ) == 0 );
649 git_oid remoteOid = createCommit( repo, wxT(
"remote.txt" ), wxT(
"remote\n" ), wxT(
"Remote commit" ) );
656 BOOST_TEST_REQUIRE( git_reset( repo, initial, GIT_RESET_HARD,
nullptr ) == 0 );
657 git_object_free( initial );
659 createCommit( repo, wxT(
"local.txt" ), wxT(
"local\n" ), wxT(
"Local commit" ) );
661 git_config* cfg =
nullptr;
662 BOOST_TEST_REQUIRE( git_repository_config( &cfg, repo ) == 0 );
663 git_config_set_bool( cfg,
"pull.rebase", 1 );
664 git_config_free( cfg );
670 "Rebase pull failed: " + handler.
GetErrorString().ToStdString() );
671 BOOST_CHECK_EQUAL( git_repository_state( repo ),
static_cast<int>( GIT_REPOSITORY_STATE_NONE ) );
673 git_commit* head =
nullptr;
674 BOOST_TEST_REQUIRE( git_revparse_single( (git_object**) &head, repo,
"HEAD" ) == 0 );
675 BOOST_CHECK( git_oid_equal( git_commit_parent_id( head, 0 ), &remoteOid ) );
676 git_commit_free( head );
678 git_repository_free( repo );
685 BOOST_TEST_REQUIRE( ready() );
688 BOOST_TEST_REQUIRE( repo );
692 createCommit( repo, wxT(
"file.txt" ), wxT(
"second\n" ), wxT(
"Second commit" ) );
695 clearUpstreamConfig( repo, wxT(
"master" ) );
703 BOOST_CHECK_EQUAL( readConfig( repo, wxT(
"branch.master.remote" ) ), wxString(
"origin" ) );
704 BOOST_CHECK_EQUAL( readConfig( repo, wxT(
"branch.master.merge" ) ), wxString(
"refs/heads/master" ) );
706 git_repository_free( repo );
714 BOOST_TEST_REQUIRE( ready() );
717 BOOST_TEST_REQUIRE( repo );
719 createCommit( repo, wxT(
"file.txt" ), wxT(
"second\n" ), wxT(
"Second commit" ) );
732 BOOST_CHECK_MESSAGE( error.Contains( wxS(
"branch" ) ),
733 "the refusal should say the project is not on a branch, got: " + error.ToStdString() );
735 git_repository_free( repo );
742 BOOST_TEST_REQUIRE( ready() );
745 BOOST_TEST_REQUIRE( repo );
749 BOOST_REQUIRE_EQUAL( git_repository_open( &remote, remotePath().ToUTF8().data() ), GIT_OK );
752 BOOST_REQUIRE_EQUAL( git_reference_name_to_id( &remoteHead, remote,
"refs/heads/master" ), GIT_OK );
754 git_oid ahead = createDetachedCommit( remote, remoteHead, wxT(
"theirs.txt" ),
"theirs\n",
"Remote commit" );
756 git_reference* ref =
nullptr;
757 BOOST_REQUIRE_EQUAL( git_reference_create( &ref, remote,
"refs/heads/master", &ahead, 1,
nullptr ), GIT_OK );
758 git_reference_free( ref );
759 git_repository_free( remote );
762 createCommit( repo, wxT(
"file.txt" ), wxT(
"second\n" ), wxT(
"Local commit" ) );
772 git_repository_free( repo );
781 BOOST_TEST_REQUIRE( ready() );
784 BOOST_TEST_REQUIRE( repo );
786 createCommit( repo, wxT(
"file.txt" ), wxT(
"second\n" ), wxT(
"Local commit" ) );
789 wxString headsDir = remotePath() + wxFileName::GetPathSeparator() + wxT(
"refs" ) + wxFileName::GetPathSeparator()
799 struct WRITABLE_AGAIN
802 ~WRITABLE_AGAIN() { chmod( dir.fn_str(), 0755 ); }
803 } restore{ headsDir };
805 chmod( headsDir.fn_str(), 0555 );
818 BOOST_CHECK_MESSAGE( !errors.front().EndsWith( wxS(
"No error" ) ),
819 "the refusal lost git's reason: " + errors.front().ToStdString() );
821 git_repository_free( repo );
829 BOOST_TEST_REQUIRE( ready() );
832 BOOST_TEST_REQUIRE( repo );
836 BOOST_REQUIRE_EQUAL( git_repository_open( &remote, remotePath().ToUTF8().data() ), GIT_OK );
839 BOOST_REQUIRE_EQUAL( git_reference_name_to_id( &remoteHead, remote,
"refs/heads/master" ), GIT_OK );
841 git_oid ahead = createDetachedCommit( remote, remoteHead, wxT(
"file.txt" ),
"remote\n",
"Remote change" );
843 git_reference* ref =
nullptr;
844 BOOST_REQUIRE_EQUAL( git_reference_create( &ref, remote,
"refs/heads/master", &ahead, 1,
nullptr ), GIT_OK );
845 git_reference_free( ref );
846 git_repository_free( remote );
849 git_oid localHead = createCommit( repo, wxT(
"file.txt" ), wxT(
"local\n" ), wxT(
"Local change" ) );
852 setUpstreamConfig( repo, wxT(
"master" ) );
855 git_config* cfg =
nullptr;
857 git_config_set_bool( cfg,
"pull.rebase", 1 );
858 git_config_free( cfg );
871 BOOST_CHECK( git_oid_equal( &headNow, &localHead ) );
873 wxTextFile file( repoPath() + wxFileName::GetPathSeparator() + wxT(
"file.txt" ) );
877 git_repository_free( repo );
884 BOOST_TEST_REQUIRE( ready() );
887 BOOST_TEST_REQUIRE( repo );
893 BOOST_REQUIRE_EQUAL( git_repository_open( &remote, remotePath().ToUTF8().data() ), GIT_OK );
896 git_reference* masterRef =
nullptr;
897 BOOST_REQUIRE_EQUAL( git_reference_lookup( &masterRef, remote,
"refs/heads/master" ), GIT_OK );
899 git_reference* mainRef =
nullptr;
900 BOOST_REQUIRE_EQUAL( git_reference_rename( &mainRef, masterRef,
"refs/heads/main", 0,
nullptr ), GIT_OK );
901 git_reference_free( masterRef );
904 git_oid remoteHead = *git_reference_target( mainRef );
905 git_reference_free( mainRef );
907 ahead = createDetachedCommit( remote, remoteHead, wxT(
"theirs.txt" ),
"theirs\n",
"Remote commit" );
909 git_reference* ref =
nullptr;
910 BOOST_REQUIRE_EQUAL( git_reference_create( &ref, remote,
"refs/heads/main", &ahead, 1,
nullptr ), GIT_OK );
911 git_reference_free( ref );
912 git_repository_free( remote );
918 git_config* cfg =
nullptr;
920 git_config_set_string( cfg,
"branch.master.remote",
"origin" );
921 git_config_set_string( cfg,
"branch.master.merge",
"refs/heads/main" );
922 git_config_free( cfg );
936 git_repository_free( repo );
944 BOOST_TEST_REQUIRE( ready() );
947 BOOST_TEST_REQUIRE( repo );
952 wxString trackedPath = repoPath() + wxFileName::GetPathSeparator() + wxT(
"file.txt" );
953 wxString contentBefore;
955 wxFFile f( trackedPath, wxT(
"rb" ) );
956 f.ReadAll( &contentBefore );
962 BOOST_REQUIRE_EQUAL( git_repository_open( &remote, remotePath().ToUTF8().data() ), GIT_OK );
965 BOOST_REQUIRE_EQUAL( git_reference_name_to_id( &remoteHead, remote,
"refs/heads/master" ), GIT_OK );
967 ahead = createDetachedCommit( remote, remoteHead, wxT(
"file.txt" ),
"changed by remote\n",
"Remote edit" );
969 git_reference* ref =
nullptr;
970 BOOST_REQUIRE_EQUAL( git_reference_create( &ref, remote,
"refs/heads/master", &ahead, 1,
nullptr ), GIT_OK );
971 git_reference_free( ref );
972 git_repository_free( remote );
978 wxString bystanderPath = repoPath() + wxFileName::GetPathSeparator() + wxT(
"bystander.txt" );
980 wxFFile bystander( bystanderPath, wxT(
"wb" ) );
981 BOOST_TEST_REQUIRE( bystander.IsOpened() );
982 bystander.Write( wxT(
"written by something else\n" ) );
986 wxString refLock = repoPath() + wxFileName::GetPathSeparator() + wxT(
".git" ) + wxFileName::GetPathSeparator()
987 + wxT(
"refs" ) + wxFileName::GetPathSeparator() + wxT(
"heads" )
988 + wxFileName::GetPathSeparator() + wxT(
"master.lock" );
990 wxFFile lock( refLock, wxT(
"wb" ) );
991 BOOST_TEST_REQUIRE( lock.IsOpened() );
992 lock.Write( wxT(
"locked\n" ) );
1002 wxRemoveFile( refLock );
1003 git_repository_free( repo );
1011 BOOST_CHECK_MESSAGE( git_oid_equal( &headAfter, &before ),
"HEAD must not have moved" );
1013 wxString contentAfter;
1015 wxFFile f( trackedPath, wxT(
"rb" ) );
1016 f.ReadAll( &contentAfter );
1019 BOOST_CHECK_MESSAGE( contentAfter == contentBefore,
"the working file must be back at the commit HEAD points at" );
1022 git_status_options opts;
1023 git_status_init_options( &opts, GIT_STATUS_OPTIONS_VERSION );
1024 opts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
1026 git_status_list* list =
nullptr;
1028 size_t dirty = git_status_list_entrycount( list );
1029 git_status_list_free( list );
1031 BOOST_CHECK_MESSAGE( dirty == 0,
"the rollback must leave no phantom local changes" );
1034 BOOST_CHECK_MESSAGE( wxFileName::FileExists( bystanderPath ),
1035 "the rollback must not remove a file outside the paths the pull wrote" );
1037 git_repository_free( fresh );
1045 BOOST_TEST_REQUIRE( ready() );
1048 BOOST_TEST_REQUIRE( repo );
1053 BOOST_REQUIRE_EQUAL( git_repository_open( &remote, remotePath().ToUTF8().data() ), GIT_OK );
1056 BOOST_REQUIRE_EQUAL( git_reference_name_to_id( &remoteHead, remote,
"refs/heads/master" ), GIT_OK );
1058 git_oid ahead = createDetachedCommit( remote, remoteHead, wxT(
"notes" ),
"from the remote\n",
"Add notes" );
1060 git_reference* ref =
nullptr;
1061 BOOST_REQUIRE_EQUAL( git_reference_create( &ref, remote,
"refs/heads/master", &ahead, 1,
nullptr ), GIT_OK );
1062 git_reference_free( ref );
1063 git_repository_free( remote );
1070 wxString notesDir = repoPath() + wxFileName::GetPathSeparator() + wxT(
"notes" );
1071 BOOST_REQUIRE( wxFileName::Mkdir( notesDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) );
1073 wxString keptFile = notesDir + wxFileName::GetPathSeparator() + wxT(
"keep.txt" );
1075 wxFFile f( keptFile, wxT(
"wb" ) );
1076 BOOST_TEST_REQUIRE( f.IsOpened() );
1077 f.Write( wxT(
"the only copy\n" ) );
1086 BOOST_CHECK_MESSAGE(
static_cast<int>(
result ) < 0,
"the checkout cannot succeed over a directory" );
1088 git_repository_free( repo );
1090 BOOST_CHECK_MESSAGE( wxFileName::DirExists( notesDir ),
1091 "the rollback must not remove an untracked directory it did not write" );
1096 wxFFile f( keptFile, wxT(
"rb" ) );
1097 f.ReadAll( &after );
1106 BOOST_TEST_REQUIRE( ready() );
1108 wxString emptyDir = tempBase() + wxFileName::GetPathSeparator() + wxT(
"unborn_rollback" );
1109 wxFileName::Mkdir( emptyDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
1112 BOOST_REQUIRE_EQUAL( git_repository_init( &fresh, emptyDir.ToUTF8().data(), 0 ), GIT_OK );
1115 git_remote* remote =
nullptr;
1116 BOOST_REQUIRE_EQUAL( git_remote_create( &remote, fresh,
"origin", remotePath().ToUTF8().data() ), GIT_OK );
1117 git_remote_free( remote );
1121 wxString
collide = emptyDir + wxFileName::GetPathSeparator() + wxT(
"file.txt" );
1123 wxFFile f(
collide, wxT(
"wb" ) );
1124 f.Write( wxT(
"mine\n" ) );
1133 "a colliding untracked file must not be overwritten" );
1135 git_repository_free( fresh );
1138 BOOST_REQUIRE_EQUAL( git_repository_open( &reopened, emptyDir.ToUTF8().data() ), GIT_OK );
1140 BOOST_CHECK_MESSAGE( git_repository_head_unborn( reopened ) == 1,
1141 "the branch must still be unborn after a refused checkout" );
1145 wxFFile f(
collide, wxT(
"rb" ) );
1151 git_repository_free( reopened );
1153 if( wxFileName::DirExists( emptyDir ) )
1154 wxFileName::Rmdir( emptyDir, wxPATH_RMDIR_RECURSIVE );
1160 BOOST_TEST_REQUIRE( ready() );
1163 BOOST_TEST_REQUIRE( repo );
1170 std::unique_lock<std::mutex> held = common.
LockAction();
1183 git_repository_free( repo );
1190 BOOST_TEST_REQUIRE( ready() );
1193 BOOST_TEST_REQUIRE( repo );
1197 BOOST_REQUIRE_EQUAL( git_repository_open( &remote, remotePath().ToUTF8().data() ), GIT_OK );
1200 BOOST_REQUIRE_EQUAL( git_reference_name_to_id( &remoteHead, remote,
"refs/heads/master" ), GIT_OK );
1202 git_oid ahead = createDetachedCommit( remote, remoteHead, wxT(
"theirs.txt" ),
"theirs\n",
"Remote adds" );
1204 git_reference* ref =
nullptr;
1205 BOOST_REQUIRE_EQUAL( git_reference_create( &ref, remote,
"refs/heads/master", &ahead, 1,
nullptr ), GIT_OK );
1206 git_reference_free( ref );
1207 git_repository_free( remote );
1210 wxString collidingPath = repoPath() + wxFileName::GetPathSeparator() + wxT(
"theirs.txt" );
1212 std::ofstream f( collidingPath.ToStdString() );
1213 f <<
"mine, never committed\n";
1217 setUpstreamConfig( repo, wxT(
"master" ) );
1232 BOOST_CHECK( git_oid_equal( &headBefore, &headAfter ) );
1234 wxTextFile file( collidingPath );
1238 git_repository_free( repo );
1245 BOOST_TEST_REQUIRE( ready() );
1248 BOOST_TEST_REQUIRE( repo );
1252 BOOST_REQUIRE_EQUAL( git_repository_open( &remote, remotePath().ToUTF8().data() ), GIT_OK );
1255 BOOST_REQUIRE_EQUAL( git_reference_name_to_id( &remoteHead, remote,
"refs/heads/master" ), GIT_OK );
1257 git_oid ahead = createDetachedCommit( remote, remoteHead, wxT(
"theirs.txt" ),
"theirs\n",
"Remote adds" );
1259 git_reference* ref =
nullptr;
1260 BOOST_REQUIRE_EQUAL( git_reference_create( &ref, remote,
"refs/heads/master", &ahead, 1,
nullptr ), GIT_OK );
1261 git_reference_free( ref );
1262 git_repository_free( remote );
1265 git_oid localHead = createCommit( repo, wxT(
"other.txt" ), wxT(
"local\n" ), wxT(
"Local change" ) );
1267 wxString collidingPath = repoPath() + wxFileName::GetPathSeparator() + wxT(
"theirs.txt" );
1269 std::ofstream f( collidingPath.ToStdString() );
1270 f <<
"mine, never committed\n";
1274 setUpstreamConfig( repo, wxT(
"master" ) );
1287 BOOST_CHECK( git_oid_equal( &localHead, &headAfter ) );
1289 git_repository_free( repo );
1296 BOOST_TEST_REQUIRE( ready() );
1298 wxString freshPath = tempBase() + wxFileName::GetPathSeparator() + wxT(
"fresh" );
1301 git_repository_init_options initOpts;
1302 git_repository_init_options_init( &initOpts, GIT_REPOSITORY_INIT_OPTIONS_VERSION );
1303 initOpts.flags = GIT_REPOSITORY_INIT_MKPATH;
1304 initOpts.initial_head =
"master";
1305 BOOST_REQUIRE_EQUAL( git_repository_init_ext( &repo, freshPath.ToUTF8().data(), &initOpts ), GIT_OK );
1318 BOOST_CHECK( wxFileName::FileExists( freshPath + wxFileName::GetPathSeparator() + wxT(
"file.txt" ) ) );
1320 git_repository_free( repo );
1326 BOOST_TEST_REQUIRE( ready() );
1329 BOOST_TEST_REQUIRE( repo );
1334 git_oid side = createDetachedCommit( repo, base, wxT(
"file.txt" ),
"side\n",
"Side change" );
1335 git_oid localHead = createCommit( repo, wxT(
"file.txt" ), wxT(
"local\n" ), wxT(
"Local change" ) );
1338 git_annotated_commit* sideCommit =
nullptr;
1341 const git_annotated_commit* heads[1] = { sideCommit };
1342 git_checkout_options checkoutOpts = GIT_CHECKOUT_OPTIONS_INIT;
1343 checkoutOpts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_ALLOW_CONFLICTS;
1346 git_annotated_commit_free( sideCommit );
1362 git_index*
index =
nullptr;
1365 git_index_free(
index );
1369 BOOST_CHECK( git_oid_equal( &headNow, &localHead ) );
1371 wxTextFile file( repoPath() + wxFileName::GetPathSeparator() + wxT(
"file.txt" ) );
1375 git_repository_free( repo );
1387 BOOST_TEST_REQUIRE( ready() );
1390 BOOST_TEST_REQUIRE( repo );
1393 createCommit( repo, wxT(
"bystander.txt" ), wxT(
"keep\n" ), wxT(
"Add bystander" ) );
1398 git_oid sideEdit = createDetachedCommit( repo, base, wxT(
"file.txt" ),
"side\n",
"Side change" );
1401 git_oid side = createDetachedCommit( repo, sideEdit, wxT(
"fromside.txt" ),
"new\n",
"Side addition" );
1403 createCommit( repo, wxT(
"file.txt" ), wxT(
"local\n" ), wxT(
"Local change" ) );
1406 wxString bystanderPath = repoPath() + wxFileName::GetPathSeparator() + wxT(
"bystander.txt" );
1408 std::ofstream f( bystanderPath.ToStdString() );
1409 f <<
"my own work\n";
1413 git_annotated_commit* sideCommit =
nullptr;
1416 const git_annotated_commit* heads[1] = { sideCommit };
1417 git_checkout_options checkoutOpts = GIT_CHECKOUT_OPTIONS_INIT;
1418 checkoutOpts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_ALLOW_CONFLICTS;
1421 git_annotated_commit_free( sideCommit );
1434 git_index*
index =
nullptr;
1440 std::ifstream f( ( repoPath() + wxFileName::GetPathSeparator() + wxT(
"file.txt" ) ).
ToStdString() );
1441 std::string content( ( std::istreambuf_iterator<char>( f ) ), std::istreambuf_iterator<char>() );
1446 BOOST_CHECK( !wxFileName::FileExists( repoPath() + wxFileName::GetPathSeparator() + wxT(
"fromside.txt" ) ) );
1450 std::ifstream f( bystanderPath.ToStdString() );
1451 std::string content( ( std::istreambuf_iterator<char>( f ) ), std::istreambuf_iterator<char>() );
1455 git_repository_free( repo );
1461 BOOST_TEST_REQUIRE( ready() );
1464 BOOST_TEST_REQUIRE( repo );
1470 wxString gitDir = repoPath() + wxFileName::GetPathSeparator() + wxT(
".git" ) + wxFileName::GetPathSeparator();
1473 std::ofstream log( ( gitDir + wxT(
"BISECT_LOG" ) ).
ToStdString() );
1474 log <<
"git bisect start\n";
1478 std::ofstream start( ( gitDir + wxT(
"BISECT_START" ) ).
ToStdString() );
1479 start <<
"master\n";
1487 BOOST_CHECK_MESSAGE( !common.
AbandonOperation( error ),
"a bisect must not be abandoned from here" );
1489 BOOST_CHECK_MESSAGE( wxFileName::FileExists( gitDir + wxT(
"BISECT_LOG" ) ),
1490 "the bisect bookkeeping must survive" );
1492 wxRemoveFile( gitDir + wxT(
"BISECT_LOG" ) );
1493 wxRemoveFile( gitDir + wxT(
"BISECT_START" ) );
1494 git_repository_free( repo );
1500 BOOST_TEST_REQUIRE( ready() );
1503 BOOST_TEST_REQUIRE( repo );
1505 const wxString sep = wxFileName::GetPathSeparator();
1508 const wxString rebaseDir = repoPath() + sep + wxT(
".git" ) + sep + wxT(
"rebase-merge" );
1510 BOOST_REQUIRE( wxFileName::Mkdir( rebaseDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) );
1515 const std::string headHash = git_oid_tostr_s( &head );
1517 auto writeRebaseFile = [&](
const wxString& aName,
const std::string& aText )
1519 std::ofstream out( ( rebaseDir + sep + aName ).
ToStdString() );
1520 out << aText <<
"\n";
1523 writeRebaseFile( wxT(
"interactive" ),
"" );
1524 writeRebaseFile( wxT(
"head-name" ),
"refs/heads/master" );
1525 writeRebaseFile( wxT(
"onto" ), headHash );
1526 writeRebaseFile( wxT(
"orig-head" ), headHash );
1528 BOOST_REQUIRE_EQUAL( git_repository_state( repo ), GIT_REPOSITORY_STATE_REBASE_INTERACTIVE );
1534 BOOST_CHECK_MESSAGE( error.Contains( wxT(
"another program" ) ), error );
1535 BOOST_CHECK_MESSAGE( !error.Lower().Contains( wxT(
"not supported" ) ), error );
1537 for(
const wxString&
name : { wxT(
"interactive" ), wxT(
"head-name" ), wxT(
"onto" ), wxT(
"orig-head" ) } )
1538 wxRemoveFile( rebaseDir + sep +
name );
1540 wxFileName::Rmdir( rebaseDir );
1541 git_repository_free( repo );
1547 BOOST_TEST_REQUIRE( ready() );
1550 BOOST_TEST_REQUIRE( repo );
1555 git_oid side = createDetachedCommit( repo, base, wxT(
"file.txt" ),
"side\n",
"Side change" );
1556 git_oid localHead = createCommit( repo, wxT(
"file.txt" ), wxT(
"local\n" ), wxT(
"Local change" ) );
1559 git_annotated_commit* upstream =
nullptr;
1562 git_rebase* rebase =
nullptr;
1563 BOOST_REQUIRE_EQUAL( git_rebase_init( &rebase, repo,
nullptr, upstream,
nullptr,
nullptr ), GIT_OK );
1565 git_rebase_operation* op =
nullptr;
1569 git_rebase_free( rebase );
1570 git_annotated_commit_free( upstream );
1585 BOOST_CHECK( git_oid_equal( &headNow, &localHead ) );
1587 wxTextFile file( repoPath() + wxFileName::GetPathSeparator() + wxT(
"file.txt" ) );
1591 git_repository_free( repo );
1599 BOOST_TEST_REQUIRE( ready() );
1602 BOOST_TEST_REQUIRE( repo );
1606 BOOST_REQUIRE_EQUAL( git_repository_open( &remote, remotePath().ToUTF8().data() ), GIT_OK );
1609 BOOST_REQUIRE_EQUAL( git_reference_name_to_id( &remoteHead, remote,
"refs/heads/master" ), GIT_OK );
1611 git_oid ahead = createDetachedCommit( remote, remoteHead, wxT(
"file.txt" ),
"remote\n",
"Remote change" );
1613 git_reference* ref =
nullptr;
1614 BOOST_REQUIRE_EQUAL( git_reference_create( &ref, remote,
"refs/heads/master", &ahead, 1,
nullptr ), GIT_OK );
1615 git_reference_free( ref );
1616 git_repository_free( remote );
1619 wxString filePath = repoPath() + wxFileName::GetPathSeparator() + wxT(
"file.txt" );
1621 std::ofstream f( filePath.ToStdString() );
1622 f <<
"local edit\n";
1626 setUpstreamConfig( repo, wxT(
"master" ) );
1640 BOOST_CHECK( git_oid_equal( &headBefore, &headAfter ) );
1642 wxTextFile file( filePath );
1646 git_repository_free( repo );
1653 BOOST_TEST_REQUIRE( ready() );
1656 BOOST_TEST_REQUIRE( repo );
1658 createCommit( repo, wxT(
"keep.txt" ), wxT(
"keep\n" ), wxT(
"Add keep" ) );
1659 createCommit( repo, wxT(
"gone.txt" ), wxT(
"gone\n" ), wxT(
"Add gone" ) );
1661 wxString workDir = wxString::FromUTF8( git_repository_workdir( repo ) );
1663 auto writeAll = [](
const wxString& aPath,
const std::string& aContent )
1665 std::ofstream f( aPath.ToStdString(), std::ios::binary );
1669 auto readAll = [](
const wxString& aPath )
1671 std::ifstream in( aPath.ToStdString(), std::ios::binary );
1672 return std::string( ( std::istreambuf_iterator<char>( in ) ), std::istreambuf_iterator<char>() );
1675 writeAll( workDir + wxT(
"file.txt" ),
"accidental\n" );
1676 writeAll( workDir + wxT(
"keep.txt" ),
"still dirty\n" );
1677 writeAll( workDir + wxT(
"new.txt" ),
"never committed\n" );
1678 BOOST_TEST_REQUIRE( wxRemoveFile( workDir + wxT(
"gone.txt" ) ) );
1691 BOOST_CHECK_EQUAL( readAll( workDir + wxT(
"new.txt" ) ),
"never committed\n" );
1693 git_repository_free( repo );
1701 BOOST_TEST_REQUIRE( ready() );
1704 BOOST_TEST_REQUIRE( repo );
1706 createCommit( repo, wxT(
"board[1].txt" ), wxT(
"committed\n" ), wxT(
"Add bracketed" ) );
1707 createCommit( repo, wxT(
"board1.txt" ), wxT(
"other committed\n" ), wxT(
"Add plain" ) );
1709 wxString workDir = wxString::FromUTF8( git_repository_workdir( repo ) );
1711 auto writeAll = [](
const wxString& aPath,
const std::string& aContent )
1713 std::ofstream f( aPath.ToStdString(), std::ios::binary );
1717 auto readAll = [](
const wxString& aPath )
1719 std::ifstream in( aPath.ToStdString(), std::ios::binary );
1720 return std::string( ( std::istreambuf_iterator<char>( in ) ), std::istreambuf_iterator<char>() );
1723 writeAll( workDir + wxT(
"board[1].txt" ),
"edited\n" );
1724 writeAll( workDir + wxT(
"board1.txt" ),
"edited too\n" );
1734 git_repository_free( repo );
1742 BOOST_TEST_REQUIRE( ready() );
1745 BOOST_TEST_REQUIRE( repo );
1747 wxString workDir = wxString::FromUTF8( git_repository_workdir( repo ) );
1749 auto writeAll = [](
const wxString& aPath,
const std::string& aContent )
1751 wxFileName fn( aPath );
1752 fn.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
1754 std::ofstream f( aPath.ToStdString(), std::ios::binary );
1758 writeAll( workDir + wxT(
"a[1]/x.txt" ),
"one\n" );
1759 writeAll( workDir + wxT(
"a1/y.txt" ),
"two\n" );
1764 std::map<wxString, FileStatus> status = handler.
GetFileStatus( wxT(
"a[1]/" ),
true );
1766 bool bracketed =
false;
1769 for(
const auto& [
path, fileStatus] : status )
1771 bracketed |=
path.EndsWith( wxT(
"a[1]/x.txt" ) );
1772 plain |=
path.EndsWith( wxT(
"a1/y.txt" ) );
1775 BOOST_CHECK_MESSAGE( bracketed,
"the folder named in the pathspec was not listed" );
1776 BOOST_CHECK_MESSAGE( !plain,
"a folder the pathspec does not name was listed" );
1778 git_repository_free( repo );
1785 BOOST_TEST_REQUIRE( ready() );
1788 BOOST_TEST_REQUIRE( repo );
1793 git_reference* head =
nullptr;
1796 wxString branch = wxString::FromUTF8( git_reference_shorthand( head ) );
1797 std::string trackingRef = ( wxT(
"refs/remotes/origin/" ) + branch ).utf8_string();
1798 std::string upstreamName = ( wxT(
"origin/" ) + branch ).utf8_string();
1799 git_oid base = *git_reference_target( head );
1801 git_reference* tracking =
nullptr;
1802 BOOST_REQUIRE_EQUAL( git_reference_create( &tracking, repo, trackingRef.c_str(), &base, 0,
nullptr ), GIT_OK );
1803 git_reference_free( tracking );
1807 std::optional<KIGIT_UPSTREAM_STATUS> status = common.
UpstreamStatus();
1812 git_oid remoteTip = createDetachedCommit( repo, base, wxT(
"file.txt" ),
"remote\n",
"Remote change" );
1813 BOOST_REQUIRE_EQUAL( git_reference_create( &tracking, repo, trackingRef.c_str(), &remoteTip, 1,
nullptr ), GIT_OK );
1814 git_reference_free( tracking );
1820 git_reference_free( head );
1821 git_repository_free( repo );
1829 BOOST_TEST_REQUIRE( ready() );
1832 BOOST_TEST_REQUIRE( repo );
1837 createCommit( repo, wxT(
"file.txt" ), wxT(
"mine\n" ), wxT(
"Local change" ) );
1839 git_oid remoteCommitOid = createDetachedCommit( repo, baseOid, wxT(
"file.txt" ),
"remote\n",
"Remote change" );
1841 git_annotated_commit* theirs =
nullptr;
1842 BOOST_REQUIRE_EQUAL( git_annotated_commit_lookup( &theirs, repo, &remoteCommitOid ), GIT_OK );
1844 const git_annotated_commit* heads[1] = { theirs };
1846 git_annotated_commit_free( theirs );
1848 git_index*
index =
nullptr;
1851 git_index_free(
index );
1856 wxString workDir = wxString::FromUTF8( git_repository_workdir( repo ) );
1858 auto readAll = [](
const wxString& aPath )
1860 std::ifstream in( aPath.ToStdString(), std::ios::binary );
1861 return std::string( ( std::istreambuf_iterator<char>( in ) ), std::istreambuf_iterator<char>() );
1864 std::string conflictedBytes = readAll( workDir + wxT(
"file.txt" ) );
1877 std::ofstream f( ( workDir + wxT(
"other.txt" ) ).
ToStdString(), std::ios::binary );
1890 git_index_free(
index );
1900 git_index_free(
index );
1906 git_repository_free( repo );
1913 BOOST_TEST_REQUIRE( ready() );
1916 BOOST_TEST_REQUIRE( repo );
1918 wxString workDir = wxString::FromUTF8( git_repository_workdir( repo ) );
1921 std::ofstream f( ( workDir + wxT(
"staged.txt" ) ).
ToStdString(), std::ios::binary );
1922 f <<
"staged outside\n";
1925 git_index*
index =
nullptr;
1929 git_index_free(
index );
1931 BOOST_TEST_REQUIRE( wxRemoveFile( workDir + wxT(
"staged.txt" ) ) );
1939 git_repository_free( repo );
1947 BOOST_TEST_REQUIRE( ready() );
1950 BOOST_TEST_REQUIRE( repo );
1966 tokenA->store(
true );
1969 std::unique_lock<std::mutex> heldByA = common.
LockAction();
1974 BOOST_CHECK_MESSAGE( tokenB != tokenA,
"each operation must own its own token" );
1977 PushResult resultB = std::async( std::launch::async,
1986 BOOST_CHECK_MESSAGE( tokenA->load(),
"a Busy operation must not clear another's cancellation" );
1987 BOOST_CHECK_MESSAGE( !tokenB->load(),
"a Busy operation must not inherit another's cancellation" );
1989 "a Busy operation must leave the active read cancelled" );
1993 "later reads must not inherit the finished operation's cancellation" );
1998 BOOST_CHECK_MESSAGE( pushC.
CancelToken() != tokenA,
"a later operation must not inherit the retired token" );
2001 git_repository_free( repo );
2037 BOOST_TEST_REQUIRE( ready() );
2039 wxString dest = tempBase() + wxFileName::GetPathSeparator() + wxT(
"clone_cancelled" );
2044 handler.
SetRemote( wxFileSystem::FileNameToURL( wxFileName( remotePath() ) ) );
2047 auto reporter = std::make_unique<CLONE_CANCEL_REPORTER>();
2056 BOOST_CHECK_MESSAGE( !cloned,
"a clone cancelled from the progress dialog must not report success" );
2057 BOOST_CHECK_MESSAGE( !wxDirExists( dest ),
"a cancelled clone must not leave a directory that blocks a retry" );
2061 git_repository_free( common.
GetRepo() );
2070 BOOST_TEST_REQUIRE( ready() );
2073 BOOST_TEST_REQUIRE( repo );
2075 createCommit( repo, wxT(
"file.txt" ), wxT(
"second\n" ), wxT(
"Second commit" ) );
2082 token->store(
true );
2098 git_repository_free( repo );
2105 BOOST_TEST_REQUIRE( ready() );
2108 BOOST_TEST_REQUIRE( repo );
2110 createCommit( repo, wxT(
"file.txt" ), wxT(
"second\n" ), wxT(
"Second commit" ) );
2126 git_repository_free( repo );
2132 BOOST_TEST_REQUIRE( ready() );
2135 BOOST_TEST_REQUIRE( repo );
2137 git_reference* headRefBefore =
nullptr;
2138 git_repository_head( &headRefBefore, repo );
2139 git_oid oidBefore = *git_reference_target( headRefBefore );
2141 git_commit* commitBefore =
nullptr;
2142 git_reference_peel( (git_object**) &commitBefore, headRefBefore, GIT_OBJECT_COMMIT );
2143 git_oid treeBefore = *git_commit_tree_id( commitBefore );
2145 git_commit_free( commitBefore );
2146 git_reference_free( headRefBefore );
2152 git_reference* headRefAfter =
nullptr;
2153 git_repository_head( &headRefAfter, repo );
2154 git_oid oidAfter = *git_reference_target( headRefAfter );
2156 git_commit* commitAfter =
nullptr;
2157 git_reference_peel( (git_object**) &commitAfter, headRefAfter, GIT_OBJECT_COMMIT );
2158 git_oid treeAfter = *git_commit_tree_id( commitAfter );
2160 BOOST_CHECK( !git_oid_equal( &oidBefore, &oidAfter ) );
2161 BOOST_CHECK( git_oid_equal( &treeBefore, &treeAfter ) );
2163 wxString amendedMsg = wxString::FromUTF8( git_commit_message( commitAfter ) );
2166 git_commit_free( commitAfter );
2167 git_reference_free( headRefAfter );
2168 git_repository_free( repo );
2174 BOOST_TEST_REQUIRE( ready() );
2177 BOOST_TEST_REQUIRE( repo );
2179 git_reference* headRefBefore =
nullptr;
2180 git_repository_head( &headRefBefore, repo );
2182 git_commit* commitBefore =
nullptr;
2183 git_reference_peel( (git_object**) &commitBefore, headRefBefore, GIT_OBJECT_COMMIT );
2184 git_oid treeBefore = *git_commit_tree_id( commitBefore );
2185 unsigned int parentCountBefore = git_commit_parentcount( commitBefore );
2187 git_commit_free( commitBefore );
2188 git_reference_free( headRefBefore );
2191 wxString newFile = repoPath() + wxFileName::GetPathSeparator() + wxT(
"new.txt" );
2193 std::ofstream f( newFile.ToStdString() );
2194 f <<
"new content\n";
2202 git_reference* headRefAfter =
nullptr;
2203 git_repository_head( &headRefAfter, repo );
2205 git_commit* commitAfter =
nullptr;
2206 git_reference_peel( (git_object**) &commitAfter, headRefAfter, GIT_OBJECT_COMMIT );
2207 git_oid treeAfter = *git_commit_tree_id( commitAfter );
2208 unsigned int parentCountAfter = git_commit_parentcount( commitAfter );
2210 BOOST_CHECK( !git_oid_equal( &treeBefore, &treeAfter ) );
2214 git_tree* treeObj =
nullptr;
2215 git_commit_tree( &treeObj, commitAfter );
2217 const git_tree_entry* entry = git_tree_entry_byname( treeObj,
"new.txt" );
2220 git_tree_free( treeObj );
2221 git_commit_free( commitAfter );
2222 git_reference_free( headRefAfter );
2223 git_repository_free( repo );
2230 BOOST_TEST_REQUIRE( ready() );
2232 wxString unbornDir = repoPath() + wxT(
"_unborn" );
2233 wxFileName::Mkdir( unbornDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
2236 BOOST_TEST_REQUIRE( git_repository_init( &unbornRepo, unbornDir.ToUTF8().data(), 0 ) == 0 );
2244 git_repository_free( unbornRepo );
2246 if( wxFileName::DirExists( unbornDir ) )
2247 wxFileName::Rmdir( unbornDir, wxPATH_RMDIR_RECURSIVE );
2253 BOOST_TEST_REQUIRE( ready() );
2262 config.username = wxS(
"saved-user" );
2263 config.password = wxS(
"key-passphrase" );
2277 BOOST_TEST_REQUIRE( ready() );
2286 config.url = wxS(
"runner@host:path/repo" );
2287 config.username = wxS(
"saved-user" );
2300 BOOST_TEST_REQUIRE( ready() );
2309 config.username = wxS(
"saved-user" );
2321 config.password = wxS(
"typed@pass:word" );
2331 BOOST_TEST_REQUIRE( ready() );
2339 config.url = wxS(
"http://example.com/repo.git" );
2340 config.username = wxS(
"alice" );
2341 config.password = wxS(
"typed@pass:word" );
2354 BOOST_TEST_REQUIRE( ready() );
2356 wxString freshDir = repoPath() + wxT(
"_fresh" );
2357 wxFileName::Mkdir( freshDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
2365 wxFileName gitignoreFile( freshDir, wxT(
".gitignore" ) );
2366 BOOST_TEST_REQUIRE( gitignoreFile.FileExists() );
2371 useEmptyGlobalIgnore( repo.get() );
2373 const std::pair<const char*, bool> cases[] = {
2374 {
"board.kicad_pcb",
false },
2375 {
"lib.kicad_sym",
false },
2376 {
"board.kicad_pcb-bak",
true },
2377 {
"board.lck",
true },
2378 {
"board.LCK",
true },
2379 {
"~board.kicad_pcb",
true },
2380 {
"proj.kicad_prl",
true },
2381 {
"upper.KiCaD_PrL",
true },
2382 {
"proj-backups/board.zip",
true },
2383 {
"data-proj-backups/board.kicad_pcb",
true },
2384 {
"nested/proj-backups/old/board.zip",
true },
2385 {
"proj-backups-old/board.kicad_pcb",
false },
2386 {
".history/board.kicad_pcb",
true },
2387 {
".history/.git/objects/ab/cdef",
true },
2388 {
".history-notes/board.kicad_pcb",
false },
2389 {
"named/.history",
false },
2390 {
"named/proj-backups",
false },
2391 {
"_autosave-board.kicad_pcb",
true },
2392 {
"_autosave-design/board.kicad_pcb",
true },
2393 {
"fp-info-cache",
true },
2394 {
"fp-info-cache.kicad_pcb",
false },
2395 {
"cache.kicad_prl/board.kicad_pcb",
true },
2396 {
"board.kicad_pcb.mine",
true },
2397 {
"board.kicad_pcb.theirs",
true },
2398 {
"board.kicad_pcb.mine.1",
true },
2399 {
"board.kicad_pcb.theirs.17",
true },
2400 {
"board.kicad_pcb.mine.99",
true },
2401 {
"board.kicad_pcb.mine.100",
false },
2402 {
"board.kicad_pcb.mine.1notes",
false },
2403 {
"board.kicad_pcb.theirs.notes",
false },
2404 {
"board.mine.kicad_pcb",
false },
2405 {
"board.kicad_pcb.1",
false },
2408 for(
const auto& [
path, transient] : cases )
2422 if( wxFileName::DirExists( freshDir ) )
2423 wxFileName::Rmdir( freshDir, wxPATH_RMDIR_RECURSIVE );
2430 BOOST_TEST_REQUIRE( ready() );
2432 wxString freshDir = repoPath() + wxT(
"_existing" );
2433 wxFileName::Mkdir( freshDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
2435 const wxString curated = wxT(
"# my custom ignores\n.history/\nbuild/\n" );
2436 wxFileName gitignoreFile( freshDir, wxT(
".gitignore" ) );
2439 wxFFile f( gitignoreFile.GetFullPath(), wxT(
"wb" ) );
2451 wxFFile f( gitignoreFile.GetFullPath(), wxT(
"rb" ) );
2452 f.ReadAll( &after );
2457 if( wxFileName::DirExists( freshDir ) )
2458 wxFileName::Rmdir( freshDir, wxPATH_RMDIR_RECURSIVE );
2465 BOOST_TEST_REQUIRE( ready() );
2467 wxString freshDir = repoPath() + wxT(
"_emptyignore" );
2468 wxFileName::Mkdir( freshDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
2470 wxFileName gitignoreFile( freshDir, wxT(
".gitignore" ) );
2473 wxFFile f( gitignoreFile.GetFullPath(), wxT(
"wb" ) );
2482 BOOST_TEST_REQUIRE( gitignoreFile.FileExists() );
2485 if( wxFileName::DirExists( freshDir ) )
2486 wxFileName::Rmdir( freshDir, wxPATH_RMDIR_RECURSIVE );
2493 wxString
path = aDir + wxFileName::GetPathSeparator() + wxT(
"proj.kicad_pro" );
2495 if( !wxFileName::FileExists(
path ) )
2497 wxFFile f(
path, wxT(
"w" ) );
2498 f.Write( wxT(
"{\"meta\": {\"filename\": \"proj.kicad_pro\", \"version\": 3}}" ) );
2507 BOOST_TEST_REQUIRE( ready() );
2512 BOOST_TEST_REQUIRE( mgr.
LoadProject( projectPath ) );
2515 BOOST_TEST_REQUIRE(
project !=
nullptr );
2517 std::shared_ptr<KIGIT_COMMON> common =
project->GetGitCommon();
2518 BOOST_TEST_REQUIRE( common !=
nullptr );
2522 BOOST_TEST_REQUIRE(
project->AttachGitRepository() );
2524 BOOST_TEST_REQUIRE( repo !=
nullptr );
2525 BOOST_CHECK( !common->GetProjectDir().IsEmpty() );
2527 BOOST_TEST_REQUIRE(
project->AttachGitRepository() );
2532 std::shared_ptr<KIGIT_COMMON> fresh =
project->GetGitCommon();
2533 BOOST_TEST_REQUIRE( fresh !=
nullptr );
2539 BOOST_TEST_REQUIRE(
project->AttachGitRepository() );
2546 BOOST_TEST_REQUIRE( ready() );
2551 BOOST_TEST_REQUIRE( mgr.
LoadProject( projectPath ) );
2554 BOOST_TEST_REQUIRE(
project !=
nullptr );
2555 BOOST_TEST_REQUIRE(
project->AttachGitRepository() );
2558 BOOST_TEST_REQUIRE( repo !=
nullptr );
2573 git_repository_free( repo );
2579 BOOST_TEST_REQUIRE( ready() );
2581 wxFileName tempBase( repoPath(), wxEmptyString );
2582 tempBase.RemoveLastDir();
2583 wxString outsideDir = tempBase.GetPath() + wxFileName::GetPathSeparator() + wxT(
"no_repo_here" );
2584 wxFileName::Mkdir( outsideDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
2589 BOOST_TEST_REQUIRE( mgr.
LoadProject( projectPath ) );
2592 BOOST_TEST_REQUIRE(
project !=
nullptr );
2601 BOOST_TEST_REQUIRE( ready() );
2606 BOOST_TEST_REQUIRE( mgr.
LoadProject( projectPath ) );
2609 BOOST_TEST_REQUIRE(
project !=
nullptr );
2611 project->GetLocalSettings().m_GitIntegrationDisabled =
true;
2616 project->GetLocalSettings().m_GitIntegrationDisabled =
false;
2627 BOOST_TEST_REQUIRE( ready() );
2632 BOOST_TEST_REQUIRE( mgr.
LoadProject( projectPath ) );
2635 BOOST_TEST_REQUIRE(
project !=
nullptr );
2637 BOOST_TEST_REQUIRE(
project->AttachGitRepository() );
2638 std::shared_ptr<KIGIT_COMMON> common =
project->GetGitCommon();
2640 std::promise<void> lockHeld;
2641 std::promise<void> allowUnlock;
2646 std::unique_lock<std::mutex> lock = common->LockAction();
2647 lockHeld.set_value();
2648 allowUnlock.get_future().wait();
2651 lockHeld.get_future().wait();
2660 allowUnlock.set_value();
2674 BOOST_TEST_REQUIRE( ready() );
2677 BOOST_TEST_REQUIRE( repo );
2679 wxString sep = wxFileName::GetPathSeparator();
2680 BOOST_REQUIRE( wxFileName::Mkdir( repoPath() + sep + wxT(
"shared" ), 0700, wxPATH_MKDIR_FULL ) );
2683 std::ofstream f( ( repoPath() + sep + wxT(
"shared" ) + sep + wxT(
"lib.txt" ) ).
ToStdString() );
2687 BOOST_REQUIRE_EQUAL( symlink(
"shared", ( repoPath() + sep + wxT(
"link" ) ).ToUTF8().data() ), 0 );
2698 git_commit* head =
nullptr;
2701 git_tree* tree =
nullptr;
2704 git_tree_entry* entry =
nullptr;
2705 BOOST_CHECK_MESSAGE( git_tree_entry_bypath( &entry, tree,
"link" ) == GIT_OK,
2706 "the commit dropped the symlink instead of recording it" );
2709 git_tree_entry_free( entry );
2711 git_tree_free( tree );
2712 git_commit_free( head );
2713 git_repository_free( repo );
2722 BOOST_CHECK( PROJECT_GIT_UTILS::IsTransientGitFile( wxFileName(
"proj\\.history\\board.kicad_pcb", wxPATH_DOS ) ) );
2724 PROJECT_GIT_UTILS::IsTransientGitFile( wxFileName(
"proj\\data-proj-backups\\board.zip", wxPATH_DOS ) ) );
2725 BOOST_CHECK( PROJECT_GIT_UTILS::IsTransientGitFile( wxFileName(
"proj\\settings.KICAD_PRL", wxPATH_DOS ) ) );
2726 BOOST_CHECK( PROJECT_GIT_UTILS::IsTransientGitFile( wxFileName(
"proj\\board.kicad_pcb.theirs.99", wxPATH_DOS ) ) );
2727 BOOST_CHECK( !PROJECT_GIT_UTILS::IsTransientGitFile(
2728 wxFileName(
"proj\\.history-notes\\board.kicad_pcb", wxPATH_DOS ) ) );
2729 BOOST_CHECK( !PROJECT_GIT_UTILS::IsTransientGitFile( wxFileName(
"proj\\board.kicad_pcb.mine.100", wxPATH_DOS ) ) );
2738 useEmptyGlobalIgnore( repo.get() );
2741 const wxString prefix = wxS(
"workspace-backups/project/" );
2742 const wxString projectPath = repoPath() + wxS(
"/" ) + prefix;
2745 KI_TEST::WriteGitFile( repoPath(), prefix + wxS(
"deleted.kicad_pcb.mine" ),
"original recovery\n" );
2748 KI_TEST::WriteGitFile( repoPath(), prefix + wxS(
"tracked.kicad_prl" ),
"changed settings with more data\n" );
2749 BOOST_REQUIRE( wxRemoveFile( projectPath + wxS(
"deleted.kicad_pcb.mine" ) ) );
2752 git_index* rawIndex =
nullptr;
2759 const char* untracked[] = {
2760 "board.kicad_pcb",
"untracked.kicad_prl",
"board.kicad_pcb.theirs.17",
2761 "_autosave-board.kicad_pcb",
"project-backups/board.zip",
".history/revisions/board.kicad_pcb",
2764 for(
const char*
path : untracked )
2767 const std::set<wxString>
expected = {
2768 prefix + wxS(
"board.kicad_pcb" ),
2769 prefix + wxS(
"tracked.kicad_prl" ),
2770 prefix + wxS(
"deleted.kicad_pcb.mine" ),
2771 prefix + wxS(
"staged.kicad_prl" ),
2774 auto checkEntries = [&repo, &
expected](
const wxString& aProjectPath )
2777 std::unique_lock<std::mutex> lock = common.
LockAction();
2778 std::set<wxString> paths;
2781 paths.insert( entry.path );
2786 checkEntries( projectPath );
2789 const wxString alias = tempBase() + wxS(
"/project-alias" );
2791 checkEntries( alias );
2800 BOOST_TEST_REQUIRE( ready() );
2803 BOOST_TEST_REQUIRE( repo );
2805 const wxString sep = wxFileName::GetPathSeparator();
2807 createCommit( repo, wxT(
"root.kicad_sch" ), wxT(
"root\n" ), wxT(
"add root" ) );
2809 BOOST_REQUIRE( wxFileName::Mkdir( repoPath() + sep + wxT(
"sub" ), wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) );
2810 createCommit( repo, wxT(
"sub/child.kicad_sch" ), wxT(
"child\n" ), wxT(
"add child" ) );
2813 wxString dest = tempBase() + wxFileName::GetPathSeparator() + wxT(
"tree_out" );
2816 BOOST_CHECK( wxFileName::FileExists( dest + sep + wxT(
"root.kicad_sch" ) ) );
2817 BOOST_CHECK_MESSAGE( wxFileName::FileExists( dest + sep + wxT(
"sub" ) + sep + wxT(
"child.kicad_sch" ) ),
2818 "sub-sheet file in a subdirectory must be materialized alongside the root" );
2820 if( wxFileName::DirExists( dest ) )
2821 wxFileName::Rmdir( dest, wxPATH_RMDIR_RECURSIVE );
2823 git_repository_free( repo );
2831 BOOST_TEST_REQUIRE( ready() );
2834 BOOST_TEST_REQUIRE( repo );
2837 git_reference* headRef =
nullptr;
2839 git_oid baseOid = *git_reference_target( headRef );
2840 git_reference_free( headRef );
2842 createCommit( repo, wxT(
"file.txt" ), wxT(
"mine\n" ), wxT(
"Local change" ) );
2845 git_oid remoteCommitOid = createDetachedCommit( repo, baseOid, wxT(
"file.txt" ),
"remote\n",
"Remote change" );
2848 writeFetchHead( remoteCommitOid );
2852 wxString stageDir = tempBase() + wxFileName::GetPathSeparator() + wxT(
"stages" );
2853 wxString headOid, theirsOid, conflictsError;
2855 std::vector<KIGIT_CONFLICT_SIDES> conflicts;
2858 "GetMergeConflicts failed: " + conflictsError.ToStdString() );
2861 BOOST_CHECK( conflicts[0].hasAncestor && conflicts[0].hasOurs && conflicts[0].hasTheirs );
2865 char expect[GIT_OID_HEXSZ + 1] = { 0 };
2866 git_oid_tostr( expect,
sizeof( expect ), &remoteCommitOid );
2870 auto readAll = [](
const wxString& aPath )
2872 std::ifstream in( aPath.ToStdString(), std::ios::binary );
2873 return std::string( ( std::istreambuf_iterator<char>( in ) ), std::istreambuf_iterator<char>() );
2885 static_cast<int>( common.
CreateMergedCommit( wxT(
"0000000000000000000000000000000000000000" ), theirsOid,
2886 { { conflicts[0].path, conflicts[0].oursFile } }, error ) ),
2891 writeFetchHead( baseOid );
2895 wxString trackedFile = repoPath() + wxFileName::GetPathSeparator() + wxT(
"file.txt" );
2897 std::ofstream f( trackedFile.ToStdString(), std::ios::binary );
2898 f <<
"edited during resolution\n";
2902 headOid, theirsOid, { { conflicts[0].path, conflicts[0].oursFile } }, error ) ),
2906 std::ofstream f( trackedFile.ToStdString(), std::ios::binary );
2913 wxString indexLock = repoPath() + wxFileName::GetPathSeparator() + wxT(
".git" ) + wxFileName::GetPathSeparator()
2914 + wxT(
"index.lock" );
2916 std::ofstream f( indexLock.ToStdString() );
2920 wxString lockedMerged = tempBase() + wxFileName::GetPathSeparator() + wxT(
"locked_merged.txt" );
2921 std::ofstream f( lockedMerged.ToStdString(), std::ios::binary );
2928 headOid, theirsOid, { { conflicts[0].path, lockedMerged } }, error ) ),
2934 char headNowStr[GIT_OID_HEXSZ + 1] = { 0 };
2935 git_oid_tostr( headNowStr,
sizeof( headNowStr ), &headNow );
2939 wxRemoveFile( indexLock );
2945 if( geteuid() != 0 )
2949 wxString refsDir = repoPath() + wxFileName::GetPathSeparator() + wxT(
".git" ) + wxFileName::GetPathSeparator()
2950 + wxT(
"refs" ) + wxFileName::GetPathSeparator() + wxT(
"heads" );
2955 struct WRITABLE_AGAIN
2958 ~WRITABLE_AGAIN() { chmod( dir.fn_str(), 0755 ); }
2959 } restore{ refsDir };
2961 chmod( refsDir.fn_str(), 0555 );
2963 wxString refMerged = tempBase() + wxFileName::GetPathSeparator() + wxT(
"ref_merged.txt" );
2965 std::ofstream f( refMerged.ToStdString() );
2969 BOOST_CHECK_EQUAL(
static_cast<int>( common.CreateMergedCommit( headOid, theirsOid,
2970 { { conflicts[0].path, refMerged } }, error ) ),
2977 char headNowStr[GIT_OID_HEXSZ + 1] = { 0 };
2978 git_oid_tostr( headNowStr,
sizeof( headNowStr ), &headNow );
2981 std::ifstream in( trackedFile.ToStdString(), std::ios::binary );
2982 std::string rolled( ( std::istreambuf_iterator<char>( in ) ), std::istreambuf_iterator<char>() );
2990 std::ofstream f( trackedFile.ToStdString(), std::ios::binary );
2995 wxString mergedFile = tempBase() + wxFileName::GetPathSeparator() + wxT(
"merged.txt" );
2997 std::ofstream f( mergedFile.ToStdString(), std::ios::binary );
3001 BOOST_REQUIRE_MESSAGE( common.CreateMergedCommit( headOid, theirsOid, { { conflicts[0].path, mergedFile } }, error )
3003 "CreateMergedCommit failed: " + error.summary.ToStdString() );
3010 git_commit* mergeCommit =
nullptr;
3015 const git_oid* secondParent = git_commit_parent_id( mergeCommit, 1 );
3017 BOOST_CHECK( git_oid_equal( secondParent, &remoteCommitOid ) );
3018 git_commit_free( mergeCommit );
3020 BOOST_CHECK_EQUAL( readAll( repoPath() + wxFileName::GetPathSeparator() + wxT(
"file.txt" ) ),
"merged\n" );
3023 git_repository_free( repo );
3031 BOOST_TEST_REQUIRE( ready() );
3034 BOOST_TEST_REQUIRE( repo );
3036 git_reference* headRef =
nullptr;
3038 git_oid baseOid = *git_reference_target( headRef );
3039 git_reference_free( headRef );
3041 createCommit( repo, wxT(
"file.txt" ), wxT(
"mine\n" ), wxT(
"Local change" ) );
3042 git_oid remoteCommitOid = createDetachedCommit( repo, baseOid, wxT(
"file.txt" ),
"remote\n",
"Remote change" );
3043 writeFetchHead( remoteCommitOid );
3047 wxString stageDir = tempBase() + wxFileName::GetPathSeparator() + wxT(
"stages" );
3048 wxString headOid, theirsOid, conflictsError;
3050 std::vector<KIGIT_CONFLICT_SIDES> conflicts;
3053 "GetMergeConflicts failed: " + conflictsError.ToStdString() );
3058 wxString
copy = repoPath() + wxFileName::GetPathSeparator() + wxT(
"file.txt.mine" );
3059 std::ofstream f(
copy.ToStdString() );
3063 BOOST_CHECK_MESSAGE(
3064 common.
CreateMergedCommit( headOid, theirsOid, { { conflicts[0].path, conflicts[0].theirsFile } }, error )
3066 "refused with an untracked file present: " + error.summary.ToStdString() );
3068 git_repository_free( repo );
3075 BOOST_TEST_REQUIRE( ready() );
3078 BOOST_TEST_REQUIRE( repo );
3080 git_config*
config =
nullptr;
3083 git_config_free(
config );
3085 git_reference* headRef =
nullptr;
3087 git_oid baseOid = *git_reference_target( headRef );
3088 git_reference_free( headRef );
3090 createCommit( repo, wxT(
"file.txt" ), wxT(
"mine\n" ), wxT(
"Local change" ) );
3091 git_oid remoteCommitOid = createDetachedCommit( repo, baseOid, wxT(
"file.txt" ),
"remote\n",
"Remote change" );
3092 writeFetchHead( remoteCommitOid );
3096 wxString stageDir = tempBase() + wxFileName::GetPathSeparator() + wxT(
"stages" );
3097 wxString headOid, theirsOid, conflictsError;
3099 std::vector<KIGIT_CONFLICT_SIDES> conflicts;
3102 "GetMergeConflicts failed: " + conflictsError.ToStdString() );
3105 wxString mergedFile = tempBase() + wxFileName::GetPathSeparator() + wxT(
"merged.txt" );
3107 std::ofstream f( mergedFile.ToStdString(), std::ios::binary );
3108 f <<
"mine\r\nremote\r\n";
3113 "CreateMergedCommit failed: " + error.summary.ToStdString() );
3115 git_object* blob =
nullptr;
3118 const git_blob* contents =
reinterpret_cast<const git_blob*
>( blob );
3119 BOOST_CHECK_EQUAL( std::string(
static_cast<const char*
>( git_blob_rawcontent( contents ) ),
3120 static_cast<size_t>( git_blob_rawsize( contents ) ) ),
3123 git_object_free( blob );
3124 git_repository_free( repo );
3132 BOOST_TEST_REQUIRE( ready() );
3135 BOOST_TEST_REQUIRE( repo );
3139 for(
int i = 1; i <= 12; ++i )
3140 base << wxString::Format( wxT(
"line %d\n" ), i );
3142 git_oid baseOid = createCommit( repo, wxT(
"file.txt" ), base, wxT(
"Base" ) );
3144 wxString mine = base;
3145 mine.Replace( wxT(
"line 6\n" ), wxT(
"line 6 mine\n" ) );
3146 createCommit( repo, wxT(
"file.txt" ), mine, wxT(
"Local change" ) );
3149 wxString theirs = base;
3150 theirs.Replace( wxT(
"line 6\n" ), wxT(
"line 6 theirs\n" ) );
3152 git_oid theirsOidRaw;
3154 git_commit* baseCommit =
nullptr;
3156 git_tree* baseTree =
nullptr;
3159 git_treebuilder* tb =
nullptr;
3163 std::string content = theirs.utf8_string();
3165 BOOST_REQUIRE_EQUAL( git_blob_create_from_buffer( &blob, repo, content.data(), content.size() ), GIT_OK );
3166 BOOST_REQUIRE_EQUAL( git_treebuilder_insert(
nullptr, tb,
"renamed.txt", &blob, GIT_FILEMODE_BLOB ), GIT_OK );
3170 git_tree* tree =
nullptr;
3173 git_signature* sig =
nullptr;
3175 const git_commit* parents[1] = { baseCommit };
3176 BOOST_REQUIRE_EQUAL( git_commit_create( &theirsOidRaw, repo,
nullptr, sig, sig,
nullptr,
"Rename and edit",
3179 git_signature_free( sig );
3180 git_tree_free( tree );
3181 git_treebuilder_free( tb );
3182 git_tree_free( baseTree );
3183 git_commit_free( baseCommit );
3186 writeFetchHead( theirsOidRaw );
3189 wxString stageDir = tempBase() + wxFileName::GetPathSeparator() + wxT(
"stages" );
3190 wxString headOid, theirsOid, conflictsError;
3192 std::vector<KIGIT_CONFLICT_SIDES> conflicts;
3200 std::vector<std::pair<wxString, wxString>> resolved;
3203 resolved.emplace_back( c.path, c.hasTheirs ? c.theirsFile : wxString() );
3209 wxString workdir = wxString::FromUTF8( git_repository_workdir( repo ) );
3210 bool renamedExists = wxFileExists( workdir + wxT(
"renamed.txt" ) );
3211 bool oldExists = wxFileExists( workdir + wxT(
"file.txt" ) );
3213 BOOST_CHECK_MESSAGE( renamedExists,
"theirs' content must land on the renamed path" );
3214 BOOST_CHECK_MESSAGE( !oldExists,
"the old path must not survive a take-theirs of a rename" );
3216 git_repository_free( repo );
3223 BOOST_TEST_REQUIRE( ready() );
3226 BOOST_TEST_REQUIRE( repo );
3229 createCommit( repo, wxT(
"second.txt" ), wxT(
"two\n" ), wxT(
"Add second" ) );
3232 wxString filePath = repoPath() + wxFileName::GetPathSeparator() + wxT(
"file.txt" );
3233 std::ofstream f( filePath.ToStdString() );
3244 git_commit* head =
nullptr;
3247 git_tree* tree =
nullptr;
3250 BOOST_CHECK_MESSAGE( git_tree_entry_byname( tree,
"second.txt" ) !=
nullptr,
3251 "a file already in the amended commit must survive an amend that does not list it" );
3252 BOOST_CHECK( git_tree_entry_byname( tree,
"file.txt" ) !=
nullptr );
3254 git_tree_free( tree );
3255 git_commit_free( head );
3256 git_repository_free( repo );
3266 BOOST_TEST_REQUIRE( ready() );
3269 BOOST_TEST_REQUIRE( repo );
3271 git_oid localTip = createCommit( repo, wxT(
"file.txt" ), wxT(
"local\n" ), wxT(
"local" ) );
3273 git_commit* tipCommit =
nullptr;
3277 git_reference* localBranch =
nullptr;
3278 BOOST_REQUIRE_EQUAL( git_branch_create( &localBranch, repo,
"feature", tipCommit, 0 ), GIT_OK );
3279 git_reference_free( localBranch );
3282 git_oid remoteTip = createDetachedCommit( repo, localTip, wxT(
"file.txt" ),
"remote\n",
"remote" );
3283 git_reference* tracking =
nullptr;
3284 BOOST_REQUIRE_EQUAL( git_reference_create( &tracking, repo,
"refs/remotes/origin/feature", &remoteTip, 1,
nullptr ),
3286 git_reference_free( tracking );
3294 BOOST_CHECK_MESSAGE( error.Contains( wxS(
"remote" ) ),
3295 "the refusal should say the branch is on the remote, got: " + error.ToStdString() );
3300 BOOST_CHECK( git_oid_equal( &headNow, &localTip ) );
3302 std::ifstream f( ( repoPath() + wxFileName::GetPathSeparator() + wxT(
"file.txt" ) ).
ToStdString() );
3303 std::string content( ( std::istreambuf_iterator<char>( f ) ), std::istreambuf_iterator<char>() );
3306 git_repository_free( repo );
3312 BOOST_TEST_REQUIRE( ready() );
3315 BOOST_TEST_REQUIRE( repo );
3320 git_commit* headCommit =
nullptr;
3323 git_reference* oldBranch =
nullptr;
3324 BOOST_REQUIRE_EQUAL( git_branch_create( &oldBranch, repo,
"old", headCommit, 0 ), GIT_OK );
3325 git_reference_free( oldBranch );
3326 git_commit_free( headCommit );
3328 git_oid advancedOid = createCommit( repo, wxT(
"file.txt" ), wxT(
"master2\n" ), wxT(
"Advance master" ) );
3330 wxString workDir = wxString::FromUTF8( git_repository_workdir( repo ) );
3333 std::ofstream f( ( workDir + wxT(
"file.txt" ) ).
ToStdString(), std::ios::binary );
3334 f <<
"local edit\n";
3346 std::ifstream in( ( workDir + wxT(
"file.txt" ) ).
ToStdString(), std::ios::binary );
3347 std::string content( ( std::istreambuf_iterator<char>( in ) ), std::istreambuf_iterator<char>() );
3350 git_repository_free( repo );
3357 BOOST_TEST_REQUIRE( ready() );
3360 BOOST_TEST_REQUIRE( repo );
3365 git_commit* headCommit =
nullptr;
3368 git_reference* plainBranch =
nullptr;
3369 BOOST_REQUIRE_EQUAL( git_branch_create( &plainBranch, repo,
"plain", headCommit, 0 ), GIT_OK );
3370 git_reference_free( plainBranch );
3371 git_commit_free( headCommit );
3373 createCommit( repo, wxT(
"extra.txt" ), wxT(
"committed\n" ), wxT(
"Add extra" ) );
3380 wxString workDir = wxString::FromUTF8( git_repository_workdir( repo ) );
3383 std::ofstream f( ( workDir + wxT(
"extra.txt" ) ).
ToStdString(), std::ios::binary );
3389 std::ifstream in( ( workDir + wxT(
"extra.txt" ) ).
ToStdString(), std::ios::binary );
3390 std::string content( ( std::istreambuf_iterator<char>( in ) ), std::istreambuf_iterator<char>() );
3393 git_repository_free( repo );
3401 BOOST_TEST_REQUIRE( ready() );
3404 BOOST_TEST_REQUIRE( repo );
3406 createCommit( repo, wxT(
"doomed.txt" ), wxT(
"doomed\n" ), wxT(
"Add doomed" ) );
3408 wxString workDir = wxString::FromUTF8( git_repository_workdir( repo ) );
3409 BOOST_TEST_REQUIRE( wxRemoveFile( workDir + wxT(
"doomed.txt" ) ) );
3420 git_commit* head =
nullptr;
3423 git_tree* tree =
nullptr;
3426 BOOST_CHECK( git_tree_entry_byname( tree,
"doomed.txt" ) ==
nullptr );
3427 BOOST_CHECK( git_tree_entry_byname( tree,
"file.txt" ) !=
nullptr );
3429 git_tree_free( tree );
3430 git_commit_free( head );
3431 git_repository_free( repo );
3439 BOOST_TEST_REQUIRE( ready() );
3442 BOOST_TEST_REQUIRE( repo );
3444 createCommit( repo, wxT(
"board.txt" ), wxT(
"board v1\n" ), wxT(
"Add board" ) );
3445 createCommit( repo, wxT(
"doomed.txt" ), wxT(
"doomed\n" ), wxT(
"Add doomed" ) );
3447 wxString workDir = wxString::FromUTF8( git_repository_workdir( repo ) );
3449 auto writeAll = [&](
const wxString& aName,
const std::string& aContent )
3451 std::ofstream f( ( workDir + aName ).
ToStdString(), std::ios::binary );
3455 auto readAll = [&](
const wxString& aName )
3457 std::ifstream in( ( workDir + aName ).
ToStdString(), std::ios::binary );
3458 return std::string( ( std::istreambuf_iterator<char>( in ) ), std::istreambuf_iterator<char>() );
3462 auto stagedContent = [&](
const char* aPath )
3464 std::string
result =
"<none>";
3465 git_index*
index =
nullptr;
3469 if(
const git_index_entry* entry = git_index_get_bypath(
index, aPath, 0 ) )
3471 git_blob* blob =
nullptr;
3473 result.assign(
static_cast<const char*
>( git_blob_rawcontent( blob ) ), git_blob_rawsize( blob ) );
3474 git_blob_free( blob );
3477 git_index_free(
index );
3481 auto committedContent = [&](
const char* aPath )
3483 std::string
result =
"<none>";
3487 git_commit* head =
nullptr;
3490 git_tree* tree =
nullptr;
3493 git_tree_entry* entry =
nullptr;
3495 if( git_tree_entry_bypath( &entry, tree, aPath ) == GIT_OK )
3497 git_blob* blob =
nullptr;
3498 BOOST_REQUIRE_EQUAL( git_blob_lookup( &blob, repo, git_tree_entry_id( entry ) ), GIT_OK );
3499 result.assign(
static_cast<const char*
>( git_blob_rawcontent( blob ) ), git_blob_rawsize( blob ) );
3500 git_blob_free( blob );
3501 git_tree_entry_free( entry );
3504 git_tree_free( tree );
3505 git_commit_free( head );
3511 writeAll( wxT(
"notes.txt" ),
"staged A\n" );
3512 writeAll( wxT(
"board.txt" ),
"board staged\n" );
3514 git_index*
index =
nullptr;
3520 git_index_free(
index );
3524 writeAll( wxT(
"notes.txt" ),
"working B\n" );
3525 writeAll( wxT(
"board.txt" ),
"board working\n" );
3528 writeAll( wxT(
"file.txt" ),
"selected\n" );
3552 BOOST_TEST_REQUIRE( wxRemoveFile( workDir + wxT(
"file.txt" ) ) );
3574 writeAll( wxT(
"late.txt" ),
"late\n" );
3582 git_repository_free( repo );
3590 BOOST_TEST_REQUIRE( ready() );
3593 BOOST_TEST_REQUIRE( repo );
3595 wxString workDir = wxString::FromUTF8( git_repository_workdir( repo ) );
3597 const wxString umlaut = wxString::FromUTF8(
"Gr\xc3\xb6\xc3\x9f"
3599 const wxString cyrillic = wxString::FromUTF8(
"\xd0\xbf\xd0\xbb\xd0\xb0\xd1\x82\xd0\xb0.txt" );
3600 const std::string umlautUtf8 = umlaut.utf8_string();
3601 const std::string cyrillicUtf8 = cyrillic.utf8_string();
3603 auto writeAll = [&](
const wxString& aName,
const std::string& aContent )
3608 auto inHeadTree = [&](
const std::string& aPath )
3613 git_commit* head =
nullptr;
3616 git_tree* tree =
nullptr;
3619 git_tree_entry* entry =
nullptr;
3620 bool found = git_tree_entry_bypath( &entry, tree, aPath.c_str() ) == GIT_OK;
3623 git_tree_entry_free( entry );
3625 git_tree_free( tree );
3626 git_commit_free( head );
3630 writeAll( umlaut,
"one\n" );
3631 writeAll( cyrillic,
"one\n" );
3642 writeAll( umlaut,
"two\n" );
3647 writeAll( umlaut,
"three\n" );
3653 BOOST_TEST_REQUIRE( wxRemoveFile( workDir + umlaut ) );
3660 git_repository_free( repo );
3668 BOOST_TEST_REQUIRE( ready() );
3671 BOOST_TEST_REQUIRE( repo );
3673 wxString workDir = wxString::FromUTF8( git_repository_workdir( repo ) );
3676 std::ofstream f( ( workDir + wxT(
"notes.txt" ) ).
ToStdString(), std::ios::binary );
3677 f <<
"staged elsewhere\n";
3681 BOOST_REQUIRE_EQUAL( git_repository_open( &foreignRepo, repoPath().ToUTF8().data() ), GIT_OK );
3683 git_index* foreign =
nullptr;
3687 git_index_free( foreign );
3688 git_repository_free( foreignRepo );
3691 std::ofstream f( ( workDir + wxT(
"file.txt" ) ).
ToStdString(), std::ios::binary );
3696 wxString indexLock = repoPath() + wxFileName::GetPathSeparator() + wxT(
".git" ) + wxFileName::GetPathSeparator()
3697 + wxT(
"index.lock" );
3699 std::ofstream f( indexLock.ToStdString() );
3712 BOOST_TEST_REQUIRE( wxRemoveFile( indexLock ) );
3715 BOOST_CHECK_MESSAGE( git_reference_name_to_id( &committed, repo,
"HEAD" ) == GIT_OK,
3716 "the commit must exist even though the index could not be rewritten" );
3719 git_index* after =
nullptr;
3723 const git_index_entry* notes = git_index_get_bypath( after,
"notes.txt", 0 );
3726 git_blob* blob =
nullptr;
3728 std::string content(
static_cast<const char*
>( git_blob_rawcontent( blob ) ), git_blob_rawsize( blob ) );
3731 git_blob_free( blob );
3732 git_index_free( after );
3733 git_repository_free( repo );
3740 BOOST_TEST_REQUIRE( ready() );
3743 BOOST_TEST_REQUIRE( repo );
3745 wxString workDir = wxString::FromUTF8( git_repository_workdir( repo ) );
3747 git_index* cached =
nullptr;
3752 std::ofstream f( ( workDir + wxT(
"notes.txt" ) ).
ToStdString(), std::ios::binary );
3753 f <<
"staged elsewhere\n";
3758 BOOST_REQUIRE_EQUAL( git_repository_open( &foreignRepo, repoPath().ToUTF8().data() ), GIT_OK );
3760 git_index* foreign =
nullptr;
3765 const git_index_entry* stagedBefore = git_index_get_bypath( foreign,
"notes.txt", 0 );
3767 git_oid stagedBlob = stagedBefore->id;
3769 git_index_free( foreign );
3770 git_repository_free( foreignRepo );
3773 std::ofstream f( ( workDir + wxT(
"file.txt" ) ).
ToStdString(), std::ios::binary );
3782 git_repository_free( repo );
3788 git_index* after =
nullptr;
3791 const git_index_entry* notes = git_index_get_bypath( after,
"notes.txt", 0 );
3793 BOOST_CHECK_MESSAGE( git_oid_equal( ¬es->id, &stagedBlob ),
3794 "the externally staged blob must be the exact one the other process wrote" );
3800 git_commit* headCommit =
nullptr;
3803 git_tree* headTree =
nullptr;
3806 git_tree_entry* leaked =
nullptr;
3807 BOOST_CHECK_MESSAGE( git_tree_entry_bypath( &leaked, headTree,
"notes.txt" ) != GIT_OK,
3808 "an unselected staged file must not ride into the amended commit" );
3809 git_tree_entry_free( leaked );
3811 git_tree_free( headTree );
3812 git_commit_free( headCommit );
3813 git_index_free( after );
3814 git_repository_free( fresh );
3820 BOOST_TEST_REQUIRE( ready() );
3823 BOOST_TEST_REQUIRE( repo );
3825 wxString workDir = wxString::FromUTF8( git_repository_workdir( repo ) );
3828 git_index* cached =
nullptr;
3834 std::ofstream f( ( workDir + wxT(
"notes.txt" ) ).
ToStdString(), std::ios::binary );
3835 f <<
"staged elsewhere\n";
3840 BOOST_REQUIRE_EQUAL( git_repository_open( &foreignRepo, repoPath().ToUTF8().data() ), GIT_OK );
3842 git_index* foreign =
nullptr;
3846 git_index_free( foreign );
3847 git_repository_free( foreignRepo );
3850 std::ofstream f( ( workDir + wxT(
"file.txt" ) ).
ToStdString(), std::ios::binary );
3859 git_index* after =
nullptr;
3863 const git_index_entry* notes = git_index_get_bypath( after,
"notes.txt", 0 );
3866 git_blob* blob =
nullptr;
3868 std::string content(
static_cast<const char*
>( git_blob_rawcontent( blob ) ), git_blob_rawsize( blob ) );
3871 git_blob_free( blob );
3872 git_index_free( after );
3873 git_repository_free( repo );
3881 BOOST_TEST_REQUIRE( ready() );
3884 BOOST_TEST_REQUIRE( repo );
3886 createCommit( repo, wxT(
"sneaky.txt" ), wxT(
"clean\n" ), wxT(
"Add sneaky" ) );
3888 wxString workDir = wxString::FromUTF8( git_repository_workdir( repo ) );
3893 std::ofstream f( ( workDir + wxT(
"sneaky.txt" ) ).
ToStdString(), std::ios::binary );
3894 f <<
"staged elsewhere\n";
3897 git_index*
index =
nullptr;
3901 git_index_free(
index );
3904 std::ofstream f( ( workDir + wxT(
"file.txt" ) ).
ToStdString(), std::ios::binary );
3917 git_commit* head =
nullptr;
3920 git_tree* tree =
nullptr;
3923 const git_tree_entry* sneaky = git_tree_entry_byname( tree,
"sneaky.txt" );
3926 git_blob* blob =
nullptr;
3927 BOOST_REQUIRE_EQUAL( git_blob_lookup( &blob, repo, git_tree_entry_id( sneaky ) ), GIT_OK );
3929 std::string sneakyContent(
static_cast<const char*
>( git_blob_rawcontent( blob ) ), git_blob_rawsize( blob ) );
3933 git_blob_free( blob );
3934 git_tree_free( tree );
3935 git_commit_free( head );
3936 git_repository_free( repo );
3943 BOOST_TEST_REQUIRE( ready() );
3946 BOOST_TEST_REQUIRE( repo );
3948 git_oid secondOid = createCommit( repo, wxT(
"file.txt" ), wxT(
"second\n" ), wxT(
"Second version" ) );
3950 git_object* firstObj =
nullptr;
3952 git_oid firstOid = *git_object_id( firstObj );
3953 git_object_free( firstObj );
3955 char firstHash[GIT_OID_HEXSZ + 1] = { 0 };
3956 git_oid_tostr( firstHash,
sizeof( firstHash ), &firstOid );
3962 wxString trackedFile = repoPath() + wxFileName::GetPathSeparator() + wxT(
"file.txt" );
3964 std::ofstream f( trackedFile.ToStdString(), std::ios::binary );
3965 f <<
"uncommitted\n";
3971 std::ofstream f( trackedFile.ToStdString(), std::ios::binary );
3977 "RestoreVersion failed: " + error.
summary.ToStdString() );
3982 git_commit* restoreCommit =
nullptr;
3985 BOOST_CHECK( git_oid_equal( git_commit_parent_id( restoreCommit, 0 ), &secondOid ) );
3986 git_commit_free( restoreCommit );
3988 std::ifstream in( trackedFile.ToStdString() );
3989 std::string content( ( std::istreambuf_iterator<char>( in ) ), std::istreambuf_iterator<char>() );
3995 git_repository_free( repo );
4002 BOOST_TEST_REQUIRE( ready() );
4009 createCommit( repo.get(),
"projects/board/f.txt",
"a1\n",
"A v1" );
4010 git_oid bothV1 = createCommit( repo.get(),
"projects/board2/g.txt",
"b1\n",
"B v1" );
4012 createCommit( repo.get(),
"projects/board/f.txt",
"a2\n",
"A v2" );
4013 createCommit( repo.get(),
"projects/board2/g.txt",
"b2\n",
"B v2" );
4015 char v1Hash[GIT_OID_HEXSZ + 1] = { 0 };
4016 git_oid_tostr( v1Hash,
sizeof( v1Hash ), &bothV1 );
4018 const wxString projectPath = repoPath() + wxS(
"/projects/board" );
4023 "RestoreVersion failed: " + error.
summary.ToStdString() );
4025 auto readAll = [](
const wxString& aPath )
4027 std::ifstream in( aPath.ToStdString(), std::ios::binary );
4028 return std::string( ( std::istreambuf_iterator<char>( in ) ), std::istreambuf_iterator<char>() );
4032 BOOST_CHECK_EQUAL( readAll( repoPath() + wxS(
"/projects/board/f.txt" ) ),
"a1\n" );
4033 BOOST_CHECK_EQUAL( readAll( repoPath() + wxS(
"/projects/board2/g.txt" ) ),
"b2\n" );
4037 char rootHash[GIT_OID_HEXSZ + 1] = { 0 };
4038 git_oid_tostr( rootHash,
sizeof( rootHash ), &rootOid );
4041 BOOST_CHECK_EQUAL( readAll( repoPath() + wxS(
"/projects/board/f.txt" ) ),
"a1\n" );
4045 const wxString projectLink = TempPath() + wxS(
"/project-link" );
4047 createCommit( repo.get(),
"projects/board/f.txt",
"a3\n",
"A v3" );
4052 "RestoreVersion failed: " + error.
summary.ToStdString() );
4053 BOOST_CHECK_EQUAL( readAll( repoPath() + wxS(
"/projects/board/f.txt" ) ),
"a1\n" );
4054 BOOST_CHECK_EQUAL( readAll( repoPath() + wxS(
"/projects/board2/g.txt" ) ),
"b2\n" );
4061 BOOST_TEST_REQUIRE( ready() );
4068 git_oid currentOid = createCommit( repo.get(),
"file.txt",
"second\n",
"Second version" );
4070 char firstHash[GIT_OID_HEXSZ + 1] = { 0 };
4071 git_oid_tostr( firstHash,
sizeof( firstHash ), &firstOid );
4073 const wxString outsidePath = repoPath() + wxS(
"2" );
4075 const std::vector<wxString> projectPaths = { wxEmptyString, TempPath(), outsidePath };
4077 for(
const wxString& projectPath : projectPaths )
4087 BOOST_CHECK( git_oid_equal( ¤tOid, &afterOid ) );
4089 unsigned int status = 0;
4094 wxFile file( repoPath() + wxS(
"/file.txt" ) );
4105 BOOST_TEST_REQUIRE( ready() );
4108 BOOST_TEST_REQUIRE( repo );
4111 git_oid withNotesOid = createCommit( repo, wxT(
"notes.txt" ), wxT(
"keep\n" ), wxT(
"Add notes" ) );
4114 git_index*
index =
nullptr;
4117 git_index_write(
index );
4121 git_index_free(
index );
4123 git_tree* tree =
nullptr;
4126 git_commit* parent =
nullptr;
4129 git_signature* sig =
nullptr;
4132 const git_commit* parents[1] = { parent };
4135 git_commit_create( &deleteOid, repo,
"HEAD", sig, sig,
nullptr,
"Delete notes", tree, 1, parents ),
4138 git_signature_free( sig );
4139 git_commit_free( parent );
4140 git_tree_free( tree );
4141 wxRemoveFile( repoPath() + wxFileName::GetPathSeparator() + wxT(
"notes.txt" ) );
4144 char withNotesHash[GIT_OID_HEXSZ + 1] = { 0 };
4145 git_oid_tostr( withNotesHash,
sizeof( withNotesHash ), &withNotesOid );
4151 wxString notesFile = repoPath() + wxFileName::GetPathSeparator() + wxT(
"notes.txt" );
4153 std::ofstream f( notesFile.ToStdString(), std::ios::binary );
4158 wxString unrelatedFile = repoPath() + wxFileName::GetPathSeparator() + wxT(
"unrelated.txt" );
4160 std::ofstream f( unrelatedFile.ToStdString(), std::ios::binary );
4164 auto readAll = [](
const wxString& aPath )
4166 std::ifstream in( aPath.ToStdString(), std::ios::binary );
4167 return std::string( ( std::istreambuf_iterator<char>( in ) ), std::istreambuf_iterator<char>() );
4174 wxRemoveFile( notesFile );
4178 "RestoreVersion failed: " + error.
summary.ToStdString() );
4182 git_repository_free( repo );
4190 BOOST_TEST_REQUIRE( ready() );
4193 BOOST_TEST_REQUIRE( repo );
4195 git_reference* headRef =
nullptr;
4197 git_oid baseOid = *git_reference_target( headRef );
4198 git_reference_free( headRef );
4202 git_index*
index =
nullptr;
4205 git_index_write(
index );
4209 git_index_free(
index );
4211 git_tree* tree =
nullptr;
4214 git_commit* baseCommit =
nullptr;
4217 git_signature* sig =
nullptr;
4220 const git_commit* parents[1] = { baseCommit };
4223 git_commit_create( &deleteOid, repo,
"HEAD", sig, sig,
nullptr,
"Delete file", tree, 1, parents ),
4226 git_signature_free( sig );
4227 git_commit_free( baseCommit );
4228 git_tree_free( tree );
4229 wxRemoveFile( repoPath() + wxFileName::GetPathSeparator() + wxT(
"file.txt" ) );
4233 git_oid remoteCommitOid = createDetachedCommit( repo, baseOid, wxT(
"file.txt" ),
"remote\n",
"Remote change" );
4235 writeFetchHead( remoteCommitOid );
4239 wxString stageDir = tempBase() + wxFileName::GetPathSeparator() + wxT(
"del_stages" );
4240 wxString headOid, theirsOid, conflictsError;
4242 std::vector<KIGIT_CONFLICT_SIDES> conflicts;
4245 "GetMergeConflicts failed: " + conflictsError.ToStdString() );
4253 "CreateMergedCommit failed: " + error.summary.ToStdString() );
4258 git_commit* mergeCommit =
nullptr;
4262 git_tree* mergedTree =
nullptr;
4264 BOOST_CHECK_MESSAGE( git_tree_entry_byname( mergedTree,
"file.txt" ) ==
nullptr,
4265 "keeping the deletion must not commit the file" );
4266 git_tree_free( mergedTree );
4267 git_commit_free( mergeCommit );
4269 BOOST_CHECK( !wxFileName::FileExists( repoPath() + wxFileName::GetPathSeparator() + wxT(
"file.txt" ) ) );
4271 git_repository_free( repo );
4279 BOOST_TEST_REQUIRE( ready() );
4282 BOOST_TEST_REQUIRE( repo );
4285 wxString filePath = repoPath() + wxFileName::GetPathSeparator() + wxT(
"file.txt" );
4287 std::ofstream f( filePath.ToStdString() );
4288 f <<
"staged-work-in-progress";
4291 git_index*
index =
nullptr;
4293 git_index_add_bypath(
index,
"file.txt" );
4294 git_index_write(
index );
4296 const git_index_entry* before = git_index_get_bypath(
index,
"file.txt", 0 );
4298 git_oid stagedOid = before->id;
4301 wxString dest = tempBase() + wxFileName::GetPathSeparator() + wxT(
"tree_out" );
4307 git_index_read(
index, 1 );
4308 const git_index_entry* after = git_index_get_bypath(
index,
"file.txt", 0 );
4310 BOOST_CHECK_MESSAGE( git_oid_equal( &stagedOid, &after->id ),
4311 "WriteTreeToDir must not rewrite the repository index" );
4313 git_index_free(
index );
4315 if( wxFileName::DirExists( dest ) )
4316 wxFileName::Rmdir( dest, wxPATH_RMDIR_RECURSIVE );
4318 git_repository_free( repo );
void AdvancePhase() override
Use the next available virtual zone of the dialog progress bar.
void SetTitle(const wxString &) override
Change the title displayed on the window caption.
void AdvanceProgress() override
Increment the progress bar length (inside the current virtual zone).
void AddPhases(int) override
void SetCurrentProgress(double) override
Set the progress value to aProgress (0..1).
void Report(const wxString &) override
Display aMessage in the progress bar dialog.
void BeginPhase(int) override
Initialize the aPhase virtual zone of the dialog progress bar.
bool IsCancelled() const override
void AdvancePhase(const wxString &) override
Use the next available virtual zone of the dialog progress bar and updates the message.
void SetMaxProgress(int) override
Fix the value that gives the 100 percent progress bar length (inside the current virtual zone).
bool KeepRefreshing(bool=false) override
Update the UI (if any).
void SetNumPhases(int) override
Set the number of phases.
BranchResult SwitchToBranch(const wxString &aBranchName)
Switch to the specified branch.
void SetRemote(const wxString &aRemote)
void SetClonePath(const wxString &aPath)
CommitResult PerformCommit(const std::vector< wxString > &aFiles, const wxString &aMessage, const wxString &aAuthorName, const wxString &aAuthorEmail)
CommitResult PerformAmend(const std::vector< wxString > &aFiles, const wxString &aMessage, const wxString &aAuthorName, const wxString &aAuthorEmail)
InitResult InitializeRepository(const wxString &aPath)
Initialize a new git repository in the specified directory.
bool SetupRemote(const RemoteConfig &aConfig)
Set up a remote for the repository.
void SetProgressReporter(std::unique_ptr< PROGRESS_REPORTER > aProgressReporter)
bool PerformFetch(bool aSkipLock=false)
PushResult PerformPush(bool aForce=false)
std::map< wxString, FileStatus > GetFileStatus(const wxString &aPathspec=wxEmptyString, bool aChangedOnly=false)
Get detailed file status for all files in the specified path.
Utility class with helper functions for project level git operations.
static bool IsTransientGitFile(const wxFileName &aFile)
Match a project-relative path against the shared transient patterns.
static bool WriteTreeToDir(git_repository *aRepo, const wxString &aRef, const wxString &aDestDir)
Check out a whole tree into a directory, leaving the repository's working copy and index alone.
static bool IsWithinProjectPath(const wxString &aAbsPath, const wxString &aProjectPath)
Test whether an absolute file path lives inside the current project directory.
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.
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
wxString GetRemote() const
bool IsOperationInProgress() const
True while a merge, rebase, cherry-pick or revert is in progress, which refuses commits.
std::unique_lock< std::mutex > LockAction()
git_repository * GetRepo() const
bool AddRemote(const wxString &aName, const wxString &aUrl)
static CANCEL_TOKEN NewCancelToken()
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,...
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 IsShuttingDown() const
Background timers ask this before starting work of their own.
bool DiscardChanges(const std::vector< wxString > &aPaths, wxString &aError)
Put the given working directory relative paths back to their committed state.
wxString GetUsername() const
void SetShuttingDown(bool aCancel)
Stop the operation running now and keep later ones from starting.
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.
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.
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.
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 SetRepo(git_repository *aRepo)
const std::vector< wxString > & GetErrorStrings() const
wxString GetErrorString()
void SetCancelToken(const KIGIT_COMMON::CANCEL_TOKEN &aToken)
Callbacks read this token rather than the session, so one operation's cancel cannot reach another.
const KIGIT_COMMON::CANCEL_TOKEN & CancelToken() const
bool IsThisOperationCancelled() const
Give each test a backend and a temporary directory.
const wxString & TempPath() const
Container for project specific data.
PROJECT * GetProject(const wxString &aFullPath) const
Retrieve a loaded project by name.
bool UnloadProject(PROJECT *aProject, bool aSave=true)
Save, unload and unregister the given PROJECT.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true, bool aOverrideLock=false)
Load a project or sets up a new project with a specified path.
static std::string ToStdString(const wxString &aStr)
void SetGitBackend(GIT_BACKEND *aBackend)
GIT_BACKEND * GetGitBackend()
@ SuccessIndexStale
Committed, but the staged list was left as another program had it. Never retry on this.
@ Busy
Another git operation held the action lock, so nothing was pushed.
std::vector< FILE_CHECKLIST_ENTRY > BuildGitChangeEntries(KIGIT_COMMON &aCommon, const wxString &aProjectPath, bool aDarkTheme)
Build the file checklist entries for the project's changed files, transient files filtered out and ea...
@ 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.
std::unique_ptr< git_repository, decltype([](git_repository *aRepo) { git_repository_free(aRepo); })> GitRepositoryPtr
A unique pointer for git_repository objects with automatic cleanup.
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_config, decltype([](git_config *aConfig) { git_config_free(aConfig); })> GitConfigPtr
A unique pointer for git_config 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_remote, decltype([](git_remote *aRemote) { git_remote_free(aRemote); })> GitRemotePtr
A unique pointer for git_remote objects with automatic cleanup.
KIGIT::GitRepositoryPtr InitGitRepository(const wxString &aPath, const char *aBranch="main", const char *aAuthorName="QA Test", const char *aAuthorEmail="
[email protected]")
Pin the branch and author so repository setup does not depend on the user's Git config.
void WriteGitFile(const wxString &aRepoPath, const wxString &aRelativePath, const std::string &aContents)
Write test data without staging it. Create parent directories when needed.
git_oid CommitAllGitFiles(git_repository *aRepo, const wxString &aMessage)
Stage all changes, including deletions, and commit them.
git_oid CommitGitFile(git_repository *aRepo, const wxString &aPath, const wxString &aMessage)
Stage one file and commit the index. Other staged changes are kept.
bool collide(T aObject, U aAnotherObject, int aLayer, int aMinDistance)
Used by SHAPE_INDEX to implement Query().
One file row in a FILE_CHECKLIST_CTRL.
Build a temp directory tree containing a local working repo with one commit and a bare "remote" repo ...
const wxString & repoPath() const
bool initRepoWithCommit()
wxString readConfig(git_repository *aRepo, const wxString &aKey)
Read a string value from the repo config, or "" if absent.
git_oid createCommit(git_repository *aRepo, const wxString &aFile, const wxString &aContent, const wxString &aMessage)
Create a new commit on the current branch from a single (path, content) pair.
git_repository * openRepo() const
Open the working repo. Caller frees with git_repository_free.
void useEmptyGlobalIgnore(git_repository *aRepo)
bool clearUpstreamConfig(git_repository *aRepo, const wxString &aBranch)
Drop branch.
bool addOrigin(git_repository *aRepo)
Add an origin remote pointing at the bare remote on disk.
const wxString & remotePath() const
bool setUpstreamConfig(git_repository *aRepo, const wxString &aBranch)
Set branch.<aBranch>.merge = refs/heads/<aBranch>, branch.<aBranch>.remote = origin.
void writeFetchHead(const git_oid &aOid)
Write .git/FETCH_HEAD naming aOid, as a fetch would leave it.
bool initBareRemoteFromRepo()
git_oid createDetachedCommit(git_repository *aRepo, const git_oid &aParentOid, const wxString &aFile, const std::string &aContent, const char *aMessage)
Create a commit on top of aParentOid setting aFile to aContent, without moving HEAD.
const wxString & tempBase() const
A summary the user can act on, with the raw text that explains it kept apart for the details.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
BOOST_REQUIRE_EQUAL(rows.size(), 1)
BOOST_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
BOOST_REQUIRE_MESSAGE(dc.CacheTableInfo(table, { "part_id", "val" }), dc.GetLastError())
BOOST_REQUIRE(res.columns()==1)
BOOST_CHECK_EQUAL_COLLECTIONS(mixed.begin(), mixed.end(), expMixed.begin(), expMixed.end())
static const char * TEST_AUTHOR_NAME
static const char * TEST_AUTHOR_EMAIL
BOOST_AUTO_TEST_SUITE_END()
IbisParser parser & reporter
static const char * TEST_AUTHOR_NAME
static const char * TEST_AUTHOR_EMAIL
BOOST_AUTO_TEST_CASE(FetchHeadMarksAtMostOneBranchToMerge)
static wxString seedProjectFile(const wxString &aDir)
VECTOR3I expected(15, 30, 45)
BOOST_TEST_CONTEXT("Test Clearance")
wxString result
Test unit parsing edge cases and error handling.
Definition of file extensions used in Kicad.