-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbranch.sh
69 lines (57 loc) · 1.48 KB
/
dbranch.sh
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
#!/bin/bash
#2 branches
#assumes both branches are updated
#specify file type eg. *
#This will find all files recursively beneath the current directory that match the name given as
#the first input.
#Explicitly skips the contents of .git, node_modules, and target directories.
#Explicitly skips .dbranches files.
function findAllFiles() {
find . -name "*${1}" \
! -name "*.dbranches" \
-not -path "*/.git/*" \
-not -path "*/node_modules/*" \
-not -path "*/target/*"
}
#deprecated because this skips empty files. ALL files that are not explicitly excluded should be found.
function findAllOfType() {
grep --include=\*${1} --exclude=\*.dbranches -rl '.'
}
function getBranch() {
git checkout ${1}
}
function stashChanges() {
git stash
}
function popChanges() {
git stash pop
}
function updateBranch() {
git pull -r
}
function contextDiff() {
diff -U 0 $1 $2
}
function currentBranch() {
git rev-parse --abbrev-ref HEAD
}
function dbranchCleanup() {
rm -v *.dbranches
}
function dbranches() {
#TODO: check arguments before running program args as follows
#$1 first branch
#$2 second branch
#$3 filename
cbranch=$(currentBranch > /dev/null 2>&1; echo $?)
stashChanges > /dev/null
getBranch $1
updateBranch
findAllFiles $3 > 1.dbranches
getBranch $2
updateBranch
findAllFiles $3 > 2.dbranches
getBranch ${cbranch}
popChanges > /dev/null
contextDiff 1.dbranches 2.dbranches
}