summaryrefslogtreecommitdiff
path: root/contrib/scripts/git-subtree-reimport.sh
blob: 733190444d2c6d15115e0b7b539561e008187a14 (plain)
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
#!/bin/bash

# In our git repository we vendor in several external projects.
# We do so via git-subtree.
#
# Run this script (without arguments) for re-importing the latest
# version of those projects.
#
# You can also specify the projects to reimport on the command line,
# ./contrib/scripts/git-subtree-reimport.sh  [ c-list | c-rbtree | c-siphash | c-stdaux | n-acd | n-dhcp4 ... ]

set -e

cd "$(dirname "$(readlink -f "$0")")/../.."

reimport() {
    local d="$1"
    local project
    local branch

    if [[ "$d" = c-* ]] ; then
        project=c-util
        branch=main
    else
        project=nettools
        branch=master
    fi

    CMD=( git subtree pull --prefix "src/$d" "git@github.com:$project/$d.git" "$branch" --squash -m \
"$d: re-import git-subtree for 'src/$d'

  git subtree pull --prefix src/$d git@github.com:$project/$d.git $branch --squash
" )

    printf '\n>>>> %s >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n' "$d"
    printf '>>>'
    for c in "${CMD[@]}"; do
        printf ' %q' "$c"
    done
    printf '\n'

    "${CMD[@]}" 2>&1

    local REMOTE_COMMIT="$(git rev-parse FETCH_HEAD)"

    echo ">>>>> RESULT:"
    printf ">>> git diff %s: HEAD:src/%s\n" "$REMOTE_COMMIT" "$d"
    GIT_PAGER=cat git diff --color=always "$REMOTE_COMMIT:" "HEAD:src/$d"
}

reimport_all() {
    local ARGS

    ARGS=( "$@" )
    if [ "${#ARGS[@]}" = 0 ]; then
        ARGS=( c-list c-rbtree c-siphash c-stdaux n-acd n-dhcp4 )
    fi
    for d in "${ARGS[@]}" ; do
        reimport "$d"
    done
}

reimport_all "$@"