views:

384

answers:

2

Is there an easy way to get a conflict summary after running a cvs update?

I work on a large project and after doing some work I need to do an update. The list of changes coming back from the cvs update command is several pages long and I'd like to see only the list of conflicts (starts with 'C') repeated at the end of the cvs update command output.

The solution needs to work from the command line.

If my normal output is:

M src/file1.txt
M src/file2.txt
cvs server: conflicts found ...
C src/file3.txt
M src/file4.txt
M src/file5.txt

I want my new output to be:

M src/file1.txt
M src/file2.txt
cvs server: conflicts found ...
C src/file3.txt
M src/file4.txt
M src/file5.txt

Conflict Summary:
C src/file3.txt

I want this to be a single command (possibly a short script or alias) that outputs the normal cvs output as it happens followed by a summary of conflicts.

A: 

I don't have cvs handy what is the exact format of the output of cvs update

I seem to remember C <filename>
If so you could use:

cvs update | tee log | grep "^C"

The full output of cvs is saved into log for use at another point. Then we grep for all lines beginning with 'C'

Hope that helps.

Martin York
+2  A: 

Given the specification, it seems that you need a minor adaptation of Martin York's solution (because that only shows the conflicts and not the normal log information). Something like this - which might be called 'cvsupd':

tmp=${TMPDIR:-/tmp}/cvsupd.$$
trap "rm -f $tmp; exit 1" 0 1 2 3 13 15
cvs update "$@" | tee $tmp
if grep -s '^C' $tmp
then
    echo
    echo Conflict Summary:
    grep '^C' $tmp
fi
rm -f $tmp
trap 0
exit 0

The trap commands ensure that the log file is not left around. It catches the normal signals - HUP, INT, QUIT, PIPE and TERM (respectively) and 0 traps any other exit from the shell.

Jonathan Leffler
Thank you, this is it exactly.
Alex B