338 BOOST_TEST_REQUIRE( ready() );
340 git_repository* repo = openRepo();
341 BOOST_TEST_REQUIRE( repo );
345 wxFileName::Mkdir( repoPath() + wxFileName::GetPathSeparator() + wxT(
"proj" ), wxS_DIR_DEFAULT,
348 std::ofstream f( ( repoPath() + wxFileName::GetPathSeparator() + wxT(
"proj/proj.kicad_sch" ) ).
ToStdString() );
352 std::ofstream f( ( repoPath() + wxFileName::GetPathSeparator() + wxT(
"outside.txt" ) ).
ToStdString() );
357 git_index*
index =
nullptr;
358 BOOST_TEST_REQUIRE( git_repository_index( &
index, repo ) == 0 );
359 git_index_add_bypath(
index,
"proj/proj.kicad_sch" );
360 git_index_add_bypath(
index,
"outside.txt" );
361 git_index_write(
index );
364 git_index_write_tree( &treeOid,
index );
365 git_index_free(
index );
367 git_tree* tree =
nullptr;
368 BOOST_TEST_REQUIRE( git_tree_lookup( &tree, repo, &treeOid ) == 0 );
370 git_signature* sig =
nullptr;
373 git_reference* headRefForParent =
nullptr;
374 git_repository_head( &headRefForParent, repo );
376 git_commit* parent =
nullptr;
377 git_reference_peel( (git_object**) &parent, headRefForParent, GIT_OBJECT_COMMIT );
378 git_reference_free( headRefForParent );
380 const git_commit* parents[1] = { parent };
382 git_commit_create( &commitOid, repo,
"HEAD", sig, sig,
nullptr,
"touch both", tree, 1, parents );
384 git_commit_free( parent );
385 git_signature_free( sig );
386 git_tree_free( tree );
390 common.
SetProjectDir( repoPath() + wxFileName::GetPathSeparator() );
394 wxString projectPath = repoWorkDir + wxT(
"proj" ) + wxFileName::GetPathSeparator();
396 std::map<wxString, int> modifiedFiles;
399 git_reference* headRef =
nullptr;
400 BOOST_TEST_REQUIRE( git_repository_head( &headRef, repo ) == GIT_OK );
402 git_commit* lastCommit =
nullptr;
403 git_reference_peel( (git_object**) &lastCommit, headRef, GIT_OBJECT_COMMIT );
405 git_commit* parentCommit =
nullptr;
406 git_commit_parent( &parentCommit, lastCommit, 0 );
408 git_tree* parentTree =
nullptr;
409 git_tree* lastTree =
nullptr;
410 git_commit_tree( &parentTree, parentCommit );
411 git_commit_tree( &lastTree, lastCommit );
413 git_diff* diff =
nullptr;
414 git_diff_tree_to_tree( &diff, repo, parentTree, lastTree,
nullptr );
416 size_t deltas = git_diff_num_deltas( diff );
418 for(
size_t ii = 0; ii < deltas; ++ii )
420 const git_diff_delta*
delta = git_diff_get_delta( diff, ii );
426 wxString absPath = repoWorkDir + wxString::FromUTF8(
path );
431 modifiedFiles[wxString::FromUTF8(
path )] |= GIT_STATUS_INDEX_MODIFIED;
434 BOOST_CHECK_MESSAGE( modifiedFiles.count( wxT(
"outside.txt" ) ) == 0,
435 "outside.txt must not leak into the amend checklist" );
436 BOOST_CHECK_MESSAGE( modifiedFiles.count( wxT(
"proj/proj.kicad_sch" ) ) == 1,
437 "the project file should still appear in the amend checklist" );
439 git_diff_free( diff );
440 git_tree_free( lastTree );
441 git_tree_free( parentTree );
442 git_commit_free( parentCommit );
443 git_commit_free( lastCommit );
444 git_reference_free( headRef );
445 git_repository_free( repo );
483 BOOST_TEST_REQUIRE( ready() );
485 git_repository* repo = openRepo();
486 BOOST_TEST_REQUIRE( repo );
489 git_oid c1 = createCommit( repo, wxT(
"file.txt" ), wxT(
"edited\n" ), wxT(
"Edit file" ) );
492 git_reference* trackingRef =
nullptr;
493 git_reference_create( &trackingRef, repo,
"refs/remotes/origin/master", &c1, 1,
nullptr );
496 git_reference_free( trackingRef );
499 setUpstreamConfig( repo, wxT(
"master" ) );
502 git_reference* headRef =
nullptr;
503 git_repository_head( &headRef, repo );
505 git_commit* headCommit =
nullptr;
506 git_reference_peel( (git_object**) &headCommit, headRef, GIT_OBJECT_COMMIT );
508 git_tree* tree =
nullptr;
509 git_commit_tree( &tree, headCommit );
511 git_signature* sig =
nullptr;
515 int rc = git_commit_amend( &amendedOid, headCommit,
"HEAD", sig, sig,
nullptr,
"Edit file (message-only amend)",
517 BOOST_TEST_REQUIRE( rc == 0 );
519 git_tree_free( tree );
520 git_commit_free( headCommit );
521 git_reference_free( headRef );
522 git_signature_free( sig );
530 BOOST_CHECK_MESSAGE( ahead.empty(),
"Message-only amend should not report any AHEAD files; got "
531 + std::to_string( ahead.size() ) );
532 BOOST_CHECK_MESSAGE( behind.empty(),
"Message-only amend should not report any BEHIND files; got "
533 + std::to_string( behind.size() ) );
535 git_repository_free( repo );
546 BOOST_TEST_REQUIRE( ready() );
548 git_repository* repo = openRepo();
549 BOOST_TEST_REQUIRE( repo );
551 git_oid c1 = createCommit( repo, wxT(
"file.txt" ), wxT(
"edited\n" ), wxT(
"Edit file" ) );
553 git_reference* trackingRef =
nullptr;
554 git_reference_create( &trackingRef, repo,
"refs/remotes/origin/master", &c1, 1,
nullptr );
557 git_reference_free( trackingRef );
560 setUpstreamConfig( repo, wxT(
"master" ) );
564 createCommit( repo, wxT(
"file.txt" ), wxT(
"edited again\n" ), wxT(
"Re-edit file" ) );
569 BOOST_CHECK_MESSAGE( ahead.count( wxT(
"file.txt" ) ) == 1,
570 "AHEAD should contain file.txt when content differs from upstream" );
572 git_repository_free( repo );
619 BOOST_TEST_REQUIRE( ready() );
621 git_repository* repo = openRepo();
622 BOOST_TEST_REQUIRE( repo );
625 setUpstreamConfig( repo, wxT(
"master" ) );
627 git_object* initial =
nullptr;
628 BOOST_TEST_REQUIRE( git_revparse_single( &initial, repo,
"HEAD" ) == 0 );
631 git_oid remoteOid = createCommit( repo, wxT(
"remote.txt" ), wxT(
"remote\n" ), wxT(
"Remote commit" ) );
638 BOOST_TEST_REQUIRE( git_reset( repo, initial, GIT_RESET_HARD,
nullptr ) == 0 );
639 git_object_free( initial );
641 createCommit( repo, wxT(
"local.txt" ), wxT(
"local\n" ), wxT(
"Local commit" ) );
643 git_config* cfg =
nullptr;
644 BOOST_TEST_REQUIRE( git_repository_config( &cfg, repo ) == 0 );
645 git_config_set_bool( cfg,
"pull.rebase", 1 );
646 git_config_free( cfg );
652 "Rebase pull failed: " + handler.
GetErrorString().ToStdString() );
653 BOOST_CHECK_EQUAL( git_repository_state( repo ),
static_cast<int>( GIT_REPOSITORY_STATE_NONE ) );
655 git_commit* head =
nullptr;
656 BOOST_TEST_REQUIRE( git_revparse_single( (git_object**) &head, repo,
"HEAD" ) == 0 );
657 BOOST_CHECK( git_oid_equal( git_commit_parent_id( head, 0 ), &remoteOid ) );
658 git_commit_free( head );
660 git_repository_free( repo );
702 BOOST_TEST_REQUIRE( ready() );
704 git_repository* repo = openRepo();
705 BOOST_TEST_REQUIRE( repo );
707 git_reference* headRefBefore =
nullptr;
708 git_repository_head( &headRefBefore, repo );
709 git_oid oidBefore = *git_reference_target( headRefBefore );
711 git_commit* commitBefore =
nullptr;
712 git_reference_peel( (git_object**) &commitBefore, headRefBefore, GIT_OBJECT_COMMIT );
713 git_oid treeBefore = *git_commit_tree_id( commitBefore );
715 git_commit_free( commitBefore );
716 git_reference_free( headRefBefore );
722 git_reference* headRefAfter =
nullptr;
723 git_repository_head( &headRefAfter, repo );
724 git_oid oidAfter = *git_reference_target( headRefAfter );
726 git_commit* commitAfter =
nullptr;
727 git_reference_peel( (git_object**) &commitAfter, headRefAfter, GIT_OBJECT_COMMIT );
728 git_oid treeAfter = *git_commit_tree_id( commitAfter );
730 BOOST_CHECK( !git_oid_equal( &oidBefore, &oidAfter ) );
731 BOOST_CHECK( git_oid_equal( &treeBefore, &treeAfter ) );
733 wxString amendedMsg = wxString::FromUTF8( git_commit_message( commitAfter ) );
736 git_commit_free( commitAfter );
737 git_reference_free( headRefAfter );
738 git_repository_free( repo );
747 BOOST_TEST_REQUIRE( ready() );
749 git_repository* repo = openRepo();
750 BOOST_TEST_REQUIRE( repo );
752 git_reference* headRefBefore =
nullptr;
753 git_repository_head( &headRefBefore, repo );
755 git_commit* commitBefore =
nullptr;
756 git_reference_peel( (git_object**) &commitBefore, headRefBefore, GIT_OBJECT_COMMIT );
757 git_oid treeBefore = *git_commit_tree_id( commitBefore );
758 unsigned int parentCountBefore = git_commit_parentcount( commitBefore );
760 git_commit_free( commitBefore );
761 git_reference_free( headRefBefore );
764 wxString newFile = repoPath() + wxFileName::GetPathSeparator() + wxT(
"new.txt" );
766 std::ofstream f( newFile.ToStdString() );
767 f <<
"new content\n";
775 git_reference* headRefAfter =
nullptr;
776 git_repository_head( &headRefAfter, repo );
778 git_commit* commitAfter =
nullptr;
779 git_reference_peel( (git_object**) &commitAfter, headRefAfter, GIT_OBJECT_COMMIT );
780 git_oid treeAfter = *git_commit_tree_id( commitAfter );
781 unsigned int parentCountAfter = git_commit_parentcount( commitAfter );
783 BOOST_CHECK( !git_oid_equal( &treeBefore, &treeAfter ) );
787 git_tree* treeObj =
nullptr;
788 git_commit_tree( &treeObj, commitAfter );
790 const git_tree_entry* entry = git_tree_entry_byname( treeObj,
"new.txt" );
791 BOOST_CHECK( entry !=
nullptr );
793 git_tree_free( treeObj );
794 git_commit_free( commitAfter );
795 git_reference_free( headRefAfter );
796 git_repository_free( repo );
806 BOOST_TEST_REQUIRE( ready() );
808 wxString unbornDir = repoPath() + wxT(
"_unborn" );
809 wxFileName::Mkdir( unbornDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
811 git_repository* unbornRepo =
nullptr;
812 BOOST_TEST_REQUIRE( git_repository_init( &unbornRepo, unbornDir.ToUTF8().data(), 0 ) == 0 );
820 git_repository_free( unbornRepo );
822 if( wxFileName::DirExists( unbornDir ) )
823 wxFileName::Rmdir( unbornDir, wxPATH_RMDIR_RECURSIVE );
833 BOOST_TEST_REQUIRE( ready() );
835 wxString freshDir = repoPath() + wxT(
"_fresh" );
836 wxFileName::Mkdir( freshDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
844 wxFileName gitignoreFile( freshDir, wxT(
".gitignore" ) );
845 BOOST_TEST_REQUIRE( gitignoreFile.FileExists() );
849 wxFFile f( gitignoreFile.GetFullPath(), wxT(
"r" ) );
850 f.ReadAll( &contents );
853 BOOST_CHECK( contents.Contains( wxT(
".history/" ) ) );
854 BOOST_CHECK( contents.Contains( wxT(
"*-backups/" ) ) );
855 BOOST_CHECK( contents.Contains( wxT(
"_autosave-*" ) ) );
856 BOOST_CHECK( contents.Contains( wxT(
"fp-info-cache" ) ) );
857 BOOST_CHECK( contents.Contains( wxT(
"~*.lck" ) ) );
859 if( wxFileName::DirExists( freshDir ) )
860 wxFileName::Rmdir( freshDir, wxPATH_RMDIR_RECURSIVE );
871 BOOST_TEST_REQUIRE( ready() );
873 wxString freshDir = repoPath() + wxT(
"_dedup" );
874 wxFileName::Mkdir( freshDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
876 wxFileName gitignoreFile( freshDir, wxT(
".gitignore" ) );
878 wxFFile f( gitignoreFile.GetFullPath(), wxT(
"w" ) );
879 f.Write( wxT(
"# my custom ignores\n.history/\nbuild/\n" ) );
889 BOOST_TEST_REQUIRE( tf.Open( gitignoreFile.GetFullPath() ) );
891 int historyCount = 0;
895 for(
size_t i = 0; i < tf.GetLineCount(); ++i )
897 wxString line = tf.GetLine( i );
898 line.Trim().Trim(
false );
900 if( line == wxT(
".history/" ) )
902 else if( line == wxT(
"build/" ) )
904 else if( line == wxT(
"fp-info-cache" ) )
912 if( wxFileName::DirExists( freshDir ) )
913 wxFileName::Rmdir( freshDir, wxPATH_RMDIR_RECURSIVE );
wxString result
Test unit parsing edge cases and error handling.
BOOST_CHECK_EQUAL(result, "25.4")