How do I determine if a directory is part of a Subversion working copy?
Vincent Lefevre <[email protected]> Wed, 25 Sep 2024 02:17:10 +0200
| Newsgroups | gmane.comp.version-control.subversion.user |
|---|---|
| Message-ID | <[email protected]> |
How do I determine if a directory is part of a Subversion working copy?
This is the same question as on
https://stackoverflow.com/questions/7172334/how-do-i-determine-if-a-directory-is-part-of-a-subversion-working-copy
but all the answers there except mine are incorrect.
The issue is that one needs to distinguish 3 cases, not 2!
1. Positive answer.
2. Negative answer.
3. Arbitrary error.
So, solutions based on "svn info 2> /dev/null" are incorrect as they
cannot distinguish case 2 and case 3. The error message is important.
I was using such a solution, and it took me some time to find the
cause of an unexpected negative answer: I had a concurrent "svn up"
running in another shell (which I forgot as it was lengthy).
I could check that this was indeed a plausible cause:
joooj:~/wd> while svn info > /dev/null ; do true; done
svn: E200033: Another process is blocking the working copy database, or the underlying filesystem does not support file locking; if the working copy is on a network filesystem, make sure file locking has been enabled on the file server
svn: E200033: sqlite[S5]: database is locked, executing statement 'PRAGMA case_sensitive_like=1;PRAGMA synchronous=OFF;PRAGMA recursive_triggers=ON;PRAGMA foreign_keys=OFF;PRAGMA locking_mode = NORMAL;PRAGMA journal_mode = TRUNCATE;'
when doing "svn up" in another shell.
So I proposed the following script:
------------------------------------------------------------
#!/bin/sh
err=$(LC_ALL=C svn info "$1" 2>&1 >/dev/null)
if [ $? = 0 ]; then
echo yes
exit 0
fi
case $err in
*"is not a working copy")
echo no
exit 0 ;;
esac
printf "%s\n" "$err" >&2
exit 1
------------------------------------------------------------
But is there a better solution?
Checking the error message might not be future-proof.
--
Vincent Lefèvre <[email protected]> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)