From 6208964ad32a7f36e03d8d14d969642255524566 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 15 Dec 2016 18:23:32 -0500 Subject: fix --- git-mirror | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'git-mirror') diff --git a/git-mirror b/git-mirror index 113379a..6fc6ebb 100755 --- a/git-mirror +++ b/git-mirror @@ -1,12 +1,10 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright © 2014, 2016 Luke Shumaker # # This work is free. You can redistribute it and/or modify it under the # terms of the Do What The Fuck You Want To Public License, Version 2, # as published by Sam Hocevar. See the COPYING file for more details. -# Depends 4.4+, as it uses the '-d' flag to 'mapfile'. -# # Depends on the 'gitget' and 'libremessages' commands. On Parabola # GNU/Linux-libre, those are the 'gitget' and 'librelib' packages, # respectively. @@ -67,13 +65,14 @@ download() { local remote=${_remote%%#*} local params=(${_remote#"$remote"}) + msg 'Downloading %s <- %s' "$repo" "${remote%%#*}" + # download the repository local url - url="$(remote "$remote" pull-url)" gitget -f -n "$repo" bare "$url" "$local" + # download the metadata - msg2 "Fetching metadata for repo '%s'" "$repo" get-meta "$remote" > "$local/git-mirror.tmp" git config --file "$local/config" --rename-section git-mirror git-mirror-bak 2>/dev/null || true local IFS='=' @@ -90,16 +89,19 @@ upload() ( local local=$2 local remote=$3 + msg 'Uploading %s -> %s' "$repo" "${remote%%#*}" + # push metadata - msg2 "Pushing metadata for repo '%s'" "$repo" local meta - mapfile -d '' meta < <(git config --file "$local/config" -z --get-regexp '^git-mirror[.]'|sed -z 's/ /=/') + mapfile meta < <(git config --file "$local/config" --list|sed -n 's/^git-mirror[.]//p') + meta=("${meta[@]%$'\n'}") set-meta "$remote" "${meta[@]}" + # push repository - msg2 "Pushing repo '%s'" "repo" local repo_mode repo_mode=$(remote "$remote" repo-mode) if [[ $repo_mode == passive ]]; then + msg2 "Pushing repo %s" "$repo" local push_url push_url="$(remote "$remote" push-url)" cd "$local" && git push --mirror "$push_url" @@ -108,11 +110,9 @@ upload() ( get-meta() ( [[ $# = 1 ]] || panic - local _remote=$1 - - local IFS='&' - local remote=${_remote%%#*} - local params=(${_remote#"$remote"}) + local IFS remote _params params + IFS='#' read remote _params <<<"$1" + IFS='&' read -a params <<<"$_params" remote "$remote" get-meta [[ ${#params[@]} = 0 ]] || printf '%s\n' "${params[@]}" @@ -120,13 +120,11 @@ get-meta() ( set-meta() { [[ $# -ge 1 ]] || panic - local _remote=$1 + local IFS remote _params params + IFS='#' read remote _params <<<"$1" + IFS='&' read -a params <<<"$_params" local args=("${@:2}") - local IFS='&' - local remote=${_remote%%#*} - local params=(${_remote#"$remote"}) - remote "$remote" set-meta "${args[@]}" "${params[@]}" } -- cgit v1.2.3