Skip to content

Update test of 'git worktree add' with no commits #670

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 3 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add Git::Lib#compare_version_to(other_version)
Signed-off-by: James Couball <jcouball@yahoo.com>
  • Loading branch information
jcouball committed Sep 17, 2023
commit e46ddcc711c41fe96810396a9c8db032af01e154
16 changes: 16 additions & 0 deletions lib/git/lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object>] 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
Expand Down
11 changes: 11 additions & 0 deletions tests/units/test_lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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