From 1b1abf00833cd4796c98dc410978d042eaf8d001 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 21 May 2013 08:37:26 -0400 Subject: pbs-plumb-shlib: add documentation for git functions --- pbs-plumb-shlib | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pbs-plumb-shlib b/pbs-plumb-shlib index ccbdffb..ded9825 100644 --- a/pbs-plumb-shlib +++ b/pbs-plumb-shlib @@ -4,28 +4,36 @@ # "Primitive" git functions ########################################## +# Usage: in_git +# Returns 0 if somewhere in a git repository, nonzero if not. in_git() { git rev-parse --git-dir &>/dev/null } +# Usage: gitdir +# Prints the .git directory for the repository we're in gitdir() { git rev-parse --git-dir } +# Usage: gitroot +# Prints the root directory of the git checkout gitroot() { git rev-parse --show-toplevel } +# Usage: gitbranch +# Prints the current git branch gitbranch() { git rev-parse --abbrev-ref HEAD } +# Usage: have_file $file +# Returns 0 if `$(gitroot)/$file` exists. have_file() { local file=$1 - if in_git; then - if [[ -f "$(gitroot)/$file" ]]; then - return 0; - fi + if in_git && [[ -f "$(gitroot)/$file" ]]; then + return 0; fi return 1 } -- cgit v1.1-4-g5e80