summaryrefslogtreecommitdiff
path: root/deps/acore/bash-lib/src/git-utils/subrepo.sh
blob: e0d36d9a820ddd24e3c2e8e00532cd0aa134cf2e (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
#!/usr/bin/env bash



CUR_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/"

echo "> Init and updating submodules..."

function subrepoUpdate() {
    repo=$1
    branch=$2
    folder=$3

    toClone=$(git ls-remote --heads "$repo" "$branch" | wc -l)

    if [[ -d "$folder" ]]; then
        if [[ ! -f "$folder/.gitrepo" ]]; then
            git subrepo init "$folder" -r "$repo" -b "$branch"
        fi

        if [[ $toClone -eq 0 ]]; then
            git subrepo push "$folder"
        fi
    else
        # try-catch
        set +e
        git subrepo clone "$repo" "$folder" -b "$branch"
        set -e
    fi

    git subrepo clean "$folder"
    git subrepo pull "$folder"
    git subrepo push "$folder" -s
    git subrepo clean "$folder"
}