33# test-post-merge.sh: A script to simulate a git merge and test the post-merge hook.
44
55EFCMS_ROOT=$( realpath " $( dirname " $0 " ) /.." )
6+ ANY_ERROR=0
67
78set -e
89
910GREEN=' \033[0;32m'
11+ RED=' \033[0;31m'
1012NC=' \033[0m' # No Color
1113
1214echo -e " ${GREEN} Setting up test environment...${NC} "
@@ -29,6 +31,32 @@ git config user.name "Test User"
2931git add CHANGES.md
3032git commit -m " Initial commit to the main branch" -q
3133
34+ git checkout -b no-changes -q
35+ echo " some text" > some-other-file.txt
36+ git add some-other-file.txt
37+ git commit -m " Add a file that is not CHANGES.md" -q
38+
39+ git checkout main -q
40+ mkdir -p .husky
41+ cp " ${EFCMS_ROOT} /.husky/post-merge" .husky/post-merge
42+ chmod +x .husky/post-merge
43+
44+ echo -e " ${GREEN} Simulating merge of 'no-changes' into 'main'...${NC} "
45+ PRE_MERGE_HEAD=$( git rev-parse HEAD)
46+ git merge no-changes --no-edit -q
47+ git update-ref ORIG_HEAD " $PRE_MERGE_HEAD "
48+
49+ echo -e " ${GREEN} Executing post-merge hook...${NC} "
50+ ./.husky/post-merge
51+ EXIT_CODE=" $? "
52+
53+ if [[ " $EXIT_CODE " -eq 0 ]]; then
54+ echo -e " ${GREEN} Exited with status ${EXIT_CODE} .${NC} "
55+ else
56+ ANY_ERROR=1
57+ echo -e " ${RED} Exited with status ${EXIT_CODE} .${NC} "
58+ fi
59+
3260git checkout -b throwaway -q
3361{
3462 echo " "
@@ -43,12 +71,20 @@ mkdir -p .husky
4371cp " ${EFCMS_ROOT} /.husky/post-merge" .husky/post-merge
4472chmod +x .husky/post-merge
4573
46-
4774echo -e " ${GREEN} Simulating merge of 'throwaway' into 'main'...${NC} "
4875PRE_MERGE_HEAD=$( git rev-parse HEAD)
4976git merge throwaway --no-edit -q
5077git update-ref ORIG_HEAD " $PRE_MERGE_HEAD "
5178
5279echo -e " ${GREEN} Executing post-merge hook...${NC} "
5380./.husky/post-merge
54- echo -e " ${GREEN} Test complete.${NC} "
81+ EXIT_CODE=" $? "
82+
83+ if [[ " $EXIT_CODE " -eq 0 ]]; then
84+ echo -e " ${GREEN} Exited with status ${EXIT_CODE} .${NC} "
85+ else
86+ ANY_ERROR=1
87+ echo -e " ${RED} Exited with status ${EXIT_CODE} .${NC} "
88+ fi
89+
90+ [[ " $ANY_ERROR " -eq 0 ]] && echo -e " ${GREEN} Test complete.${NC} " || echo -e " ${RED} Test complete with error(s).${NC} "
0 commit comments