aboutsummaryrefslogtreecommitdiffstats
path: root/git-request-get
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2023-11-18 19:29:41 +0100
committerMatěj Cepl <mcepl@cepl.eu>2024-03-01 00:22:50 +0100
commit9c93d38f9d8e07ea01d2ee007c3c3f62156cbe6f (patch)
tree581f0bf4f4b699e352242259a33bfaeeb846f810 /git-request-get
parentf159bc8c57d3f2e604b3feaac89dc39cf2bff3f7 (diff)
downloadhlupak-9c93d38f9d8e07ea01d2ee007c3c3f62156cbe6f.tar.gz
fix(git-request-get): The first draft, more or less complete and more or less useful.
Fixes: https://todo.sr.ht/~mcepl/devel/19
Diffstat (limited to 'git-request-get')
-rwxr-xr-xgit-request-get41
1 files changed, 36 insertions, 5 deletions
diff --git a/git-request-get b/git-request-get
index c5d3c3d..2ba5ec4 100755
--- a/git-request-get
+++ b/git-request-get
@@ -1,10 +1,41 @@
#!/bin/bash
-set -eux
+set -eu
+
+if [ $# -lt 1 ] ; then
+STR="$(cat)"
+else
+echo "No options yet!"
+exit 1
+fi
# 1. Collect URL of the incoming repo
-# 2. Check it is in our remotes
-# 3. If it isn't, add it
-# 4. Fetch the remote
-# 5. Create new branch
+URL="$(echo "$STR" | sed -n -e '/^are available in the Git repository at:/,+2 {
+s/[[:space:]]\+//
+s/\(=[[:digit:]]\{2\}\)\+$//
+/^\(http\|git\)/p
+}')"
+# mapfile -t -c 1 -C 'cb() { [[ "$2" =~ (git|http|ssh):// ]] && printf "%s\n" "$2"; }; cb' URLS <<<"$STR"
+# echo "$URLS[@]"
+# 2. Check it is in our remotes
mapfile REMOTES < <(git remote -v|awk '{print $1,$2;}')
+REMOTE=''
+for rem in "${REMOTES[@]}" ; do
+ if [[ ${rem} =~ $URL ]] ; then
+ REMOTE="$(echo "${rem}" | awk -F ' ' '{print $1;}' )"
+ break
+ fi
+done
+
+# 4. Create new branch
+BEG="$(echo "$STR" | awk '/^The following changes since commit / { print $NF }' | sed -e 's/[=:]*$//')"
+END="$(echo "$STR" | awk '/^for you to fetch changes up to / { print $NF }' | sed -e 's/[=:]*$//')"
+
+# 5. Fetch the remote
+if [[ -n "$REMOTE" ]] ; then
+ git fetch $REMOTE $END
+else
+ git fetch $URL $END
+fi
+
+git checkout -b _4review FETCH_HEAD