-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathpost-commit.txt
More file actions
69 lines (55 loc) · 2.07 KB
/
post-commit.txt
File metadata and controls
69 lines (55 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
# Post commit hook to force all .dspec files to always have current commit hash
# Color codes for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Define the source folder to search
# In this project
SOURCE_FOLDER="./"
echo -e "${YELLOW}Post-commit hook: Processing .dspec files in ${SOURCE_FOLDER} folder${NC}"
# Find all .dspec files in the Source folder
DSPEC_FILES=$(find "$SOURCE_FOLDER" -name "*.dspec" -type f 2>/dev/null)
if [ -z "$DSPEC_FILES" ]; then
echo -e "${YELLOW}No .dspec files found in ${SOURCE_FOLDER} folder${NC}"
exit 0
fi
echo -e "${YELLOW}Found .dspec files:${NC}"
echo "$DSPEC_FILES" | while read -r file; do
echo -e " ${YELLOW}$file${NC}"
done
# Process each .dspec file
echo "$DSPEC_FILES" | while read -r TARGET_FILE; do
echo -e "\n${YELLOW}Processing: ${TARGET_FILE}${NC}"
# Check if the target file exists
if [ -f "$TARGET_FILE" ]; then
echo -e "${RED}Deleting ${TARGET_FILE}${NC}"
rm "$TARGET_FILE"
# Verify deletion
if [ ! -f "$TARGET_FILE" ]; then
echo -e "${GREEN}File successfully deleted${NC}"
else
echo -e "${RED}Error: Failed to delete ${TARGET_FILE}${NC}"
exit 1
fi
else
echo -e "${YELLOW}File ${TARGET_FILE} does not exist, skipping deletion${NC}"
fi
# Force checkout the file from the repository
echo -e "${YELLOW}Force checking out ${TARGET_FILE} from HEAD${NC}"
# Use git checkout to restore the file from the latest commit
git checkout HEAD -- "$TARGET_FILE"
# Check if the checkout was successful
if [ $? -eq 0 ]; then
if [ -f "$TARGET_FILE" ]; then
echo -e "${GREEN}Successfully restored ${TARGET_FILE} from repository${NC}"
else
echo -e "${YELLOW}File ${TARGET_FILE} was not restored (may not exist in repository)${NC}"
fi
else
echo -e "${RED}Error: Failed to checkout ${TARGET_FILE}${NC}"
exit 1
fi
done
echo -e "\n${GREEN}Post-commit hook completed successfully${NC}"