diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 1b586f60..1ac987ff 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -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? + [] + 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 diff --git a/tests/units/test_tree_ops.rb b/tests/units/test_tree_ops.rb index 1f38cae9..b4e4ce32 100644 --- a/tests/units/test_tree_ops.rb +++ b/tests/units/test_tree_ops.rb @@ -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 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