forked from scheib/git-config
-
Notifications
You must be signed in to change notification settings - Fork 1
/
git-functions
40 lines (37 loc) · 1.48 KB
/
git-functions
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
#!/bin/bash
# meldgit and variants open meld with an editable comparison of a file and
# it's version from HEAD, upstream, or origin.
meldgit () { (meldgit-implementation HEAD $1) }
meldgitupstream () { (meldgit-implementation $(git merge-base @{upstream} HEAD) $1) }
meldgitorigin () { (meldgit-implementation $(git merge-base origin/HEAD HEAD) $1) }
meldgitish () { (meldgit-implementation $1 $2) }
meldgitall () { (meldgitall-implementation HEAD) }
meldgitupstreamall () { (meldgitall-implementation $(git merge-base @{upstream} HEAD)) }
meldgitoriginall () { (meldgitall-implementation $(git merge-base origin/HEAD HEAD)) }
meldgitishall () { (meldgitall-implementation $1) }
# Why not just git difftool? Because if the file has no edits yet it won't launch a diff.
# git difftool --tool meld HEAD:$(git ls-files --full-name -- $1) $1
meldgit-implementation () {
base_branch=$1
file=$2
if [ "$file." == "." ]; then
echo specify a file
else
meld <(git show $base_branch:$(git ls-files --full-name -- $file)) $file
fi
}
meldgitall-implementation () {
base_branch=$1
if [ "base_branch." == "." ]; then
echo specify a base_branch for git diff
else
gitnames=$(git diff --name-only $base_branch)
for file in $gitnames; do
read -p "meldgit $file [Yy]? " -n 1
if [[ $REPLY != "" ]]; then echo; fi
if [[ $REPLY =~ ^[Yy]$ ]] || [[ $REPLY == "" ]]; then
meldgit-implementation $base_branch $file &
fi
done
fi
}