From e42d401d0f379a6c6ec541eaf05682973abf4bf9 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 18 Mar 2013 10:18:17 -0400 Subject: add a shlib, use .pbs-root and .pbs-package to identify directories --- pbs-package-commit | 12 +++----- pbs-package-fork | 4 ++- pbs-package-merge | 9 ++---- pbs-package-new | 6 ++-- pbs-plumb-shlib | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 97 insertions(+), 18 deletions(-) create mode 100644 pbs-plumb-shlib diff --git a/pbs-package-commit b/pbs-package-commit index d07d3f9..0f52401 100755 --- a/pbs-package-commit +++ b/pbs-package-commit @@ -1,6 +1,6 @@ #!/bin/bash -euE -. libremessages +. pbs-plumb-shlib cmd=${0##*/} usage() { @@ -24,17 +24,13 @@ main() { return 0 fi - if ! git rev-parse --git-dir &>/dev/null; then - error "Must be in a package (git) directory" - return 1 - fi - cd "$(git rev-parse --show-cdup)" - + ensure_in_pbs-package git commit "$@" git push local msg="$(git log -n1 --pretty=format:%B)" local dir="$(pwd)" - cd .. + + cdto_pbs-root git add "${dir##*/}" git commit -m "$msg" } diff --git a/pbs-package-fork b/pbs-package-fork index 56d0663..97aeec9 100755 --- a/pbs-package-fork +++ b/pbs-package-fork @@ -1,6 +1,6 @@ #!/bin/bash -euE -. libremessages +. pbs-plumb-shlib cmd=${0##*/} usage() { @@ -42,6 +42,8 @@ main() { local dest=$3 local newpackage="${dest##*/}" + cdto_pbs-root + git submodule add -b "packages/${oldpackage}" "${repository}" "${dest}" cd "${dest}" git checkout -b "packages/${newpackage}" diff --git a/pbs-package-merge b/pbs-package-merge index f99484b..eca9d1b 100755 --- a/pbs-package-merge +++ b/pbs-package-merge @@ -1,6 +1,6 @@ #!/bin/bash -euE -. libremessages +. pbs-plumb-shlib cmd=${0##*/} usage() { @@ -27,12 +27,7 @@ main() { return 1 fi - if ! git rev-parse --git-dir &>/dev/null; then - error "Must be in a package (git) directory" - return 1 - fi - cd "$(git rev-parse --show-cdup)" - + cdto_pbs-package-root if [[ ! -r pbstrack ]]; then error "No pbstrack file found, don't know where to pull from" return 1 diff --git a/pbs-package-new b/pbs-package-new index bd76f8a..a99fd30 100755 --- a/pbs-package-new +++ b/pbs-package-new @@ -1,6 +1,6 @@ #!/bin/bash -euE -. libremessages +. pbs-plumb-shlib cmd=${0##*/} usage() { @@ -19,7 +19,7 @@ main() { esac done shift $(($OPTIND - 1)) - if [[ $# > 0 ]]; then + if [[ $# != 1 ]]; then usage return 1 fi @@ -27,9 +27,11 @@ main() { local dest=$1 local package="${dest##*/}" + cdto_pbs-root git submodule add ./ "${dest}" cd "${dest}" git checkout --orphan "packages/${package}" + touch .pbs-package } main "$@" diff --git a/pbs-plumb-shlib b/pbs-plumb-shlib new file mode 100644 index 0000000..c51ddd0 --- /dev/null +++ b/pbs-plumb-shlib @@ -0,0 +1,84 @@ +#!/bin/bash + +. libremessages + +# "Primitive" git functions ########################################## + +in_git() { + git rev-parse --git-dir &>/dev/null +} + +gitdir() { + git rev-parse --git-dir +} + +gitroot() { + git rev-parse --show-toplevel +} + +have_file() { + local file=$1 + if in_git; then + if [[ -f "$(gitroot)/$file" ]]; then + return 0; + fi + fi + return 1 +} + +# Deal with being in a PBS package repository ######################## + +in_pbs-package() { + have_file .pbs-package +} + +ensure_in_pbs-package() { + if ! in_pbs-package; then + error "Not in a PBS package directory" + exit 1 + fi +} + +pbs-package-root() { + ensure_in_pbs-package + gitroot +} + +cdto_pbs-package-root() { + ensure_in_pbs-package + cd "$(gitroot)" +} + +# Deal with being in a PBS repository ################################ + +in_pbs() ( + if in_pbs-package; then + cd "$(pbs-package-root)/.." + fi + have_file .pbs-root +) + +ensure_in_pbs() { + if ! in_pbs; then + error "Not in a PBS directory" + exit 1 + fi +} + +pbs-root() { + ensure_in_pbs + ( + if in_pbs-package; then + cd "$(pbs-package-root)/.." + fi + gitroot + ) +} + +cdto_pbs-root() { + ensure_in_pbs + if in_pbs-package; then + cd "$(pbs-package-root)/.." + fi + cd "$(gitroot)" +} -- cgit v1.1-4-g5e80