diff options
author | Alex David <flu0r1ne@flu0r1ne.net> | 2021-08-29 17:24:11 -0500 |
---|---|---|
committer | Alex David <flu0r1ne@flu0r1ne.net> | 2021-08-29 17:24:11 -0500 |
commit | edf7f22508e1df818b5c92d6e8e4669a9f95c81f (patch) | |
tree | a203e1a8d433965b23878035563b79aea7b458a8 /git-update-agent | |
parent | 09e7a2252f28b9627bd02a60e16bd4b64ac7d57d (diff) | |
parent | f000ca24f33409c6f688d170444a6203c53204e5 (diff) | |
download | deb-git-update-agent-edf7f22508e1df818b5c92d6e8e4669a9f95c81f.tar.xz deb-git-update-agent-edf7f22508e1df818b5c92d6e8e4669a9f95c81f.zip |
Merge branch 'upstream' into ppa
Merge 0.0.4
Diffstat (limited to 'git-update-agent')
-rw-r--r-- | git-update-agent | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/git-update-agent b/git-update-agent index b32305e..b0c91f4 100644 --- a/git-update-agent +++ b/git-update-agent @@ -1,4 +1,5 @@ #!/bin/bash +set -eE -o pipefail # GLOBAL VARIABLES: # - UPSTREAM_BRANCH: The branch in the upstream repo used for updates (defaults to remote's head if set) @@ -236,7 +237,6 @@ update() { dir="$1" - mkbase_or_die "$dir" cd_or_die "$dir" previous_version="$(current_version)" @@ -272,11 +272,11 @@ update() { fi } -mkbase_or_die() { - if [[ ! -d "$1" ]] && ! mkdir "$1"; then - die <<_EOF -Cannot create $1 directory -_EOF +clean_partial_clone() { + if [[ -n "${INIT_DIR}" ]]; then + rm -rf "${INIT_DIR}" + else + rm -rf .git fi } @@ -295,7 +295,16 @@ init_repo() { dir="$1" - mkbase_or_die "$dir" + if [[ ! -d "$dir" ]]; then + if ! mkdir "$dir"; then + die "Cannot create $dir directory" + fi + + INIT_DIR="$(pwd)/$dir" + fi + + trap 'clean_partial_clone' EXIT + cd_or_die "$dir" remote_url="$2" @@ -303,30 +312,22 @@ init_repo() { DEFAULT_BRANCH="main" - trap '{ rm -rf .git; die_init_failure; }' EXIT - - set -e git init &>/dev/null git config "remote.${remote}.url" "$remote_url" git config "remote.${remote}.fetch" "+refs/heads/*:refs/remotes/$remote/*" set_should_track true - set +e if ! git fetch --force --tags "$remote" 2>/dev/null; then die "Could not download content from \"$remote_url\" on \"$DEFAULT_BRANCH\"." fi - - set -e + git checkout "$DEFAULT_BRANCH" - git remote set-head "$remote" --auto >/dev/null - trap - EXIT - set +e } print_version() { - echo "0.0.2" + echo "0.0.4" } # @@ -369,6 +370,7 @@ git_update_agent() { ;; --track) track=1; shift ;; --disable-tracking) disable_tracking=1; shift ;; + --debug) debug=1; shift ;; --version) print_version; exit 0 ;; *) die "$(print_usage)" ;; esac @@ -376,6 +378,10 @@ git_update_agent() { depends git + if [[ -n "$debug" ]]; then + set -x + fi + if [[ -z "$dir" ]]; then dir="." fi |