diff options
-rwxr-xr-x | git-obranch | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/git-obranch b/git-obranch index 5c30553..49920b2 100755 --- a/git-obranch +++ b/git-obranch @@ -1,11 +1,12 @@ -#!/bin/sh +#!/bin/bash # Requires: coreutils, curl, jq, git -set -ue +set -uex API_KEY="$(cat "$(dirname "$(readlink -f "$0")")"/gitea-api-token.txt)" gitea_cmd () { ADD_PARAMS=${2:-} + # shellcheck disable=SC2048,SC2086 curl -s -H 'accept: application/json' -H 'Content-Type: application/json' \ -H "Authorization: token $API_KEY" ${ADD_PARAMS[*]} \ "https://src.opensuse.org/api/v1/$1" 2>/dev/null @@ -22,20 +23,27 @@ else PKG="$2" fi -# osc co should not finish with exit 1 -osc co -u -c "$DEVPRJ" "$PKG" || /bin/true -cd "$PKG" +osc co "$DEVPRJ" "$PKG" +cd "$DEVPRJ/$PKG" -# Fork +# Init git? +if ! git rev-parse --git-dir >/dev/null 2>&1 ; then + git init -q -b obs_state + git add -A . && git rm --cached -r .osc/ && git commit -m 'OBS last state' + git remote add origin "https://src.opensuse.org/pool/$PKG.git" +fi + +# # Fork # Whoami? LOGIN="$(gitea_cmd "user" | jq -r '.login')" # Check whether the fork already exists FRK_OUT="$(gitea_cmd "repos/pool/$PKG/forks")" -FORKS="$(echo $FRK_OUT | jq -r '.[].full_name | select(startswith("rpm/") | not)')" +FORKS="$(echo "$FRK_OUT" | jq -r '.[].full_name | select(startswith("rpm/") | not)')" if [ -n "$FORKS" ] ; then - MY_FORK="$(echo $FRK_OUT | jq -r ".[].full_name | select(startswith("$LOGIN/"))")" + # shellcheck disable=SC2086 + MY_FORK="$(echo "$FRK_OUT" | jq -r ".[].full_name | select(startswith(\""$LOGIN/"\"))")" else MY_FORK="" fi @@ -46,10 +54,24 @@ if [ -z "$MY_FORK" ] ; then MY_FORK="$(echo "$FRK_OUT" | jq -r '.full_name')" fi +# Set URLs for the forked repository +git remote add myproj "https://src.opensuse.org/$MY_FORK.git" +git remote set-url --push myproj "gitea@src.opensuse.org:$MY_FORK.git" +git remote update + +# # Final cleanup # Add ignore echo '.osc/' >> .git/info/exclude echo '_scmsync.obsinfo' >> .git/info/exclude -# Set URLs for the forked repository -git remote add myproj "https://src.opensuse.org/$MY_FORK.git" -git remote set-url --push myproj "gitea@src.opensuse.org:$MY_FORK.git" +# # SCM Sync settings +OSC_META=$(mktemp /tmp/osc_meta_data.XXXXXX.xml) +trap 'rm -f $OSC_META' EXIT + +osc meta pkg "$DEVPRJ" "$PKG" >"$OSC_META" 2>/dev/null + +if ! grep '<scmsync>' "$OSC_META" >/dev/null 2>&1 ; then + sed -e "/<description>/a\ \ <scmsync>$(git remote get-url myproj)<\/scmsync>" \ + "$OSC_META" | osc meta pkg "$DEVPRJ" "$PKG" -F - +fi + |