Skip to content

Commit 8cad329

Browse files
Vasfedv-kolesnikov
andcommitted
Add start_point option for checkout command
Co-authored-by: V.Kolesnikov <re.vkolesnikov@gmail.com> Signed-off-by: Vasily Fedoseyev <vasilyfedoseyev@gmail.com>
1 parent ff6dcf4 commit 8cad329

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/git/lib.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,11 +764,21 @@ def branch_delete(branch)
764764
command('branch', '-D', branch)
765765
end
766766

767+
# Runs checkout command to checkout or create branch
768+
#
769+
# accepts options:
770+
# :new_branch
771+
# :force
772+
# :start_point
773+
#
774+
# @param [String] branch
775+
# @param [Hash] opts
767776
def checkout(branch, opts = {})
768777
arr_opts = []
769778
arr_opts << '-b' if opts[:new_branch] || opts[:b]
770779
arr_opts << '--force' if opts[:force] || opts[:f]
771780
arr_opts << branch
781+
arr_opts << opts[:start_point] if opts[:start_point] && (arr_opts.include?('-b') || arr_opts.include?('--force'))
772782

773783
command('checkout', arr_opts)
774784
end

tests/units/test_lib.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def test_commit_with_no_verify
8383

8484
def test_checkout
8585
assert(@lib.checkout('test_checkout_b',{:new_branch=>true}))
86+
assert(@lib.checkout('test_checkout_b2', {new_branch: true, start_point: 'master'}))
8687
assert(@lib.checkout('.'))
8788
assert(@lib.checkout('master'))
8889
end

0 commit comments

Comments
 (0)