-
Notifications
You must be signed in to change notification settings - Fork 279
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
Rugged::Repository.init_at does not create a branch #952
Comments
I create my first branch with below code require 'rugged'
def with_default_branch(name)
config = Rugged::Config.global
old_value = config['init.defaultBranch']
config['init.defaultBranch'] = name
yield
ensure
config['init.defaultBranch'] = old_value
end
with_default_branch('foobar') do
repo = Rugged::Repository.init_at('/tmp/b')
repo.branches.to_a
index = repo.index
options = {}
options[:tree] = index.write_tree(repo)
options[:author] = { :email => "[email protected]", :name => 'Test Author', :time => Time.now }
options[:message] = "init"
options[:parents] = []
options[:update_ref] = 'HEAD'
commit_hash = Rugged::Commit.create(repo, options)
repo.branches.to_a
end |
The reported problem was due to The First Git Branch Is Created Lazily. As I demonstrate in that article, git branches do not exist, and cannot be created, before the initial commit. This is not a bug, instead, it is a documented but not well-known fact (see Error when creating a new branch for an empty repository).
This is true! If you want a branch, make a commit to the default branch, then create the branch. To configure the initial branch name for use in all new repositories, set the git config --global init.defaultBranch master |
The
git-init
docs say:However,
Rugged::Repository.init_at
does not create any branches:Is this a bug?
Also, attempting to create a branch after calling
init_at
fails:However, attempting to create the branch using the command line after calling
init_at
works:The text was updated successfully, but these errors were encountered: