Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Orphan branch tracking is not updated after remote branch creation #82

Closed
xvik opened this issue Mar 13, 2020 · 0 comments
Closed

Orphan branch tracking is not updated after remote branch creation #82

xvik opened this issue Mar 13, 2020 · 0 comments
Labels

Comments

@xvik
Copy link

xvik commented Mar 13, 2020

I found this case only because of my plugin's tests fail after updating gradle-git-publish from 0.3.4 to 2.1.3. This is very minor.

The case: publishing site to github pages when a remote gh-pages branch does not exist.

First site publication (gitPublishPush):

  • gitPublishReset detects that remote gh-pages branch does not exist and creates orphan local branch gh-pages
  • gitPublishPush publish local branch, creating a remote branch

On the next publication, gitPublishReset already detects that remote for gh-pages exists, but it did not set tracking for the local branch! So the local branch remains orphan.

Of course, everything will work correctly (all subsequent publications).

It only affects UP_TO_DATE check for gitPublishPush as it will never be able to check the branch status: because the branch is orphan, gitPublishPush.onlyIf will never return false

My workaround (just in case) is to set tracking just after publication (groovy):

def myReopDir = ...  // just published gh-pages dir
def myBranchName = 'gh-pages'
project.tasks.gitPublishPush.doLast {            
            Grgit git = Grgit.open({ OpenOp op -> op.dir = project.file(repoDir) } as Configurable<OpenOp>)
            // assume published repo remains on correct branch
            Branch branch = git.branch.current() 

            if (branch?.name == myBranchName && branch?.trackingBranch == null) {
                git.branch.change({ BranchChangeOp op ->
                    op.name = branch.name
                    op.startPoint = "origin/${branch.name}"
                    op.mode = BranchChangeOp.Mode.TRACK
                } as Configurable<BranchChangeOp>)
            }
        }

It would be great if the plugin would be able to detect the orphan branch automatically and update it's tracking (just after publication or in gitPublishReset (on next run)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants