Thread (3 messages) flat view 3 messages, 1 author, 2016-06-15
DORMANTno replies

[PATCH 1/2] Make 'stg cp' 2nd form safe.

From: Yann Dirson <hidden>
Date: 2016-06-15 22:42:59
Subsystem: documentation, the rest · Maintainers: Jonathan Corbet, Linus Torvalds



Signed-off-by: Yann Dirson <redacted>
---

 Documentation/stg-cp.txt |    9 +++++----
 stgit/git.py             |    9 +++++++++
 2 files changed, 14 insertions(+), 4 deletions(-)
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)
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help