aboutsummaryrefslogtreecommitdiffstats
path: root/git-devproj.sh
blob: ff3740d841c9615d0fafe4dededae18e162c7fe7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
# Requires: coreutils, curl, jq, git
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
}

[ "$#" -lt 2 ] && exit 1

if [ "$1" = "openSUSE:Factory" ] ; then
    OUT=$(osc develproject "$1" "$2")
    DEVPRJ="$(dirname "$OUT")"
    PKG="$(basename "$OUT")"
else
    DEVPRJ="$1"
    PKG="$2"
fi

OBS_LOGIN="$(osc who |cut -d: -f 1)"

HOME_BRANCH="home:$OBS_LOGIN:branches:$DEVPRJ"

osc meta prj -e "$HOME_BRANCH"
osc co "$HOME_BRANCH"
cd "$HOME_BRANCH"

osc meta prjconf "$DEVPRJ" |osc meta prjconf -F - "$HOME_BRANCH"

osc checkout -c "$DEVPRJ" "$PKG"
######################################
# osc co "$DEVPRJ" "$PKG"
# cd "$DEVPRJ/$PKG"
# 
# # 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="$(tea logins ls -o simple|head -n 1|cut -d ' ' -f 4)"
# # Do we have our own configuration for MYORG?
# MYORG="$(git config --get -default '' obs.org)"
# if [ -z "${MYORG}" ] ; then
#     MYORG="${LOGIN}"
# fi
# 
# 
# # 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)')"
# 
# if [ -n "$FORKS" ] ; then
#     # shellcheck disable=SC2086
#     MY_FORK="$(echo "$FRK_OUT" | jq -r ".[].full_name | select(startswith(\""$MYORG/"\"))")"
# else
#     MY_FORK=""
# fi
# 
# # If not, make a fork
# if [ -z "$MY_FORK" ] ; then
#     if [ "$MYORG" = "$LOGIN" ] ; then
#         FRK_OUT="$(gitea_cmd "repos/pool/$PKG/forks" "-X POST")"
#     else
#         # shellcheck disable=SC2086
#         FRK_OUT="$(echo '{ "organization": "'$MYORG'" }' \
#             | gitea_cmd "repos/pool/$PKG/forks" "-d @-")"
#     fi
#     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 config
# git config "lfs.$(git remote get-url myproj)/info/lfs.locksverify" true
# # Switch to factory branch, obs_state is just a record of the old state
# git checkout --force -B factory myproj/factory
# 
# # # 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 this is considered a bad idea
# # (https://stackoverflow.com/a/1732454/164233) we can use
# # xmlstarlet instead.
# if ! grep '<scmsync>' "$OSC_META" >/dev/null 2>&1 ; then
#     sed -e "/<\/package>/i\ \ <scmsync>https://src.opensuse.org/pool/$PKG#factory<\/scmsync>" \
#         "$OSC_META" | osc meta pkg "$DEVPRJ" "$PKG" -F -
# fi