Skip to content

Instantly share code, notes, and snippets.

@jwerle
Created March 30, 2022 14:34
Show Gist options
  • Save jwerle/5f937115818b76712efca575c73b8a9f to your computer and use it in GitHub Desktop.
Save jwerle/5f937115818b76712efca575c73b8a9f to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
declare -a tags=($(git tag -l))
for tag in "${tags[@]}"; do
## checkout current tag
git checkout "$tag"
## checkout `setup.sh` from master branch with latest changes
git checkout master -- setup.sh
## get current version
declare version="$(bpkg package version)"
## version replacement regex for `sed(1)`
declare regex="s/VERSION=.*/VERSION=\"$version\"/g"
## set versions in files
sed -i "$regex" bpkg.sh
sed -i "$regex" setup.sh
## remove current tag
git tag -d "$tag"
## amend HEAD for current tag
git commit -a --amend --no-edit
## retag
git tag "$tag"
## force push update
git push origin "$tag" -f
done
git checkout master
@Potherca
Copy link

@jwerle Running this one the repo:

#!/usr/bin/env bash

declare -a tags=($(git tag -l))

for tag in "${tags[@]}"; do
  ## checkout current tag
  git checkout --quiet "$tag"
  ./bpkg package version
done

git checkout master

Returns:

 "0.0.2"
 "0.0.3"
 "0.0.4"
 "0.0.5"
 "0.0.6"
 "0.0.7"
 "0.0.8"
 "0.0.9"
 "0.1.0"
 "0.2.0"
 "0.2.1"
 "0.2.2"
 "0.2.3"
 "0.2.4"
 "0.2.5"
 "0.2.6"
 "0.2.7"
 "0.2.8"
 "0.2.9"
 "0.3.0"
 "0.3.1"
 "0.3.2"
["version"]	"1.0.0"
["version"]	"1.0.1"
1.0.101.0.111.0.121.0.131.0.141.0.151.0.16
1.0.17
1.0.18
1.0.19
["version"]	"1.0.2"
1.0.20
1.0.21
1.0.22
1.0.23
1.0.24
1.0.25
["version"]	"1.0.3"
1.0.41.0.51.0.61.0.71.0.81.0.91.1.0
1.1.1
1.1.2

So it looks like:

  • versions 0.0.2 to 0.3.2 return the version in quotes, prefixed with a space)
  • version 1.0.0 and 1.0.1 return the version in quotes prefixed with ["version"]
  • versions 1.0.4 to 1.1.0 return only the version, without newline
  • version 1.1.1 and 1.1.2 return the version, with newline

@Potherca
Copy link

My fix would be to only grab the version (using tr -dc) and add a manual check before commit/push:

diff --git a/fix-tag-history.sh b/fix-tag-history.sh
index 1d0d93d..32fc2b6 100644
--- a/fix-tag-history.sh
+++ b/fix-tag-history.sh
@@ -8,12 +8,18 @@ for tag in "${tags[@]}"; do
   ## checkout `setup.sh` from master branch with latest changes
   git checkout master -- setup.sh
   ## get current version
-  declare version="$(bpkg package version)"
+  declare version="$(echo "$(bpkg package version | tr -dc '0-9.')")"
   ## version replacement regex for `sed(1)`
   declare regex="s/VERSION=.*/VERSION=\"$version\"/g"
   ## set versions in files
   sed -i "$regex" bpkg.sh
   sed -i "$regex" setup.sh
+
+  git diff
+
+  echo 'Please check the repository content'
+  read -r -s -n 1 -p "<Press any key to continue>"
+  
   ## remove current tag
   git tag -d "$tag"
   ## amend HEAD for current tag

@jwerle
Copy link
Author

jwerle commented Jun 13, 2022

okay I hope bpkg/bpkg#151 fixes this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment