#!/bin/sh # @(#) unified command line access to CVS, SVN, GIT # Copyright (c) 2008..2010 by Dirk Jagdmann # # This software is provided 'as-is', without any express or implied # warranty. In no event will the authors be held liable for any damages # arising from the use of this software. # # Permission is granted to anyone to use this software for any purpose, # including commercial applications, and to alter it and redistribute it # freely, subject to the following restrictions: # # 1. The origin of this software must not be misrepresented; you # must not claim that you wrote the original software. If you use # this software in a product, an acknowledgment in the product # documentation would be appreciated but is not required. # # 2. Altered source versions must be plainly marked as such, and # must not be misrepresented as being the original software. # # 3. This notice may not be removed or altered from any source # distribution. # Version 2010-05-20 if [ "$1" = diffl -o "$1" = dil ] ; then shift $0 diff "$@" | less exit 0 fi if [ -d CVS ] ; then if [ "$1" = status -o "$1" = stat -o "$1" = st ] ; then perl <<'EOF' open(A, 'cvs status 2>&1 |') or die "could not execute 'cvs status'"; while() { if(/cvs status: Examining (.+)\s*$/) { if($1 eq ".") { $dir=""; } else { $dir=$1; } } if(/File\:\s+(.+?)\s+(Status\:.+)\s*$/) { next if $2 eq 'Status: Up-to-date'; print "$dir/" if $dir; print "$1\t$2\n"; } if(/^\?/) { print; } } EOF elif [ "$1" = diff -o "$1" = di ] ; then shift cvs diff -u "$@" 2>/dev/null elif [ "$1" = rm -o "$1" = del -o "$1" = delete -o "$1" = remove ] ; then shift cvs rm -f "$@" elif [ "$1" = mv -o "$1" = ren -o "$1" = rename -o "$1" = move ] ; then shift if [ $# -lt 2 ] ; then echo "usage: vc move " exit 1 fi if [ ! -f "$1" ] ; then echo "could not find $1" exit 1 fi if [ -f "$2" ] ; then echo "$2 already exists" exit 1 fi cp "$1" "$2" || exit 1 cvs add "$2" || exit 1 cvs rm -f "$1" elif [ "$1" = cp -o "$1" = copy ] ; then shift if [ $# -lt 2 ] ; then echo "usage: vc copy " exit 1 fi if [ ! -f "$1" ] ; then echo "could not find $1" exit 1 fi if [ -f "$2" ] ; then echo "$2 already exists" exit 1 fi cp "$1" "$2" || exit 1 cvs add "$2" || exit 1 elif [ "$1" = mkdir ] ; then if [ -z "$2" -o -x "$2" ] ; then echo "usage: vc mkdir " exit 1 fi mkdir "$2" || exit 1 cvs add "$2" elif [ "$1" = revert ] ; then if [ -z "$2" -o ! -f "$2" ] ; then echo "usage: vc revert " exit 1 fi rm -f "$2" cvs up "$2" elif [ "$1" = add ] ; then shift for i in "$@"; do cvs add "$i" done elif [ "$1" = update -o "$1" = up ] ; then shift cvs up -dP "$@" else cvs "$@" fi elif [ -d .svn ] ; then svn "$@" elif [ -d .git ] ; then if [ "$1" = ci -o "$1" = commit ] ; then shift git commit -a "$@" elif [ "$1" = st -o "$1" = stat ] ; then shift git status "$@" elif [ "$1" = up -o "$1" = update ] ; then shift git pull "$@" elif [ "$1" = di -o "$1" = diff ] ; then echo "==================" echo "===== CACHED =====" echo "==================" git diff --cached echo "=========================" echo "===== NOT YET ADDED =====" echo "=========================" git diff elif [ "$1" = rename ] ; then shift git mv "$@" else git "$@" fi else echo no version control found here exit 1 fi