-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMergeMain2Work.sh
More file actions
executable file
·31 lines (25 loc) · 964 Bytes
/
MergeMain2Work.sh
File metadata and controls
executable file
·31 lines (25 loc) · 964 Bytes
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
#!/bin/bash
cd "$(dirname "$0")"
cd ..
git fetch origin
# Get the name of the current branch
current_branch=$(git branch --show-current)
# Check if the current branch follows the naming pattern 'workYYYYMMDDHHMMSS'
if [[ $current_branch =~ ^work[0-9]{14}$ ]]; then
# Extract the datetime part from the branch name
datetime_part=${current_branch:4}
# Construct the parent branch name
parent_branch="main$datetime_part"
# Check if the parent branch exists in the remote repository
if git show-ref --verify --quiet "refs/remotes/origin/$parent_branch"; then
# Parent branch exists, so create a pull request
echo "Merging from $parent_branch to $current_branch..."
git merge "origin/$parent_branch"
else
echo "Parent branch $parent_branch does not exist in the remote repository."
exit 1
fi
else
echo "The current branch name does not follow the expected naming pattern."
exit 1
fi