38 git_repository* repo =
GetRepo();
43 git_reference* branchRef =
nullptr;
47 git_reference_free( branchRef );
54 git_repository* repo =
GetRepo();
60 if( git_reference_lookup( aReference, repo, aBranchName.mb_str() ) == GIT_OK )
64 if( git_reference_dwim( aReference, repo, aBranchName.mb_str() ) == GIT_OK )
72 git_repository* repo =
GetRepo();
77 return BranchResult::Error;
81 git_reference* branchRef =
nullptr;
85 AddErrorString( wxString::Format(
_(
"Failed to lookup branch '%s': %s" ),
87 return BranchResult::BranchNotFound;
91 const char* branchRefName = git_reference_name( branchRef );
92 git_object* branchObj =
nullptr;
94 if( git_revparse_single( &branchObj, repo, aBranchName.mb_str() ) != GIT_OK )
96 AddErrorString( wxString::Format(
_(
"Failed to find branch head for '%s': %s" ),
98 return BranchResult::Error;
104 if( git_checkout_tree( repo, branchObj,
nullptr ) != GIT_OK )
106 AddErrorString( wxString::Format(
_(
"Failed to switch to branch '%s': %s" ),
108 return BranchResult::CheckoutFailed;
112 if( git_repository_set_head( repo, branchRefName ) != GIT_OK )
114 AddErrorString( wxString::Format(
_(
"Failed to update HEAD reference for branch '%s': %s" ),
116 return BranchResult::Error;
119 wxLogTrace(
traceGit,
"Successfully switched to branch '%s'", aBranchName );
120 return BranchResult::Success;
BranchResult SwitchToBranch(const wxString &aBranchName)
Switch to the specified branch.
void UpdateProgress(int aCurrent, int aTotal, const wxString &aMessage) override
bool BranchExists(const wxString &aBranchName)
Check if a branch exists.
bool LookupBranchReference(const wxString &aBranchName, git_reference **aReference)
Look up a branch reference by name.
virtual ~GIT_BRANCH_HANDLER()
GIT_BRANCH_HANDLER(KIGIT_COMMON *aCommon)
void ReportProgress(int aCurrent, int aTotal, const wxString &aMessage)
static wxString GetLastGitError()
void AddErrorString(const wxString aErrorString)
git_repository * GetRepo() const
Get a pointer to the git repository.
const wxChar *const traceGit
Flag to enable Git debugging output.
std::unique_ptr< git_object, decltype([](git_object *aObject) { git_object_free(aObject) GitObjectPtr
A unique pointer for git_object objects with automatic cleanup.
std::unique_ptr< git_reference, decltype([](git_reference *aRef) { git_reference_free(aRef) GitReferencePtr
A unique pointer for git_reference objects with automatic cleanup.
wxLogTrace helper definitions.