diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 27934aa3..1b586f60 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -1108,6 +1108,22 @@ def current_command_version version_parts.fill(0, version_parts.length...3) end + # Returns current_command_version <=> other_version + # + # @example + # lib.current_command_version #=> [2, 42, 0] + # + # lib.compare_version_to(2, 41, 0) #=> 1 + # lib.compare_version_to(2, 42, 0) #=> 0 + # lib.compare_version_to(2, 43, 0) #=> -1 + # + # @param other_version [Array] the other version to compare to + # @return [Integer] -1 if this version is less than other_version, 0 if equal, or 1 if greater than + # + def compare_version_to(*other_version) + current_command_version <=> other_version + end + def required_command_version [1, 6] end diff --git a/tests/units/test_lib.rb b/tests/units/test_lib.rb index 577d7d73..c7283d4e 100644 --- a/tests/units/test_lib.rb +++ b/tests/units/test_lib.rb @@ -325,4 +325,15 @@ def test_show assert(@lib.show('gitsearch1', 'scott/text.txt') == "hello\nthis is\na file\nthat is\nput here\nto search one\nto search two\nnothing!\n") end + def test_compare_version_to + lib = Git::Lib.new(nil, nil) + current_version = [2, 42, 0] + lib.define_singleton_method(:current_command_version) { current_version } + assert lib.compare_version_to(0, 43, 9) == 1 + assert lib.compare_version_to(2, 41, 0) == 1 + assert lib.compare_version_to(2, 42, 0) == 0 + assert lib.compare_version_to(2, 42, 1) == -1 + assert lib.compare_version_to(2, 43, 0) == -1 + assert lib.compare_version_to(3, 0, 0) == -1 + end end diff --git a/tests/units/test_repack.rb b/tests/units/test_repack.rb index abe2442a..da7be542 100644 --- a/tests/units/test_repack.rb +++ b/tests/units/test_repack.rb @@ -3,20 +3,18 @@ require 'test_helper' class TestRepack < Test::Unit::TestCase - def test_repack + test 'should be able to call repack with the right args' do in_bare_repo_clone do |r1| new_file('new_file', 'new content') - r1.add r1.commit('my commit') - # see how big the repo is - size1 = r1.repo_size - - r1.repack + # assert_nothing_raised { r1.repack } - # see how big the repo is now, should be smaller - assert(size1 > r1.repo_size) + expected_command_line = ['repack', '-a', '-d'] + git_cmd = :repack + git_cmd_args = [] + assert_command_line(expected_command_line, git_cmd, git_cmd_args) end end end diff --git a/tests/units/test_worktree.rb b/tests/units/test_worktree.rb index 021a82a3..bbe377ce 100644 --- a/tests/units/test_worktree.rb +++ b/tests/units/test_worktree.rb @@ -31,6 +31,8 @@ def setup end test 'adding a worktree when there are no commits should fail' do + omit('Omitted since git version is >= 2.42.0') if Git::Lib.new(nil, nil).compare_version_to(2, 42, 0) >= 0 + in_temp_dir do |path| Dir.mkdir('main_worktree') Dir.chdir('main_worktree') do @@ -47,6 +49,33 @@ def setup end end + test 'adding a worktree when there are no commits should succeed' do + omit('Omitted since git version is < 2.42.0') if Git::Lib.new(nil, nil).compare_version_to(2, 42, 0) < 0 + + in_temp_dir do |path| + Dir.mkdir('main_worktree') + Dir.chdir('main_worktree') do + `git init` + # `git commit --allow-empty -m "first commit"` + end + + git = Git.open('main_worktree') + + assert_nothing_raised do + git.worktree('feature1').add + end + + assert_equal(2, git.worktrees.size) + + expected_worktree_dirs = [ + File.join(path, 'main_worktree'), + File.join(path, 'feature1') + ].each_with_index do |expected_worktree_dir, i| + assert_equal(expected_worktree_dir, git.worktrees.to_a[i].dir) + end + end + end + test 'adding a worktree when there is at least one commit should succeed' do in_temp_dir do |path| Dir.mkdir('main_worktree') 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