forked from oridb/git9
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpull
executable file
·107 lines (98 loc) · 2.07 KB
/
pull
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
#!/bin/rc -e
rfork en
. /sys/lib/git/common.rc
usage='
git/pull [-u upstream] [-b branch]
-b work with branch "branch"
-f fetch updates without checking out
-i display incoming commits
-u pull from "upstream" (default "origin")
'
fn update{
branch=$1
upstream=$2
url=$3
dir=$4
bflag=()
if(! ~ $branch '')
bflag=(-b $branch)
{git/fetch $bflag -u $upstream $url >[2=3] || die $status} | awk '
/^remote/{
if($2=="HEAD")
next
ref=$2
hash=$3
gsub("^refs/heads", "refs/remotes/'$upstream'", ref)
outfile = ".git/"ref
system("mkdir -p `{basename -d "outfile"}");
print hash > outfile;
close(outfile);
}
' |[3] tr '\x0d' '\x0a'
}
gitup
branch=refs/`{git/branch}
remote=()
incoming=true
checkout='true'
upstream=origin
while(~ $1 -*){
switch($1){
case -u
upstream=$2
remote=`{git/conf 'remote "'$upstream'".url'}
if(~ $#remote 0){
upstream=SOMEONE
remote=$2
}
shift
case -b
branch=$2
shift
case -a
branch=''
case -f
checkout=()
case -q
incoming=()
case *
usage
}
shift
}
if(! ~ $#* 0)
usage
if(~ $#remote 0)
remote=`{git/conf 'remote "'$upstream'".url'}
if(~ $#remote 0)
die 'no remote to pull from'
update $branch $upstream $remote
if (~ $#checkout 0)
exit
local=`{git/branch}
remote=`{git/branch | subst '^(refs/)?heads' 'remotes/'$upstream}
# we have local commits, but the remote hasn't changed.
# in this case, we want to keep the local commits untouched.
if(~ `{git/query HEAD $remote @} `{git/query $remote}){
echo 'up to date' >[1=2]
exit
}
# The remote repository and our HEAD have diverged: we
# need to merge.
if(! ~ `{git/query HEAD $remote @} `{git/query HEAD}){
>[1=2]{
echo ours: `{git/query HEAD}
echo theirs: `{git/query $remote}
echo common: `{git/query HEAD $remote @}
echo git/merge $remote
}
exit diverged
}
# The remote is directly ahead of the local, and we have
# no local commits that need merging.
if(! ~ $#incoming 0)
git/log -s -e $local'..'$remote >[1=2]
echo
echo $remote':' `{git/query $local} '=>' `{git/query $remote} >[1=2]
git/branch -n -b $remote $local
exit ''