aboutsummaryrefslogtreecommitdiff
path: root/paludis/syncers/dosvn.in
blob: 9210e1c388bbacf715dc0827e952c25faf08827d (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash

source "${PALUDIS_EBUILD_DIR}/echo_functions.bash"

old_set=$-
set -a
for f in ${PALUDIS_BASHRC_FILES}; do
    [[ -f "${f}" ]] && source "${f}"
done
[[ "${old_set}" == *a* ]] || set +a

LOCAL=
REMOTE=

SVN_CHECKOUT_OPTIONS=( )

while [[ $# -gt 0 ]]; do
    case "${1}" in

        --svn-checkout-option=*)
            SVN_CHECKOUT_OPTIONS[${#SVN_CHECKOUT_OPTIONS[@]}]="${1#*=}"
            ;;

        --help)
            PROTO="${0##*/do}"
            if [[ "${PROTO}" == svn ]]; then
                echo "    URL syntax: svn://[USERNAME@]SERVER/PATH"
            elif [[ "${PROTO}" == svn+ssh ]]; then
                echo "    URL syntax: svn+ssh://[USERNAME[:PASSWORD]@]SERVER:/PATH"
            elif [[ "${PROTO}" == svn+http || "${PROTO}" == svn+https ]]; then
                echo "    URL syntax: ${PROTO}://[USERNAME[:PASSWORD]@]SERVER[:PORT]/PATH"
            elif [[ "${PROTO}" == svn+file ]]; then
                echo "    URL syntax: svn+file:///PATH"
            else
                ewarn "URL syntax for ${PROTO} is unknown.  This script will likely not work with the ${PROTO} protocol"
            fi
            echo "    Options:"
            echo "        --svn-checkout-option=OPTION    Pass OPTION to svn checkout"
            exit 0
            ;;

        --*)
            ewarn "${0}: unknown option '${1%%=*}'"
            ;;

        *)
            if [[ -z "${LOCAL}" ]]; then
                LOCAL="${1}"
            elif [[ -z "${REMOTE}" ]]; then
                REMOTE="${1}"
            else
                eerror "${0}: extra argument '${1}'"
                exit 1
            fi
            ;;

    esac
    shift
done

if [[ -z "${LOCAL}" ]]; then
    eerror "${0}: unspecified local repository directory"
    exit 1
elif [[ -z "${REMOTE}" ]]; then
    eerror "${0}: unspecified remote repository URL"
    exit 1
fi

[[ "${REMOTE}" == svn+http* || "${REMOTE}" == svn+file://* ]] && REMOTE="${REMOTE#svn+}"

if [[ -d "${LOCAL}/.svn" ]]; then
    cd "${LOCAL}"
    OLD_REMOTE="$(${SVN_WRAPPER} svn info | sed -ne 's/^URL: //p')"
    if [[ "${OLD_REMOTE}" != "${REMOTE}" ]]; then
        if ! ${SVN_WRAPPER} svn switch --relocate "${OLD_REMOTE}" "${REMOTE}" &&
            ! ${SVN_WRAPPER} svn switch "${REMOTE}"; then
            eerror "${0}: could not switch from '${OLD_REMOTE}' to '${REMOTE}'"
            exit 1
        fi
    fi
    cd - >/dev/null
fi

${SVN_WRAPPER} svn checkout "${SVN_CHECKOUT_OPTIONS[@]}" "${REMOTE}" "${LOCAL}/"