chiark / gitweb /
Make 'stg cp' 2nd form safe.
authorYann Dirson <ydirson@altern.org>
Mon, 12 Mar 2007 22:44:21 +0000 (22:44 +0000)
committerCatalin Marinas <catalin.marinas@gmail.com>
Mon, 12 Mar 2007 22:44:21 +0000 (22:44 +0000)
Signed-off-by: Yann Dirson <ydirson@altern.org>
Documentation/stg-cp.txt
stgit/git.py

index f499309b507f2779e5aa95369a0bdc990c760774..723d811b5fe01ffd28da3a12b8c354162307dcab 100644 (file)
@@ -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
 --------------
index 9129c92a303c9e5f0013a4b04cbe18db6b5e1b39..f6d6b43e5daa682ced028c84acf206569310ac08 100644 (file)
@@ -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)