112 lines
2.4 KiB
Bash
Executable File
112 lines
2.4 KiB
Bash
Executable File
#!/usr/bin/env sh
|
|
set -eu
|
|
|
|
REPO_URL="${REPO_URL:-http://100.64.0.1:30087/virgil-admin/rta-mock-docs.git}"
|
|
TARGET_DIR="${TARGET_DIR:-$HOME/Developer/Section0/rta-mock-docs}"
|
|
COMMAND_DIR="${COMMAND_DIR:-$HOME/.local/bin}"
|
|
COMMAND_NAME="${COMMAND_NAME:-rta-mock-docs}"
|
|
COMMAND_PATH="$COMMAND_DIR/$COMMAND_NAME"
|
|
|
|
step() {
|
|
printf "\n==> %s\n" "$*"
|
|
}
|
|
|
|
if ! command -v git >/dev/null 2>&1; then
|
|
echo "git is required but was not found on PATH" >&2
|
|
exit 1
|
|
fi
|
|
|
|
step "Preparing local Markdown workspace"
|
|
if [ -d "$TARGET_DIR/.git" ]; then
|
|
echo "Repo already exists: $TARGET_DIR"
|
|
git -C "$TARGET_DIR" remote set-url origin "$REPO_URL"
|
|
git -C "$TARGET_DIR" fetch origin
|
|
git -C "$TARGET_DIR" checkout main
|
|
git -C "$TARGET_DIR" pull --ff-only
|
|
else
|
|
mkdir -p "$(dirname "$TARGET_DIR")"
|
|
git clone "$REPO_URL" "$TARGET_DIR"
|
|
fi
|
|
|
|
git -C "$TARGET_DIR" config pull.ff only
|
|
|
|
step "Installing helper command"
|
|
mkdir -p "$COMMAND_DIR"
|
|
cat > "$COMMAND_PATH" <<EOF
|
|
#!/usr/bin/env sh
|
|
set -eu
|
|
|
|
REPO_DIR="$TARGET_DIR"
|
|
|
|
usage() {
|
|
cat <<USAGE
|
|
rta-mock-docs - helper for the RTA mock docs projection repo
|
|
|
|
Commands:
|
|
open print the repo path
|
|
pull pull latest Markdown with --ff-only
|
|
status show Git status
|
|
commit commit all current changes with MESSAGE
|
|
push push current branch
|
|
help show this help
|
|
|
|
Examples:
|
|
rta-mock-docs pull
|
|
rta-mock-docs status
|
|
MESSAGE="Update concept notes" rta-mock-docs commit
|
|
rta-mock-docs push
|
|
|
|
AFFiNE is read-only for this repo. Durable edits happen in Markdown, then the
|
|
projection operator pulls and projects.
|
|
USAGE
|
|
}
|
|
|
|
case "\${1:-help}" in
|
|
open)
|
|
printf "%s\n" "\$REPO_DIR"
|
|
;;
|
|
pull)
|
|
git -C "\$REPO_DIR" pull --ff-only
|
|
;;
|
|
status)
|
|
git -C "\$REPO_DIR" status --short --branch
|
|
;;
|
|
commit)
|
|
: "\${MESSAGE:?Set MESSAGE before running commit}"
|
|
git -C "\$REPO_DIR" add .
|
|
git -C "\$REPO_DIR" commit -m "\$MESSAGE"
|
|
;;
|
|
push)
|
|
git -C "\$REPO_DIR" push
|
|
;;
|
|
help|--help|-h)
|
|
usage
|
|
;;
|
|
*)
|
|
usage >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
EOF
|
|
chmod +x "$COMMAND_PATH"
|
|
|
|
cat <<EOF
|
|
Ready.
|
|
|
|
Repo: $TARGET_DIR
|
|
Remote: $REPO_URL
|
|
Helper: $COMMAND_PATH
|
|
|
|
Daily flow:
|
|
$COMMAND_NAME pull
|
|
# edit Markdown
|
|
$COMMAND_NAME status
|
|
MESSAGE="Update docs" $COMMAND_NAME commit
|
|
$COMMAND_NAME push
|
|
|
|
AFFiNE updates after the projection operator pulls and runs projection.
|
|
|
|
If $COMMAND_DIR is not on PATH, add this to your shell profile:
|
|
export PATH="$COMMAND_DIR:\$PATH"
|
|
EOF
|