Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/git/lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1040,10 +1040,19 @@ def commit_tree(tree, opts = {})
t.write(opts[:message])
t.close

# Adapted from activesupport Array.wrap
parents = if opts[:parents].nil?
Copy link
Member

Choose a reason for hiding this comment

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

I read up on Array.wrap but don't understand why you would choose that implementation instead of Kernel#Array. I am interested to hear why you would go this route instead of reducing this change to:

arr_opts += Array(opts[:parent]).map { |p| ['-p', p] }.flatten

I think calling #to_a if #to_ary doesn't exist would be the desired behavior.

[]
elsif opts[:parents].respond_to?(:to_ary)
opts[:parents].to_ary || [opts[:parents]]
else
[opts[:parents]]
end
parents << opts[:parent] if opts[:parent]

arr_opts = []
arr_opts << tree
arr_opts << '-p' << opts[:parent] if opts[:parent]
arr_opts += [opts[:parents]].map { |p| ['-p', p] }.flatten if opts[:parents]
arr_opts += parents.map { |p| ['-p', p] }.flatten
command('commit-tree', *arr_opts, redirect: "< #{escape t.path}")
end

Expand Down
8 changes: 8 additions & 0 deletions tests/units/test_tree_ops.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ def test_read_tree
assert(c.commit?)
assert_equal('b40f7a9072cdec637725700668f8fdebe39e6d38', c.gtree.sha)

c = g.commit_tree(tr, :parent => 'HEAD')
assert(c.commit?)
assert_equal('b40f7a9072cdec637725700668f8fdebe39e6d38', c.gtree.sha)

c = g.commit_tree(tr, :parents => ['HEAD', 'testbranch1'])
assert(c.commit?)
assert_equal('b40f7a9072cdec637725700668f8fdebe39e6d38', c.gtree.sha)

tmp = Tempfile.new('tesxt')
tmppath = tmp.path
tmp.close
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy