git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Yann Dirson <ydirson@altern.org>
Date
Mar 11, 2007, 21:44 UTC
Message-ID
<20070311214412.3142.58190.stgit@gandelf.nowhere.earth>
In-Reply-To
<20070311214133.3142.11407.stgit@gandelf.nowhere.earth>
Signed-off-by: Yann Dirson <ydirson@altern.org>
---
 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)
Previous: Yann DirsonNext: Yann Dirson
Message 2 of 3 in “Fixes for recent stgit issues”
  1. 0/2 Fixes for recent stgit issuesYann Dirson, Mar 11, 2007
  2. 1/2 Make 'stg cp' 2nd form safe.Yann Dirson, Mar 11, 2007
  3. 2/2 Fixed t2102-pull-policy-rebase to really test 'rebase' policy.Yann Dirson, Mar 11, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.