Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
pcreux committed Oct 17, 2011
0 parents commit b407a50
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
*.gem
.bundle
Gemfile.lock
pkg/*
4 changes: 4 additions & 0 deletions Gemfile
@@ -0,0 +1,4 @@
source "http://rubygems.org"

# Specify your gem's dependencies in git-branch-delete-orphans.gemspec
gemspec
1 change: 1 addition & 0 deletions Rakefile
@@ -0,0 +1 @@
require "bundler/gem_tasks"
39 changes: 39 additions & 0 deletions bin/git-branch-delete-orphans
@@ -0,0 +1,39 @@
#! /usr/bin/env ruby

def remotes
puts "Listing remote branches..."
@remote ||= `git ls-remote | grep 'refs/heads'`.map { |l| l.gsub(/^.*refs\/heads\//, '').strip }
end

def locals
@local ||= `cat .git/config | grep "refs/heads/\\w"`.map { |l| l.gsub(/^.*refs\/heads\//, '').strip }
end

def cli(orphans)
puts ""
puts "The following branches track a remote branch which does not exist anymore:"
orphans.each { |b| puts " - #{b}" }

delete_all = false
keep_all = false
orphans.each do |b|
delete = false
keep = false
until delete || delete_all || keep || keep_all
puts ""
puts "#{b} tracks a remote branch which does not exist anymore. Do you want to [d]elete it, [D]elete all, [k]eep it or [K]eep all?"
case STDIN.gets.chomp
when 'd' then delete = true
when 'D' then delete_all = true
when 'k' then keep = true
when 'K' then keep_all = true
end
end
if (delete_all || delete) && !(keep_all || keep)
system("git branch -D #{b}") # git outputs success / error messages
end
end
end

orphans = locals - remotes
cli(orphans)
24 changes: 24 additions & 0 deletions git-branch-delete-orphans.gemspec
@@ -0,0 +1,24 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "git-branch-delete-orphans/version"

Gem::Specification.new do |s|
s.name = "git-branch-delete-orphans"
s.version = Git::Branch::Delete::Orphans::VERSION
s.authors = ["Philippe Creux"]
s.email = ["pcreux@gmail.com"]
s.homepage = ""
s.summary = %q{Delete tracking branches which remote branch does not exist anymore.}
s.description = %q{`git branch-delete-orphans` lists orphan tracking branches and prompts you to delete or keep them.}

s.default_executable = %q{git-branch-delete-orphans}

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]

# specify any dependencies here; for example:
# s.add_development_dependency "rspec"
# s.add_runtime_dependency "rest-client"
end
11 changes: 11 additions & 0 deletions lib/git-branch-delete-orphans.rb
@@ -0,0 +1,11 @@
require "git-branch-delete-orphans/version"

module Git
module Branch
module Delete
module Orphans
# Your code goes here...
end
end
end
end
9 changes: 9 additions & 0 deletions lib/git-branch-delete-orphans/version.rb
@@ -0,0 +1,9 @@
module Git
module Branch
module Delete
module Orphans
VERSION = "0.0.1"
end
end
end
end

0 comments on commit b407a50

Please sign in to comment.