utils/index-repository: support calling on existing repository
Make utils/index-repository idempotent, meaning we can call it multiple times on the same repo and same remotes without issues. Also allow adding new remotes to an existing repo. Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
This commit is contained in:
parent
a34a6c692a
commit
9d90b07201
1 changed files with 14 additions and 1 deletions
|
|
@ -14,13 +14,26 @@ mkdir -p $dir/data $dir/repo
|
|||
|
||||
git="git -C $dir/repo"
|
||||
|
||||
# This doesn't fail if repo already exists
|
||||
$git init --bare
|
||||
|
||||
git config --system --add safe.directory $dir/repo
|
||||
|
||||
existing_remotes="$($git remote | xargs -L1 -r $git remote get-url | sort -u)"
|
||||
|
||||
shift
|
||||
i=0
|
||||
i="$($git remote | awk '
|
||||
BEGIN { n=-1; }
|
||||
$0 ~ /^remote[0-9]+$/ { i=substr($0, length("remote")+1);
|
||||
if (i>n) n=i; }
|
||||
END { print n+1; }')"
|
||||
for remote
|
||||
do
|
||||
# Don't `git remote add` remotes that already exist, which is not an error.
|
||||
if echo "$existing_remotes" | grep -qF "$remote"; then
|
||||
continue;
|
||||
fi
|
||||
|
||||
$git remote add remote$i $remote
|
||||
i=$(($i+1))
|
||||
done
|
||||
|
|
|
|||
Loading…
Reference in a new issue