Skip to content

Commit

Permalink
Fix b4mboo#88, allow [tag] in commit message.
Browse files Browse the repository at this point in the history
  • Loading branch information
xystushi committed Mar 22, 2014
1 parent 8843cc6 commit 689a5a0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 5 additions & 7 deletions lib/git-review/local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,12 @@ def remotes_for_branches

# Finds the correct remote for a given branch name.
def remote_for_branch(branch_name)
git_call('branch -lvv').gsub('* ', '').split("\n").each do |line|
entries = line.split(' ')
next unless entries.first == branch_name
# Return the remote name or nil for local branches.
match = entries[2].match(%r(\[(.*)(\]|:)))
return match[1].split('/').first if match
remote = git_call("for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD)")
return nil if remote.strip.empty? # no remote tracking branch
remote.split("\n").each do |line|
match = line.match(%r((.*)\/(.*)))
return line.split('/').first if match
end
nil
end

# @return [Array<String>] all existing branches
Expand Down
10 changes: 6 additions & 4 deletions spec/git-review/local_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,17 @@
end

it 'finds an existing remote for a branch' do
subject.should_receive(:git_call).with('branch -lvv').and_return(
"#{branch_name} 00aa0a0 [#{remote}/#{branch_name}: ahead 1] Foo Bar\n"
cmd = "for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD)"
subject.should_receive(:git_call).with(cmd).and_return(
"#{remote}/#{branch_name}\n"
)
subject.remote_for_branch(branch_name).should == remote
end

it 'returns nil for a local branch without a remote' do
subject.should_receive(:git_call).with('branch -lvv').
and_return("* #{branch_name} 00aa0a0 Foo Bar\n")
cmd = "for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD)"
subject.should_receive(:git_call).with(cmd).
and_return("\n")
subject.remote_for_branch(branch_name).should == nil
end

Expand Down

0 comments on commit 689a5a0

Please sign in to comment.