Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit.

  • Loading branch information...
commit b407a50fe72efd6de32352b6a5a2eb39e585df77 0 parents
@pcreux authored
4 .gitignore
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
4 Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in git-branch-delete-orphans.gemspec
+gemspec
1  Rakefile
@@ -0,0 +1 @@
+require "bundler/gem_tasks"
39 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 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 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 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
Please sign in to comment.
Something went wrong with that request. Please try again.