2021-05-17 01:49:45 +00:00
|
|
|
#!/bin/rc -e
|
|
|
|
rfork en
|
|
|
|
. /sys/lib/git/common.rc
|
|
|
|
|
|
|
|
fn update{
|
2022-04-28 03:35:54 +00:00
|
|
|
upstream=$1
|
|
|
|
url=$2
|
|
|
|
dir=$3
|
2021-05-17 01:49:45 +00:00
|
|
|
dflag=()
|
|
|
|
if(! ~ $#debug 0)
|
|
|
|
dflag='-d'
|
2022-04-17 17:03:47 +00:00
|
|
|
{git/get $dflag -u $upstream $url >[2=3] || die $status} | awk '
|
2021-05-17 01:49:45 +00:00
|
|
|
/^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
|
|
|
|
|
2022-04-28 03:35:54 +00:00
|
|
|
flagfmt='d:debug, q:quiet, f:fetchonly,
|
|
|
|
u:upstream upstream'
|
2021-05-17 01:49:45 +00:00
|
|
|
args=''
|
|
|
|
eval `''{aux/getflags $*} || exec aux/usage
|
|
|
|
|
|
|
|
if(~ $#upstream 0)
|
|
|
|
upstream=origin
|
|
|
|
remote=`$nl{git/conf 'remote "'$upstream'".url'}
|
|
|
|
if(~ $#remote 0){
|
|
|
|
remote=$upstream
|
|
|
|
upstream=THEM
|
|
|
|
}
|
|
|
|
|
2022-04-28 03:35:54 +00:00
|
|
|
update $upstream $remote
|
2021-05-17 01:49:45 +00:00
|
|
|
if (~ $fetchonly 1)
|
|
|
|
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(~ $#quiet 0)
|
2021-08-17 04:31:15 +00:00
|
|
|
git/log -s -e $local'..'$remote
|
|
|
|
echo $remote':' `{git/query $local} '=>' `{git/query $remote}
|
2021-05-17 01:49:45 +00:00
|
|
|
git/branch -mnb $remote $local
|
|
|
|
exit ''
|