345 BOOST_TEST_REQUIRE( ready() );
347 git_repository* repo = openRepo();
348 BOOST_TEST_REQUIRE( repo );
352 wxFileName::Mkdir( repoPath() + wxFileName::GetPathSeparator() + wxT(
"proj" ), wxS_DIR_DEFAULT,
355 std::ofstream f( ( repoPath() + wxFileName::GetPathSeparator() + wxT(
"proj/proj.kicad_sch" ) ).
ToStdString() );
359 std::ofstream f( ( repoPath() + wxFileName::GetPathSeparator() + wxT(
"outside.txt" ) ).
ToStdString() );
364 git_index*
index =
nullptr;
365 BOOST_TEST_REQUIRE( git_repository_index( &
index, repo ) == 0 );
366 git_index_add_bypath(
index,
"proj/proj.kicad_sch" );
367 git_index_add_bypath(
index,
"outside.txt" );
368 git_index_write(
index );
371 git_index_write_tree( &treeOid,
index );
372 git_index_free(
index );
374 git_tree* tree =
nullptr;
375 BOOST_TEST_REQUIRE( git_tree_lookup( &tree, repo, &treeOid ) == 0 );
377 git_signature* sig =
nullptr;
380 git_reference* headRefForParent =
nullptr;
381 git_repository_head( &headRefForParent, repo );
383 git_commit* parent =
nullptr;
384 git_reference_peel( (git_object**) &parent, headRefForParent, GIT_OBJECT_COMMIT );
385 git_reference_free( headRefForParent );
387 const git_commit* parents[1] = { parent };
389 git_commit_create( &commitOid, repo,
"HEAD", sig, sig,
nullptr,
"touch both", tree, 1, parents );
391 git_commit_free( parent );
392 git_signature_free( sig );
393 git_tree_free( tree );
397 common.
SetProjectDir( repoPath() + wxFileName::GetPathSeparator() );
401 wxString projectPath = repoWorkDir + wxT(
"proj" ) + wxFileName::GetPathSeparator();
403 std::map<wxString, int> modifiedFiles;
406 git_reference* headRef =
nullptr;
407 BOOST_TEST_REQUIRE( git_repository_head( &headRef, repo ) == GIT_OK );
409 git_commit* lastCommit =
nullptr;
410 git_reference_peel( (git_object**) &lastCommit, headRef, GIT_OBJECT_COMMIT );
412 git_commit* parentCommit =
nullptr;
413 git_commit_parent( &parentCommit, lastCommit, 0 );
415 git_tree* parentTree =
nullptr;
416 git_tree* lastTree =
nullptr;
417 git_commit_tree( &parentTree, parentCommit );
418 git_commit_tree( &lastTree, lastCommit );
420 git_diff* diff =
nullptr;
421 git_diff_tree_to_tree( &diff, repo, parentTree, lastTree,
nullptr );
423 size_t deltas = git_diff_num_deltas( diff );
425 for(
size_t ii = 0; ii < deltas; ++ii )
427 const git_diff_delta*
delta = git_diff_get_delta( diff, ii );
433 wxString absPath = repoWorkDir + wxString::FromUTF8(
path );
438 modifiedFiles[wxString::FromUTF8(
path )] |= GIT_STATUS_INDEX_MODIFIED;
441 BOOST_CHECK_MESSAGE( modifiedFiles.count( wxT(
"outside.txt" ) ) == 0,
442 "outside.txt must not leak into the amend checklist" );
443 BOOST_CHECK_MESSAGE( modifiedFiles.count( wxT(
"proj/proj.kicad_sch" ) ) == 1,
444 "the project file should still appear in the amend checklist" );
446 git_diff_free( diff );
447 git_tree_free( lastTree );
448 git_tree_free( parentTree );
449 git_commit_free( parentCommit );
450 git_commit_free( lastCommit );
451 git_reference_free( headRef );
452 git_repository_free( repo );
490 BOOST_TEST_REQUIRE( ready() );
492 git_repository* repo = openRepo();
493 BOOST_TEST_REQUIRE( repo );
496 git_oid c1 = createCommit( repo, wxT(
"file.txt" ), wxT(
"edited\n" ), wxT(
"Edit file" ) );
499 git_reference* trackingRef =
nullptr;
500 git_reference_create( &trackingRef, repo,
"refs/remotes/origin/master", &c1, 1,
nullptr );
503 git_reference_free( trackingRef );
506 setUpstreamConfig( repo, wxT(
"master" ) );
509 git_reference* headRef =
nullptr;
510 git_repository_head( &headRef, repo );
512 git_commit* headCommit =
nullptr;
513 git_reference_peel( (git_object**) &headCommit, headRef, GIT_OBJECT_COMMIT );
515 git_tree* tree =
nullptr;
516 git_commit_tree( &tree, headCommit );
518 git_signature* sig =
nullptr;
522 int rc = git_commit_amend( &amendedOid, headCommit,
"HEAD", sig, sig,
nullptr,
"Edit file (message-only amend)",
524 BOOST_TEST_REQUIRE( rc == 0 );
526 git_tree_free( tree );
527 git_commit_free( headCommit );
528 git_reference_free( headRef );
529 git_signature_free( sig );
537 BOOST_CHECK_MESSAGE( ahead.empty(),
"Message-only amend should not report any AHEAD files; got "
538 + std::to_string( ahead.size() ) );
539 BOOST_CHECK_MESSAGE( behind.empty(),
"Message-only amend should not report any BEHIND files; got "
540 + std::to_string( behind.size() ) );
542 git_repository_free( repo );
553 BOOST_TEST_REQUIRE( ready() );
555 git_repository* repo = openRepo();
556 BOOST_TEST_REQUIRE( repo );
558 git_oid c1 = createCommit( repo, wxT(
"file.txt" ), wxT(
"edited\n" ), wxT(
"Edit file" ) );
560 git_reference* trackingRef =
nullptr;
561 git_reference_create( &trackingRef, repo,
"refs/remotes/origin/master", &c1, 1,
nullptr );
564 git_reference_free( trackingRef );
567 setUpstreamConfig( repo, wxT(
"master" ) );
571 createCommit( repo, wxT(
"file.txt" ), wxT(
"edited again\n" ), wxT(
"Re-edit file" ) );
576 BOOST_CHECK_MESSAGE( ahead.count( wxT(
"file.txt" ) ) == 1,
577 "AHEAD should contain file.txt when content differs from upstream" );
579 git_repository_free( repo );
626 BOOST_TEST_REQUIRE( ready() );
628 git_repository* repo = openRepo();
629 BOOST_TEST_REQUIRE( repo );
632 setUpstreamConfig( repo, wxT(
"master" ) );
634 git_object* initial =
nullptr;
635 BOOST_TEST_REQUIRE( git_revparse_single( &initial, repo,
"HEAD" ) == 0 );
638 git_oid remoteOid = createCommit( repo, wxT(
"remote.txt" ), wxT(
"remote\n" ), wxT(
"Remote commit" ) );
645 BOOST_TEST_REQUIRE( git_reset( repo, initial, GIT_RESET_HARD,
nullptr ) == 0 );
646 git_object_free( initial );
648 createCommit( repo, wxT(
"local.txt" ), wxT(
"local\n" ), wxT(
"Local commit" ) );
650 git_config* cfg =
nullptr;
651 BOOST_TEST_REQUIRE( git_repository_config( &cfg, repo ) == 0 );
652 git_config_set_bool( cfg,
"pull.rebase", 1 );
653 git_config_free( cfg );
659 "Rebase pull failed: " + handler.
GetErrorString().ToStdString() );
660 BOOST_CHECK_EQUAL( git_repository_state( repo ),
static_cast<int>( GIT_REPOSITORY_STATE_NONE ) );
662 git_commit* head =
nullptr;
663 BOOST_TEST_REQUIRE( git_revparse_single( (git_object**) &head, repo,
"HEAD" ) == 0 );
664 BOOST_CHECK( git_oid_equal( git_commit_parent_id( head, 0 ), &remoteOid ) );
665 git_commit_free( head );
667 git_repository_free( repo );
709 BOOST_TEST_REQUIRE( ready() );
711 git_repository* repo = openRepo();
712 BOOST_TEST_REQUIRE( repo );
714 git_reference* headRefBefore =
nullptr;
715 git_repository_head( &headRefBefore, repo );
716 git_oid oidBefore = *git_reference_target( headRefBefore );
718 git_commit* commitBefore =
nullptr;
719 git_reference_peel( (git_object**) &commitBefore, headRefBefore, GIT_OBJECT_COMMIT );
720 git_oid treeBefore = *git_commit_tree_id( commitBefore );
722 git_commit_free( commitBefore );
723 git_reference_free( headRefBefore );
729 git_reference* headRefAfter =
nullptr;
730 git_repository_head( &headRefAfter, repo );
731 git_oid oidAfter = *git_reference_target( headRefAfter );
733 git_commit* commitAfter =
nullptr;
734 git_reference_peel( (git_object**) &commitAfter, headRefAfter, GIT_OBJECT_COMMIT );
735 git_oid treeAfter = *git_commit_tree_id( commitAfter );
737 BOOST_CHECK( !git_oid_equal( &oidBefore, &oidAfter ) );
738 BOOST_CHECK( git_oid_equal( &treeBefore, &treeAfter ) );
740 wxString amendedMsg = wxString::FromUTF8( git_commit_message( commitAfter ) );
743 git_commit_free( commitAfter );
744 git_reference_free( headRefAfter );
745 git_repository_free( repo );
754 BOOST_TEST_REQUIRE( ready() );
756 git_repository* repo = openRepo();
757 BOOST_TEST_REQUIRE( repo );
759 git_reference* headRefBefore =
nullptr;
760 git_repository_head( &headRefBefore, repo );
762 git_commit* commitBefore =
nullptr;
763 git_reference_peel( (git_object**) &commitBefore, headRefBefore, GIT_OBJECT_COMMIT );
764 git_oid treeBefore = *git_commit_tree_id( commitBefore );
765 unsigned int parentCountBefore = git_commit_parentcount( commitBefore );
767 git_commit_free( commitBefore );
768 git_reference_free( headRefBefore );
771 wxString newFile = repoPath() + wxFileName::GetPathSeparator() + wxT(
"new.txt" );
773 std::ofstream f( newFile.ToStdString() );
774 f <<
"new content\n";
782 git_reference* headRefAfter =
nullptr;
783 git_repository_head( &headRefAfter, repo );
785 git_commit* commitAfter =
nullptr;
786 git_reference_peel( (git_object**) &commitAfter, headRefAfter, GIT_OBJECT_COMMIT );
787 git_oid treeAfter = *git_commit_tree_id( commitAfter );
788 unsigned int parentCountAfter = git_commit_parentcount( commitAfter );
790 BOOST_CHECK( !git_oid_equal( &treeBefore, &treeAfter ) );
794 git_tree* treeObj =
nullptr;
795 git_commit_tree( &treeObj, commitAfter );
797 const git_tree_entry* entry = git_tree_entry_byname( treeObj,
"new.txt" );
798 BOOST_CHECK( entry !=
nullptr );
800 git_tree_free( treeObj );
801 git_commit_free( commitAfter );
802 git_reference_free( headRefAfter );
803 git_repository_free( repo );
813 BOOST_TEST_REQUIRE( ready() );
815 wxString unbornDir = repoPath() + wxT(
"_unborn" );
816 wxFileName::Mkdir( unbornDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
818 git_repository* unbornRepo =
nullptr;
819 BOOST_TEST_REQUIRE( git_repository_init( &unbornRepo, unbornDir.ToUTF8().data(), 0 ) == 0 );
827 git_repository_free( unbornRepo );
829 if( wxFileName::DirExists( unbornDir ) )
830 wxFileName::Rmdir( unbornDir, wxPATH_RMDIR_RECURSIVE );
840 BOOST_TEST_REQUIRE( ready() );
842 wxString freshDir = repoPath() + wxT(
"_fresh" );
843 wxFileName::Mkdir( freshDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
851 wxFileName gitignoreFile( freshDir, wxT(
".gitignore" ) );
852 BOOST_TEST_REQUIRE( gitignoreFile.FileExists() );
856 wxFFile f( gitignoreFile.GetFullPath(), wxT(
"r" ) );
857 f.ReadAll( &contents );
860 BOOST_CHECK( contents.Contains( wxT(
".history/" ) ) );
861 BOOST_CHECK( contents.Contains( wxT(
"*-backups/" ) ) );
862 BOOST_CHECK( contents.Contains( wxT(
"_autosave-*" ) ) );
863 BOOST_CHECK( contents.Contains( wxT(
"fp-info-cache" ) ) );
864 BOOST_CHECK( contents.Contains( wxT(
"~*.lck" ) ) );
866 if( wxFileName::DirExists( freshDir ) )
867 wxFileName::Rmdir( freshDir, wxPATH_RMDIR_RECURSIVE );
878 BOOST_TEST_REQUIRE( ready() );
880 wxString freshDir = repoPath() + wxT(
"_dedup" );
881 wxFileName::Mkdir( freshDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
883 wxFileName gitignoreFile( freshDir, wxT(
".gitignore" ) );
885 wxFFile f( gitignoreFile.GetFullPath(), wxT(
"w" ) );
886 f.Write( wxT(
"# my custom ignores\n.history/\nbuild/\n" ) );
896 BOOST_TEST_REQUIRE( tf.Open( gitignoreFile.GetFullPath() ) );
898 int historyCount = 0;
902 for(
size_t i = 0; i < tf.GetLineCount(); ++i )
904 wxString line = tf.GetLine( i );
905 line.Trim().Trim(
false );
907 if( line == wxT(
".history/" ) )
909 else if( line == wxT(
"build/" ) )
911 else if( line == wxT(
"fp-info-cache" ) )
919 if( wxFileName::DirExists( freshDir ) )
920 wxFileName::Rmdir( freshDir, wxPATH_RMDIR_RECURSIVE );
wxString result
Test unit parsing edge cases and error handling.
BOOST_CHECK_EQUAL(result, "25.4")