Skip to content

Commit 0034088

Browse files
committed
fix logic errors in main.sh
1 parent cb08e30 commit 0034088

File tree

1 file changed

+104
-73
lines changed

1 file changed

+104
-73
lines changed

generate_patches/main.sh

Lines changed: 104 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set -e
44

55
branch="main"
66
local_patch_path="/Users/marion/dev/git_local/Code/patchrepo"
7+
debug_flag="0"
78

89
# These are the required components to generate all the cases:
910
patch_1988="$local_patch_path/1988/${branch}_1988.patch"
@@ -45,32 +46,45 @@ cto_no_switcher="$local_patch_path/customtypeone_looppatches/cto_no_switcher.pat
4546
# must already be here: cd Loop_main/LoopWorkspace
4647

4748
function git_cleanup_submodule() {
48-
local submodule_path=$1
49+
local submodule_path=$1
4950

50-
echo "Cleaning up $submodule_path..."
51-
cd $submodule_path
52-
git clean -fd
53-
git branch --format='%(refname:short)' | grep -v 'HEAD detached at' | grep -v "dev" | xargs -r git branch -D
54-
cd ..
51+
echo "Cleaning up $submodule_path..."
52+
cd $submodule_path
53+
git clean -fd
54+
git branch --format='%(refname:short)' | grep -v 'HEAD detached at' | grep -v "${branch}" | xargs -r git branch -D
55+
if [[ $debug_flag -eq "1" ]]; then
56+
echo " *** git_cleanup_submodule completed for $submodule_path"
57+
git status
58+
fi
59+
cd ..
5560
}
5661

57-
# Reset the LoopWorkspace repository
58-
function reset_workspace() {
59-
local branch=$1
62+
# Restore the LoopWorkspace to original
63+
function restore_workspace() {
64+
git checkout ${branch}
65+
git submodule update
6066
git clean -fd
6167
git fetch origin
6268
git reset --hard origin/$branch
6369
git submodule update --init --recursive --force
70+
git branch --format='%(refname:short)' | grep -v 'HEAD detached at' | grep -v "${branch}" | xargs -r git branch -D
6471

6572
# Clean up the repositories
6673
git_cleanup_submodule Loop
6774
git_cleanup_submodule LoopKit
75+
if [[ "$debug_flag" -eq "1" ]]; then
76+
echo " *** restore_workspace completed"
77+
git status -v
78+
fi
6879
}
6980

7081

7182
create_patch() {
7283
local patch_name="$1"
73-
git diff --submodule=diff | sed 's/[[:space:]]*$//' > "$patch_name"
84+
if [[ "$debug_flag" -eq "1" ]]; then
85+
echo " *** create_patch for $patch_name"
86+
fi
87+
git diff tmp1 tmp2 --submodule=diff | sed 's/[[:space:]]*$//' > "$patch_name"
7488
}
7589

7690
apply_patch() {
@@ -83,110 +97,127 @@ reverse_patch() {
8397
git apply --whitespace=nowarn "${patch_name}" --reverse
8498
}
8599

86-
commit() {
100+
commit_tmp1() {
87101
if [[ $# -eq 0 ]]; then
88102
# No arguments, commit in the current directory
89103
git add .
104+
git switch -c tmp1
90105
git commit -m "commit"
91106
else
92107
# There are arguments, treat each one as a submodule
93108
for submodule in "$@"
94109
do
95110
cd "$submodule"
96111
git add .
97-
git switch -c tmp
112+
git switch -c tmp1
98113
git commit -m "commit"
99114
cd ..
100115
done
101116
fi
102117
}
103118

119+
commit_tmp2() {
120+
if [[ $# -eq 0 ]]; then
121+
# No arguments, commit in the current directory
122+
git add .
123+
git switch -c tmp2
124+
git commit -m "commit"
125+
else
126+
# There are arguments, treat each one as a submodule
127+
for submodule in "$@"
128+
do
129+
cd "$submodule"
130+
git add .
131+
git switch -c tmp2
132+
git commit -m "commit"
133+
cd ..
134+
done
135+
fi
136+
}
104137

105138
#############################
106139
echo "1988 based on 2008 = combined_1988_2008"
107140
# current state is 2008, create patch to add 1988
108141
#############################
109-
reset_workspace ${branch}
110-
apply_patch $patch_2008
111-
112-
# commit this so we can reverse patch
113-
commit Loop
114-
115-
# now reverse that same patch
116-
reverse_patch $patch_2008
117-
118-
# add in new patch
119-
apply_patch $combined_1988_2008
120-
142+
this_patch="$local_patch_path/1988/${branch}_1988_2008.patch"
143+
restore_workspace
144+
# configure initial state and commit
145+
apply_patch "$patch_2008"
146+
commit_tmp1 Loop
147+
commit_tmp1
148+
# reverse state
149+
reverse_patch "$patch_2008"
150+
# modify to desired configuration and commit
151+
apply_patch "$combined_1988_2008"
152+
commit_tmp2 Loop
153+
commit_tmp2
121154
# create the patch
122-
cd Loop; git add .; cd ..
123-
create_patch "$local_patch_path/1988/${branch}_1988_2008.patch"
155+
create_patch "$this_patch"
124156

125157

126158
#############################
127159
echo "2008 based on 1988 -> combined_1988_2008"
128160
# current state is 1988, create patch to add 2008
129161
#############################
130-
reset_workspace ${branch}
131-
apply_patch $patch_1988
132-
133-
# commit this so we can reverse patch
134-
commit Loop
135-
136-
# now reverse that same patch
137-
reverse_patch $patch_1988
138-
139-
# add in new patch
140-
apply_patch $combined_1988_2008
141-
162+
this_patch="$local_patch_path/2008/${branch}_2008_1988.patch"
163+
restore_workspace
164+
# configure initial state and commit
165+
apply_patch "$patch_1988"
166+
commit_tmp1 Loop
167+
commit_tmp1
168+
# reverse state
169+
reverse_patch "$patch_1988"
170+
# modify to desired configuration and commit
171+
apply_patch "$combined_1988_2008"
172+
commit_tmp2 Loop
173+
commit_tmp2
142174
# create the patch
143-
cd Loop; git add .; cd ..
144-
create_patch "$local_patch_path/2008/${branch}_2008_1988.patch"
175+
create_patch "$this_patch"
145176

146177

147178
#############################
148179
echo "1988 over original cto"
149180
# current state is original cto, create patch to add 1988
150181
# with cto_no_switcher
151182
#############################
152-
reset_workspace ${branch}
153-
#Set workspace cto original
154-
apply_patch $cto_original
155-
commit Loop LoopKit
156-
157-
#Remove original cto
158-
git apply --reverse $cto_original
159-
160-
# add in 1988 and cto_no_switcher
161-
apply_patch $patch_1988
162-
apply_patch $cto_no_switcher
163-
183+
this_patch="$local_patch_path/1988/${branch}_1988_cto.patch"
184+
restore_workspace
185+
# configure initial state and commit
186+
apply_patch "$cto_original"
187+
commit_tmp1 Loop LoopKit
188+
commit_tmp1
189+
# reverse state
190+
reverse_patch "$cto_original"
191+
# modify to desired configuration and commit
192+
apply_patch "$patch_1988"
193+
apply_patch "$cto_no_switcher"
194+
commit_tmp2 Loop
195+
commit_tmp2
164196
# create the patch
165-
cd Loop; git add .; cd ..
166-
cd LoopKit; git add .; cd ..
167-
create_patch "$local_patch_path/1988/${branch}_1988_cto.patch"
197+
create_patch "$this_patch"
168198

169199
#############################
170200
echo "1988 over original cto + 2008"
171201
# current state is original cto + 2008,
172202
# create patch to add 1988 with cto_no_switcher
173203
#############################
174-
reset_workspace ${branch}
175-
176-
#Set workspace cto original with 2008
177-
apply_patch $cto_original
178-
apply_patch $patch_2008
179-
commit Loop LoopKit
180-
181-
#Remove original cto and 2008
182-
git apply --reverse $cto_original
183-
git apply --reverse $patch_2008
184-
185-
# add 1988 and 2008 and cto_no_switcher
186-
apply_patch $combined_1988_2008
187-
apply_patch $cto_no_switcher
188-
204+
this_patch="$local_patch_path/1988/${branch}_1988_2008_cto.patch"
205+
restore_workspace
206+
# configure initial state and commit
207+
apply_patch "$cto_original"
208+
apply_patch "$patch_2008"
209+
commit_tmp1 Loop LoopKit
210+
commit_tmp1
211+
# reverse state
212+
reverse_patch "$patch_2008"
213+
reverse_patch "$cto_original"
214+
# modify to desired configuration and commit
215+
apply_patch "$combined_1988_2008"
216+
apply_patch "$cto_no_switcher"
217+
commit_tmp2 Loop
218+
commit_tmp2
189219
# create the patch
190-
cd Loop; git add .; cd ..
191-
cd LoopKit; git add .; cd ..
192-
create_patch "$local_patch_path/1988/${branch}_1988_2008_cto.patch"
220+
create_patch "$this_patch"
221+
222+
########### restore before leaving #########
223+
restore_workspace

0 commit comments

Comments
 (0)