50 lines
750 B
Bash
Executable File
50 lines
750 B
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Just mirror (clone or fetch) specified git repository
|
|
# - no other mess (eg submodules, just clean mirror)
|
|
#
|
|
# Usage:
|
|
# mirror-main-repo <url>
|
|
|
|
|
|
# Unofficial strict mode
|
|
set -euo pipefail
|
|
IFS=$'\n\t'
|
|
|
|
source $(dirname $(realpath $0))/gen-mirror-path
|
|
|
|
|
|
function updateOrCreate(){
|
|
url=$1
|
|
repodir=$(getRepoPath $url)
|
|
|
|
if [ ! -d $repodir ]
|
|
then
|
|
echo "Clone of $url"
|
|
git clone --bare --mirror $url $repodir
|
|
else
|
|
cd $repodir
|
|
echo "Update of $url"
|
|
git fetch --prune
|
|
fi
|
|
|
|
# tags
|
|
}
|
|
|
|
function getLastCommit(){
|
|
url=$1
|
|
repodir=$(getRepoPath $url)
|
|
if [ -d $repodir ]
|
|
then
|
|
cd $repodir
|
|
git --no-pager log --full-history --all -1 --pretty=format:"%H%n"
|
|
else
|
|
echo '-'
|
|
fi
|
|
|
|
}
|
|
|
|
oldPwd=$(pwd)
|
|
updateOrCreate $1
|
|
cd $oldPwd
|