summaryrefslogtreecommitdiff
path: root/git-update-agent
diff options
context:
space:
mode:
Diffstat (limited to 'git-update-agent')
-rw-r--r--git-update-agent37
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