Skip to content

Commit f2e2d06

Browse files
authored
gh-6 : add add-as-submodule function (#33)
- New Features: Added git-artifact command "add-as-submodule" to add a repo as a submodule by URL and path. CLI options: -d/--debug and -t/--testcase to enable debug mode and run a single test. - Bug Fixes: More robust tag fetching/checkout and safer command argument handling. Documentation - Tests: Modernized test runner with dynamic discovery, per-test logs under a centralized root, per-test failure handling, consolidated summary, and a new end-to-end submodule test. - Updated help/usage to include the new command and options.
1 parent eb2c48d commit f2e2d06

3 files changed

Lines changed: 147 additions & 55 deletions

File tree

.test/10/git-reference.log

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
* (HEAD -> main, origin/main) Added submodule repo
2+
| * (tag: v2.0) v2.0
3+
|/
4+
| * (tag: v1.0) v1.0
5+
|/
6+
* First commit of git artifact
7+
[submodule "submodule-repo"]
8+
path = submodule-repo
9+
url = ../.remote
10+
On branch main
11+
Your branch is up to date with 'origin/main'.
12+
13+
nothing to commit, working tree clean

_tests.sh

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/usr/bin/env bash
2+
# shellcheck disable=SC2317
3+
# shellcheck disable=SC2329
24

35

46
function usage() {
@@ -7,8 +9,9 @@ Usage: $(basename "$0") [options]
79
810
Options:
911
-h, --help Show this help message and exit
10-
--debug Enable debug mode
12+
-d, --debug Enable debug mode
1113
--verbose Enable verbose output
14+
-t|--testcase <#> Specify a single test case to run (e.g., 1, 2, 3.1, etc.)
1215
1316
Description:
1417
This script runs integration tests for git-artifact.
@@ -89,7 +92,6 @@ remote_tester_repo=.remote
8992
clone_tester_repo=.clone
9093
global_exit_code=0
9194

92-
# shellcheck disable=SC2317
9395
function testcase_header() {
9496
[[ ! -d "${test}" ]] && {
9597
echo "Creating test directory: ${test} and empty git-reference.log"
@@ -103,13 +105,11 @@ function testcase_header() {
103105
echo "--------------------------------------------------------------------------------"
104106
}
105107

106-
# shellcheck disable=SC2317
107108
function generate_git_test_log() {
108109
rm -rf .git/refs/remotes/origin/HEAD
109110
git log --graph --all --oneline --format="%d %s" >> "${root_folder}/${test}/git-test.log"
110111
}
111112

112-
# shellcheck disable=SC2317
113113
function eval_testcase() {
114114
# expect to be in repo to test against
115115

@@ -141,7 +141,6 @@ function eval_testcase() {
141141
echo
142142
}
143143

144-
# shellcheck disable=SC2317
145144
function generate_base_repo() {
146145
rm -rf "${local_tester_repo:?}/" "${remote_tester_repo:?}/" "${clone_tester_repo:?}/"
147146
git init --bare -b "${default_branch:-main}" $remote_tester_repo || {
@@ -167,7 +166,6 @@ echo " - <test>/ok.log(all good)"
167166
echo " - <test>/nok.log(failed tests)"
168167
echo
169168

170-
# shellcheck disable=SC2317
171169
function 1 {
172170
export test="1"
173171
testcase_synopsis="base-repo default-branch; clone"
@@ -180,7 +178,6 @@ function 1 {
180178
eval_testcase
181179
}
182180

183-
# shellcheck disable=SC2317
184181
function 1.1 {
185182
export test="1.1"
186183
testcase_synopsis="base-repo master-branch; clone"
@@ -195,7 +192,6 @@ function 1.1 {
195192
eval_testcase
196193
}
197194

198-
# shellcheck disable=SC2317
199195
function 2 {
200196
test="${FUNCNAME[0]}"
201197
testcase_synopsis="base-repo ; clone; fetch-co : the repo has two tags and the latest is checked out"
@@ -211,7 +207,6 @@ function 2 {
211207
eval_testcase
212208
}
213209

214-
# shellcheck disable=SC2317
215210
function 3 {
216211
test="${FUNCNAME[0]}"
217212
testcase_synopsis="base-repo ; clone - gives a repo without any artifacts"
@@ -225,7 +220,6 @@ function 3 {
225220
eval_testcase
226221
}
227222

228-
# shellcheck disable=SC2317
229223
function 4 {
230224
export test="4"
231225
testcase_synopsis="base-repo ; clone; add-n-push with branch"
@@ -243,7 +237,6 @@ function 4 {
243237
eval_testcase
244238
}
245239

246-
# shellcheck disable=SC2317
247240
function 5 {
248241
test="${FUNCNAME[0]}"
249242
testcase_synopsis="base-repo ; clone; fetch-co-latest pattern"
@@ -279,7 +272,6 @@ function 5 {
279272
eval_testcase
280273
}
281274

282-
# shellcheck disable=SC2317
283275
function 5.1 {
284276
test="${FUNCNAME[0]}"
285277
testcase_synopsis="base-repo ; clone; find-latest pattern"
@@ -297,7 +289,6 @@ function 5.1 {
297289
}
298290

299291

300-
# shellcheck disable=SC2317
301292
function 6 {
302293
test="${FUNCNAME[0]}"
303294
testcase_synopsis="base-repo ; clone; fetch-tags"
@@ -315,7 +306,6 @@ function 6 {
315306
eval_testcase
316307
}
317308

318-
# shellcheck disable=SC2317
319309
function 7 {
320310
test="${FUNCNAME[0]}"
321311
testcase_synopsis="base-repo ; clone; list"
@@ -342,7 +332,6 @@ function 7 {
342332
eval_testcase
343333
}
344334

345-
# shellcheck disable=SC2317
346335
function 8 {
347336
test="${FUNCNAME[0]}"
348337
testcase_synopsis="base-repo ; clone; summary"
@@ -377,7 +366,6 @@ function 8 {
377366
eval_testcase
378367
}
379368

380-
# shellcheck disable=SC2317
381369
function 9 {
382370
test="${FUNCNAME[0]}"
383371

@@ -400,26 +388,56 @@ function 9 {
400388
sleep 1
401389
done
402390

403-
generate_git_test_log
404-
git artifact prune --glob 'v*.*' --keep 5 --dryrun >> ${root_folder}/${test}/git-test.log
405-
git artifact prune --glob 'v*.*' --keep 5
406-
git fetch origin -pP
391+
generate_git_test_log
392+
git artifact prune --glob 'v*.*' --keep 5 --dryrun >> ${root_folder}/${test}/git-test.log
393+
git artifact prune --glob 'v*.*' --keep 5
394+
git fetch origin -pP
407395

408-
generate_git_test_log
396+
generate_git_test_log
397+
398+
git artifact list --glob 'v*.*' >> ${root_folder}/${test}/git-test.log
409399

410-
git artifact list --glob 'v*.*' >> ${root_folder}/${test}/git-test.log
400+
} > ${root_folder}/${test}/run.log 2>&1 || { pwd && cat ${root_folder}/${test}/run.log; }
401+
eval_testcase
402+
}
403+
404+
function 10 {
405+
test="${FUNCNAME[0]}"
411406

407+
testcase_synopsis="base-repo ; add-as-submodule"
408+
testcase_header
409+
{
410+
cd $test
411+
generate_base_repo
412+
413+
cd $local_tester_repo
414+
415+
git artifact add-as-submodule --url "../$remote_tester_repo" --path submodule-repo
416+
417+
git status
412418

419+
git commit -m "Added submodule repo"
420+
git push origin HEAD:"${default_branch:-main}"
421+
git fetch origin -apP
422+
423+
generate_git_test_log
424+
cat .gitmodules >> ${root_folder}/${test}/git-test.log
425+
git status >> ${root_folder}/${test}/git-test.log
426+
413427
} > ${root_folder}/${test}/run.log 2>&1 || { pwd && cat ${root_folder}/${test}/run.log; }
414428
eval_testcase
415429
}
416430

431+
417432
if [[ ${arg_testcase:-} == "" ]]; then
418433
# Dynamically list and call test functions
419434
mapfile -t test_functions < <(declare -F | awk '{print $3}' | grep -E '^[0-9]+(\.[0-9]+)?$')
420435

421436
for fn in "${test_functions[@]}"; do
422-
"$fn"
437+
"$fn" || {
438+
echo "Test case '$fn' failed. Check the logs in .test/$fn/run.log"
439+
global_exit_code=1
440+
}
423441
done
424442
else
425443
# Run a specific test case if provided
@@ -430,6 +448,8 @@ else
430448
exit 1
431449
fi
432450
fi
451+
452+
433453
echo
434454
echo "########################################"
435455
echo "All tests completed. Checking results..."

0 commit comments

Comments
 (0)