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

When does push() set the upstream tracking branch? #375

Closed
jdblischak opened this issue Jan 28, 2019 · 5 comments
Closed

When does push() set the upstream tracking branch? #375

jdblischak opened this issue Jan 28, 2019 · 5 comments

Comments

@jdblischak
Copy link
Contributor

The documentation for push() states that it adds an upstream tracking branch (source):

## Push commits from repository to bare repository
## Adds an upstream tracking branch to branch 'master'
push(repo, "origin", "refs/heads/master")

And the unit tests confirm this behavior. Below I've copied line line 64 through line of 68 of tests/push.R followed by a test I added:

## No tracking branch assigned to master
tools::assertError(push(branches(repo)[[1]]))

## Push changes from repo to origin
push(repo, "origin", "refs/heads/master")

## My addition: Confirm that an upstream tracking branch was added
stopifnot(identical(branch_get_upstream(branches(repo)[[1]])$name, "origin/master"))

However, for these unit tests, the remote repository is a local Git repository on the same machine. When I try to replicate this behavior when the remote repository is on GitHub, the upstream tracking branch is not set.

I checked the usethis package, and they also manually set the upstream tracking branch after running git2r::push (source):

    pushed <- tryCatch({
      git2r::push(r, "origin", "refs/heads/master", credentials = cred)
      TRUE
    }, error = function(e) FALSE)
  }
  if (pushed) {
    git2r::branch_set_upstream(git2r::repository_head(r), "origin/master")
  }

What is the expected behavior of git2r::push() in regards to setting the upstream tracking branch? Is it supposed to when the remote repository is hosted on GitHub or another online provider? If not, could the documentation be updated to describes the rules for when it does or doesn't set the upstream tracking branch?

Potentially related: #133

@jennybc
Copy link
Member

jennybc commented Jan 28, 2019

I actually checked this behaviour myself in the past couple of days and, when we're talking about a push to Github, git2r::push() definitely does NOT set upstream tracking branch in my hands.

@jdblischak
Copy link
Contributor Author

I actually checked this behaviour myself in the past couple of days and, when we're talking about a push to Github, git2r::push() definitely does NOT set upstream tracking branch in my hands.

@jennybc Thanks for the confirmation! I'm struggling to figure out if it ever worked for me. I tried installing git2r 0.21.0, but observed this same behavior. I switch back and forth between git2r and Git so often, I'm thinking I may have just missed this the whole time.

@stewid
Copy link
Member

stewid commented Jan 29, 2019

When does push() set the upstream tracking branch?

That's a very good question. I have studied the code and I can't find that the push function actually sets the upstream tracking branch as described by the documentation. To fix this bug, I can add the argument set_upstream = FALSE to the push function to add the upstream reference, if the branch was successfully pushed (similar to the usethis package). What do you think?

@jennybc
Copy link
Member

jennybc commented Jan 29, 2019

Yes, I think it would be great to expose this in a similar fashion as git push [-u | --set-upstream] does.

@jdblischak
Copy link
Contributor Author

To fix this bug, I can add the argument set_upstream = FALSE to the push function to add the upstream reference, if the branch was successfully pushed

@stewid Yes, it would be useful to have that option. Though since it does appear to sometimes add the upstream tracking branch, the documentation should probably explain that set_upstream = FALSE is not a guarantee that it won't happen, just that git2r won't explicitly try to do it.

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

No branches or pull requests

3 participants