-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
135 lines (118 loc) · 2.98 KB
/
setup.sh
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/sh
pwd=$(pwd)
# We now have these branches:
# A topic
# /
# B---C---D main
# This script can re-create 3 scenarios
if [ $# -eq 0 ]; then
echo "Please provide a number 1, 2 or 3:"
echo ""
echo " sh $0 1"
echo ""
echo "Each number will prepare a specific scenario for you to try."
echo "This will *destroy* your local remote location."
echo
echo "1:"
echo "Both your local and the remote have commits."
echo "Trying to pull from the remote will result in an unresolved merge."
echo
echo "2:"
echo "Your local has uncommitted changes and the remote has commits."
echo "Trying to pull from the remote will result in an unresolved merge."
echo
echo "3:"
echo "Both your local and the remote have commits."
echo "Trying to push to the remote will result in an error."
exit 1
fi
case $1 in
1|2|3)
option=$1
;;
*)
echo "Unknown option? $1"
exit 1
;;
esac
# Create a new clone of this repo
dir=$(pwd)/.fake_remote
if [ ! -d $dir ]; then
# initialize the directory
# as a copy of this one
git init $dir
cd $dir
git remote add origin $pwd
git fetch origin
git checkout -b main origin/main
git checkout -b topic origin/topic
cd ..
(
cd $dir
git checkout topic
# 1: we move topic to main1
git branch main1 topic
# 2: we move topic to main2
git branch main2 topic
# 3: we move main~1 into main3
git branch main3 main~1
git checkout main
) > /dev/null 2>/dev/null
echo "Done setting up the fake remote repository"
fi
if ! git remote show host >/dev/null 2>/dev/null ; then
# ensure the remote exists
git remote add host $dir
git fetch host
fi
# 1.
# You are trying to pull down a remote that has commits and you have too
# git switch main
# git pull host
if [ $option -eq 1 ]; then
# run things locally
git branch main1 main
git switch main1
git branch -u host/main1 main1
echo ""
echo "Now run:"
echo " git pull host"
echo "And to see why it happened:"
echo " git status"
fi
# 2.
# You are trying to pull down a remote where you have local uncommitted
# changes.
# git switch main
# echo "" >> file
# git commit ...
# git push host
if [ $option -eq 2 ]; then
# run things locally
git branch main2 main
git switch main2
git branch -u host/main2 main2
echo ""
echo "Now run:"
echo " git push host"
echo "And to see why it happened:"
echo " git status"
fi
# 3.
# You are trying to pull commits but you have local uncommitted changes
# git switch main
# echo "" >> file
# git pull host
if [ $option -eq 3 ]; then
# run things locally
git branch main3 main~1
git switch main3
git branch -u host/main3 main3
echo "Adding something to src/source_2.py"
echo "erroneous edit: " >> src/source_2.py
echo ""
echo "Now run:"
echo " git pull host"
echo "And to see why it happened:"
echo " git status"
fi