From: Yann Dirson Date: Mon, 12 Mar 2007 22:44:21 +0000 (+0000) Subject: Make 'stg cp' 2nd form safe. X-Git-Tag: v0.13~123 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/stgit/commitdiff_plain/d92a3fd72956ed39ace26699aaf0d6d1ab84e5ed Make 'stg cp' 2nd form safe. Signed-off-by: Yann Dirson --- diff --git a/Documentation/stg-cp.txt b/Documentation/stg-cp.txt index f499309..723d811 100644 --- a/Documentation/stg-cp.txt +++ b/Documentation/stg-cp.txt @@ -35,10 +35,11 @@ file not known to Git will not be copied. CAVEATS ------- -The first form doesn't allow yet to overwrite an existing file -(whether it could be recovered from Git or not), and the second form -does not check before overwriting any file, possibly leading to loss -of non-committed modifications. +This command does not allow yet to overwrite an existing file (whether +it could be recovered from Git or not). Further more, when copying a +directory, the second form does not allow to proceed if a directory by +that name already exists inside the target, even when no file inside +that directory would be overwritten. FUTURE OPTIONS -------------- diff --git a/stgit/git.py b/stgit/git.py index 9129c92..f6d6b43 100644 --- a/stgit/git.py +++ b/stgit/git.py @@ -464,6 +464,15 @@ def copy(filespecs, target): if os.path.isdir(target): # target is a directory: copy each entry on the command line, # with the same name, into the target + target = target.rstrip('/') + + # first, check that none of the children of the target + # matching the command line aleady exist + for filespec in filespecs: + entry = target+ '/' + os.path.basename(filespec.rstrip('/')) + if os.path.exists(entry): + raise GitException, 'Target "%s" already exists' % entry + for filespec in filespecs: filespec = filespec.rstrip('/') basename = '/' + os.path.basename(filespec)