SERVER=
TO_CLONE=()
TO_FETCH=()
+MIRROR_CONFIG_FILENAME=".mirror.conf"
+BRANCH="master"
+
+clone_repos() {
+ local name
+ for repo in "${TO_CLONE[@]}"; do
+ name="$(basename "$repo")"
+ "$GIT" clone --mirror "$repo" "$name" > /dev/null 2>&1
+ (cd "$name" && "$GIT" update-server-info)
+ extract_files "$name"
+ done
+
+ log_info "cloned ${#TO_CLONE[@]} repos"
+}
detect_git() {
log_info "detecting git"
fi
}
+extract_files() {
+ local config_files
+ local contents
+
+ readarray -t config_files < <(cd "$1" && get_file_contents "$MIRROR_CONFIG_FILENAME")
+
+ for name in "${config_files[@]}"; do
+ if [[ -n "$name" ]]; then
+ contents="$(cd "$1" && get_file_contents "$name")"
+ (cd "$1" && echo "$contents" > "$name")
+ log_info "extracted $name from $1"
+ fi
+ done
+}
+
fetch_repos() {
local name
for repo in "${TO_FETCH[@]}"; do
name="$(basename "$repo")"
(cd "$name" && "$GIT" fetch --prune --prune-tags && git update-server-info) > /dev/null 2>&1
+ extract_files "$name"
done
log_info "fetched ${#TO_FETCH[@]} repos"
}
+get_file_contents() {
+ local contents
+ local content_hash
+
+ content_hash="$("$GIT" ls-tree --object-only "$BRANCH" -- "$1")"
+
+ if [[ -z "$content_hash" ]]; then
+ echo ""
+ else
+ contents="$("$GIT" cat-file blob "$content_hash")"
+ echo "$contents"
+ fi
+}
+
find_local_directories() {
local repos
done
}
-clone_repos() {
- local name
- for repo in "${TO_CLONE[@]}"; do
- name="$(basename "$repo")"
- "$GIT" clone --mirror "$repo" "$name" > /dev/null 2>&1
- echo "$name" > "$name/description"
- (cd "$name" && "$GIT" update-server-info)
- done
-
- log_info "cloned ${#TO_CLONE[@]} repos"
-}
-
log() {
if [[ "$LOG_LEVEL" != "error" ]]; then
echo -e "$@"
RESULT=$(<result)
assert "$EXPECTED" "$RESULT"
-assert "$(<repo3/description)" "repo3"
-
assert "$(cd repo3 && git rev-parse HEAD)" "$(cd ../repos/repo1 && git rev-parse HEAD)"
cd ..
--- /dev/null
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+# this command will fail if not executed in test/ directory
+source setup.sh
+
+setup_env
+
+TO_CLONE+=("../repos/repo3")
+LOG_LEVEL=info
+
+cd repos/repo1
+echo -e "description\ncloneurl\n" > .mirror.conf
+git add .mirror.conf > /dev/null 2>&1
+git commit -m ... > /dev/null 2>&1
+(cd ../repo3 && git fetch > /dev/null 2>&1)
+
+cd ../../mirrors
+clone_repos > result 2>&1
+EXPECTED=$'extracted description from repo3\n'
+EXPECTED+=$'extracted cloneurl from repo3\n'
+EXPECTED+=$'cloned 1 repos'
+RESULT=$(<result)
+assert "$EXPECTED" "$RESULT"
+
+assert "$(<repo3/description)" ""
+assert "$(<repo3/cloneurl)" ""
+
+cd ../repos/repo1
+
+DESCRIPTION="thisisadescription"
+CLONEURL="cloneualsief"
+
+echo "$DESCRIPTION" > description
+echo "$CLONEURL" > cloneurl
+git add description cloneurl > /dev/null 2>&1
+git commit -m ... > /dev/null 2>&1
+(cd ../repo3 && git fetch > /dev/null 2>&1)
+
+cd ../../mirrors
+
+TO_FETCH+=("../repos/repo3")
+fetch_repos > result 2>&1
+EXPECTED=$'extracted description from repo3\n'
+EXPECTED+=$'extracted cloneurl from repo3\n'
+EXPECTED+=$'fetched 1 repos'
+RESULT=$(<result)
+assert "$EXPECTED" "$RESULT"
+
+assert "$(<repo3/description)" "$DESCRIPTION"
+assert "$(<repo3/cloneurl)" "$CLONEURL"
+
+cd ..
+
+test_succeeded