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