1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
From: =?UTF-8?q?Samo=20Poga=C4=8Dnik?= <samo_pogacnik@t-2.net>
Date: Sat, 19 Oct 2024 19:11:41 +0200
Forwarded: https://github.com/ingydotnet/git-subrepo/pull/639
Subject: Generate test git-repos instead of committed binaries
Instead of having test repos: foo, bar and init committed in a
binary form, generate them using the test/gen* scripts before
starting the first 'test' session. Running 'make clean' removes
the generated test repos.
The original 'binary' test repos are being handled via d/rules
while still existing upstrem.
---
Makefile | 2 +-
test/genbar | 31 +++++++++++++++++++++++++++
test/genfoo | 26 +++++++++++++++++++++++
test/geninit | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++
test/setup | 12 +++++++++++
5 files changed, 130 insertions(+), 1 deletion(-)
create mode 100755 test/genbar
create mode 100755 test/genfoo
create mode 100755 test/geninit
diff --git a/Makefile b/Makefile
index 7521bc6..7a930e1 100644
--- a/Makefile
+++ b/Makefile
@@ -110,7 +110,7 @@ compgen: force
$(SHARE)/zsh-completion/_git-subrepo
clean:
- rm -fr tmp test/tmp .gitconfig
+ rm -fr tmp test/tmp test/repo .gitconfig
define docker-make-test
docker run --rm \
diff --git a/test/genbar b/test/genbar
new file mode 100755
index 0000000..9d3a276
--- /dev/null
+++ b/test/genbar
@@ -0,0 +1,31 @@
+#!/bin/bash
+set -xe
+
+if [ -z "${1}" ]; then
+ echo "${BASH_SOURCE[0]}: Single argument required (common test repos path)"
+ exit 1
+fi
+
+REPO="bar"
+NAME="Bar"
+TARGET="${1}/$REPO"
+TMPREPO="${1}/tmp/$REPO"
+
+rm -rf "$TMPREPO"
+mkdir -p "$TMPREPO"
+cd "$TMPREPO"
+git init --initial-branch=master .
+git config user.name "${NAME}User"
+git config user.email "${REPO}@${REPO}"
+touch $NAME
+git add $NAME
+git commit -m"$NAME"
+git tag A -m"$NAME"
+mkdir -p bard
+touch bard/Bard
+git add bard
+git commit -m"bard/Bard"
+git config --bool core.bare true
+cd -
+mkdir -p "$1"
+mv "$TMPREPO/.git" "$TARGET"
diff --git a/test/genfoo b/test/genfoo
new file mode 100755
index 0000000..a9b9167
--- /dev/null
+++ b/test/genfoo
@@ -0,0 +1,26 @@
+#!/bin/bash
+set -xe
+
+if [ -z "${1}" ]; then
+ echo "${BASH_SOURCE[0]}: Single argument required (common test repos path)"
+ exit 1
+fi
+
+REPO="foo"
+NAME="Foo"
+TARGET="${1}/$REPO"
+TMPREPO="${1}/tmp/$REPO"
+
+rm -rf "$TMPREPO"
+mkdir -p "$TMPREPO"
+cd "$TMPREPO"
+git init --initial-branch=master .
+git config user.name "${NAME}User"
+git config user.email "${REPO}@${REPO}"
+touch $NAME
+git add $NAME
+git commit -m"$NAME"
+git config --bool core.bare true
+cd -
+mkdir -p "$1"
+mv "${TMPREPO}/.git" "$TARGET"
diff --git a/test/geninit b/test/geninit
new file mode 100755
index 0000000..b70f9f1
--- /dev/null
+++ b/test/geninit
@@ -0,0 +1,60 @@
+#!/bin/bash
+set -xe
+
+if [ -z "${1}" ]; then
+ echo "${BASH_SOURCE[0]}: Single argument required (common test repos path)"
+ exit 1
+fi
+
+REPO="init"
+NAME="Init"
+TARGET="${1}/$REPO"
+TMPREPO="${1}/tmp/$REPO"
+
+rm -rf "$TMPREPO"
+mkdir -p "$TMPREPO"
+cd "$TMPREPO"
+git init --initial-branch=master .
+git config user.name "${NAME}User"
+git config user.email "${REPO}@${REPO}"
+cat <<EOF > ReadMe
+This is a repo to test \`git subrepo init\`.
+
+We will make a short history with a subdir, then we can turn that subdir into a
+subrepo.
+EOF
+git add ReadMe
+git commit -m"Initial commit"
+mkdir -p doc
+cat <<EOF > doc/init.swim
+== Subrepo Init!
+
+This is a file to test the \`git subrepo init\` command.
+EOF
+git add doc
+git commit -m"Add a file in a subdir."
+cat <<EOF >> ReadMe
+
+This repo will go in the git-subrepo test suite.
+EOF
+git add ReadMe
+git commit -m"Add a commit to the mainline."
+cat <<EOF >> doc/init.swim
+
+It lives under the doc directory which will become a subrepo.
+EOF
+git add doc/init.swim
+git commit -m"Add a commit to the subdir."
+cat <<EOF >> ReadMe
+
+EOF
+git add ReadMe
+cat <<EOF >> doc/init.swim
+
+EOF
+git add doc/init.swim
+git commit -m"Add a commit that affects both."
+git config --bool core.bare true
+cd -
+mkdir -p "$1"
+mv "${TMPREPO}/.git" "$TARGET"
diff --git a/test/setup b/test/setup
index ab945f3..baea72d 100644
--- a/test/setup
+++ b/test/setup
@@ -14,6 +14,18 @@ export XDG_CONFIG_HOME=$PWD
export HOME=$PWD
export GIT_CONFIG_NOSYSTEM=1
+# Generate additional testing git repos, if not already present.
+mkdir -p "${SCRIPT_DIR}/repo"
+if [ ! -d "${SCRIPT_DIR}/repo/bar" ]; then
+ "${SCRIPT_DIR}/genbar" "${SCRIPT_DIR}/repo"
+fi
+if [ ! -d "${SCRIPT_DIR}/repo/foo" ]; then
+ "${SCRIPT_DIR}/genfoo" "${SCRIPT_DIR}/repo"
+fi
+if [ ! -d "${SCRIPT_DIR}/repo/init" ]; then
+ "${SCRIPT_DIR}/geninit" "${SCRIPT_DIR}/repo"
+fi
+
BASHLIB=$(
find "$PWD"/ -type d -name bin -o -type d -name lib | grep -v "\/\.pc\/" | tr '\n' ':'
)
|