summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--git-update-agent40
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