Skip to content

Commit 882df20

Browse files
committed
Add upmerge script
1 parent 5a23d43 commit 882df20

2 files changed

Lines changed: 75 additions & 0 deletions

File tree

Git/podspec-merge-driver.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python
2+
3+
import difflib
4+
import sys
5+
6+
def extract_hunks(unified_diff):
7+
hunks = []
8+
hunk = []
9+
10+
for diff in unified_diff:
11+
# Strip out all whitespace characters
12+
line = "".join(diff.split())
13+
14+
if line == '---' or line == '+++':
15+
continue
16+
elif line.startswith('@@'):
17+
if len(hunk) > 0 :
18+
hunks.append(hunk)
19+
hunk = []
20+
else:
21+
hunk.append(line)
22+
23+
if len(hunk) > 0:
24+
hunks.append(hunk)
25+
26+
return hunks
27+
28+
def check_for_only_version_change(hunks):
29+
# If only version is changed, we will have only one hunk
30+
if len(hunks) > 1:
31+
return False
32+
33+
hunk = hunks[0]
34+
35+
# Make sure the hunk only contains the version change
36+
for line in hunk:
37+
if not '.version=' in line:
38+
return False
39+
40+
return True
41+
42+
43+
# Create unified diff between ancestor podpsec and other
44+
diff = difflib.unified_diff(open(sys.argv[1]).readlines() ,open(sys.argv[3]).readlines(), n=0)
45+
hunks = extract_hunks(diff)
46+
47+
if check_for_only_version_change(hunks) == True:
48+
# If only versions are different, we will just take the current version
49+
sys.exit(0)
50+
else:
51+
# Other differences require manual merge
52+
sys.exit(1)

Git/upmerge.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
if [ "$#" -ne 2 ]; then
4+
echo "Wrong number of parameters, should be <source branch> <destination branch>. Example: ./upmerge.sh 12.2 13.2"
5+
exit 1
6+
fi
7+
8+
if [[ -n $(git status -s) ]]; then
9+
echo "Git tree is dirty, please commit changes before upmerging"
10+
exit 1
11+
fi
12+
13+
git checkout origin/$2/master
14+
15+
git checkout -b $2/upmerge
16+
17+
git config merge.ours-driver.driver true
18+
git config merge.podspec-merge-driver.driver "./Submodules/SMF-iOS-CommonProjectSetupFiles/Git/podspec-merge-driver.py %O %A %B"
19+
20+
git merge origin/$1/master --no-edit
21+
22+
git config --unset merge.ours-driver.driver
23+
git config --unset merge.podspec-merge-driver

0 commit comments

Comments
 (0)