summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorflu0r1ne <flu0r1ne@flu0r1ne.net>2021-08-22 23:11:03 -0500
committerflu0r1ne <flu0r1ne@flu0r1ne.net>2021-08-22 23:11:03 -0500
commitdfecbd5b588c1fbdaacf3df8a0ab93a668c282d2 (patch)
tree0306b625a07878f9dc439ac3b98dc6bdf62b079d
parentf26cc625b365f00420b04ab4bf5f59a4e8d09010 (diff)
downloadgit-update-agent-dfecbd5b588c1fbdaacf3df8a0ab93a668c282d2.tar.xz
git-update-agent-dfecbd5b588c1fbdaacf3df8a0ab93a668c282d2.zip
handle --dir with --init-with
-rw-r--r--git-update-agent30
1 files changed, 22 insertions, 8 deletions
diff --git a/git-update-agent b/git-update-agent
index 6c205a7..e932afe 100644
--- a/git-update-agent
+++ b/git-update-agent
@@ -169,9 +169,10 @@ init_if_empty() {
if [[ -z "$REMOTE_URL" ]]; then
die_no_git_dir
else
- init_repo "$REMOTE_URL"
- fi
+ init_repo "$1" "$REMOTE_URL"
+ echo "INITIALIZED"
+ fi
fi
}
@@ -195,7 +196,7 @@ cat <<_EOF
Usage: ${PROGRAM} [OPTIONS]...
-h, --help output this help info
-d, --dir update in directory
- --init initialize a project with the given URL
+ --init-with initialize a project with the given URL
--track track a git repository not initialized with $PROGRAM
--disable-tracking disable tracking
_EOF
@@ -229,12 +230,12 @@ update() {
local next_version
dir="$1"
- cd_or_die "$dir"
+ mkbase_or_die "$dir"
+ cd_or_die "$dir"
+
previous_version="$(current_version)"
- init_if_empty
-
if [[ "$(should_track)" != "true" ]]; then
die_not_tracking
fi
@@ -266,14 +267,27 @@ update() {
fi
}
+mkbase_or_die() {
+ if [[ ! -d "$1" ]] && ! mkdir "$1"; then
+ die <<_EOF
+Cannot create $1 directory
+_EOF
+ fi
+}
init_repo() {
+ local dir
local remote
local remote_url
local upstream_branch
local remote_ref
- remote_url="$1"
+ dir="$1"
+
+ mkbase_or_die "$dir"
+ cd_or_die "$dir"
+
+ remote_url="$2"
remote="$(remote)"
DEFAULT_BRANCH="main"
@@ -359,7 +373,7 @@ git_update_agent() {
fi
if [[ -n "$remote_url" ]]; then
- init_repo "$remote_url"
+ init_repo "$dir" "$remote_url"
exit 0
fi