diff --git a/src/git_update.sh b/src/git_update.sh new file mode 100755 index 0000000..7781165 --- /dev/null +++ b/src/git_update.sh @@ -0,0 +1,107 @@ +#!/bin/bash + +# Clone un dépôt git au bon endroit +# Stocker un minum de données (et donc nettoyer) +# Télécharger un minimum de données +# En cas de conflit donner raison au remote (on écrase les versions locales) + + +declare -A usage +declare -A varia + +summary="$0 [options] " + +usage[b]="Branch of git repo" +varia[b]=branch +branch=master + +usage[t]="Tog of git repo" +varia[t]=tag +tag= + +usage[d]="Destination of clone" +varia[d]=dst +dst='.' + +usage[i]="privkey used to ssh pull" +varia[i]=privkey +privkey='' + +usage[N]="Clone to a Non-empty target. Existing files will be overwriten" +varia[N]=nonempty_target +nonempty_target=false + +usage[K]="Remote host key file (known_hosts) for ssh connections" +varia[K]=hostkeyfile +hostkeyfile='' + +usage[H]="Use real home dir" +varia[H]=use_home +use_home=false + + +. driglibash-args + + +# Some SSH options +ssh_opt='ssh' +if [ -n "$privkey" ] ; then + ssh_opt="$ssh_opt -i $privkey" +fi + +if [ -n "$hostkeyfile" ] ; then + ssh_opt="$ssh_opt -o 'UserKnownHostsFile $hostkeyfile'" +fi + +repo="$1" +if [ -z "$repo" ] ; then + die "$0: Empty repo given\n$summary" +fi + +if [ ! $use_home ] ; then + set -a + export HOME=/dev/null + set +a +fi + +run mkdir -p "$dst" +run cd "$dst" + + +if [ -d .git ] ; then + + # Compute git branch and tag + tagref= + if [ -n "$tag" ] ; then + tagref="tags/$tag" + fi + + run git fetch origin "$branch" --tags -f + run git checkout --force $tagref "origin/$branch" + run git reset --hard # TODO we can keep some files? + # Preserve existing files in some cases + if ! "$nonempty_target" ; then + git clean -qffdx + fi + run git submodule update --init --recursive --force --recommend-shallow + run git submodule foreach git fetch + run git submodule foreach git checkout --force HEAD + run git submodule foreach git reset --hard + run git submodule foreach git clean -fdx +else + clone_dst='.' + + # To override an existing dir, we need to clone elsewhere first + if "$nonempty_target" ; then + clone_dst="$(mktemp -d)" + fi + + run git clone -b "$branch" --single-branch --recurse-submodules --shallow-submodules --depth 1 --config core.sshCommand="$ssh_opt" "$repo" "$clone_dst" + + # To override an existing dir, we then move everything to that dir + if "$nonempty_target" ; then + run mv "$clone_dst/"{*,.*} . + run rmdir "$clone_dst" + fi +fi + diff --git a/src/pre-push b/src/pre-push new file mode 100755 index 0000000..de70fc2 --- /dev/null +++ b/src/pre-push @@ -0,0 +1,16 @@ +#!/bin/bash + +# Get package version +# TODO Add some well-known version provider mechanisms +version="" +[ -f package.json ] && version=$(npm pkg get version | tr -d '\"') +[ -f version ] && version=$(cat version) +[ -f VERSION ] && version=$(cat VERSION) + +# Create semver tags +git tag -f v${version%.*.*} +git tag -f v${version%.*} +git tag -f v$version + +# Push the tags +git push --no-verify --tags -f