diff --git a/src/tools/ecode/plugins/git/git.cpp b/src/tools/ecode/plugins/git/git.cpp index 42b0e5c7c..d9177b9c6 100644 --- a/src/tools/ecode/plugins/git/git.cpp +++ b/src/tools/ecode/plugins/git/git.cpp @@ -165,11 +165,19 @@ Git::Result Git::push( const std::string& projectDir ) { } Git::Result Git::pushNewBranch( const std::string& branch, const std::string& projectDir ) { - return gitSimple( + auto res = gitSimple( String::format( "push --porcelain --recurse-submodules=check origin refs/heads/%s:refs/heads/%s", branch, branch ), projectDir ); + + if ( res.fail() ) + return res; + + gitSimple( String::format( "branch --set-upstream-to=origin/%s %s", branch, branch ), + projectDir ); + + return res; } Git::CheckoutResult Git::checkout( const std::string& branch, @@ -278,8 +286,10 @@ Git::Result Git::deleteBranch( const std::string& branch, const std::string& pro return gitSimple( String::format( "branch -D %s", branch ), projectDir ); } -Git::Result Git::mergeBranch( const std::string& branch, const std::string& projectDir ) { - return gitSimple( String::format( "merge --no-ff %s", branch ), projectDir ); +Git::Result Git::mergeBranch( const std::string& branch, bool fastForward, + const std::string& projectDir ) { + return gitSimple( String::format( "merge %s %s", fastForward ? "--ff" : "--no-ff", branch ), + projectDir ); } Git::Result Git::commit( const std::string& commitMsg, bool ammend, bool byPassCommitHook, diff --git a/src/tools/ecode/plugins/git/git.hpp b/src/tools/ecode/plugins/git/git.hpp index e76181291..7832884db 100644 --- a/src/tools/ecode/plugins/git/git.hpp +++ b/src/tools/ecode/plugins/git/git.hpp @@ -267,7 +267,8 @@ class Git { Result deleteBranch( const std::string& branch, const std::string& projectDir = "" ); - Result mergeBranch( const std::string& branch, const std::string& projectDir = "" ); + Result mergeBranch( const std::string& branch, bool fastForward = false, + const std::string& projectDir = "" ); Result commit( const std::string& commitMsg, bool ammend, bool byPassCommitHook, const std::string& projectDir = "" ); diff --git a/src/tools/ecode/plugins/git/gitplugin.cpp b/src/tools/ecode/plugins/git/gitplugin.cpp index 6c197f0bb..92ba9c896 100644 --- a/src/tools/ecode/plugins/git/gitplugin.cpp +++ b/src/tools/ecode/plugins/git/gitplugin.cpp @@ -35,6 +35,7 @@ using json = nlohmann::json; namespace ecode { static constexpr auto DEFAULT_HIGHLIGHT_COLOR = "var(--font-highlight)"sv; +static constexpr auto GIT_STATUS_UPDATE_TAG = String::hash( "git::status-update" ); std::string GitPlugin::statusTypeToString( Git::GitStatusType type ) { switch ( type ) { @@ -91,6 +92,8 @@ GitPlugin::~GitPlugin() { endModelStyler(); + getUISceneNode()->removeActionsByTag( GIT_STATUS_UPDATE_TAG ); + { Lock l( mGitBranchMutex ); } { Lock l( mGitStatusMutex ); } { Lock l( mRepoMutex ); } @@ -292,8 +295,7 @@ void GitPlugin::updateUI() { if ( !mGit || !getUISceneNode() ) return; - getUISceneNode()->debounce( [this] { updateUINow(); }, mRefreshFreq, - String::hash( "git::status-update" ) ); + getUISceneNode()->debounce( [this] { updateUINow(); }, mRefreshFreq, GIT_STATUS_UPDATE_TAG ); } void GitPlugin::updateStatusBarSync() { @@ -733,8 +735,9 @@ void GitPlugin::branchMerge( Git::Branch branch ) { branch.name ) ); msgBox->on( Event::OnConfirm, [this, branch]( auto ) { - runAsync( [this, branch]() { return mGit->mergeBranch( branch.name, repoSelected() ); }, - true, true, true, true, true ); + runAsync( + [this, branch]() { return mGit->mergeBranch( branch.name, false, repoSelected() ); }, + true, true, true, true, true ); } ); msgBox->setCloseShortcut( { KEY_ESCAPE, KEYMOD_NONE } ); msgBox->setTitle( i18n( "git_confirm", "Confirm" ) ); @@ -902,8 +905,12 @@ void GitPlugin::commit( const std::string& repoPath ) { void GitPlugin::fastForwardMerge( Git::Branch branch ) { runAsync( [this, branch]() { - if ( branch.name == gitBranch() ) - return mGit->fastForwardMerge( repoSelected() ); + if ( branch.name == gitBranch() ) { + auto res = mGit->fastForwardMerge( repoSelected() ); + if ( res.success() ) + return res; + return mGit->mergeBranch( "", true, repoSelected() ); + } auto remoteBranch = mGit->getAllBranchesAndTags( Git::RefType::Remote, "refs/remotes/" + branch.remote, repoSelected() );