jean-cloud-services/provisioning/roles/deploy_all/files/bin/git_update.sh

51 lines
1011 B
Bash
Raw Normal View History

2023-08-28 18:25:32 +00:00
#!/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
2023-09-07 17:50:05 +00:00
2023-08-28 18:25:32 +00:00
# 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
2023-09-07 17:50:05 +00:00
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
2023-08-28 18:25:32 +00:00
else
2023-09-07 17:50:05 +00:00
git clone -b "$branch" --single-branch --recurse-submodules --shallow-submodules --depth 1 --config core.sshCommand="$ssh_opt" "$repo" .
2023-08-28 18:25:32 +00:00
fi