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;
435 "outside.txt must not leak into the amend checklist" );
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" ) );
570 "AHEAD should contain file.txt when content differs from upstream" );
572 git_repository_free( repo );
651 BOOST_TEST_REQUIRE( ready() );
653 git_repository* repo = openRepo();
654 BOOST_TEST_REQUIRE( repo );
656 git_reference* headRefBefore =
nullptr;
657 git_repository_head( &headRefBefore, repo );
658 git_oid oidBefore = *git_reference_target( headRefBefore );
660 git_commit* commitBefore =
nullptr;
661 git_reference_peel( (git_object**) &commitBefore, headRefBefore, GIT_OBJECT_COMMIT );
662 git_oid treeBefore = *git_commit_tree_id( commitBefore );
664 git_commit_free( commitBefore );
665 git_reference_free( headRefBefore );
671 git_reference* headRefAfter =
nullptr;
672 git_repository_head( &headRefAfter, repo );
673 git_oid oidAfter = *git_reference_target( headRefAfter );
675 git_commit* commitAfter =
nullptr;
676 git_reference_peel( (git_object**) &commitAfter, headRefAfter, GIT_OBJECT_COMMIT );
677 git_oid treeAfter = *git_commit_tree_id( commitAfter );
679 BOOST_CHECK( !git_oid_equal( &oidBefore, &oidAfter ) );
680 BOOST_CHECK( git_oid_equal( &treeBefore, &treeAfter ) );
682 wxString amendedMsg = wxString::FromUTF8( git_commit_message( commitAfter ) );
685 git_commit_free( commitAfter );
686 git_reference_free( headRefAfter );
687 git_repository_free( repo );
696 BOOST_TEST_REQUIRE( ready() );
698 git_repository* repo = openRepo();
699 BOOST_TEST_REQUIRE( repo );
701 git_reference* headRefBefore =
nullptr;
702 git_repository_head( &headRefBefore, repo );
704 git_commit* commitBefore =
nullptr;
705 git_reference_peel( (git_object**) &commitBefore, headRefBefore, GIT_OBJECT_COMMIT );
706 git_oid treeBefore = *git_commit_tree_id( commitBefore );
707 unsigned int parentCountBefore = git_commit_parentcount( commitBefore );
709 git_commit_free( commitBefore );
710 git_reference_free( headRefBefore );
713 wxString newFile = repoPath() + wxFileName::GetPathSeparator() + wxT(
"new.txt" );
715 std::ofstream f( newFile.ToStdString() );
716 f <<
"new content\n";
724 git_reference* headRefAfter =
nullptr;
725 git_repository_head( &headRefAfter, repo );
727 git_commit* commitAfter =
nullptr;
728 git_reference_peel( (git_object**) &commitAfter, headRefAfter, GIT_OBJECT_COMMIT );
729 git_oid treeAfter = *git_commit_tree_id( commitAfter );
730 unsigned int parentCountAfter = git_commit_parentcount( commitAfter );
732 BOOST_CHECK( !git_oid_equal( &treeBefore, &treeAfter ) );
736 git_tree* treeObj =
nullptr;
737 git_commit_tree( &treeObj, commitAfter );
739 const git_tree_entry* entry = git_tree_entry_byname( treeObj,
"new.txt" );
740 BOOST_CHECK( entry !=
nullptr );
742 git_tree_free( treeObj );
743 git_commit_free( commitAfter );
744 git_reference_free( headRefAfter );
745 git_repository_free( repo );
755 BOOST_TEST_REQUIRE( ready() );
757 wxString unbornDir = repoPath() + wxT(
"_unborn" );
758 wxFileName::Mkdir( unbornDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
760 git_repository* unbornRepo =
nullptr;
761 BOOST_TEST_REQUIRE( git_repository_init( &unbornRepo, unbornDir.ToUTF8().data(), 0 ) == 0 );
769 git_repository_free( unbornRepo );
771 if( wxFileName::DirExists( unbornDir ) )
772 wxFileName::Rmdir( unbornDir, wxPATH_RMDIR_RECURSIVE );
782 BOOST_TEST_REQUIRE( ready() );
784 wxString freshDir = repoPath() + wxT(
"_fresh" );
785 wxFileName::Mkdir( freshDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
793 wxFileName gitignoreFile( freshDir, wxT(
".gitignore" ) );
794 BOOST_TEST_REQUIRE( gitignoreFile.FileExists() );
798 wxFFile f( gitignoreFile.GetFullPath(), wxT(
"r" ) );
799 f.ReadAll( &contents );
802 BOOST_CHECK( contents.Contains( wxT(
".history/" ) ) );
803 BOOST_CHECK( contents.Contains( wxT(
"*-backups/" ) ) );
804 BOOST_CHECK( contents.Contains( wxT(
"_autosave-*" ) ) );
805 BOOST_CHECK( contents.Contains( wxT(
"fp-info-cache" ) ) );
806 BOOST_CHECK( contents.Contains( wxT(
"~*.lck" ) ) );
808 if( wxFileName::DirExists( freshDir ) )
809 wxFileName::Rmdir( freshDir, wxPATH_RMDIR_RECURSIVE );
820 BOOST_TEST_REQUIRE( ready() );
822 wxString freshDir = repoPath() + wxT(
"_dedup" );
823 wxFileName::Mkdir( freshDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
825 wxFileName gitignoreFile( freshDir, wxT(
".gitignore" ) );
827 wxFFile f( gitignoreFile.GetFullPath(), wxT(
"w" ) );
828 f.Write( wxT(
"# my custom ignores\n.history/\nbuild/\n" ) );
838 BOOST_TEST_REQUIRE( tf.Open( gitignoreFile.GetFullPath() ) );
840 int historyCount = 0;
844 for(
size_t i = 0; i < tf.GetLineCount(); ++i )
846 wxString line = tf.GetLine( i );
847 line.Trim().Trim(
false );
849 if( line == wxT(
".history/" ) )
851 else if( line == wxT(
"build/" ) )
853 else if( line == wxT(
"fp-info-cache" ) )
861 if( wxFileName::DirExists( freshDir ) )
862 wxFileName::Rmdir( freshDir, wxPATH_RMDIR_RECURSIVE );
wxString result
Test unit parsing edge cases and error handling.
BOOST_CHECK_EQUAL(result, "25.4")