Skip to content

Commit 438798e

Browse files
committed
implementation of --t switch on git branch command
1 parent e804206 commit 438798e

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

lib/git/base.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,11 @@ def branches
181181
end
182182

183183
# returns a Git::Branch object for branch_name
184-
def branch(branch_name = 'master')
185-
Git::Branch.new(self, branch_name)
184+
# -- addition of options noticeably to implement
185+
# --t switch on 'git branch' command
186+
def branch(branch_name = 'master', options={})
187+
#
188+
Git::Branch.new(self, branch_name, options[:track])
186189
end
187190

188191
# returns +true+ if the branch exists locally

lib/git/branch.rb

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,25 @@ class Branch < Path
33

44
attr_accessor :full, :remote, :name
55

6-
def initialize(base, name)
6+
# -- addition of track parameter for --t switch
7+
def initialize(base, name, track=nil)
8+
#
79
@remote = nil
810
@full = name
911
@base = base
1012
@gcommit = nil
1113
@stashes = nil
1214

13-
parts = name.split('/')
14-
if parts[1]
15-
@remote = Git::Remote.new(@base, parts[0])
16-
@name = parts[1]
17-
else
18-
@name = parts[0]
15+
# -- addition of track attribute to implement
16+
# --t switch
17+
@track = track
18+
name, remote = name.split(' ').first.split('/').reverse
19+
if remote
20+
@remote = Git::Remote.new(@base, remote)
21+
name = "#{remote}/#{name}"
1922
end
23+
@name = name
24+
#
2025
end
2126

2227
def gcommit
@@ -93,7 +98,9 @@ def to_s
9398
private
9499

95100
def check_if_create
96-
@base.lib.branch_new(@name) rescue nil
101+
# -- addition of track attribute
102+
@base.lib.branch_new(@name, @track) rescue nil
103+
#
97104
end
98105

99106
def determine_current

lib/git/lib.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -478,11 +478,15 @@ def stash_clear
478478
def stash_list
479479
command('stash list')
480480
end
481-
482-
def branch_new(branch)
483-
command('branch', branch)
481+
482+
# -- implement --t switch on git branch command
483+
def branch_new(branch, track=nil)
484+
options = [branch]
485+
options << '--t' << track if track
486+
command('branch', options)
484487
end
485-
488+
#
489+
486490
def branch_delete(branch)
487491
command('branch', ['-D', branch])
488492
end

0 commit comments

Comments
 (0)