-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmerge631.sh
More file actions
155 lines (135 loc) · 3.33 KB
/
merge631.sh
File metadata and controls
155 lines (135 loc) · 3.33 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/sh
checkout()
{
echo "Checking out $1";
git checkout $1;
}
pull()
{
echo "Pulling for $1";
git pull;
}
checkoutAndPull()
{
checkout $1;
pull $1;
}
recordOurDifferences()
{
echo "Matching files with pattern '$3'";
git diff --name-only $1 $2 | grep -i $3 > ${4}Ours.txt;
}
recordTheirDifferences()
{
echo "Inverse matching files with pattern '$3'";
git diff --name-only $1 $2 | grep -iv $3 > ${4}Theirs.txt;
}
move()
{
echo "Saving $1":
mv $1 ${1}.bak;
}
updateGitAttributes()
{
echo "Updating .gitattributes";
move ".gitattributes";
createAttributes $1;
}
addWithLine()
{
echo "$1" >> .gitattributes;
echo "" >> .gitattributes;
}
createAttributes()
{
diffs=$1;
echo "*.java text" > .gitattributes;
echo "" >> .gitattributes;
addWithLine "* text=auto";
ourFile=${diffs}Ours.txt;
theirFile=${diffs}Theirs.txt;
addFileToAttributes "$ourFile" "efx";
addFileToAttributes "$theirFile" "mine";
}
addFileToAttributes()
{
file=$1;
driver=$2;
for line in $(cat $file)
do
addWithLine "$line merge=$driver";
done
}
removeSpaces()
{
tr '\n' ' ' < $1 > $1.bak && mv $1.bak $1;
}
removeDeletedByUs()
{
file="deletedByUs.txt"
echo "Deleting items that are marked as deleted by us (non-MWP)";
git status --short |grep -iv mwp|grep ^DU|while read a b; do echo "$b";done > $file;
removeSpaces $file;
git rm $(cat $file);
}
removeAddedByThem()
{
file="addedByThem.txt"
echo "Deleting items that are marked as added by them (non-MWP)";
git status --short |grep -iv mwp|grep "^UA"|while read a b; do echo "$b";done > $file;
removeSpaces $file;
git rm $(cat $file);
}
removeExtraAdded()
{
file="extraAdded.txt"
echo "Deleting items that were added and not in MWP";
git status --short |grep -iv mwp|grep "^A "|while read a b; do echo "$b";done > $file;
removeSpaces $file;
git reset HEAD $(cat $file);
rm -r $(cat $file);
}
removeExtraModified()
{
file="extraAdded.txt"
echo "Deleting items that were modified and not in MWP";
git status --short |grep -iv mwp|grep "^M "|while read a b; do echo "$b";done > $file;
removeSpaces $file;
git reset HEAD $(cat $file);
}
removeExtraDeleted()
{
file="extraAdded.txt"
echo "Deleting items that were deleted and not in MWP";
git status --short |grep -iv mwp|grep "^D "|while read a b; do echo "$b";done > $file;
removeSpaces $file;
git reset HEAD $(cat $file);
rm -r $(cat $file);
}
fixConflicts()
{
removeDeletedByUs
removeAddedByThem
removeExtraAdded
removeExtraModified
removeExtraDeleted
}
mergeBranches()
{
# Assume a merge driver called "mine" has been configured.
from=$1;
to=$2;
diffs=diffs
echo "Merging from $from to $to";
checkoutAndPull $from;
checkoutAndPull $to;
recordOurDifferences $from $to mwp $diffs;
recordTheirDifferences $from $to mwp $diffs;
updateGitAttributes $diffs;
git merge $from;
fixConflicts
}
# Merge workplanner_4.0 to workplanner_4.0_6.3.1
#mergeBranches workplanner_4.0 workplanner_4.0_6.3.1;
# Merge workplanner to workplanner_6.3.1
mergeBranches workplanner workplanner_6.3.1