forked from eacousineau/util
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-emeld.sh
executable file
·113 lines (97 loc) · 1.71 KB
/
git-emeld.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
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
#!/bin/sh
# Variant of git-meld that uses git-new-workdir to compare so you can edit and commit changes on those branchs
# TODO Three-way merge?
bin_path=$0
bin=$(basename $bin_path)
usage()
{
echo "Usage: $bin [-t|--tool TOOL] [-d|--dir DIR] [-r|--remove] [-v|--verbose] REPO REV_A REV_B"
exit $1
}
die()
{
echo $1 >&2
exit 1
}
tool=meld
stdout=/dev/null
stderr=/dev/stderr
remove=
dir=
while [ $# -gt 0 ]
do
case $1 in
-t|--tool)
tool=$2
shift
;;
-v|--verbose)
stdout=/dev/stdout
;;
-h|--help)
usage 0
;;
-r|--remove)
remove=1
;;
-d|--dir)
dir=$2
shift
;;
*)
break
;;
esac
shift
done
repo=$1
rev_a=$2
rev_b=$3
# Need a way to resolve
rev_label_resolve()
{
# NOTE: Changes directory
cd $1
ref=$(git rev-parse --abbrev-ref $2)
if test "$ref" = "HEAD" -o -z "$ref"
then
# Use hash
ref=$(git rev-parse --short $2)
fi
echo $ref
}
rev_label_a=$(rev_label_resolve $repo $rev_a)
rev_label_b=$(rev_label_resolve $repo $rev_b)
if test "$rev_label_a" = "$rev_label_b"
then
echo "Both commits are the same ($rev_label_a). Aborting."
usage 1
fi
repo_setup()
{
new=$1
branch=$2
# Make leading structure for slashy branches
mkdir -p $(dirname $new)
git-new-workdir $repo $new $branch > $stdout 2> $stderr || die "Error with git-new-workdir"
}
if test -z "$dir"
then
# Create temporary directory
template="/tmp/git-emeld.XXXXX"
dir=$(mktemp -d $template)
fi
repo_a=$dir/$rev_label_a
repo_b=$dir/$rev_label_b
echo "A ($rev_label_a)\n\t$repo_a"
echo "B ($rev_label_b)\n\t$repo_b"
repo_setup $repo_a $rev_a
repo_setup $repo_b $rev_b
$tool $repo_a $repo_b
if test -n "$remove"
then
echo "Removing directory: $dir"
rm -rf $dir
else
echo "Keeping directory: $dir"
fi