Skip to content

Commit

Permalink
feat(git-deploy): use remote ghq.root
Browse files Browse the repository at this point in the history
  • Loading branch information
midchildan committed Jul 3, 2023
1 parent 9d3f1a4 commit 1c190d0
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions files/.local/bin/git-deploy
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

ENABLE_DRYRUN=
ENABLE_PREFIX=1
USE_GHQ=1

main() {
local gitref=HEAD
Expand All @@ -10,7 +10,7 @@ main() {
case "$n" in
-n|--dry-run) ENABLE_DRYRUN=1; shift ;;
-b) gitref="$2"; shift; shift ;;
-r) ENABLE_PREFIX=; shift ;;
-r) USE_GHQ=; shift ;;
-h|--help) usage ;;
*) break ;;
esac
Expand All @@ -26,17 +26,21 @@ main() {
repo_root="${repo_root/#\~/$HOME}"
local_path="$(git rev-parse --show-toplevel)"

if [[ -n "$ENABLE_PREFIX" ]]; then
if [[ -n "$USE_GHQ" ]]; then
if [[ "$remote_url" =~ :$ ]]; then
local remote_host="${remote_url%:}"
local remote_path="${local_path#$repo_root/}"
local remote_path="${local_path#"$repo_root/"}"
elif [[ "$remote_url" =~ : ]]; then
local remote_host="${remote_url%%:*}"
local remote_prefix="${remote_url#*:}"
local remote_path="${local_path/#$repo_root/$remote_prefix}"
else
local remote_host="$remote_url"
local remote_path="${local_path#$repo_root/}"
local remote_host remote_home remote_root remote_path
remote_host="$remote_url"
remote_home="$(ssh "$remote_host" 'printf "%s" "$HOME"')"
remote_root="$(ssh "$remote_host" git config --get ghq.root)"
remote_root="${remote_root/#\~/$remote_home}"
remote_path="${remote_root}${remote_root:+/}${local_path#"$repo_root/"}"
fi
else
if [[ "$remote_url" =~ : ]]; then
Expand Down

0 comments on commit 1c190d0

Please sign in to comment.