summaryrefslogtreecommitdiff
path: root/src/gitget
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2013-10-30 21:11:25 -0400
committerLuke Shumaker <LukeShu@sbcglobal.net>2013-10-30 21:33:44 -0400
commited02bca748ef72df528d6749e9b384862d320492 (patch)
tree39bcf130b9d353f3c202d31f2f03b4cf3d021f0a /src/gitget
parente90114b0122a8b8338b472a0c4d475a9fd3eb66f (diff)
gitget: learn -p and -f
Diffstat (limited to 'src/gitget')
-rwxr-xr-xsrc/gitget/gitget81
1 files changed, 68 insertions, 13 deletions
diff --git a/src/gitget/gitget b/src/gitget/gitget
index 0ec959b..461dffc 100755
--- a/src/gitget/gitget
+++ b/src/gitget/gitget
@@ -37,11 +37,12 @@ cd_safe() {
}
# from makepkg
-download_git_checkout() (
+download_git_checkout() {
local url=$1
local ref=$2
local dir=$3
- local name=${4:-${dir##*/}}
+ local name=$4
+ local push=${5:-}
if [[ ! -d "$dir/.git" ]] ; then
msg2 "Cloning %s %s repo..." "${name}" "git"
@@ -51,14 +52,37 @@ download_git_checkout() (
exit 1
fi
cd_safe "$dir"
+ if [[ -n $push ]]; then
+ git config remote.origin.pushUrl "$push"
+ fi
git checkout "$ref"
else
cd_safe "$dir"
# Make sure we are fetching the right repo
- if [[ "$repo" != "$(git config --get remote.origin.url)" ]] ; then
- error "%s is not a clone of %s" "$dir" "$url"
- plain "Aborting..."
- exit 1
+ if [[ "$url" != "$(git config --get remote.origin.url)" ]] ; then
+ if $FORCE; then
+ git config remote.origin.url "$url"
+ else
+ error "%s is not a clone of %s" "$dir" "$url"
+ plain "Aborting..."
+ exit 1
+ fi
+ fi
+ if [[ -n $push ]] ; then
+ if $FORCE; then
+ git config remote.origin.pushUrl "$push"
+ else
+ local curpush="$(git config --get remote.origin.pushUrl)"
+ if [[ $? != 0 ]] ; then
+ error "%s does not have a %s configured" pushUrl "$name"
+ plain "Aborting..."
+ exit 1
+ elif [[ $curpush != "$push" ]]; then
+ error "%s has %s configured, but it doesn't match %s" "$name" pushUrl "$push"
+ plain "Aborting..."
+ exit 1
+ fi
+ fi
fi
msg2 "Updating %s %s repo..." "${name}" "git"
if ! git pull origin "$ref"; then
@@ -66,13 +90,14 @@ download_git_checkout() (
warning "Failure while updating %s %s repo" "${repo}" "git"
fi
fi
-)
+}
# from makepkg
-download_git_bare() (
+download_git_bare() {
local url=$1
local dir=$2
- local name=${3:-${dir##*/}}
+ local name=$3
+ local push=${4:-}
if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then
msg2 "Cloning %s %s repo..." "${name}" "git"
@@ -81,6 +106,10 @@ download_git_bare() (
plain "Aborting..."
exit 1
fi
+ if [[ -n $push ]]; then
+ cd_safe "$dir"
+ git config remote.origin.pushUrl "$push"
+ fi
else
cd_safe "$dir"
# Make sure we are fetching the right repo
@@ -89,13 +118,29 @@ download_git_bare() (
plain "Aborting..."
exit 1
fi
+ if [[ -n $push ]] ; then
+ if $FORCE; then
+ git config remote.origin.pushUrl "$push"
+ else
+ local curpush="$(git config --get remote.origin.pushUrl)"
+ if [[ $? != 0 ]] ; then
+ error "%s does not have a %s configured" pushUrl "$name"
+ plain "Aborting..."
+ exit 1
+ elif [[ $curpush != "$push" ]]; then
+ error "%s has %s configured, but it doesn't match %s" "$name" pushUrl "$push"
+ plain "Aborting..."
+ exit 1
+ fi
+ fi
+ fi
msg2 "Updating %s %s repo..." "${name}" "git"
if ! git fetch --all -p; then
# only warn on failure to allow offline builds
warning "Failure while updating %s %s repo" "${name}" "git"
fi
fi
-)
+}
usage() {
print 'Usage: %s [OPTIONS] bare URL DIRECTORY' "${0##*/}"
@@ -121,16 +166,26 @@ usage() {
pasted again and again."
echo
print "Options:"
+ flag '-f' \
+ 'Instead of checking to make sure configured URLs match, force
+ the update, and set the URLs.'
+ flag "-p $(_ URL)" \
+ 'In addition to setting or checking `remotes.origin.url`, also
+ set or check `remotes.origin.pushUrl`'
flag "-n $(_ NAME)" \
'In messages, instead of using the basename of DIRECTORY as the
repository name, use NAME'
flag '-h' 'Show this message'
}
+FORCE=false
main() {
+ local push=''
local name=''
- while getopts 'n:h' flag; do
+ while getopts 'fp:n:h' flag; do
case "${flag}" in
+ f) FORCE=true;;
+ p) push=$OPTARG;;
n) name=$OPTARG;;
h) usage; return 0;;
*) usage >&2; return 1;;
@@ -148,8 +203,8 @@ main() {
name=${name:-${dir##*/}}
case "$mode" in
- checkout) download_git_checkout "$urlmain" "$ref" "$dir" "$name";;
- bare) download_git_bare "$urlmain" "$dir" "$name";;
+ checkout) download_git_checkout "$urlmain" "$ref" "$dir" "$name" "$push";;
+ bare) download_git_bare "$urlmain" "$dir" "$name" "$push";;
*) usage >&2; return 1;;
esac
}