Last active
February 23, 2022 04:48
-
-
Save arronmabrey/83de0757ce25d14f7cf6f875f62d4d95 to your computer and use it in GitHub Desktop.
Checks if feature branches have been merged/squashed/rebased into master
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 characters
#!/usr/bin/env ruby | |
ENV["GIT_MERGE_AUTOEDIT"] = "no" | |
master_branch = "master" | |
merge_branch = "gitmerged-master" | |
`git fetch` | |
fail "uncommited changes" unless `git status --porcelain`.empty? | |
branches = `git branch`.lines.map {|l| l.gsub('*','').strip.chomp }.reject { |branch| branch == master_branch } | |
if branches.include?(merge_branch) | |
branches = branches - [merge_branch] | |
else | |
`git checkout --quiet #{master_branch} && git checkout --quiet -b #{merge_branch}` | |
end | |
branches.each do |branch| | |
puts branch | |
system "git checkout --quiet #{merge_branch} && git reset --quiet --hard #{master_branch} && git clean -df && git merge --quiet #{branch} && git diff --quiet #{master_branch}...#{merge_branch}" | |
if $?.success? | |
puts "merged" | |
else | |
`git reset --quiet --hard #{master_branch}` if `git branch | grep '*'`.include?(merge_branch) | |
puts "not-merged" | |
end | |
puts | |
end | |
`git checkout #{master_branch} && git branch -D #{merge_branch}` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment