Skip to content

Commit

Permalink
Add git-{merged,unmerged,merge-status}.
Browse files Browse the repository at this point in the history
  • Loading branch information
nvie committed Sep 3, 2013
1 parent 144be6c commit ace41f4
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Expand Up @@ -15,6 +15,7 @@ Everyday helpful commands:
* git-root
* git-update-all
* git-workon
* git-merged / git-unmerged / git-merge-status

Common aliases:

Expand Down Expand Up @@ -289,6 +290,16 @@ changes. Will only update if a pull succeeds cleanly (i.e. is a fast-forward
pull).


### git-merged / git-unmerged / git-merge-status

This trio of subcommands makes it easy to inspect merge status of local
branches. Use them to check whether any local branches have or haven't been
merged into the target branch (defaults to master).

git-merge-status is a useful command that presents both lists in a single
overview (not for machine processing).


### git force-checkout

Don't care about your local working copy's state and really want to switch to
Expand Down
45 changes: 45 additions & 0 deletions git-merge-status
@@ -0,0 +1,45 @@
#!/bin/sh
#!/bin/sh
set -e

usage () {
echo "usage: git merge-status [-h] [<branch>]" >&2
echo >&2
echo "Shows merge status of all local branches against branch (defaults to master)." >&2
echo >&2
echo "Options:" >&2
echo "-h Show this help" >&2
}

while getopts h flag; do
case "$flag" in
h) usage; exit 2;;
esac
done
shift $(($OPTIND - 1))

bulletize () {
sed -Ee 's/^/ - &/'
}

fail_if_empty () {
empty=1
while read line; do
echo "$line"
empty=0
done
test $empty -eq 0
}

base="${1-master}"

echo "Merged into $base:"
if ! git merged "$base" | bulletize | fail_if_empty; then
echo "(no branches)"
fi

echo
echo "Not merged into $base:"
if ! git merged -u "$base" | bulletize | fail_if_empty; then
echo "(no branches)"
fi
30 changes: 30 additions & 0 deletions git-merged
@@ -0,0 +1,30 @@
#!/bin/sh
set -e

usage () {
echo "usage: git merged [-uh] [<branch>]" >&2
echo >&2
echo "Shows what local branches have been merged into branch (defaults to master)." >&2
echo >&2
echo "Options:" >&2
echo "-u Show unmerged branches instead of merged branches" >&2
echo "-h Show this help" >&2
}

unmerged=0
while getopts uh flag; do
case "$flag" in
u) unmerged=1;;
h) usage; exit 2;;
esac
done
shift $(($OPTIND - 1))

if [ $unmerged -eq 1 ]; then
opts="--no-merged"
else
opts="--merged"
fi

base="${1-master}"
git branch $opts "$base" | cut -c3- | grep -vxF "$base"
3 changes: 3 additions & 0 deletions git-unmerged
@@ -0,0 +1,3 @@
#!/bin/sh
set -e
git merged -u "$@"

0 comments on commit ace41f4

Please sign in to comment.