KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_libgit_backend.cpp File Reference

Regression tests for LIBGIT_BACKEND, KIGIT_COMMON, GIT_INIT_HANDLER, GIT_PULL_HANDLER, GIT_PUSH_HANDLER, GIT_COMMIT_HANDLER focused on the recent Git integration bug fixes and the Amend Last Commit feature. More...

#include <qa_utils/wx_utils/unit_test_utils.h>
#include <git/git_backend.h>
#include <git/libgit_backend.h>
#include <git/kicad_git_common.h>
#include <git/git_init_handler.h>
#include <git/git_pull_handler.h>
#include <git/git_push_handler.h>
#include <git/git_commit_handler.h>
#include <git2.h>
#include <fstream>
#include <wx/ffile.h>
#include <wx/filename.h>
#include <wx/textfile.h>
#include <wx/utils.h>

Go to the source code of this file.

Classes

struct  GIT_BACKEND_FIXTURE
 Build a temp directory tree containing a local working repo with one commit and a bare "remote" repo cloned from it. More...
 

Functions

 BOOST_AUTO_TEST_CASE (GetUpstreamShorthand_NoUpstreamFallsBackToRemoteSlashBranch)
 When the local branch has no upstream configured, GetUpstreamShorthand must synthesise <remote>/<branch> so the pull fallback and first-push paths have a meaningful target to display and act on.
 
 BOOST_AUTO_TEST_CASE (GetDifferentFiles_SameTreeAmendHidesAheadFiles)
 Regression for the spurious clock icon after a message-only amend: when HEAD and the upstream tracking ref point at different commit OIDs but the commits share an identical tree, no file should be reported as AHEAD or BEHIND.
 
 BOOST_AUTO_TEST_CASE (GetDifferentFiles_DifferentTreeAmendKeepsAheadFile)
 Positive control: if the amend genuinely changes the file content, the file should still appear in the AHEAD set.
 
 BOOST_AUTO_TEST_CASE (PerformPull_NoUpstreamConfig_FallbackSucceedsAndWritesUpstream)
 Regression for the original issue #24332 surface: pull on a fresh repo where Add Version Control wired up origin but never set per-branch upstream tracking used to fail with "Could not lookup commit" because FETCH_HEAD has no merge-marked entry.
 
 BOOST_AUTO_TEST_CASE (Push_FirstPushSetsUpstreamTracking)
 Push -u behavior: after the first successful push from a branch with no upstream configured, branch.
 
 BOOST_AUTO_TEST_CASE (Amend_MessageOnlyRewritesHeadKeepsTree)
 Amend rewrites HEAD with a new commit OID.
 
 BOOST_AUTO_TEST_CASE (Amend_StagedFileChangesTreeAndKeepsParent)
 Amend with new files: the tree changes and includes the newly staged content.
 
 BOOST_AUTO_TEST_CASE (Amend_UnbornBranchReturnsError)
 Amending an unborn branch (a fresh repo with no commits yet) must fail cleanly rather than crash or produce a bogus commit.
 
 BOOST_AUTO_TEST_CASE (InitializeRepository_SeedsGitignoreWithKicadEntries)
 InitializeRepository seeds a project-level .gitignore with KiCad-specific transient paths (.history/, -backups/, _autosave-, fp-info-cache, ~*.lck).
 
 BOOST_AUTO_TEST_CASE (InitializeRepository_GitignoreDoesNotDuplicateEntries)
 InitializeRepository must not duplicate entries that the user (or a template) has already written.
 

Variables

static const char * TEST_AUTHOR_NAME = "Test Author"
 
static const char * TEST_AUTHOR_EMAIL = "[email protected]"
 

Detailed Description

Regression tests for LIBGIT_BACKEND, KIGIT_COMMON, GIT_INIT_HANDLER, GIT_PULL_HANDLER, GIT_PUSH_HANDLER, GIT_COMMIT_HANDLER focused on the recent Git integration bug fixes and the Amend Last Commit feature.

Definition in file test_libgit_backend.cpp.

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/10]

BOOST_AUTO_TEST_CASE ( Amend_MessageOnlyRewritesHeadKeepsTree )

Amend rewrites HEAD with a new commit OID.

For a message-only amend, the tree (and therefore the working tree) is unchanged.

Definition at line 490 of file test_libgit_backend.cpp.

References BOOST_CHECK_EQUAL(), GIT_COMMIT_HANDLER::PerformAmend(), result, Success, TEST_AUTHOR_EMAIL, and TEST_AUTHOR_NAME.

◆ BOOST_AUTO_TEST_CASE() [2/10]

BOOST_AUTO_TEST_CASE ( Amend_StagedFileChangesTreeAndKeepsParent )

Amend with new files: the tree changes and includes the newly staged content.

Definition at line 535 of file test_libgit_backend.cpp.

References BOOST_CHECK_EQUAL(), GIT_COMMIT_HANDLER::PerformAmend(), result, Success, TEST_AUTHOR_EMAIL, and TEST_AUTHOR_NAME.

◆ BOOST_AUTO_TEST_CASE() [3/10]

BOOST_AUTO_TEST_CASE ( Amend_UnbornBranchReturnsError )

Amending an unborn branch (a fresh repo with no commits yet) must fail cleanly rather than crash or produce a bogus commit.

Definition at line 594 of file test_libgit_backend.cpp.

References BOOST_CHECK_EQUAL(), Error, GIT_COMMIT_HANDLER::GetErrorString(), GIT_COMMIT_HANDLER::PerformAmend(), result, TEST_AUTHOR_EMAIL, and TEST_AUTHOR_NAME.

◆ BOOST_AUTO_TEST_CASE() [4/10]

BOOST_AUTO_TEST_CASE ( GetDifferentFiles_DifferentTreeAmendKeepsAheadFile )

Positive control: if the amend genuinely changes the file content, the file should still appear in the AHEAD set.

Verifies the content-aware filter doesn't over-filter.

Definition at line 385 of file test_libgit_backend.cpp.

References BOOST_CHECK_MESSAGE(), and KIGIT_COMMON::GetDifferentFiles().

◆ BOOST_AUTO_TEST_CASE() [5/10]

BOOST_AUTO_TEST_CASE ( GetDifferentFiles_SameTreeAmendHidesAheadFiles )

Regression for the spurious clock icon after a message-only amend: when HEAD and the upstream tracking ref point at different commit OIDs but the commits share an identical tree, no file should be reported as AHEAD or BEHIND.

Without the content-aware filter in GetDifferentFiles, the AHEAD set would contain every file touched by the local commit relative to the merge-base.

Definition at line 322 of file test_libgit_backend.cpp.

References BOOST_CHECK_MESSAGE(), KIGIT_COMMON::GetDifferentFiles(), TEST_AUTHOR_EMAIL, and TEST_AUTHOR_NAME.

◆ BOOST_AUTO_TEST_CASE() [6/10]

BOOST_AUTO_TEST_CASE ( GetUpstreamShorthand_NoUpstreamFallsBackToRemoteSlashBranch )

When the local branch has no upstream configured, GetUpstreamShorthand must synthesise <remote>/<branch> so the pull fallback and first-push paths have a meaningful target to display and act on.

Definition at line 296 of file test_libgit_backend.cpp.

References BOOST_AUTO_TEST_CASE(), BOOST_CHECK_EQUAL(), and KIGIT_COMMON::GetUpstreamShorthand().

◆ BOOST_AUTO_TEST_CASE() [7/10]

BOOST_AUTO_TEST_CASE ( InitializeRepository_GitignoreDoesNotDuplicateEntries )

InitializeRepository must not duplicate entries that the user (or a template) has already written.

An existing .history/ line should be left alone while the other four KiCad defaults are appended.

Definition at line 659 of file test_libgit_backend.cpp.

References BOOST_CHECK_EQUAL(), GIT_INIT_HANDLER::InitializeRepository(), result, and Success.

◆ BOOST_AUTO_TEST_CASE() [8/10]

BOOST_AUTO_TEST_CASE ( InitializeRepository_SeedsGitignoreWithKicadEntries )

InitializeRepository seeds a project-level .gitignore with KiCad-specific transient paths (.history/, -backups/, _autosave-, fp-info-cache, ~*.lck).

Definition at line 621 of file test_libgit_backend.cpp.

References BOOST_CHECK_EQUAL(), GIT_INIT_HANDLER::InitializeRepository(), result, and Success.

◆ BOOST_AUTO_TEST_CASE() [9/10]

BOOST_AUTO_TEST_CASE ( PerformPull_NoUpstreamConfig_FallbackSucceedsAndWritesUpstream )

Regression for the original issue #24332 surface: pull on a fresh repo where Add Version Control wired up origin but never set per-branch upstream tracking used to fail with "Could not lookup commit" because FETCH_HEAD has no merge-marked entry.

The fallback in PerformPull resolves the implicit target via refs/remotes/origin/<branch> and persists the upstream config.

Definition at line 424 of file test_libgit_backend.cpp.

References BOOST_CHECK_EQUAL(), BOOST_CHECK_MESSAGE(), FastForward, KIGIT_ERRORS::GetErrorString(), GIT_PULL_HANDLER::PerformPull(), result, Success, and UpToDate.

◆ BOOST_AUTO_TEST_CASE() [10/10]

BOOST_AUTO_TEST_CASE ( Push_FirstPushSetsUpstreamTracking )

Push -u behavior: after the first successful push from a branch with no upstream configured, branch.

<name>.merge and .remote should be populated so subsequent pull/push hit the FETCH_HEAD path instead of the fallback.

Definition at line 459 of file test_libgit_backend.cpp.

References BOOST_CHECK_EQUAL(), GIT_PUSH_HANDLER::PerformPush(), result, and Success.

Variable Documentation

◆ TEST_AUTHOR_EMAIL

◆ TEST_AUTHOR_NAME