-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpush
More file actions
executable file
·88 lines (73 loc) · 2.44 KB
/
Copy pathpush
File metadata and controls
executable file
·88 lines (73 loc) · 2.44 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
# Set Colors and handle errors
source ~/bin/colors
# Ensure that the branch name is provided as an argument
if [ -z "$1" ]; then
echo -e " "
echo -e "${RED}Error: No branch name provided.${NC}"
echo -e "${YELLOW}Usage: $0 <branch_name>${NC}"
echo -e " "
exit 1
fi
BRANCH_NAME=$1
# Reset pip requirements.txt file
reset_requirements
# Check the status of the repository
echo -e " "
echo -e "${YELLOW}Gathering Project Changes...${NC}"
# Add all changes to staging
echo -e "${YELLOW}Adding all changes to staging...${NC}"
git add .
# Check the status again to show what has been staged
git_status=$(git -c color.status=always status)
# Check if there is nothing to commit (working tree is clean)
if echo "$git_status" | grep -q "nothing to commit, working tree clean"; then
echo -e " "
echo -e "Nothing to commit, working tree clean. Exiting..."
echo -e " "
exit 0
fi
# Show the status to the user
echo -e "$git_status"
while true; do
# Prompt for a commit message
echo -e "${YELLOW}Please enter your commit message. (You do NOT need quotes): ${NC}"
if ! read commit_message; then
echo -e "${RED}Exiting script.${NC}"
echo -e " "
reset
exit 0
fi
# Show the draft of the commit message and ask for confirmation
echo -e " "
echo -e "${YELLOW}Your commit message is: ${NC}"
echo -e "${BLUE}${commit_message} ${NC}"
echo -e " "
echo -e "${YELLOW}Do you want to proceed with this commit message? (yes/no): ${NC}"
read confirmation
if [[ "$confirmation" == "y" || "$confirmation" == "yes" ]]; then
# Make the commit with the provided message
echo -e " "
echo -e "${YELLOW}Committing changes...${NC}"
git commit -m "$commit_message"
if [ $? -ne 0 ]; then
handle_error "Commit failed. Exiting..."
echo -e " "
fi
# Push the changes to the main branch
echo -e " "
echo -e "${YELLOW}Pushing changes to the remote branch '${BRANCH_NAME}...${NC}"
git push origin "$BRANCH_NAME"
if [ $? -ne 0 ]; then
handle_error "Push failed. Exiting..."
echo -e " "
fi
echo -e " "
echo -e "${GREEN}Changes pushed successfully to the '${BRANCH_NAME}' branch!${NC}"
echo -e " "
exit 0
else
echo -e "${RED}Commit aborted by user. Please provide a new commit message.${NC}"
echo -e " "
fi
done