Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Import the meat.

  • Loading branch information...
commit 2ef186829cf2029a3ee298fbc2bb7404b80da55a 1 parent 1fc96d5
@knu authored
Showing with 318 additions and 0 deletions.
  1. +44 −0 README.md
  2. +222 −0 bin/sup
  3. +52 −0 man/sup.1
View
44 README.md
@@ -0,0 +1,44 @@
+# sup - do <whatever SCM> update
+
+## NAME
+
+`sup(1) - do <whatever SCM> update`
+
+## SYNOPSIS
+
+```
+sup [<path>...]
+vcs [<path>...]
+```
+
+## DESCRIPTION
+
+`sup(1)` is a tool to just "update" a working directory using whatever
+SCM commands appropriate for the directory. Updating is performed for
+each given path, or the current directory if none is given.
+
+`sup` currently supports CVS (`cvs`), Subversion (`svn`), Git
+(`git`/`git-svn`), Mercurial (`hg`) and Bazaar (`bzr`).
+
+If called as `vcs`, the name of SCM detected is printed for each given
+path.
+
+## BUGS
+
+- The name obviously collides with the legendary tool "SUP"
+ (Software Upgrade Protocol).
+
+- `sup` calls `rebase` in Git instead of `merge` and there is no way
+ to configure that.
+
+- There is no command line option, no configuration and no nothing.
+
+## AUTHOR
+
+Copyright (c) 2008, 2009, 2012 Akinori MUSHA.
+
+Licensed under the 2-clause BSD license. See `LICENSE.txt` for
+details.
+
+Visit [GitHub Repository](https://github.com/knu/sup) for the latest
+information.
View
222 bin/sup
@@ -0,0 +1,222 @@
+#!/bin/sh
+#
+# sup(1) - do <whatever SCM> update
+#
+# Copyright (c) 2008, 2009, 2012 Akinori MUSHA
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+
+main () {
+ case "$(basename "$0")" in
+ sup)
+ sup "${@:-.}"
+ ;;
+ *)
+ vcs "${@:-.}"
+ ;;
+ esac
+}
+
+warn () {
+ echo "$0: $@" >&2
+}
+
+dir_of () {
+ local file="${1:-.}"; shift
+ if [ -d "$file" ]; then
+ echo "$file"
+ else
+ dirname "$file"
+ fi
+}
+
+vcs_of () {
+ local file="${1:-.}" dir; shift
+ (
+ dir="$(dir_of "$file")"
+
+ cd "$dir" || exit
+
+ if [ -d CVS ]; then
+ echo cvs
+ exit
+ fi
+
+ if [ -f config -a -d objects -a -d refs ]; then
+ case "$dir" in
+ ?*.git)
+ echo git-bare
+ exit
+ ;;
+ esac
+ fi
+
+ while :; do
+ if [ -d .git ]; then
+ if [ -d .git/svn ]; then
+ echo git-svn
+ else
+ echo git
+ fi
+ exit
+ elif [ -d .hg ]; then
+ echo hg
+ exit
+ elif [ -d .bzr ]; then
+ echo bzr
+ exit
+ elif [ -d .svn ]; then
+ echo svn
+ exit
+ fi
+
+ if [ "$(pwd)" = / ]; then
+ break
+ fi
+ cd -P ..
+ done
+ exit 1
+ )
+}
+
+setup () {
+ trap 'exit 129' 1
+ trap 'exit 130' 2
+ trap 'exit 131' 3
+ trap 'exit 143' 15
+}
+
+sup () {
+ local file ret=0
+
+ for file; do
+ do_sup "$(vcs_of "$file")" "$file" || ret="$?"
+ done
+
+ if [ $ret -gt 128 ]; then
+ if [ $ret -le 165 ]; then
+ kill -$((ret - 128)) $$
+ sleep 3
+ fi
+ exit "$ret"
+ fi
+
+ return $ret
+}
+
+do_sup () {
+ local vcs="$1" file="$2"
+ local dir="$(dir_of "$file")"
+ local ret=0
+
+ if [ -z "$vcs" ]; then
+ warn "VCS unknown"
+ return 1
+ fi
+
+ case "$vcs" in
+ svn)
+ echo "[Updating \`$file' with $vcs]"
+ ( setup; "$vcs" update "$file" )
+ ;;
+ cvs)
+ echo "[Updating \`$file' with $vcs]"
+ if [ -d "$file" ]; then
+ ( setup; cd "$file" && cvs update )
+ else
+ ( setup; cd "$dir" && cvs update "$(basename "$file")" )
+ fi
+ ;;
+ git|git-svn)
+ if [ "$vcs" = git ]; then
+ echo "[Updating \`$file' with $vcs]"
+ else
+ echo "[Updating \`$file' with git + $vcs]"
+ fi
+ ( setup; cd "$dir" && {
+ if [ "$vcs" = git-svn ]; then
+ git svn fetch || exit
+ fi
+ if git remote update; then
+ local="$(git symbolic-ref HEAD 2>/dev/null)"
+ if [ -n "$local" ]; then
+ remote="$(git for-each-ref --format='%(upstream:short)' "$local" 2>/dev/null)"
+ if [ -n "$remote" ]; then
+ git rebase "$remote" || exit
+ fi
+ fi
+ fi
+ git svn rebase -l
+ } )
+ ;;
+ git-bare)
+ echo "[Updating \`$file' with $vcs]"
+ ( setup; GIT_DIR="$dir" git fetch )
+ ;;
+ hg)
+ echo "[Updating \`$file' with $vcs]"
+ if [ -d "$file" ]; then
+ ( setup; cd "$file" && hg pull -u )
+ else
+ ( setup; cd "$dir" && {
+ hg pull
+ hg update "$file"
+ } )
+ fi
+ ;;
+ bzr)
+ echo "[Updating \`$file' with $vcs]"
+ if [ -d "$file" ]; then
+ ( setup; cd "$file" && bzr update && bzr merge )
+ else
+ ( setup; cd "$dir" && {
+ bzr update
+ bzr merge "$file"
+ } )
+ fi
+ ;;
+ *)
+ warn "Skipping \`$file'"
+ ;;
+ esac
+}
+
+vcs () {
+ local file ret=0
+
+ for file; do
+ local vcs="$(vcs_of "$file")"
+
+ if [ -z "$vcs" ]; then
+ warn "unknown"
+ ret=1
+ fi
+
+ echo "$vcs"
+ done
+
+ return "$ret"
+}
+
+main "$@"
View
52 man/sup.1
@@ -0,0 +1,52 @@
+.Dd April 3, 2012
+.Dt E 1
+.Os FreeBSD
+.Sh NAME
+.Nm sup
+.Nd do <whatever SCM> update
+.Sh SYNOPSIS
+.Nm
+.Op Ar path ...
+.Sh DESCRIPTION
+.Nm
+is a tool to just
+.Qq update
+a working directory using whatever SCM commands appropriate for the
+directory. Updating is performed for each given path, or the current
+directory if none is given.
+.Pp
+.Nm
+currently supports CVS
+.Pq Sq Nm cvs ,
+Subversion
+.Pq Sq Nm svn ,
+Git
+.Pq So Nm git Sc Ns Pf / So Nm git-svn Sc ,
+Mercurial
+.Pq Sq Nm hg ,
+and Bazaar
+.Pq Sq Nm bzr .
+.Pp
+If called as
+.Sq Nm vcs ,
+the name of SCM detected is printed for each given path.
+.Sh BUGS
+.Bl -dash -compact
+.It
+The command name obviously collides with the legendary tool
+.Qq SUP
+.Pq Software Upgrade Protocol .
+.Pp
+.It
+.Nm
+calls
+.Sq rebase
+in updating a Git working directory instead of
+.Sq merge
+and there is no way to configure that.
+.Pp
+.It
+There is no command line option, no configuration and no nothing.
+.El
+.Sh AUTHOR
+.An Akinori MUSHA Aq knu@iDaemons.org
Please sign in to comment.
Something went wrong with that request. Please try again.