Skip to content

Do not assume the default branch is 'master' in tests #588

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

Merged
merged 2 commits into from
Aug 19, 2022

Conversation

liijunwei
Copy link
Contributor

@liijunwei liijunwei commented Jul 23, 2022

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

Fix test case by extracting init.defaultBranch into variable
#587

@jcouball
Copy link
Member

This code does not work when init.defaultBranch is not set (see the failed CI builds for this PR).

In this case, you see the following:

$ irb
2.7.6 :001 > `git config --get init.defaultBranch`
 => "" 
2.7.6 :002 > $?
 => #<Process::Status: pid 54561 exit 1> 
2.7.6 :003 > 

I think you could get away with adding this line:

initial_branch = 'master' if initial_branch.empty?

See the docs for git init --initial-branch for more context.

@liijunwei
Copy link
Contributor Author

yes, thanks for reminding me 🙏

I reproduced by removing defaultBranch = main in my ~/.gitconfig and changed the test case as your suggestion
I also did some commit cleanup(cherry-pick and force pushed)

+ fix test when `init.defaultBranch` is not set by assigning default value
Signed-off-by: lijunwei <ljw532344863@sina.com>
@liijunwei
Copy link
Contributor Author

also suggest rename test_git_init to test_git_init_with_default_init_default_branch

@jcouball jcouball changed the title Fix test case for https://github.com/ruby-git/ruby-git/issues/587 Do not assume the default branch is master in tests Aug 19, 2022
@jcouball jcouball changed the title Do not assume the default branch is master in tests Do not assume the default branch is 'master' in tests Aug 19, 2022
Copy link
Member

@jcouball jcouball left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, @liijunwei! Thank you for the contribution.

@jcouball jcouball merged commit ff6dcf4 into ruby-git:master Aug 19, 2022
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.

2 participants