You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by cm...@apache.org on 2012/10/05 21:38:17 UTC

svn commit: r1394748 - /subversion/trunk/subversion/libsvn_client/add.c

Author: cmpilato
Date: Fri Oct  5 19:38:16 2012
New Revision: 1394748

URL: http://svn.apache.org/viewvc?rev=1394748&view=rev
Log:
Make 'svn add --force /path/to/wc-root' work as expected.

* subversion/libsvn_client/add.c
  (svn_client_add4): Check the to-be-added path to see if it's a
    directory and working copy root.  If so, we know it's under
    version control so --force is required to go further.  We also
    know that we can't get a WC lock on its parent, so adjust our
    locking parameters accordingly.

Modified:
    subversion/trunk/subversion/libsvn_client/add.c

Modified: subversion/trunk/subversion/libsvn_client/add.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/add.c?rev=1394748&r1=1394747&r2=1394748&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/add.c (original)
+++ subversion/trunk/subversion/libsvn_client/add.c Fri Oct  5 19:38:16 2012
@@ -671,6 +671,9 @@ svn_client_add4(const char *path,
   const char *parent_abspath;
   const char *local_abspath;
   const char *existing_parent_abspath;
+  svn_node_kind_t disk_kind;
+  svn_boolean_t is_wc_root = FALSE;
+  svn_error_t *err;
 
   if (svn_path_is_url(path))
     return svn_error_createf(SVN_ERR_ILLEGAL_TARGET, NULL,
@@ -678,6 +681,38 @@ svn_client_add4(const char *path,
 
   SVN_ERR(svn_dirent_get_absolute(&local_abspath, path, pool));
 
+  /* See if we're being asked to add a wc-root.  That's typically not
+     okay, unless we're in "force" mode.  We'll check the node kind
+     first, because wc-roots must be directories.  But also,
+     svn_wc_is_wc_root2() will return TRUE even if LOCAL_ABSPATH is a
+     *symlink* to a working copy root, which is a scenario we want to
+     treat differently.  */
+  SVN_ERR(svn_io_check_path(local_abspath, &disk_kind, pool));
+  if (disk_kind == svn_node_dir)
+    {
+      err = svn_wc_is_wc_root2(&is_wc_root, ctx->wc_ctx,
+                               local_abspath, pool);
+      if (err)
+        {
+          if (err->apr_err == SVN_ERR_ENTRY_NOT_FOUND)
+            {
+              svn_error_clear(err);
+              err = SVN_NO_ERROR;
+              is_wc_root = FALSE;
+            }
+          else
+            {
+              return err;
+            }
+        }
+    }
+  if (is_wc_root && (! force))
+    {
+      return svn_error_createf(SVN_ERR_ENTRY_EXISTS, NULL,
+                               _("'%s' is already under version control"),
+                               svn_dirent_local_style(local_abspath, pool));
+    }
+  
   /* ### this is a hack.
      ### before we switched to absolute paths, if a user tried to do
      ### 'svn add .', PATH would be "" and PARENT_PATH would also be "",
@@ -708,7 +743,9 @@ svn_client_add4(const char *path,
     add(local_abspath, depth, force, no_ignore, existing_parent_abspath,
         ctx, pool),
     ctx->wc_ctx,
-    existing_parent_abspath ? existing_parent_abspath : parent_abspath,
+    is_wc_root ? local_abspath
+               : (existing_parent_abspath ? existing_parent_abspath 
+                                          : parent_abspath),
     FALSE /* lock_anchor */, pool);
   return SVN_NO_ERROR;
 }