gbs-tests-constants.sh.inc 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. # gbs-tests-constants.sh.inc - test suite for git-branch-status
  2. #
  3. # Copyright 2020-2021,2023 bill-auger <bill-auger@programmer.net>
  4. #
  5. # git-branch-status is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License version 3
  7. # as published by the Free Software Foundation.
  8. #
  9. # git-branch-status is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License version 3
  15. # along with git-branch-status. If not, see <http://www.gnu.org/licenses/>.
  16. ## string constants ##
  17. readonly GBS_CMD=git-branch-status
  18. readonly CLIME='\033[1;32m'
  19. readonly CBLUE='\033[0;36m'
  20. readonly CGREEN='\033[0;32m'
  21. readonly CRED='\033[0;31m'
  22. readonly CEND='\033[0m'
  23. readonly MKTEMP_TEMPLATE='gbs-test-XXXXXXXXXX'
  24. readonly LOCAL_NAME='local'
  25. readonly UPSTREAM_NAME='the-upstream'
  26. readonly PEER_NAME='a-collaborator'
  27. readonly MASTER_BRANCH='master'
  28. readonly COMMON_BRANCH='development'
  29. readonly PEER_RENAMED_BRANCH='devel'
  30. readonly WIP_BRANCH='my-wip'
  31. readonly TRACKED_FILE='tracked_file'
  32. readonly TEST_CFG_FILE='test_gbs_config'
  33. ## expected config test results ##
  34. readonly CFG_FILE_LOC_ENV_TEXT="GBS_CFG_FILE=(exists):"
  35. readonly CFG_FILE_LOC_DEF_TEXT="GBS_CFG_FILE="
  36. read -r -d '' FETCH_PERIOD_ENV_TEXT <<'EOF'
  37. GBS_FETCH_PERIOD=42
  38. CFG_FETCH_PERIOD=-42
  39. FETCH_PERIOD=42
  40. EOF
  41. read -r -d '' FETCH_PERIOD_CFG_TEXT <<'EOF'
  42. GBS_FETCH_PERIOD=
  43. CFG_FETCH_PERIOD=-42
  44. FETCH_PERIOD=-42
  45. EOF
  46. read -r -d '' FETCH_PERIOD_DEF_TEXT <<'EOF'
  47. GBS_FETCH_PERIOD=
  48. CFG_FETCH_PERIOD=
  49. FETCH_PERIOD=-1
  50. EOF
  51. read -r -d '' LAST_FETCH_ENV_TEXT <<'EOF'
  52. GBS_LAST_FETCH_FILE=DUMMY
  53. CFG_LAST_FETCH_FILE=__TMP_DIR__/GBS_LAST_FETCH
  54. LAST_FETCH_FILE=DUMMY
  55. EOF
  56. read -r -d '' LAST_FETCH_CFG_TEXT <<'EOF'
  57. GBS_LAST_FETCH_FILE=
  58. CFG_LAST_FETCH_FILE=__TMP_DIR__/GBS_LAST_FETCH
  59. LAST_FETCH_FILE=__TMP_DIR__/GBS_LAST_FETCH
  60. EOF
  61. read -r -d '' LAST_FETCH_DEF_TEXT <<'EOF'
  62. GBS_LAST_FETCH_FILE=
  63. CFG_LAST_FETCH_FILE=
  64. LAST_FETCH_FILE=__HOME_DIR__/.GBS_LAST_FETCH
  65. EOF
  66. read -r -d '' ANSI_COLOR_ENV_TEXT <<'EOF'
  67. GBS_USE_ANSI_COLOR=0
  68. CFG_USE_ANSI_COLOR=1
  69. USE_ANSI_COLOR=0
  70. EOF
  71. read -r -d '' ANSI_COLOR_CFG_TEXT <<'EOF'
  72. GBS_USE_ANSI_COLOR=
  73. CFG_USE_ANSI_COLOR=1
  74. USE_ANSI_COLOR=1
  75. EOF
  76. read -r -d '' ANSI_COLOR_DEF_TEXT <<'EOF'
  77. GBS_USE_ANSI_COLOR=
  78. CFG_USE_ANSI_COLOR=
  79. USE_ANSI_COLOR=1
  80. EOF
  81. ## expected normal test results ##
  82. # NOTE: the upstream and branch names are intentionally explicit
  83. # eg: the-upstream/development could be ${UPSTREAM_NAME}/${COMMON_BRANCH}
  84. # that would be less brittle if the constants are changed;
  85. # but the explicit text is more readable for debugging
  86. IFS= read -r -d '' LOCAL_TRACKING_TEXT <<'EOF'
  87. local <-> upstream
  88. EOF
  89. IFS= read -r -d '' LOCAL_COLLAB_TEXT <<'EOF'
  90. local <-> a-collaborator
  91. EOF
  92. IFS= read -r -d '' LOCAL_UPSTREAM_TEXT <<'EOF'
  93. local <-> the-upstream
  94. EOF
  95. IFS= read -r -d '' LOCALDEV_LOCALWIP_TEXT <<'EOF'
  96. development <-> my-wip
  97. EOF
  98. IFS= read -r -d '' LOCALDEV_PEERDEV_TEXT <<'EOF'
  99. development <-> a-collaborator/devel
  100. EOF
  101. IFS= read -r -d '' PEERWIP_LOCALWIP_TEXT <<'EOF'
  102. a-collaborator/my-wip <-> my-wip
  103. EOF
  104. IFS= read -r -d '' UPSTRMASTER_PEERMASTER_TEXT <<'EOF'
  105. the-upstream/master <-> a-collaborator/master
  106. EOF
  107. IFS= read -r -d '' LOCALS_CLEANUP_TEXT <<'EOF'
  108. locals <-> master
  109. EOF
  110. readonly ARG_REQUIRED_TEXT="fatal: This option requires an argument"
  111. IFS= read -r -d '' TRACKED_ALL_INSYNC_TEXT <<'EOF'
  112. ---------------------------------------------------------------
  113. | All tracking branches are synchronized with their upstreams |
  114. ---------------------------------------------------------------
  115. EOF
  116. IFS= read -r -d '' TRACKED_INSYNC_TEXT <<'EOF'
  117. -----------------------------------------------------------
  118. | This tracking branch is synchronized with it's upstream |
  119. -----------------------------------------------------------
  120. EOF
  121. IFS= read -r -d '' UNTRACKED_INSYNC_TEXT <<'EOF'
  122. -----------------------------------------------------------------
  123. | These branches are synchronized with no tracking relationship |
  124. -----------------------------------------------------------------
  125. EOF
  126. IFS= read -r -d '' REMOTES_INSYNC_TEXT <<'EOF'
  127. ------------------------------------------------------------------------------------------------
  128. | All local branches with corresponding names on this remote are synchronized with that remote |
  129. ------------------------------------------------------------------------------------------------
  130. EOF
  131. IFS= read -r -d '' OUTOFSYNCH_TEXT <<'EOF'
  132. ---------------------------------------------------------------
  133. *| development | (even)-|-(ahead 1) | the-upstream/development |
  134. ---------------------------------------------------------------
  135. EOF
  136. IFS= read -r -d '' ARBITRARYBRANCHES_LOCALDEV_LOCALWIP_TEXT <<'EOF'
  137. -------------------------------------------------
  138. *| development | (behind 2) | (ahead 1) | my-wip |
  139. -------------------------------------------------
  140. EOF
  141. IFS= read -r -d '' ARBITRARYBRANCHES_LOCALDEV_PEERDEV_TEXT <<'EOF'
  142. -----------------------------------------------------------
  143. *| development | (even) | (ahead 1) | a-collaborator/devel |
  144. -----------------------------------------------------------
  145. EOF
  146. IFS= read -r -d '' ARBITRARYBRANCHES_PEERWIP_LOCALWIP_TEXT <<'EOF'
  147. -----------------------------------------------------------
  148. | a-collaborator/my-wip | (behind 2) | (ahead 1) | my-wip |
  149. -----------------------------------------------------------
  150. EOF
  151. IFS= read -r -d '' CURRENTBRANCH_TEXT <<'EOF'
  152. ---------------------------------------------------------------
  153. *| development | (even)-|-(ahead 1) | the-upstream/development |
  154. ---------------------------------------------------------------
  155. EOF
  156. IFS= read -r -d '' SPECIFICBRANCH_TEXT <<'EOF'
  157. --------------------------------------
  158. | my-wip | n/a | n/a | (no upstream) |
  159. --------------------------------------
  160. EOF
  161. IFS= read -r -d '' OUTOFSYNCH_DATES_TEXT <<'EOF'
  162. -------------------------------------------------------------------------------------
  163. | 2000-01-06 development | (even)-|-(ahead 1) | 2000-01-02 the-upstream/development |
  164. -------------------------------------------------------------------------------------
  165. EOF
  166. IFS= read -r -d '' CLEANUP_TEXT <<'EOF'
  167. --------------------------------------------------------------------------
  168. | 2000-01-01 merged-into-master | (even) | (even) | 2000-01-01 master |
  169. | 2000-01-05 my-wip | (even) | (ahead 3) | 2000-01-01 master |
  170. | 2000-01-06 development | (even) | (ahead 2) | 2000-01-01 master |
  171. --------------------------------------------------------------------------
  172. branch: merged-into-master is identical to: master
  173. Delete merged-into-master? [y/N]
  174. EOF
  175. IFS= read -r -d '' HELP_TEXT <<'EOF'
  176. USAGE:
  177. git-branch-status
  178. git-branch-status [ base-branch-name compare-branch-name ]
  179. git-branch-status [ -a | --all ]
  180. git-branch-status [ -b | --branch ] [ filter-branch-name ]
  181. git-branch-status [ -d | --dates ]
  182. git-branch-status [ -h | --help ]
  183. git-branch-status [ -l | --local ]
  184. git-branch-status [ -r | --remotes ]
  185. git-branch-status [ -v | --verbose ]
  186. EXAMPLES:
  187. # show only branches for which upstream differs from local
  188. $ git-branch-status
  189. | collab-branch | (behind 1) | (ahead 2) | origin/collab-branch |
  190. | feature-branch | (even) | (ahead 2) | origin/feature-branch |
  191. | master | (behind 1) | (even) | origin/master |
  192. # compare two arbitrary branches - local or remote
  193. $ git-branch-status a-branch another-branch
  194. | a-branch | (even) | (even) | another-branch |
  195. $ git-branch-status a-branch a-remote/any-branch
  196. | a-branch | (even) | (even) | a-remote/any-branch |
  197. $ git-branch-status a-remote/any-branch a-branch
  198. | a-remote/any-branch | (behind 1) | (even) | a-branch |
  199. $ git-branch-status a-remote/any-branch other-remote/other-branch
  200. | a-remote/any-branch | (behind 1) | (even) | other-remote/other-branch |
  201. # show all branches - local and remote, regardless of state or relationship
  202. $ git-branch-status -a
  203. $ git-branch-status --all
  204. *| master | (even) | (ahead 1) | origin/master |
  205. | tracked-branch | (even) | (even) | origin/tracked-branch |
  206. | (no local) | n/a | n/a | origin/untracked-branch |
  207. | local-branch | n/a | n/a | (no upstream) |
  208. | master | (behind 1) | (ahead 1) | a-remote/master |
  209. | (no local) | n/a | n/a | a-remote/untracked-branch |
  210. # show the current branch
  211. $ git-branch-status -b
  212. $ git-branch-status --branch
  213. *| current-branch | (even) | (ahead 2) | origin/current-branch |
  214. # show a specific branch
  215. $ git-branch-status specific-branch
  216. $ git-branch-status -b specific-branch
  217. $ git-branch-status --branch specific-branch
  218. | specific-branch | (even) | (ahead 2) | origin/specific-branch |
  219. # compare a specific local branch against all other local branches
  220. $ git-branch-status -c master
  221. $ git-branch-status --cleanup master
  222. *| master | (behind 2) | (even) | master |
  223. | merged-into-master | (even) | (even) | master |
  224. | wip | (even) | (ahead 1) | master |
  225. branch: merged-into-master is identical to: master
  226. Delete merged-into-master? [y/N]
  227. # show the timestamp of each out-of-sync local ref
  228. $ git-branch-status -d
  229. $ git-branch-status --dates
  230. | 1999-12-30 master | (even) | (even) | 1999-12-30 origin/master |
  231. | 1999-12-31 devel | (behind 2) | (even) | 2000-01-01 origin/devel |
  232. # show the timestamp of arbitrary branch refs
  233. $ git-branch-status -d a-branch another-branch
  234. $ git-branch-status --dates a-branch another-branch
  235. | 1999-12-31 a-branch | (even) | (even) | 2000-01-01 another-branch |
  236. # print this usage message
  237. $ git-branch-status -h
  238. $ git-branch-status --help
  239. "prints this usage message"
  240. # show all local branches - including those synchronized or non-tracking
  241. $ git-branch-status -l
  242. $ git-branch-status --local
  243. *| master | (even) | (ahead 1) | origin/master |
  244. | tracked-branch | (even) | (even) | origin/tracked-branch |
  245. | local-branch | n/a | n/a | (no upstream) |
  246. # show all remote branches - including those not checked-out
  247. $ git-branch-status -r
  248. $ git-branch-status --remotes
  249. | master | (behind 1) | (even) | a-remote/master |
  250. | (no local) | n/a | n/a | a-remote/untracked-branch |
  251. # show all branches with timestamps (like -a -d)
  252. $ git-branch-status -v
  253. $ git-branch-status --verbose
  254. | 1999-12-31 master | (behind 1) | (even) | 2000-01-01 origin/master |
  255. | 1999-12-31 tracked | (even) | (even) | 2000-01-01 origin/tracked |
  256. *| 1999-12-31 local-wip | n/a | n/a | (no upstream) |
  257. EOF
  258. IFS= read -r -d '' LOCALS_TEXT <<'EOF'
  259. ---------------------------------------------------------------
  260. *| development | (even)-|-(ahead 1) | the-upstream/development |
  261. | master | (even)-|-(even) | the-upstream/master |
  262. | my-wip | n/a | n/a | (no upstream) |
  263. ---------------------------------------------------------------
  264. EOF
  265. IFS= read -r -d '' REMOTES_COLLAB_TEXT <<'EOF'
  266. ---------------------------------------------------------------
  267. | (no local) | n/a | n/a | a-collaborator/devel |
  268. | master | (even) | (even) | a-collaborator/master |
  269. | my-wip | (behind 1) | (ahead 2) | a-collaborator/my-wip |
  270. ---------------------------------------------------------------
  271. EOF
  272. IFS= read -r -d '' REMOTES_ORIGIN_TEXT <<'EOF'
  273. ---------------------------------------------------------------
  274. *| development | (even)-|-(ahead 1) | the-upstream/development |
  275. | master | (even)-|-(even) | the-upstream/master |
  276. ---------------------------------------------------------------
  277. EOF
  278. IFS= read -r -d '' REMOTES_COLLAB_INSYNC_TEXT <<'EOF'
  279. --------------------------------------------------------
  280. | (no local) | n/a | n/a | a-collaborator/devel |
  281. | master | (even) | (even) | a-collaborator/master |
  282. | my-wip | (even) | (even) | a-collaborator/my-wip |
  283. --------------------------------------------------------
  284. EOF
  285. IFS= read -r -d '' LOCALS_DATES_TEXT <<'EOF'
  286. -------------------------------------------------------------------------------------------------------------------
  287. | 2000-01-01 master: upstream-initial | (even)-|-(even) | 2000-01-01 the-upstream/master: upstream-initial |
  288. | 2000-01-03 my-wip: peer-change | n/a | n/a | (no upstream) |
  289. | 2000-01-06 development: rm | (even)-|-(ahead 1) | 2000-01-02 the-upstream/development: upstream-change |
  290. -------------------------------------------------------------------------------------------------------------------
  291. EOF
  292. IFS= read -r -d '' REMOTES_COLLAB_DATES_TEXT <<'EOF'
  293. --------------------------------------------------------------------------------------------------------------
  294. | 2000-01-01 master: upstream-initial | (even) | (even) | 2000-01-01 a-collaborator/master: upstream-initial |
  295. | (no local) | n/a | n/a | 2000-01-02 a-collaborator/devel: upstream-change |
  296. | 2000-01-03 my-wip: peer-change | (even) | (even) | 2000-01-03 a-collaborator/my-wip: peer-change |
  297. --------------------------------------------------------------------------------------------------------------
  298. EOF
  299. IFS= read -r -d '' REMOTES_ORIGIN_DATES_TEXT <<'EOF'
  300. -------------------------------------------------------------------------------------------------------------------
  301. | 2000-01-01 master: upstream-initial | (even)-|-(even) | 2000-01-01 the-upstream/master: upstream-initial |
  302. | 2000-01-06 development: rm | (even)-|-(ahead 1) | 2000-01-02 the-upstream/development: upstream-change |
  303. -------------------------------------------------------------------------------------------------------------------
  304. EOF
  305. IFS= read -r -d '' NCOMMITS_OVERCAP_TEXT <<'EOF'
  306. -----------------------------------------------------------------
  307. *| development | (even)-|-(ahead>999) | the-upstream/development |
  308. -----------------------------------------------------------------
  309. EOF
  310. IFS= read -r -d '' NCOMMITS_UNDERCAP_TEXT <<'EOF'
  311. -----------------------------------------------------------------
  312. *| development | (even)-|-(ahead 999) | the-upstream/development |
  313. -----------------------------------------------------------------
  314. EOF