Skip to content

Commit

Permalink
Allows partial matching on latest-features
Browse files Browse the repository at this point in the history
Before this was relying on pattern for git for-each-ref however
it only allowed matching branch names between slashes.

Eg.: refs/remotes/origin/foo-branch/

-p foo # no match
-p foo-branch # matches

This now keeps the same API as before (-p pattern) but allows partial
matching so -p foo and -f foo-branch both yield the same results for
the same scenario

This closes #24
  • Loading branch information
Pedro Cunha committed Dec 17, 2013
1 parent 2b04b77 commit c40acf5
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions bin/git-latest-pushes
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ class App < Git::Whistles::App
super
parse_args!(args)

results = `git for-each-ref --sort=-committerdate --count=#{options.results} refs/remotes/origin/#{options.pattern} --format='[%(committerdate:relative)] (%(authorname)) %(refname)'`
results = `git for-each-ref --sort=-committerdate --format='[%(committerdate:relative)] (%(authorname)) %(refname)' refs/remotes/origin/ | grep '#{options.pattern}'`
results = results.split("\n")

if results.any?
puts "Latest #{ [results.length, options.results].min } pushed branches:"
results = results.slice(0, [results.length, options.nr_results].min)
puts "Latest #{ results.length } pushed branches:"

results.each do |branch|
puts branch.gsub('refs/remotes/origin/', '')
Expand All @@ -36,7 +37,7 @@ class App < Git::Whistles::App

def defaults
{
:results => 20,
:nr_results => 20,
:pattern => ''
}
end
Expand All @@ -49,7 +50,7 @@ Usage: git latest-pushes [-n NR_RESULTS] [-p PATTERN]
}

op.on("-n", "--n [NR_RESULTS]", "Number of results to display, defaults to 20") do |n|
options.nr_results = n
options.nr_results = n.to_i
end

op.on("-p", "--p [PATTERN]", "Pattern to lookup. Eg. -p my-team-name") do |pattern|
Expand Down

0 comments on commit c40acf5

Please sign in to comment.