ref: e43ded677ea2a176f637ce90a6fa1b2ec038d09b
dir: /pull/
#!/bin/rc -e rfork en . /sys/lib/git/common.rc fn update{ branch=$1 upstream=$2 url=$3 dir=$4 bflag=() if(! ~ $branch '') bflag=(-b $branch) {/$cputype/bin/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 flagfmt='a:allbranch, b:branch branch, f:fetchonly, u:upstream upstream, q:quiet' args='' eval `''{aux/getflags $*} || exec aux/usage if(~ $#branch 0) branch=refs/`{/$cputype/bin/git/branch} if(~ $allbranch 1) branch='' if(~ $#upstream 0) upstream=origin remote=`{/$cputype/bin/git/conf 'remote "'$upstream'".url'} if(~ $#remote 0) die 'no remote to pull from' update $branch $upstream $remote if (~ $fetchonly 1) exit local=`{//$cputype/bin/git/branch} remote=`{/$cputype/bin/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(~ `{/$cputype/bin/git/query HEAD $remote @} `{/$cputype/bin/git/query $remote}){ echo 'up to date' >[1=2] exit } # The remote repository and our HEAD have diverged: we # need to merge. if(! ~ `{/$cputype/bin/git/query HEAD $remote @} `{/$cputype/bin/git/query HEAD}){ >[1=2]{ echo ours: `{/$cputype/bin/git/query HEAD} echo theirs: `{/$cputype/bin/git/query $remote} echo common: `{/$cputype/bin/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) /$cputype/bin/git/log -s -e $local'..'$remote >[1=2] echo echo $remote':' `{/$cputype/bin/git/query $local} '=>' `{/$cputype/bin/git/query $remote} >[1=2] /$cputype/bin/git/branch -n -b $remote $local exit ''