Repository navigation
Expand file tree
/
Copy pathv
More file actions
executable file
·140 lines (133 loc) · 3.34 KB
/
Copy pathv
File metadata and controls
executable file
·140 lines (133 loc) · 3.34 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
#!/bin/sh
# DWIM cvs/svn/whatever wrapper.
# (public domain) 2008, 2009 Christoph Berg <cb@df7cb.de>
# One of the scripts I should have written years ago.
set -eu
try_vcs_dir ()
{
dir="$1"
#echo "Looking in $dir ..."
if [ -e $dir/.git ] ; then
VCS=git
elif [ -d $dir/.svn ] ; then
VCS=svn
elif [ -d $dir/.hg ] ; then
VCS=hg
elif [ -d $dir/.bzr ] ; then
VCS=bzr
elif [ -d $dir/CVS ] ; then
VCS=cvs
else
return 1
fi
return 0
}
find_vcs ()
{
for dir in . .. ../.. ../../.. ../../../.. ../../../../.. ../../../../../..; do
if try_vcs_dir $dir; then
#echo "Found $VCS in $dir"
return 0
fi
done
echo "No VCS found" 1>&2
exit 1
}
b=$(basename $0)
case $b in
v)
command="$1"
test "$command" && shift
;;
*)
command="$b"
;;
esac
find_vcs
case $command in
br|branch) $VCS branch "$@" ;;
cdi|cdiff) case $VCS in
git) GIT_EXTERNAL_DIFF=git-context-diff git diff "$@" ;;
*) echo "Not supported yet" >&2 ;;
esac ;;
ci|cia|com|commit) case $VCS in
bzr) $VCS $command "$@" && {
read -p "Push? y:yes [y] " push
case $push in
"") $VCS push ;;
y|p) $VCS push ;;
esac
} ;;
hg) hg $command "$@" && hg push ;;
git) $VCS $command "$@" && {
read -p "Push? y:yes r:pull --rebase and push [y] " push
case $push in
"") $VCS push ;;
y|p) $VCS push ;;
r) $VCS pull --stat --rebase && $VCS push ;;
esac
} ;;
*) $VCS $command "$@" ;;
esac ;;
di|diff) if [ "$VCS" != git ] && [ -t 1 ] && [ -x /usr/bin/colordiff ] ; then
$VCS $command "$@" | colordiff
else
$VCS $command "$@"
fi ;;
wd|wdi|wdiff) case $VCS in
git) git diff --color-words "$@" ;;
svn) svn diff --diff-cmd wdiff.sh "$@" ;;
*) $VCS diff "$@" | wdiff -d ;;
esac ;;
pull) case $VCS in
hg) hg pull -u "$@" ;;
svn) [ "$1" = "-u" ] && shift
svn update "$@" ;;
*) $VCS $command "$@" ;;
esac ;;
push) case $VCS in
#git) $VCS $command "$@" && git push --tags ;;
*) $VCS $command "$@" ;;
esac ;;
revert) case $VCS in
git) $VCS co -- "$@" ;;
*) $VCS $command "$@" ;;
esac ;;
st|status|sti) case $VCS in
cvs) cvs update "$@" ;;
*) $VCS $command "$@" ;;
esac ;;
# default action
up|update|"") case $VCS in
bzr) bzr pull "$@" ;;
hg) hg pull -u "$@" ;;
git)
git pull --prune "$@"
# fast-forward Debian packaging branches
current_branch=$(git symbolic-ref --short HEAD)
for branch in master experimental upstream upstream/latest upstream/master debian/upstream pristine-lfs pristine-tar; do
[ "$branch" = "$current_branch" ] && continue # skip currently checked out branch
origin=$(git rev-parse --verify origin/$branch 2> /dev/null) || continue
mine=$(git rev-parse --verify $branch 2> /dev/null || :) # branch might not exist yet
if [ "$mine" != "$origin" ]; then
if [ -z "$mine" ] || git merge-base --is-ancestor $mine $origin; then
echo "+ Updating $branch $mine..$origin"
git update-ref refs/heads/$branch $origin $mine
elif git merge-base --is-ancestor $origin $mine; then
echo "+ $branch is ahead of origin/$branch"
else
echo "+ $branch cannot be fast-forwarded"
exit 1
fi
else
echo "+ $branch is up-to-date"
fi
done
;;
*) $VCS update "$@" ;;
esac ;;
add|blame|co|cp|info|log|mv|resolved|revert|rm)
$VCS $command "$@" ;;
*) #echo "$0: $VCS command '$command' not recognized. YMMV." 1>&2
$VCS "$command" "$@" ;;
esac