-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdownstream.sh
More file actions
65 lines (53 loc) · 2.21 KB
/
Copy pathdownstream.sh
File metadata and controls
65 lines (53 loc) · 2.21 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
#!/usr/bin/env bash
set -o errexit
set -o pipefail
set -o nounset
url_monorepo="git@github.com:shapediver/MonorepoTemplate.git"
remote_name="monorepo"
remote_branch="master"
# Stop when repo is dirty
if [ -n "$(git diff --shortstat)" ]; then
echo "ERROR: Detected uncommitted changes in this repository." >&2
exit 1
fi
# Add the Monorepo Template remote
if ! git remote add "${remote_name}" "${url_monorepo}" 2>/dev/null; then
echo "ERROR: Git remote of name '${remote_name}' already exists!"
exit 1
fi
cleanup() {
# Remove remote - this also removes the fetched branch
git remote remove "${remote_name}"
}
trap 'cleanup' ERR EXIT
# Just to make sure, prevent pushing to the new remote
git remote set-url --push "${remote_name}" no_push
# Fetch the newest changes
git fetch "${remote_name}" "${remote_branch}"
# Merge the changes - this will most likely lead to conflicts!
# Since a non-zero exit code is returned when conflicts appear, we prevent the script from stopping.
git merge --log --allow-unrelated-histories --squash "${remote_name}/${remote_branch}" || :
# If there are merge conflicts, wait for the user to resolve them
if [ -n "$(git ls-files --unmerged)" ]; then
echo -e "\nMERGE CONFLICTS DETECTED!"
echo "Please resolve all conflicts manually before continuing the script."
read -p "Press [Enter] key to resume ..."
# Prevent the user from continuing without resolving all conflicts
while [ -n "$(git ls-files --unmerged)" ]; do
echo -e "\nStill found some open conflicts - resolve them before continuing the script."
read -p "Press [Enter] key to resume ..."
done
fi
# Add all tracked files
git add --update
# If there are any untracked files, ask the user what to do with them
if [ -n "$(git ls-files --other --directory --exclude-standard)" ]; then
echo -e "\nDETECTED UNTRACKED FILES!"
echo -e "The following untracked files have been found:\n"
git ls-files --other --directory --exclude-standard
echo -e "\nIf you want to add one or more of these files to the merge, add them via 'git add <file_path>'."
echo "Otherwise, these files will stay untracked."
read -p "Press [Enter] key to resume ..."
fi
# Finalize the merge
git commit -m "Downstream changes from MonorepoTemplate" --no-verify