Skip to content

Commit aef0050

Browse files
committed
add generate patches tools for main and to reset workspace
1 parent 40c8c4b commit aef0050

File tree

2 files changed

+221
-0
lines changed

2 files changed

+221
-0
lines changed

generate_patches/main.sh

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
#!/bin/bash
2+
#set -x
3+
set -e
4+
5+
branch="main"
6+
local_patch_path="/Users/marion/dev/git_local/Code/patchrepo"
7+
8+
# These are the required components to generate all the cases:
9+
patch_1988="$local_patch_path/1988/${branch}_1988.patch"
10+
patch_2008="$local_patch_path/2008/${branch}_2008.patch"
11+
combined_1988_2008="$local_patch_path/generate_patches/components/${branch}_combined_1988_2008.patch"
12+
cto_original="$local_patch_path/customtypeone_looppatches/cto_original.patch"
13+
cto_no_switcher="$local_patch_path/customtypeone_looppatches/cto_no_switcher.patch"
14+
15+
16+
# prior to running, go to LoopWorkspace folder for main
17+
# make sure to source configure_alias_names so the sh script are run
18+
19+
20+
# diff with respect to dev.sh
21+
# cannot create patches automatically from the GitHub repositories
22+
# but, can use exiting main patches to create the combinations required
23+
# once each component is prepared
24+
# Components are:
25+
# 1988/main_1988.patch
26+
# 2008/main_2008.patch
27+
# generate_patches/main_components/main_combined_1988_2008.patch
28+
# customtypeone_looppatches/cto_original.patch
29+
# customtypeone_looppatches/cto_no_switcher.patch
30+
#
31+
# Final products are:
32+
# 1988:
33+
# main_1988.patch
34+
# main_1988_2008.patch
35+
# main_1988_2008_cto.patch
36+
# main_1988_cto.patch
37+
# 2008:
38+
# main_2008.patch
39+
# main_2008_1988.patch
40+
41+
# configure some stand alone sh scripts to use:
42+
# configure_alias_names
43+
# reset_workspace main
44+
45+
# must already be here: cd Loop_main/LoopWorkspace
46+
47+
function git_cleanup_submodule() {
48+
local submodule_path=$1
49+
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 ..
55+
}
56+
57+
# Reset the LoopWorkspace repository
58+
function reset_workspace() {
59+
local branch=$1
60+
git clean -fd
61+
git fetch origin
62+
git reset --hard origin/$branch
63+
git submodule update --init --recursive --force
64+
65+
# Clean up the repositories
66+
git_cleanup_submodule Loop
67+
git_cleanup_submodule LoopKit
68+
}
69+
70+
71+
create_patch() {
72+
local patch_name="$1"
73+
git diff --submodule=diff | sed 's/[[:space:]]*$//' > "$patch_name"
74+
}
75+
76+
apply_patch() {
77+
local patch_name="$1"
78+
git apply --whitespace=nowarn "${patch_name}"
79+
}
80+
81+
reverse_patch() {
82+
local patch_name="$1"
83+
git apply --whitespace=nowarn "${patch_name}" --reverse
84+
}
85+
86+
commit() {
87+
if [[ $# -eq 0 ]]; then
88+
# No arguments, commit in the current directory
89+
git add .
90+
git commit -m "commit"
91+
else
92+
# There are arguments, treat each one as a submodule
93+
for submodule in "$@"
94+
do
95+
cd "$submodule"
96+
git add .
97+
git switch -c tmp
98+
git commit -m "commit"
99+
cd ..
100+
done
101+
fi
102+
}
103+
104+
105+
#############################
106+
echo "1988 based on 2008 = combined_1988_2008"
107+
# current state is 2008, create patch to add 1988
108+
#############################
109+
reset_workspace ${branch}
110+
apply_patch $combined_1988_2008
111+
112+
# commit this so we can reverse patch
113+
commit Loop
114+
115+
# now reverse that same patch
116+
reverse_patch $combined_1988_2008
117+
118+
# add in new patch
119+
apply_patch $patch_2008
120+
121+
# create the patch
122+
cd Loop; git add .; cd ..
123+
create_patch "$local_patch_path/1988/${branch}_1988_2008.patch"
124+
125+
126+
#############################
127+
echo "2008 based on 1988 -> combined_1988_2008"
128+
# current state is 1988, create patch to add 2008
129+
#############################
130+
reset_workspace ${branch}
131+
apply_patch $combined_1988_2008
132+
133+
# commit this so we can reverse patch
134+
commit Loop
135+
136+
# now reverse that same patch
137+
reverse_patch $combined_1988_2008
138+
139+
# add in new patch
140+
apply_patch $patch_1988
141+
142+
# create the patch
143+
cd Loop; git add .; cd ..
144+
create_patch "$local_patch_path/2008/${branch}_2008_1988.patch"
145+
146+
147+
#############################
148+
echo "1988 over original cto"
149+
# current state is original cto, create patch to add 1988
150+
# with cto_no_switcher
151+
#############################
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+
164+
# 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"
168+
169+
#############################
170+
echo "1988 over original cto + 2008"
171+
# current state is original cto + 2008,
172+
# create patch to add 1988 with cto_no_switcher
173+
#############################
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+
189+
# 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"

generate_patches/reset_workspace.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
#set -x
3+
set -e
4+
5+
branch=$1
6+
echo "branch selected = ${branch}"
7+
8+
function git_cleanup_submodule() {
9+
local submodule_path=$1
10+
local branch=$2
11+
12+
echo "Cleaning up $submodule_path..."
13+
cd $submodule_path
14+
# Delete branches, but preserve ${branch}
15+
git branch --format='%(refname:short)' | grep -v 'HEAD detached at' | grep -v "${branch}" | xargs -r git branch -D
16+
git clean -fd
17+
cd ..
18+
}
19+
20+
# Reset the LoopWorkspace repository
21+
git clean -fd
22+
git fetch origin
23+
git reset --hard origin/$branch
24+
git submodule update --init --recursive --force
25+
26+
# Clean up the repositories
27+
git_cleanup_submodule Loop $branch
28+
git_cleanup_submodule LoopKit $branch
29+

0 commit comments

Comments
 (0)