~miconoco/woo

woo/cmd/boot -rw-r--r-- 1.5 KiB
0b1818b1Christoph Polcin build 3 months ago
                                                                                
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
#!/bin/sh
# boot . | URL-SUPER-PROJECT.GIT [REF]
#   Bootstraps a project into the workspace.

_boot() { # .|WOO-SUPER.GIT [REF] {{{
    _repo="${1:?no woo-super-project.git}"
    _ref="${2:-master}"
    [ "${_repo}" = "." ] && _bare="woo-${PWD##*/}" || _bare="${_repo##*:}"
    _bare="${_bare%.git}"
    _bare=".git-${_bare##*/}"

    [ ! -e "${WOOWS}/${_bare}" ] && {
        git init --separate-git-dir="${WOOWS}/${_bare}" -- "${WOOWS}"
        if [ "${_repo}" != "." ]
        then
            git -C "${WOOWS}" remote add origin "${_repo}"
            git -C "${WOOWS}" fetch
            _br="$(git -C "${WOOWS}" branch -a --contains "${_ref}" 2>/dev/null || :)"
            if [ -n "${_br}" ]
            then
                git -C "${WOOWS}" checkout -f --track "${_br#*remotes/}"
                git -C "${WOOWS}" reset --hard "${_ref}"
            else
                git -C "${WOOWS}" checkout -f --track "origin/${_ref}"
            fi
        fi
        [ ! -e "${WOOWS}/.git" ] && printf "gitdir: %s" "./${_bare}" > "${WOOWS}/.git"
        git -C "${WOOWS}" config status.showUntrackedFiles no
    }

    [ -e "${MANIFEST}" ] && _clone

    if ! grep "/${_bare}" "${WOOWS}/.gitignore" >/dev/null 2>&1
    then
        printf "/%s\n" "${_bare}" >> "${WOOWS}/.gitignore"
    fi

    [ ! -e "${WOOWS}/bin/woo" ] && {
        mkdir -p "${WOOWS}/bin"
        cp "$(which "$0")" "${WOOWS}/bin/woo"
    }

    [ ! -e "${WOOWS}/activate" ] && _activate > "${WOOWS}/activate"

} # }}}