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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

#531 add API to get default branch #532

Closed
wants to merge 3 commits into from

Conversation

CAMOBAP
Copy link
Contributor

@CAMOBAP CAMOBAP commented Jul 15, 2021

Your checklist for this pull request

馃毃Please review the guidelines for contributing to this repository.

  • Ensure all commits include DCO sign-off.
  • Ensure that your contributions pass unit testing.
  • Ensure that your contributions contain documentation if applicable.

Description

#531 solution based on https://stackoverflow.com/a/44750379/902217

Open questions:

  • by default origin is used for remote, maybe there is a better alternative

@jcouball
Copy link
Member

@CAMOBAP thank you for the PR.

The default branch of the remote seems like it should be a property of a Remote object.

If it were, I would like to get the remote's default branch by doing this:
Git.open(working_dir).remote(remote_name).default_branch

or:
Git.open(working_dir).current_branch.remote.default_branch

or (as a bonus) without having to have a local repository:
Git.remote_default_branch(repository)

What do you think of this design?

@CAMOBAP
Copy link
Contributor Author

CAMOBAP commented Dec 17, 2021

@jcouball sounds reasonable to me

Signed-off-by: Alexande B <abobrikovich@gmail.com>
@CAMOBAP
Copy link
Contributor Author

CAMOBAP commented Jan 31, 2022

@CAMOBAP thank you for the PR.

The default branch of the remote seems like it should be a property of a Remote object.

If it were, I would like to get the remote's default branch by doing this: Git.open(working_dir).remote(remote_name).default_branch

or: Git.open(working_dir).current_branch.remote.default_branch

or (as a bonus) without having to have a local repository: Git.remote_default_branch(repository)

What do you think of this design?

@jcouball done

@baweaver
Copy link

Very useful feature indeed, was going to mention the taint error for YARDoc but it looks like @jcouball was a few steps ahead there:

lsegal/yard@7dca12c

@jcouball
Copy link
Member

@CAMOBAP Git.remote_default_branch(repository) isn't implemented as I had intended. Pardon if I wasn't clear before. My intention was that you would give it a repository (like Git.clone) however:

$ irb -I lib
2.7.5 :001 > require 'git'
 => true 
2.7.5 :002 > Git.remote_default_branch('https://github.com/ruby-git/ruby-git')
Traceback (most recent call last):
        1: from /Users/couballj/SynologyDrive/Documents/Projects/ruby-git-clean/https:/github.com/ruby-git/ruby-git
ArgumentError (path does not exist)
2.7.5 :003 > 

I have this implemented with tests, so if you remove Git.remote_default_branch and it's test from this PR, I accept it and then follow with a separate PR for that.

2.7.5 :002 > Git.remote_default_branch('https://github.com/ruby-git/ruby-git')
 => "master" 
2.7.5 :003 > Git.remote_default_branch('https://github.com/rspec/rspec-core')
 => "main" 

Also, it seems like Lib#branch_default should be named Lib#default_branch... if you agree, can you rename it?

@jcouball
Copy link
Member

@CAMOBAP and @baweaver what do you think about #571 as a replacement for this PR's implementation of Git.remote_default_branch?

@CAMOBAP
Copy link
Contributor Author

CAMOBAP commented Apr 15, 2022

@CAMOBAP and @baweaver what do you think about #571 as a replacement for this PR's implementation of Git.remote_default_branch?

To me #571 looks more elegant, so I'm totally ok if my PR will be rejected in favor of #571

@jcouball
Copy link
Member

jcouball commented Mar 4, 2023

Closing this PR in favor of #571

@jcouball jcouball closed this Mar 4, 2023
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

Successfully merging this pull request may close these issues.

None yet

3 participants