Skip to content

Commit 73debc6

Browse files
committed
add fetch-co-lastst functionality
1 parent 5812496 commit 73debc6

File tree

4 files changed

+99
-26
lines changed

4 files changed

+99
-26
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
**/.local
33
**/.clone
44
**/git-test.log
5+
**/run.log

.test/5/git-reference.log

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
* (HEAD -> main, tag: v5.1) v5.1
2+
| * (tag: v5.0) v5.0
3+
|/
4+
| * (tag: v2.0) v2.0
5+
|/
6+
* (origin/main) First commit of git artifact

_tests.sh

Lines changed: 69 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,57 +28,103 @@ function generate_base_repo() {
2828
cd ..
2929
}
3030

31+
echo "Running testcases; You can find run details for each test in <test>/run.log"
32+
echo
33+
3134
export test="1"
32-
cd $test
33-
generate_base_repo
34-
git -C $local_tester_repo log --graph --all --oneline --decorate --format="%d %s" > git-test.log
35+
testcase_synopsis="base-repo ; clone; "
36+
{
37+
cd $test
38+
generate_base_repo
39+
git -C $local_tester_repo log --graph --all --oneline --decorate --format="%d %s" > git-test.log
40+
} > ${test}/run.log 2>&1
3541
diff git-test.log git-reference.log || {
3642
echo "ERROR: Test $test failed"
3743
exit 1
3844
}
45+
echo "INFO: Test $test pass: ${testcase_synopsis}"
3946
cd $root_folder
4047

4148
export test="2"
42-
cd $test
43-
generate_base_repo
44-
git artifact clone --url=$(pwd)/$remote_tester_repo --path $clone_tester_repo
45-
cd $clone_tester_repo
46-
git artifact fetch-co -t v1.0
47-
git artifact fetch-co -t v2.0
49+
testcase_synopsis="base-repo ; clone; fetch-co : the repo has two tags and the latest is checked out"
50+
{
51+
cd $test
52+
generate_base_repo
53+
git artifact clone --url=$(pwd)/$remote_tester_repo --path $clone_tester_repo
54+
cd $clone_tester_repo
55+
git artifact fetch-co -t v1.0
56+
git artifact fetch-co -t v2.0
57+
} > ${test}/run.log 2>&1
4858
git log --graph --all --oneline --decorate --format="%d %s" > ../git-test.log
4959
cd ..
5060
diff git-test.log git-reference.log || {
5161
echo "ERROR: Test $test failed"
5262
exit 1
5363
}
64+
echo "INFO: Test $test pass: ${testcase_synopsis}"
5465
cd $root_folder
5566

5667
export test="3"
57-
cd $test
58-
generate_base_repo "latest"
59-
git artifact clone --url=$(pwd)/$remote_tester_repo --path $clone_tester_repo
60-
git -C $clone_tester_repo log --graph --all --oneline --decorate --format="%d %s" > git-test.log
68+
testcase_synopsis="base-repo ; clone - gives a repo without any artifacts"
69+
{
70+
cd $test
71+
generate_base_repo "latest"
72+
git artifact clone --url=$(pwd)/$remote_tester_repo --path $clone_tester_repo
73+
git -C $clone_tester_repo log --graph --all --oneline --decorate --format="%d %s" > git-test.log
74+
} > ${test}/run.log 2>&1
6175
diff git-test.log git-reference.log || {
6276
echo "ERROR: Test $test failed"
6377
exit 1
6478
}
79+
echo "INFO: Test $test pass: ${testcase_synopsis}"
6580
cd $root_folder
6681

67-
export test="4"
68-
cd $test
69-
generate_base_repo
70-
git artifact clone --url=$(pwd)/$remote_tester_repo -b latest --path $clone_tester_repo
71-
cd $clone_tester_repo
72-
touch test$test.txt
73-
git artifact add-n-push -t v${test}.0 -b latest
74-
touch test$test.1.txt
75-
git artifact add-n-push -t v${test}.1 -b latest
82+
test="4"
83+
testcase_synopsis="base-repo ; clone; add-n-push with branch"
84+
{
85+
cd $test
86+
generate_base_repo
87+
git artifact clone --url=$(pwd)/$remote_tester_repo -b latest --path $clone_tester_repo
88+
cd $clone_tester_repo
89+
touch test$test.txt
90+
git artifact add-n-push -t v${test}.0 -b latest
91+
touch test$test.1.txt
92+
git artifact add-n-push -t v${test}.1 -b latest
93+
} > ${test}/run.log 2>&1
7694
git log --graph --all --oneline --decorate --format="%d %s" > ../git-test.log
7795
cd ..
7896
diff git-test.log git-reference.log || {
7997
echo "ERROR: Test $test failed"
8098
exit 1
8199
}
82-
echo "ERROR: Test $test pass"
100+
echo "INFO: Test $test pass: ${testcase_synopsis}"
101+
cd $root_folder
83102

103+
test="5"
104+
testcase_synopsis="base-repo ; clone; fetch-co-latest pattern"
105+
{
106+
cd $test
107+
generate_base_repo
108+
git artifact clone --url=$(pwd)/$remote_tester_repo --path $clone_tester_repo
109+
cd $clone_tester_repo
110+
git artifact fetch-co-latest -r 'v[0-9]+.[0-9]+'
111+
git artifact reset
112+
touch test$test.txt
113+
git artifact add-n-push -t v${test}.0
114+
git tag -d v${test}.0
115+
git artifact fetch-co-latest -r 'v[0-9]+.[0-9]+'
116+
git artifact reset
117+
touch test$test.1.txt
118+
git artifact add-n-push -t v${test}.1
119+
sleep 1
120+
git tag -d v${test}.1
121+
git artifact fetch-co-latest --regex 'v[0-9]+.[0-9]+'
122+
} > ${test}/run.log 2>&1 || cat ${test}/run.log
123+
git log --graph --all --oneline --decorate --format="%d %s" > ../git-test.log
124+
cd ..
125+
diff git-test.log git-reference.log || {
126+
echo "ERROR: Test $test failed: ${testcase_synopsis}"
127+
exit 1
128+
}
129+
echo "INFO: Test $test pass: ${testcase_synopsis}"
84130
cd $root_folder

git-artifact

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ push push a tag
3636
add-n-push add and commit files to repo and then push them
3737
fetch-co fetch tag from remote and checkout it out
3838
reset reset workspace and branches
39+
fetch-co-latest Get latest tag form remote using grep reg-ex and reset hard to it
40+
3941
--
4042
h,help show the help
4143
q quiet
@@ -45,11 +47,14 @@ d show debug messages
4547
u,url= the remote url
4648
p,path= the optional path for init and clone
4749
48-
options for 'init', 'clone', 'add-n-tag', 'push', 'add-n-push', 'fetch-co', 'reset'
50+
options for 'init', 'clone', 'add-n-tag', 'push', 'add-n-push', 'fetch-co'
4951
b,branch= use branch for local changes and pushes
5052
5153
options for 'add-n-tag', 'push', 'add-n-push', 'fetch-co'
5254
t,tag= the tag to be created
55+
56+
options for 'fetch-co-latest'
57+
r,regex= the reg-ex pattern to latest of
5358
"
5459

5560
debug () {
@@ -240,6 +245,12 @@ cmd_fetch-co() {
240245
git log -1 --oneline --decorate
241246
}
242247

248+
cmd_fetch-co-latest() {
249+
latest_tag=$(git ls-remote --tags origin | grep -v '\^{}' | grep -E "[a-f0-9].*refs/tags/${arg_regex}" | tail -1 | cut -f2 )
250+
git fetch origin +$latest_tag:$latest_tag
251+
git reset --hard $latest_tag
252+
}
253+
243254
main () {
244255
[[ ${debug:-} == true ]] && set -x
245256
if [[ $# -eq 0 ]] ; then
@@ -281,6 +292,10 @@ main () {
281292
arg_path="$1"
282293
shift
283294
;;
295+
--regex|-r)
296+
arg_regex="$1"
297+
shift
298+
;;
284299
--)
285300
;;
286301
*)
@@ -346,9 +361,14 @@ main () {
346361
# shellcheck source=/dev/null
347362
. git-sh-setup
348363
require_work_tree
349-
if test -n "${arg_branch:-}" ; then
364+
;;
365+
fetch-co-latest)
366+
# shellcheck source=/dev/null
367+
. git-sh-setup
368+
require_work_tree
369+
if test -z "${arg_regex:-}" ; then
350370
git artifact -h
351-
echo "ERROR: -b|--branch is required for $arg_command"
371+
echo "ERROR: -r|--regex is required for $arg_command"
352372
exit 1
353373
fi
354374
;;

0 commit comments

Comments
 (0)