You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.3 KiB

  1. #!/bin/bash
  2. #Documentation :
  3. #grep : https://stackoverflow.com/questions/3717772/regex-grep-for-multi-line-search-needed
  4. #
  5. #
  6. if [ -z "$1" ];then
  7. echo "Missing repository loca path to retag"
  8. exit 1
  9. fi
  10. repo_dir="$1"
  11. if [ ! -d "$repo_dir" ];then
  12. echo "$repo_dir is not a directory"
  13. exit 1
  14. fi
  15. if [ ! -d "$repo_dir/.git" ];then
  16. echo "$repo_dir is not a git workspace"
  17. exit 1
  18. fi
  19. branch="master"
  20. git="git -C $repo_dir"
  21. version_previous=""
  22. echo "$repo_dir"
  23. for commit in $($git rev-list "$branch"|tac)
  24. do
  25. version=""
  26. content=""
  27. #Find plugin xml first
  28. if $git ls-tree --name-only -r "$commit" |grep -q '^plugin.xml$'; then
  29. content=$($git show "$commit":plugin.xml|tr -d "\\r\\n\\0" 2>/dev/null)
  30. if [ "$content" ]; then
  31. version=$(echo "$content" | grep -oP "<\\s*version\\s*>\\s*\\K([0-9.]*)")
  32. fi
  33. fi
  34. #Override result by paquet.xml data
  35. if $git ls-tree --name-only -r "$commit" |grep -q '^paquet.xml$'; then
  36. content=$($git show "$commit":paquet.xml|tr -d "\\r\\n\\0" 2>/dev/null)
  37. if [ "$content" ]; then
  38. version=$(echo "$content" | grep -oP "<paquet.*version\\s*=\\s*.\\K[0-9.]*")
  39. fi
  40. fi
  41. # Set version
  42. if [ -n "$version" ] && [ "$version" != "$version_previous" ]; then
  43. $git tag v"$version" "$commit" 2>/dev/null
  44. echo "v$version at $commit"
  45. version_previous="$version"
  46. fi
  47. done