Skip to content

Commit

Permalink
Speed up branch fetching. Limit to local branches.
Browse files Browse the repository at this point in the history
  • Loading branch information
ccallebs committed May 26, 2016
1 parent c56269c commit 6869953
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 27 deletions.
8 changes: 4 additions & 4 deletions lib/git_left.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "git_left/version"
require "git_left/branches"
require "git_left/key_parser"
require "git_left/cli"
require_relative "git_left/version"
require_relative "git_left/branches"
require_relative "git_left/key_parser"
require_relative "git_left/cli"

module GitLeft
end
4 changes: 2 additions & 2 deletions lib/git_left/branches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def self.branches
@@skipped_branches ||= []
@@deleted_branches ||= []

@@all_branches = Git.open('.').branches.to_a
@@all_branches.select { |b| !branches_to_omit.include?(b.name) }
@@all_branches ||= Git.open('.').branches.to_a
@@all_branches.select { |b| !branches_to_omit.include?(b.name) && !b.remote }
end
end
end
47 changes: 26 additions & 21 deletions lib/git_left/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,35 @@ def begin(opts = {})
puts "Time to clean up your #{GitLeft::Branches.branches.count} local branches..."

while(1) do
random_branch = GitLeft::Branches.random_branch
begin
@random_branch = GitLeft::Branches.random_branch

if random_branch.nil?
puts "\nYou cleaned up all your branches!"
puts "\t#{GitLeft::Branches.skipped_branches.count} skipped"
puts "\t#{GitLeft::Branches.deleted_branches.count} deleted"
break
end
if @random_branch.nil?
puts "\nYou cleaned up all your branches!"
puts "\t#{GitLeft::Branches.skipped_branches.count} skipped"
puts "\t#{GitLeft::Branches.deleted_branches.count} deleted"
break
end

underlined = "\e[4m" << random_branch.name << "\e[24m"
puts "\nDeciding time: #{underlined} (h to delete, l to skip, anything else to quit)\n"
underlined = "\e[4m" << @random_branch.name << "\e[24m"
puts "\nDeciding time: #{underlined} (h to delete, l to skip, anything else to quit)\n"

case GitLeft::KeyParser.new(STDIN.getch).action
when :delete
GitLeft::Branches.delete(random_branch)
puts "#{random_branch.name} deleted"
next
when :skip
GitLeft::Branches.skip(random_branch)
puts "#{random_branch.name} skipped"
next
when :quit
puts "See ya!"
break
case GitLeft::KeyParser.new(STDIN.getch).action
when :delete
GitLeft::Branches.delete(@random_branch)
puts "#{@random_branch.name} deleted"
next
when :skip
GitLeft::Branches.skip(@random_branch)
puts "#{@random_branch.name} skipped"
next
when :quit
puts "See ya!"
break
end
rescue
puts "A problem occurred performing that action. Skipping."
GitLeft::Branches.skip(@random_branch)
end
end
end
Expand Down

0 comments on commit 6869953

Please sign in to comment.