Skip to content

Commit

Permalink
Merge pull request #8 from praxxis/master
Browse files Browse the repository at this point in the history
Add an option that lets you specify the "master" branch
  • Loading branch information
mloughran committed Sep 4, 2013
2 parents 96b3aa1 + ec48440 commit ecc41c6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions bin/git-cleanup
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ opts = OptionParser.new do |opts|
opts.on("-o","--only FILTER", "Only branches that match FILTER will be included") do |only_filter|
conf[:only_filter] = only_filter
end
opts.on("-m", "--master BRANCH", "Consider BRANCH the \"master\" branch") do |branch|
conf[:master_branch] = branch
end
opts.on("-v", "--version", "Shows version") do
puts GitCleanup::VERSION
exit
Expand Down
18 changes: 15 additions & 3 deletions lib/git-cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,21 @@ def initialize

class GitCleanup
def self.run(options = {})
repo = Grit::Repo.new(Dir.pwd)
begin
repo = Grit::Repo.new(Dir.pwd)
rescue Grit::InvalidGitRepositoryError
Formatador.display_line(%Q{[bold][red] Could not find git repository in "#{Dir.pwd}".[/]})
exit
end

master_branch_name = options[:master_branch] || 'master'

master = repo.heads.find { |h| h.name == 'master' }
master = repo.heads.find { |h| h.name == master_branch_name }

unless master
Formatador.display_line(%Q{[bold][red] Could not find branch "#{master_branch_name}". Try using "-m BRANCH" to specify the master branch.[/]})
exit
end

self.prune(repo)

Expand All @@ -23,7 +35,7 @@ def self.run(options = {})
remote_branches = Branch.remote(repo).select { |b| b.commit.lazy_source }

remote_branches.sort.reverse.each_with_index do |branch, index|
next if branch.name == 'master'
next if branch.name == master_branch_name
next if options[:only_filter] and !branch.name.match(options[:only_filter])

msg = "Branch #{branch.to_s} (#{index+1}/#{remote_branches.size})"
Expand Down
2 changes: 1 addition & 1 deletion lib/git-cleanup/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class GitCleanup
VERSION = "0.2.2"
VERSION = "0.2.3"
end

0 comments on commit ecc41c6

Please sign in to comment.