-
-
Save jsanders/2968558 to your computer and use it in GitHub Desktop.
Revisions
-
jsanders revised this gist
Jun 21, 2012 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -48,4 +48,5 @@ set -e git branch $branch_opts --merged $ref | tr -d '* ' | grep "${remote:-.}" | grep -v "^${ref}$" | grep -v "^smartgrid-v.*-maint$" -
Simon Chiang revised this gist
Jun 21, 2012 . 1 changed file with 10 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -34,9 +34,14 @@ Example output: $ git old-branches github/master | format_branch_deletes # schiang@comverge.com git push github :30434977_fix_the_clock # a262408 (3 weeks ago) <schiang@comverge.com> git push github :add_non_existant_methods # f47c5c9 (10 days ago) <schiang@comverge.com> git push github :manual_requires # c9bcc3f (3 weeks ago) <schiang@comverge.com> git push github :unnecessary_fsr # 54f4eb4 (9 days ago) <schiang@comverge.com> The idea is that you can check the delete commands and execute as needed. Note that once the remote branches are deleted your teammates may have to prune the deleted branches from their local copies: # use --dry-run option first as a precaution git remote prune github -
Simon Chiang revised this gist
Jun 21, 2012 . 2 changed files with 20 additions and 23 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -23,21 +23,20 @@ Now go to your project. # format branch delete commands according to user: git old-branches github/master | format_branch_deletes Example output: $ git old-branches | format_branch_deletes # schiang@comverge.com git branch -d remove_new_relic # 301a52b (5 hours ago) <schiang@comverge.com> git branch -d something # 301a52b (5 hours ago) <schiang@comverge.com> $ git old-branches github/master | format_branch_deletes # schiang@comverge.com git push thinkerbot :30434977_fix_the_clock # a262408 (3 weeks ago) <schiang@comverge.com> git push thinkerbot :add_non_existant_methods # f47c5c9 (10 days ago) <schiang@comverge.com> git push thinkerbot :manual_requires # c9bcc3f (3 weeks ago) <schiang@comverge.com> git push thinkerbot :unnecessary_fsr # 54f4eb4 (9 days ago) <schiang@comverge.com> The idea is that you can check the delete commands and execute as needed. This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -7,11 +7,18 @@ require 'ostruct' ############################################################################# OptionParser.new do |opts| opts.banner = %{ Usage: #{$0} [options] [BRANCHES] Formats a list of branches for deletion. If no branches are listed then branches are read from stdin. Local branches are formatted like git branch -d BRANCH Remote branches (remote/branch) are formatted like: git push REMOTE :BRANCH Options: }.lstrip @@ -24,8 +31,6 @@ Options: end.parse! ############################################################################# # read branches from stdin and sort by email @@ -35,7 +40,7 @@ while branch = gets logline = `git log --format="%ae,%h,%cr" -n1 '#{branch}'` email, sha, date = logline.strip.split(',') msg = "#{sha} (#{date}) <#{email}>" if branch.include?('/') remote, branch = branch.split('/') @@ -46,13 +51,6 @@ while branch = gets branches_by_email[email] << [remote, branch, msg] end # print assignments template = ERB.new <<-EOF, nil, "<>" # <%= email %> -
Simon Chiang revised this gist
Jun 21, 2012 . 1 changed file with 7 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -28,11 +28,16 @@ Now go to your project. Example output: $ git old-branches | format_branch_deletes # simon.a.chiang@gmail.com git branch -d remove_new_relic # 301a52b (4 hours ago) git branch -d do_a_great_thing # 301a52b (2 hours ago) $ git old-branches github/master | format_branch_deletes # simon.a.chiang@gmail.com git push github :remove_new_relic # 301a52b (4 hours ago) git push github :do_a_great_thing # 301a52b (2 hours ago) The idea is that you can check the delete commands and execute as needed. -
Simon Chiang revised this gist
Jun 21, 2012 . 1 changed file with 38 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ Description ====================== Find and delete old git branches that are no longer needed. Usage ====================== Clone the repo and add to your path (just for ease of use): git clone git://gist.github.com/2891516.git gist-2891516 cd gist-2891516 export PATH="$PATH:$(pwd)" Now go to your project. # list branches that have been merged to the current branch git old-branches # list branches that have been merged to the remote: git old-branches github/master # format branch delete commands according to user: git old-branches github/master | format_branch_deletes # filter branch delete commands by user: git old-branches github/master | format_branch_deletes doej Example output: # simon.a.chiang@gmail.com git branch -d remove_new_relic # 301a52b (4 hours ago) git branch -d do_a_great_thing # 301a52b (2 hours ago) # john.doe@gmail.com git branch -d what_was_that # 301a52b (10 days ago) -
Simon Chiang revised this gist
Jun 21, 2012 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -59,9 +59,9 @@ template = ERB.new <<-EOF, nil, "<>" <% branches.sort.each do |(remote, branch, msg)| %> <% if remote.empty? %> git branch -d <%= branch.ljust(max) %> # <%= msg %> <% else %> git push <%= remote %> :<%= branch.ljust(max) %> # <%= msg %> <% end %> <% end %> -
Simon Chiang revised this gist
Jun 21, 2012 . 1 changed file with 51 additions and 48 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,81 +1,84 @@ #!/usr/bin/env ruby begin require 'optparse' require 'erb' require 'ostruct' ############################################################################# OptionParser.new do |opts| opts.banner = %{ Usage: #{$0} [options] [USERS] Reads a list of branches from stdin and formats them for deletion based on the email of the last person to commit to that branch. Filters for the specified users, all users by default. Options: }.lstrip opts.on("-h", "--help", "print this help") do puts opts puts exit end end.parse! patterns = ARGV.dup ARGV.clear ############################################################################# # read branches from stdin and sort by email branches_by_email = Hash.new {|hash, key| hash[key] = [] } while branch = gets branch.strip! logline = `git log --format="%ae,%h,%cr" -n1 '#{branch}'` email, sha, date = logline.strip.split(',') msg = "#{sha} (#{date})" if branch.include?('/') remote, branch = branch.split('/') else remote = "" end branches_by_email[email] << [remote, branch, msg] end # filter branches by email unless patterns.empty? branches_by_email.delete_if do |email, branches| ! patterns.any? {|fragment| email.include?(fragment) } end end # print assignments template = ERB.new <<-EOF, nil, "<>" # <%= email %> <% branches.sort.each do |(remote, branch, msg)| %> <% if remote.empty? %> git branch -d <%= branch.ljust(max) %> # <%= msg %> <% else %> git push <%= remote %> :<%= branch.ljust(max) %> # <%= msg %> <% end %> <% end %> EOF branches_by_email.keys.sort.each do |email| branches = branches_by_email[email] binding = OpenStruct.new( :email => email, :branches => branches, :max => branches.map {|r,b,m| b.length }.max ).send(:binding) puts template.result(binding) end ############################################################################# rescue(Errno::EPIPE) raise if $DEBUG if $!.class == Errno::EPIPE -
Simon Chiang revised this gist
Jun 21, 2012 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,5 @@ #!/bin/bash ############################################################################ progname="${0##*/}" version="1.0" author="Simon Chiang" -
Simon Chiang renamed this gist
Jun 21, 2012 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ begin opts.banner = %{ Usage: #{$0} [options] [USERS] Reads a list of branches from stdin and formats them for deletion based on the email of the last person to commit to that branch. Filters for the specified users, all users by default. @@ -53,7 +53,7 @@ Options: # print assignments template = ERB.new <<-EOF, nil, "<>" # <%= email %> <% branches.sort.each do |(remote, branch, msg)| %> <% if remote.empty? %> -
Simon Chiang revised this gist
Jun 21, 2012 . 1 changed file with 67 additions and 25 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,58 @@ #!/usr/bin/env ruby begin require 'optparse' require 'erb' require 'ostruct' OptionParser.new do |opts| opts.banner = %{ Usage: #{$0} [options] [USERS] Reads a list of branches from stdin and assigns them for deletion based on the email of the last person to commit to that branch. Filters for the specified users, all users by default. Options: }.lstrip opts.on("-h", "--help", "print this help") do puts opts puts exit end end.parse! patterns = ARGV.dup ARGV.clear # read branches from stdin and sort by email branches_by_email = Hash.new {|hash, key| hash[key] = [] } while branch = gets branch.strip! logline = `git log --format="%ae,%h,%cr" -n1 '#{branch}'` email, sha, date = logline.strip.split(',') msg = "#{sha} (#{date})" if branch.include?('/') remote, branch = branch.split('/') else remote = "" end branches_by_email[email] << [remote, branch, msg] end # filter branches by email unless patterns.empty? branches_by_email.delete_if do |email, branches| ! patterns.any? {|fragment| email.include?(fragment) } end end # print assignments template = ERB.new <<-EOF, nil, "<>" %% <%= email %> <% branches.sort.each do |(remote, branch, msg)| %> @@ -16,30 +65,23 @@ template = ERB.new <<-EOF, nil, "<>" EOF branches_by_email.keys.sort.each do |email| branches = branches_by_email[email] binding = OpenStruct.new( :email => email, :branches => branches, :max => branches.map {|r,b,m| b.length }.max ).send(:binding) puts template.result(binding) end rescue(Errno::EPIPE) raise if $DEBUG if $!.class == Errno::EPIPE exit 0 else puts "#{$!.message} (see '#{$0} --help')" exit 1 end end -
Simon Chiang renamed this gist
Jun 21, 2012 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Simon Chiang revised this gist
Jun 21, 2012 . 2 changed files with 45 additions and 35 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ #!/usr/bin/env ruby require 'erb' require 'ostruct' template = ERB.new <<-EOF, nil, "<>" %% <%= email %> <% branches.sort.each do |(remote, branch, msg)| %> <% if remote.empty? %> git branch -d <%= branch.ljust(max) %> # <%= msg %> <% else %> git push <%= remote %> :<%= branch.ljust(max) %> # <%= msg %> <% end %> <% end %> EOF branches_by_email = Hash.new {|hash, key| hash[key] = [] } while branch = gets branch.strip! logline = `git log --format="%ae,%h,%cr" -n1 '#{branch}'` email, sha, date = logline.strip.split(',') msg = "#{sha} (#{date})" if branch.include?('/') remote, branch = branch.split('/') else remote = "" end branches_by_email[email] << [remote, branch, msg] end branches_by_email.keys.sort.each do |email| branches = branches_by_email[email] binding = OpenStruct.new( :email => email, :branches => branches, :max => branches.map {|r,b,m| b.length }.max ).send(:binding) puts template.result(binding) end This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,35 +0,0 @@ -
Simon Chiang revised this gist
Jun 21, 2012 . 1 changed file with 23 additions and 40 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -5,66 +5,49 @@ progname="${0##*/}" version="1.0" author="Simon Chiang" usestr="usage: %s [-h] [reference_branch] Prints branches already merged to the reference branch (by default the current branch). If a remote branch is given, then branches for that remote are considered. " optstr=" %s %s\n" while getopts "h" opt do case $opt in d ) delete="true" ;; h ) printf "$usestr" "$progname" printf "%s" "$hel" printf "options:\n" printf "$optstr" "-h" "prints this help" printf "\n" exit 0 ;; r ) remote="$OPTARG/" ;; \? ) printf "$usestr" "$progname" exit 2 ;; esac done shift $(($OPTIND - 1)) ############################################################################ current_branch () { git branch | grep '*' | awk '{print $2}' } ref="${1:-$(current_branch)}" remote=$(printf "%s" "$ref" | sed -ne 's/\/.*//p') branch_opts="" if ! [ x"$remote" = x ] then branch_opts="-r" fi ############################################################################ set -e git branch $branch_opts --merged $ref | tr -d '* ' | grep "${remote:-.}" | grep -v "^${ref}$" -
Simon Chiang revised this gist
Jun 21, 2012 . 2 changed files with 39 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -64,4 +64,7 @@ join <(merged_branches) <(branches) | awk '{ print $2 " " $1 }' | grep "$branch_filter" | grep -v -e "^$($git log --format='%h' -n 1 "$ref")" | join -v1 - <(reverted_commits) | while read sha ref do git log -n1 --format="%ae %h $ref %an" $sha done This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ #!/usr/bin/env ruby require 'erb' require 'ostruct' template = ERB.new <<-EOF Hello Mr. or Mrs. "<%= names %>" These commands will delete branches that have already been merged into master. You were the last person to commit to the branch, so you probably know best whether or not the branch is still needed. <% branches.sort.each do |(remote, branch, sha)| %> git push git@github.com:comverge/IntelliSOURCE.git :<%= branch %>\t# <%= sha.strip %><% end %> Thanks! EOF emails={} while line=gets email, sha, ref, name = line.split(' ', 4) remote, branch = ref.split('/') emails[email] ||= { :names => name.strip, :branches => [] } emails[email][:branches] << [remote, branch, sha] end emails.each do |email, data| data = OpenStruct.new(data) puts "%%" puts email puts "Old Branches on GitHub" puts template.result(data.send(:binding)) end -
Simon Chiang revised this gist
Jun 20, 2012 . 1 changed file with 15 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -42,21 +42,26 @@ fi set -e # list reverted commits reverted_commits () { $git log "$ref" | grep 'This reverts commit' | awk '{ print substr($4, 1, 7) }' | tr -d '.,' } # list branched merged to ref branches () { $git_branch -v | tr -d '*' } merged_branches () { $git_branch --merged "$ref" | tr -d '*' } # list sha+branches that have been merged, # minus any reverts and the ref commit itself join <(merged_branches) <(branches) | awk '{ print $2 " " $1 }' | grep "$branch_filter" | grep -v -e "^$($git log --format='%h' -n 1 "$ref")" | join -v1 - <(reverted_commits) -
Simon Chiang revised this gist
Jun 20, 2012 . 1 changed file with 2 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -5,11 +5,10 @@ progname="${0##*/}" version="1.0" author="Simon Chiang" usestr="usage: %s [-h] [-r remote] [ref]\n" optstr=" %s %s\n" remote="" while getopts "hr:" opt do case $opt in @@ -26,11 +25,10 @@ do done shift $(($OPTIND - 1)) ref="${2:-master}" ############################################################################ git="git" git_branch="$git branch" branch_filter="." -
Simon Chiang revised this gist
Jun 20, 2012 . 1 changed file with 7 additions and 19 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,19 @@ #!/bin/bash ############################################################################ # Lists merged branches locally or on a remote ############################################################################ progname="${0##*/}" version="1.0" author="Simon Chiang" usestr="usage: %s [-h] [-r remote] [path_to_repo] [ref]\n" optstr=" %s %s\n" remote="" delete="false" while getopts "hr:" opt do case $opt in d ) delete="true" ;; h ) printf "$usestr" "$progname" printf "$optstr" "-h" "prints this help" printf "$optstr" "-r" "operate on named remote" @@ -55,22 +59,6 @@ join merged.tmp branches.tmp | awk '{ print $2 " " $1 }' | grep "$branch_filter" | grep -v -e "^$($git log --format='%h' -n 1 "$ref")" | join -v1 - reverts.tmp rm branches.tmp merged.tmp reverts.tmp -
Simon Chiang revised this gist
Jun 20, 2012 . 1 changed file with 5 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,18 +3,14 @@ progname="${0##*/}" version="1.0" author="Simon Chiang" usestr="usage: %s [-h] [path_to_repo] [ref]\n" optstr=" %s %s\n" remote="" while getopts "hr:" opt do case $opt in h ) printf "$usestr" "$progname" printf "$optstr" "-h" "prints this help" printf "$optstr" "-r" "operate on named remote" printf "\n" @@ -25,7 +21,9 @@ do esac done shift $(($OPTIND - 1)) repo="${1:-.}" ref="${2:-master}" ############################################################################ git="git --git-dir $repo/.git" -
Simon Chiang revised this gist
Jun 20, 2012 . 1 changed file with 70 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,22 +1,78 @@ #!/bin/bash ############################################################################ progname="${0##*/}" version="1.0" author="Simon Chiang" usestr="usage: %s [-h] [ref]\n" optstr=" %s %s\n" repo=`pwd` remote="" while getopts "d:hr:" opt do case $opt in d ) repo="$OPTARG" ;; h ) printf "$usestr" "$progname" printf "$optstr" "-d" "path to repo" printf "$optstr" "-h" "prints this help" printf "$optstr" "-r" "operate on named remote" printf "\n" exit 0 ;; r ) remote="$OPTARG" ;; \? ) printf "$usestr" "$progname" exit 2 ;; esac done shift $(($OPTIND - 1)) ref="${1:-master}" ############################################################################ git="git --git-dir $repo/.git" git_branch="$git branch" branch_filter="." if ! [ x"$remote" = x ] then git_branch="$git_branch -r" branch_filter="$remote/" fi ############################################################################ set -e # list reverted commits $git log "$ref" | grep 'This reverts commit' | awk '{ print substr($4, 1, 7) }' | tr -d '.,' > reverts.tmp # list branched merged to ref $git_branch -v | tr -d '*' > branches.tmp $git_branch --merged "$ref" | tr -d '*' > merged.tmp # list sha+branches that have been merged, # minus any reverts and the ref commit itself join merged.tmp branches.tmp | awk '{ print $2 " " $1 }' | grep "$branch_filter" | grep -v -e "^$($git log --format='%h' -n 1 "$ref")" | join -v1 - reverts.tmp rm branches.tmp merged.tmp reverts.tmp # remove the branches # | awk '{print $2}' | # if [ x"$remote" = x ] # then # while read name # do $git branch -d "$name" # done # else # awk -F '/' '{print $2}' | # while read name # do $git push "$remote" ":$name" # done # # $git remote prune "$remote" # fi -
thinkerbot created this gist
Jun 7, 2012 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ #!/bin/bash set -e branch=remotes/$1 function reverted_commits () { git log | grep 'This reverts commit' | awk '{ print substr($4, 1, 7) }' | tr -d '.,' } function branches () { git branch -av | grep "$1" | sed -e "s|$1/||" | awk '{ print $2 " " $1 }' } branches "$branch" | sort > branches.tmp reverted_commits | sort > reverts.tmp # Remove branches that have been reverted join -v1 branches.tmp reverts.tmp > candidates.tmp git log --format='%h' "$branch"/master | sort | join candidates.tmp - rm branches.tmp reverts.tmp candidates.tmp