gitrepo.bash 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/usr/bin/env bash
  2. set -e
  3. set -x
  4. readonly tmpdir="$(mktemp -d)"
  5. trap "rm -rf '$tmpdir'" EXIT
  6. readonly outdir="${BASH_SOURCE%/*}"
  7. readonly defaultBranch='master'
  8. export GIT_AUTHOR_NAME='testauthor'
  9. export GIT_AUTHOR_EMAIL='[email protected]'
  10. export GIT_COMMITTER_NAME='testauthor'
  11. export GIT_COMMITTER_EMAIL='[email protected]'
  12. (
  13. cd "$tmpdir"
  14. git --bare init -b "$defaultBranch" gitrepo.git
  15. rm -f gitrepo.git/hooks/*.sample
  16. mkdir gitrepo
  17. cd gitrepo
  18. git init -b "$defaultBranch"
  19. echo 'cmake_minimum_required(VERSION 3.19)
  20. project(Example NONE)
  21. add_custom_target(example ALL
  22. COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/example.cmake.in example.cmake
  23. )' >CMakeLists.txt
  24. echo 'message(STATUS example)' >example.cmake.in
  25. git add CMakeLists.txt example.cmake.in
  26. git commit -m "Initial import into repo."
  27. git push ../gitrepo.git "$defaultBranch"
  28. cd ../gitrepo.git
  29. git gc --prune
  30. cd ..
  31. ln -s gitrepo.git GIT
  32. git --bare init -b "$defaultBranch" gitrepo-sub.git
  33. rm -f gitrepo-sub.git/hooks/*.sample
  34. mkdir gitrepo-sub
  35. cd gitrepo-sub
  36. git init -b "$defaultBranch"
  37. echo 'cmake_minimum_required(VERSION 3.19)
  38. project(ExampleWithSub NONE)
  39. file(STRINGS "${CMAKE_SOURCE_DIR}/.git/config" git_config_strings
  40. REGEX "^\\[submodule")
  41. foreach(submodule m1 m2)
  42. option(WITH_${submodule} "Enable ${submodule}" OFF)
  43. set(${submodule}_INITED FALSE)
  44. set(${submodule}_UPDATED FALSE)
  45. foreach(s ${git_config_strings})
  46. if("${s}" MATCHES "${submodule}")
  47. set(${submodule}_INITED TRUE)
  48. endif()
  49. endforeach()
  50. if(EXISTS "${CMAKE_SOURCE_DIR}/m/${submodule}/CMakeLists.txt")
  51. set(${submodule}_UPDATED TRUE)
  52. endif()
  53. if(WITH_${submodule})
  54. if(NOT ${submodule}_INITED)
  55. message(FATAL_ERROR "${submodule} not inited")
  56. elseif(NOT ${submodule}_UPDATED)
  57. message(FATAL_ERROR "${submodule} not updated")
  58. endif()
  59. else()
  60. if(${submodule}_INITED)
  61. message(FATAL_ERROR "${submodule} inited")
  62. elseif(${submodule}_UPDATED)
  63. message(FATAL_ERROR "${submodule} updated")
  64. endif()
  65. endif()
  66. endforeach()' >CMakeLists.txt
  67. git add CMakeLists.txt
  68. git submodule add -- ../GIT m/m1
  69. git submodule add -- ../GIT m/m2
  70. git submodule add -- ../GIT m/m3
  71. git commit -m "Initial import into repo."
  72. git push ../gitrepo-sub.git "$defaultBranch"
  73. cd ../gitrepo-sub.git
  74. git gc --prune
  75. cd ..
  76. ln -s gitrepo-sub.git GIT-with-submodules
  77. git --bare init -b "$defaultBranch" gitrepo-sub-rec.git
  78. rm -f gitrepo-sub-rec.git/hooks/*.sample
  79. mkdir gitrepo-sub-rec
  80. cd gitrepo-sub-rec
  81. git init -b "$defaultBranch"
  82. echo 'cmake_minimum_required(VERSION 3.19)
  83. project(ExampleWithRecSub NONE)
  84. set(top_submodule_dir "${CMAKE_SOURCE_DIR}/submodule")
  85. if(NOT EXISTS "${top_submodule_dir}/CMakeLists.txt")
  86. message(FATAL_ERROR "Top submodule not updated")
  87. endif()
  88. option(WITH_RECURSIVE "Submodules are updated recursively" ON)
  89. foreach(submodule m1 m2 m3)
  90. set(${submodule}_UPDATED FALSE)
  91. if(EXISTS "${top_submodule_dir}/m/${submodule}/CMakeLists.txt")
  92. set(${submodule}_UPDATED TRUE)
  93. endif()
  94. if(WITH_RECURSIVE)
  95. if(NOT ${submodule}_UPDATED)
  96. message(FATAL_ERROR "${submodule} not updated")
  97. endif()
  98. else()
  99. if(${submodule}_UPDATED)
  100. message(FATAL_ERROR "${submodule} updated")
  101. endif()
  102. endif()
  103. endforeach()' >CMakeLists.txt
  104. git add CMakeLists.txt
  105. git submodule add -- ../GIT-with-submodules submodule
  106. git commit -m "Initial import into repo."
  107. git push ../gitrepo-sub-rec.git "$defaultBranch"
  108. cd ../gitrepo-sub-rec.git
  109. git gc --prune
  110. cd ..
  111. )
  112. tar cvzf "$outdir/gitrepo.tgz" -C "$tmpdir" gitrepo.git
  113. tar cvzf "$outdir/gitrepo-sub.tgz" -C "$tmpdir" gitrepo-sub.git
  114. tar cvzf "$outdir/gitrepo-sub-rec.tgz" -C "$tmpdir" gitrepo-sub-rec.git
  115. git_tag=$(cd "$tmpdir/gitrepo.git" ; git rev-parse HEAD)
  116. sed -i "/generated by gitrepo.bash/ s/ [0-9a-f]\\+ / $git_tag /" "$outdir/CMakeLists.txt"