Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b407a50
Showing
7 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
*.gem | |||
.bundle | |||
Gemfile.lock | |||
pkg/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
source "http://rubygems.org" | |||
|
|||
# Specify your gem's dependencies in git-branch-delete-orphans.gemspec | |||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
require "bundler/gem_tasks" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,9 @@ | |||
module Git | |||
module Branch | |||
module Delete | |||
module Orphans | |||
VERSION = "0.0.1" | |||
end | |||
end | |||
end | |||
end |