#!/bin/bash # @(#) unified command line access to CVS, SVN, GIT, Perforce, quilt # Copyright (c) 2008..2017 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 2017-05-05 # shortcut for "diff|less" which calls the vc program again. if [ "$1" = diffl -o "$1" = dil -o "$1" = diffless ] ; then shift $0 diff "$@" | less exit 0 fi # find out which version control we're using in the current working directory VC= if [ -d CVS ] ; then VC=cvs else # look into current and parent directories D="$PWD" while [ "$PWD" != / ] ; do if [ -f .perforce ] ; then VC=p4 break elif [ -d .svn ] ; then VC=svn break elif [ -d .git ] ; then VC=git break elif [ -d .pc -a -d patches ] ; then VC=quilt break fi cd .. done TOPLEVEL="$PWD" cd "$D" fi if [ -z "$VC" ] ; then echo "could not determine which version control is used" exit 1 fi # now execute the commands for the different version control systems if [ "$VC" = 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 [ "$VC" = svn ] ; then if [ "$1" = st -o "$1" = status ] ; then svn st | perl -ne 'next if /^(X\s+| M\s+|Performing status on external item at )|^\s+$/;print' else svn "$@" fi elif [ "$VC" = 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 elif [ "$VC" = quilt ] ; then exec quilt "$@" elif [ "$VC" = p4 ] ; then if [ "$1" = st -o "$1" = status -o "$1" = opened ] ; then p4 opened echo '************** files not managed by p4 *********************' TMP=/tmp/vc$$ find . -type f -not -name '*~' | p4 -x- have > /dev/null 2> $TMP cat $TMP rm $TMP elif [ "$1" = up -o "$1" = update -o "$1" = sync ] ; then shift p4 sync -f "$@" elif [ "$1" = ci -o "$1" = commit -o "$1" = submit ] ; then shift p4 submit "$@" elif [ "$1" = di -o "$1" = diff ] ; then shift p4 diff -du -db -dl "$@" elif [ "$1" = bl -o "$1" = blame -o "$1" = annotate -o "$1" = ann ] ; then shift p4 annotate -I "$@" elif [ "$1" = log ] ; then shift p4 changes -c $(p4 info | perl -ne 'print $1 if /Client name: (.+)/') "$@" elif [ "$1" = describe -o "$1" = desc ] ; then shift p4 describe -du "$@" fi else echo no version control found here exit 1 fi