4
4
5
5
branch=" main"
6
6
local_patch_path=" /Users/marion/dev/git_local/Code/patchrepo"
7
+ debug_flag=" 0"
7
8
8
9
# These are the required components to generate all the cases:
9
10
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
45
46
# must already be here: cd Loop_main/LoopWorkspace
46
47
47
48
function git_cleanup_submodule() {
48
- local submodule_path=$1
49
+ local submodule_path=$1
49
50
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 ..
55
60
}
56
61
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
60
66
git clean -fd
61
67
git fetch origin
62
68
git reset --hard origin/$branch
63
69
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
64
71
65
72
# Clean up the repositories
66
73
git_cleanup_submodule Loop
67
74
git_cleanup_submodule LoopKit
75
+ if [[ " $debug_flag " -eq " 1" ]]; then
76
+ echo " *** restore_workspace completed"
77
+ git status -v
78
+ fi
68
79
}
69
80
70
81
71
82
create_patch () {
72
83
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 "
74
88
}
75
89
76
90
apply_patch () {
@@ -83,110 +97,127 @@ reverse_patch() {
83
97
git apply --whitespace=nowarn " ${patch_name} " --reverse
84
98
}
85
99
86
- commit () {
100
+ commit_tmp1 () {
87
101
if [[ $# -eq 0 ]]; then
88
102
# No arguments, commit in the current directory
89
103
git add .
104
+ git switch -c tmp1
90
105
git commit -m " commit"
91
106
else
92
107
# There are arguments, treat each one as a submodule
93
108
for submodule in " $@ "
94
109
do
95
110
cd " $submodule "
96
111
git add .
97
- git switch -c tmp
112
+ git switch -c tmp1
98
113
git commit -m " commit"
99
114
cd ..
100
115
done
101
116
fi
102
117
}
103
118
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
+ }
104
137
105
138
# ############################
106
139
echo " 1988 based on 2008 = combined_1988_2008"
107
140
# current state is 2008, create patch to add 1988
108
141
# ############################
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
121
154
# 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 "
124
156
125
157
126
158
# ############################
127
159
echo " 2008 based on 1988 -> combined_1988_2008"
128
160
# current state is 1988, create patch to add 2008
129
161
# ############################
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
142
174
# 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 "
145
176
146
177
147
178
# ############################
148
179
echo " 1988 over original cto"
149
180
# current state is original cto, create patch to add 1988
150
181
# with cto_no_switcher
151
182
# ############################
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
164
196
# 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 "
168
198
169
199
# ############################
170
200
echo " 1988 over original cto + 2008"
171
201
# current state is original cto + 2008,
172
202
# create patch to add 1988 with cto_no_switcher
173
203
# ############################
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
189
219
# 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