]> git.phdru.name Git - git-scripts.git/commitdiff
Add a script to resolve rewritten URL
authorOleg Broytman <phd@phdru.name>
Wed, 29 Nov 2023 15:18:03 +0000 (18:18 +0300)
committerOleg Broytman <phd@phdru.name>
Wed, 29 Nov 2023 15:20:18 +0000 (18:20 +0300)
git-resolve-remote [new file with mode: 0755]

diff --git a/git-resolve-remote b/git-resolve-remote
new file mode 100755 (executable)
index 0000000..4c76cf6
--- /dev/null
@@ -0,0 +1,24 @@
+#! /bin/sh
+# See https://stackoverflow.com/q/77560684/7976758
+
+# Uses a transient repository so it's not effective to resolve many URLs.
+# For many URLs create one repository, add remotes,
+# get rewritten URLs and then remove the repository.
+
+set -e
+
+if [ $# -ne 1 ]; then
+    echo "Usage $0 URL" >&2
+    exit 1
+fi
+
+cd /tmp
+rm -rf _git_resolve_remote.tmp
+git init --quiet _git_resolve_remote.tmp
+cd _git_resolve_remote.tmp
+
+git remote add origin "$1"
+git remote get-url origin
+
+cd ..
+exec rm -rf _git_resolve_remote.tmp