diff options
author | flu0r1ne <flu0r1ne@flu0r1ne.net> | 2021-08-29 15:00:19 -0500 |
---|---|---|
committer | flu0r1ne <flu0r1ne@flu0r1ne.net> | 2021-08-29 15:00:19 -0500 |
commit | 9e9b74ba65fe59a393f64d7910a580adcff25edd (patch) | |
tree | ba2a6871f6e387bb16ac77bd581e7ee815d6a9f4 | |
parent | ac828ba769bad298cb3a404008409b0af11088c7 (diff) | |
download | git-update-agent-9e9b74ba65fe59a393f64d7910a580adcff25edd.tar.xz git-update-agent-9e9b74ba65fe59a393f64d7910a580adcff25edd.zip |
Add debugging, trap partial fetch, and rely on remote to set HEAD
-rw-r--r-- | git-update-agent | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/git-update-agent b/git-update-agent index b32305e..25c3e70 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) @@ -272,11 +273,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 +296,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,26 +313,18 @@ 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() { @@ -369,6 +371,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 +379,10 @@ git_update_agent() { depends git + if [[ -n "$debug" ]]; then + set -x + fi + if [[ -z "$dir" ]]; then dir="." fi |