39#include <wx/filename.h>
61 void writeFile(
const wxString& aFile,
const wxString& aContent )
69 wxRemoveFile(
m_repoPath + wxFileName::GetPathSeparator() + aFile );
85 writeFile( wxT(
"a.txt" ), wxT(
"alpha\n" ) );
86 writeFile( wxT(
"b.txt" ), wxT(
"bravo\n" ) );
89 writeFile( wxT(
"a.txt" ), wxT(
"alpha modified\n" ) );
91 writeFile( wxT(
"c.txt" ), wxT(
"charlie\n" ) );
107 BOOST_CHECK( head.get() !=
nullptr );
110 BOOST_CHECK( prev.get() !=
nullptr );
113 BOOST_CHECK( head.get() != prev.get() );
140 git_diff* diff =
nullptr;
141 git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
144 git_diff_tree_to_tree( &diff, repo(), baseTree.get(), headTree.get(), &opts ), 0 );
148 std::map<wxString, git_delta_t> seen;
150 [&seen](
const git_diff_delta& aDelta )
152 const char*
path = aDelta.new_file.path ? aDelta.new_file.path
153 : aDelta.old_file.path;
154 seen[wxString::FromUTF8(
path )] = aDelta.status;
158 BOOST_CHECK( seen.at( wxT(
"a.txt" ) ) == GIT_DELTA_MODIFIED );
159 BOOST_CHECK( seen.at( wxT(
"b.txt" ) ) == GIT_DELTA_DELETED );
160 BOOST_CHECK( seen.at( wxT(
"c.txt" ) ) == GIT_DELTA_ADDED );
166 std::vector<KIGIT::CHANGED_FILE> changes =
169 std::map<wxString, KIGIT::FILE_CHANGE_STATUS> byPath;
172 byPath[f.path] = f.status;
192 std::vector<KIGIT::CHANGED_FILE> changes =
KIGIT::CompareRefs( repo(), wxEmptyString, wxT(
"HEAD~1" ) );
194 std::map<wxString, KIGIT::FILE_CHANGE_STATUS> byPath;
197 byPath[f.path] = f.status;
199 BOOST_REQUIRE_EQUAL( changes.size(), 2u );
Give each test a backend and a temporary directory.
const wxString & TempPath() const
static bool empty(const wxTextEntryBase *aCtrl)
std::unique_ptr< git_tree, decltype([](git_tree *aTree) { git_tree_free(aTree); })> GitTreePtr
A unique pointer for git_tree objects with automatic cleanup.
std::vector< CHANGED_FILE > CompareRefs(git_repository *aRepo, const wxString &aBaseRef, const wxString &aHeadRef)
Compare two git refs (branch / tag / commit OID) within a repository and return the per-file change l...
std::unique_ptr< git_repository, decltype([](git_repository *aRepo) { git_repository_free(aRepo); })> GitRepositoryPtr
A unique pointer for git_repository objects with automatic cleanup.
git_tree * ResolveRefToTree(git_repository *aRepo, const wxString &aRef)
Resolve a string ref (branch name, short OID, full OID, tag) to its tree.
void CollectDiffDeltas(git_diff *aDiff, const std::function< void(const git_diff_delta &)> &aCallback)
Walk every delta in a computed diff, invoking aCallback once per delta.
std::unique_ptr< git_diff, decltype([](git_diff *aDiff) { git_diff_free(aDiff); })> GitDiffPtr
A unique pointer for git_diff 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.
Build a temp working repo with two commits.
git_repository * repo() const
KIGIT::GitRepositoryPtr m_repo
void removeFile(const wxString &aFile)
void commitAll(const wxString &aMessage)
Stage every change, including deletions, and create a commit on HEAD.
void writeFile(const wxString &aFile, const wxString &aContent)
Write a file in the working tree.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
static const char * TEST_AUTHOR_NAME
BOOST_AUTO_TEST_CASE(ResolveRefToTree_Valid)
static const char * TEST_AUTHOR_EMAIL
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")