Navigation Menu

Skip to content

Commit

Permalink
Add git-{{local,remote}-branch,tag}-exists.
Browse files Browse the repository at this point in the history
  • Loading branch information
nvie committed Aug 29, 2013
1 parent 817da9f commit 655ba99
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
17 changes: 16 additions & 1 deletion README.md
Expand Up @@ -22,6 +22,21 @@ Accepts options, too, so you can use
to force-push.


### git is-headless

Tests if `HEAD` is pointing to a branch head, or is detached.


### git local-branch-exists / git remote-branch-exists / git tag-exists

Tests if the given local branch, remote branch, or tag exists.


### git is-headless

Tests if `HEAD` is pointing to a branch head, or is detached.


### git is-merged-into

Tests if X is merged into Y:
Expand Down Expand Up @@ -125,7 +140,7 @@ conflict.)
* mybranch


### git has-local-changes
### git has-local-changes / git is-clean / git is-dirty

Helper function that determines whether there are local changes in the working
tree, by returning a 0 (local changes) or 1 (no local changes) exit code.
Expand Down
17 changes: 17 additions & 0 deletions git-local-branch-exists
@@ -0,0 +1,17 @@
#!/bin/sh
set -e

usage () {
echo "usage: git local-branch-exists <branch>" >&2
echo >&2
echo "Will return with an exit code of 0 or 1." >&2
}

if [ $# -eq 1 ]; then
branch=$1
else
usage
exit 2
fi

git show-ref --heads --quiet --verify -- "refs/heads/$branch"
21 changes: 21 additions & 0 deletions git-remote-branch-exists
@@ -0,0 +1,21 @@
#!/bin/sh
set -e

usage () {
echo "usage: git remote-branch-exists [<remote>] <branch>" >&2
echo >&2
echo "Will return with an exit code of 0 or 1." >&2
}

if [ $# -eq 1 ]; then
remote=origin
branch=$1
elif [ $# -eq 2 ]; then
remote=$1
branch=$2
else
usage
exit 2
fi

git show-ref --quiet --verify -- "refs/remotes/$remote/$branch"
17 changes: 17 additions & 0 deletions git-tag-exists
@@ -0,0 +1,17 @@
#!/bin/sh
set -e

usage () {
echo "usage: git tag-exists <tag>" >&2
echo >&2
echo "Will return with an exit code of 0 or 1." >&2
}

if [ $# -eq 1 ]; then
tag=$1
else
usage
exit 2
fi

git show-ref --tags --quiet --verify -- "refs/tags/$tag"

0 comments on commit 655ba99

Please sign in to comment.