Patchwork [1,of,3,relative-import] commands.import: accept a prefix option

login
register
mail settings
Submitter Siddharth Agarwal
Date March 10, 2015, 8:49 p.m.
Message ID <894b02e812027a4cb528.1426020595@devbig136.prn2.facebook.com>
Download mbox | patch
Permalink /patch/7982/
State Accepted
Headers show

Comments

Siddharth Agarwal - March 10, 2015, 8:49 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1425711379 28800
#      Fri Mar 06 22:56:19 2015 -0800
# Node ID 894b02e812027a4cb52821cd8f0a783b29fce2d0
# Parent  ee9d52883035d7d32b18421b33653e597f4e4cf5
commands.import: accept a prefix option

The --prefix option is meant to be relative to the root rather than the current
working directory. This is for consistency with the rest of 'hg import' --
paths in patches are otherwise considered to be relative to the root.

In upcoming patches we'll hook this option up to the patch functions.

--exact with --prefix is currently disallowed because I can't really come up
with sensible semantics for it, especially when only part of the patch is
preserved.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -4057,6 +4057,8 @@ 
      _('commit even if some hunks fail')),
     ('', 'exact', None,
      _('apply patch to the nodes from which it was generated')),
+    ('', 'prefix', '',
+     _('apply patch to directory relative to the root'), _('DIR')),
     ('', 'import-branch', None,
      _('use any branch information in patch (implied by --exact)'))] +
     commitopts + commitopts2 + similarityopts,
@@ -4156,6 +4158,8 @@ 
         raise util.Abort(_('cannot use --similarity with --bypass'))
     if opts.get('exact') and opts.get('edit'):
         raise util.Abort(_('cannot use --exact with --edit'))
+    if opts.get('exact') and opts.get('prefix'):
+        raise util.Abort(_('cannot use --exact with --prefix'))
 
     if update:
         cmdutil.checkunfinished(repo)
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -268,7 +268,7 @@ 
   heads: rev, topo, active, closed, style, template
   help: extension, command, keyword
   identify: rev, num, id, branch, tags, bookmarks, ssh, remotecmd, insecure
-  import: strip, base, edit, force, no-commit, bypass, partial, exact, import-branch, message, logfile, date, user, similarity
+  import: strip, base, edit, force, no-commit, bypass, partial, exact, prefix, import-branch, message, logfile, date, user, similarity
   incoming: force, newest-first, bundle, rev, bookmarks, branch, patch, git, limit, no-merges, stat, graph, style, template, ssh, remotecmd, insecure, subrepos
   locate: rev, print0, fullpath, include, exclude
   manifest: rev, all, template
diff --git a/tests/test-import-bypass.t b/tests/test-import-bypass.t
--- a/tests/test-import-bypass.t
+++ b/tests/test-import-bypass.t
@@ -112,6 +112,9 @@ 
   $ hg import --bypass --similarity 50 ../test.diff
   abort: cannot use --similarity with --bypass
   [255]
+  $ hg import --exact --prefix dir/ ../test.diff
+  abort: cannot use --exact with --prefix
+  [255]
 
 Test commit editor
 (this also tests that editor is invoked, if the patch doesn't contain