jean-cloud-services/provisioning/roles/deploy_all/files/bin/git_update.sh
2023-09-07 19:50:05 +02:00

51 lines
1011 B
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
declare -A usage
declare -A varia
summary="$0 [options] <repo>"
usage[b]="Branch of git repo"
varia[b]=branch
branch=master
usage[d]="Destination of clone"
varia[d]=dst
dst='.'
usage[i]="privkey used to ssh pull"
varia[i]=privkey
privkey=''
. driglibash-args
# Some SSH options
ssh_opt='ssh'
if [ -n "$privkey" ] ; then
ssh_opt="$ssh_opt -i $privkey"
fi
repo="$1"
if [ -z "$repo" ] ; then
die "$0: Empty repo given\n$summary"
fi
cd "$dst"
if [ -d .git ] ; then
git fetch origin "$branch"
git checkout --force -B "$branch" "origin/$branch"
git reset --hard
git clean -qffdx
git submodule update --init --recursive --force --recommend-shallow
git submodule foreach git fetch
git submodule foreach git checkout --force -B "$branch" "origin/$branch"
git submodule foreach git reset --hard
git submodule foreach git clean -fdx
else
git clone -b "$branch" --single-branch --recurse-submodules --shallow-submodules --depth 1 --config core.sshCommand="$ssh_opt" "$repo" .
fi