Commit Graph

106 Commits

Author SHA1 Message Date
Jun Wu
7fa918cefd perftweaks: move commit head detection removal logic to core
Summary: Also change the internal API so it no longer accepts the "heads" argument.

Reviewed By: ryanmce

Differential Revision: D6745865

fbshipit-source-id: 368742be49b192f7630421003552d0a10eb0b76d
2018-04-13 21:50:52 -07:00
Matt Harbison
7d8bebd9c1 tests: remove (glob) annotations that were only for '\' matches
# skip-blame because this was mechanically rewritten the following script.  I
ran it on both *.t and *.py, but none of the *.py changes were proper.  All *.t
ones appear to be, and they run without addition failures on both Windows and
Linux.

  import argparse
  import os
  import re

  ap = argparse.ArgumentParser()
  ap.add_argument('path', nargs='+')
  opts = ap.parse_args()

  globre = re.compile(r'^(.*) \(glob\)(.*)$')

  for p in opts.path:
      tmp = p + '.tmp'
      with open(p, 'rb') as src, open(tmp, 'wb') as dst:
          for line in src:
              m = globre.match(line)
              if not m or '$LOCALIP' in line or '*' in line:
                  dst.write(line)
                  continue
              if '?' in line[:-3] or ('?' in line[:-3] and line[-3:] != '(?)'):
                  dst.write(line)
                  continue
              dst.write(m.group(1) + m.group(2) + '\n')
      os.unlink(p)
      os.rename(tmp, p)
2017-12-10 22:50:57 -05:00
Matt Harbison
d2dab77cb0 tests: add a substitution for ENOENT/ERROR_FILE_NOT_FOUND messages
Automatic replacement seems better than trying to figure out a check-code rule.
I didn't bother looking to see why the error message and file name is reversed
in the annotate and histedit tests, based on Windows or not.

I originally had this as a list of tuples, conditional on the platform.  But
there are a couple of 'No such file or directory' messages emitted by Mercurial
itself, so unconditional is required for stability.  There are also several
variants of what I assume is 'connection refused' and 'unknown host' in
test-clone.t and test-clonebundles.t for Docker, FreeBSD jails, etc.  Yes, these
are handled by (re) tags, but maybe it would be better to capture those strings
in order to avoid whack-a-mole in future tests.  All of this points to using a
dictionary containing one or more strings-to-be-replaced values.
2017-12-02 19:33:34 -05:00
Martin von Zweigbergk
cecc308ad5 tests: fix regex in test-subrepo-git.t to match entire string
Due to a bug in the test runner (fixed by the next commit), the regex
used for matching lines like " foobar | 2 +-" stoppped at the "|" and
the test passed even though the rest of the line did not match. The
test seems to have been supposed to match "|" and "+" literally on
those lines, so this changes the regex to escape those characters. It
also changes a "\s*" to "\s+" since I think we'll always include a
space after the "|" in the diffstat output.

Differential Revision: https://phab.mercurial-scm.org/D1545
2017-11-29 10:58:32 -08:00
Gregory Szorc
bcd6d015d2 subrepo: use per-type config options to enable subrepos
We change subrepos.allowed from a list of allowed subrepo types to
a combination of a master switch and per-type boolean flag.

If the master switch is set, subrepos can be disabled wholesale.

If subrepos are globally enabled, then per-type options are
consulted. Mercurial repos are enabled by default. Everything else
is disabled by default.
2017-11-06 22:32:41 -08:00
Yuya Nishihara
e5730ba521 subrepo: disable git and svn subrepos by default (BC) (SEC)
We have a security issue with git subrepos. I'm not sure if svn subrepo is
vulnerable, but it seems not 100% safe to allow writing arbitrary data into
a metadata directory. So for now, only hg subrepo is enabled by default.

Maybe we should improve the help to describe why git/svn subrepos are
disabled.
2017-11-05 21:51:42 +09:00
Yuya Nishihara
9752ef714d subrepo: extend config option to disable subrepos by type (SEC)
This allows us to minimize the behavior change introduced by the next patch.

I have no idea which config style is preferred in UX POV, but I decided to
get things done.

 a) list: 'allowed = hg, git, svn'
 b) sub option: 'allowed.hg = True' or 'allowed:hg = True'
 c) per-type action: 'hg = allow', 'git = abort'
2017-11-05 21:48:58 +09:00
Yuya Nishihara
f864544d81 subrepo: add config option to reject any subrepo operations (SEC)
This is an alternative workaround for the issue5730.

Perhaps this is the simplest way of disabling subrepo operations. It does
nothing clever, but just aborts if Mercurial starts accessing to a subrepo.

I think Greg's patch is more useful since it allows us to at least check
out the parent repository. However, that would be confusing if the default
is flipped to checkout=False and subrepos are silently ignored.

I don't like the config name 'allowed', but I couldn't get any better name.
2017-11-05 21:22:07 +09:00
Yuya Nishihara
dac75264c0 subrepo: disallow symlink traversal across subrepo mount point (SEC)
It wasn't easy to extend the pathauditor to check symlink traversal across
subrepos because pathauditor._checkfs() rejects a directory having ".hg"
directory. That's why I added the explicit islink() check.

No idea if this patch is necessary after we've fixed the issue5730 by
splitting submerge() into planning and execution phases.
2017-11-03 20:12:50 +09:00
Denis Laxalde
9efc7f05e3 transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Upon pull or unbundle, we display a message with the range of new revisions
fetched. This revision range could readily be used after a pull to look out
what's new with 'hg log'. The algorithm takes care of filtering "obsolete"
revisions that might be present in transaction's "changes" but should not be
displayed to the end user.
2017-10-12 09:39:50 +02:00
Mark Thomas
3dfe8fba1c scmutil: don't append .orig to backups in origbackuppath (BC)
When ui.origbackuppath is set, .orig files are stored outside of the working
copy, however they still have a .orig suffix appended to them.  This can cause
unexpected conflicts, particularly when tracked files or directories have .orig
at the end.

This change removes the .orig suffix from files stored in an out-of-tree
origbackuppath.

Test Plan:
Update and run unit tests.

Differential Revision: https://phab.mercurial-scm.org/D679
2017-09-11 17:49:49 +00:00
Yuya Nishihara
509744ddfc ssh: unban the use of pipe character in user@host:port string
This vulnerability was fixed by the previous patch and there were more ways
to exploit than using '|shellcmd'. So it doesn't make sense to reject only
pipe character.

Test cases are updated to actually try to exploit the bug. As the SSH bridge
of git/svn subrepos are not managed by our code, the tests for non-hg subrepos
are just removed.

This may be folded into the original patches.
2017-08-07 22:22:28 +09:00
Sean Farley
39898f2a8a subrepo: add tests for git rogue ssh urls (SEC)
'ssh://' has an exploit that will pass the url blindly to the ssh
command, allowing a malicious person to have a subrepo with
'-oProxyCommand' which could run arbitrary code on a user's machine. In
addition, at least on Windows, a pipe '|' is able to execute arbitrary
commands.

When this happens, let's throw a big abort into the user's face so that
they can inspect what's going on.
2017-07-31 14:55:11 -07:00
Matt Harbison
86a2e6550a subrepo: make the output references to subrepositories consistent
Well, mostly.  The annotation on subrepo functions tacks on a parenthetical to
the abort message, which seems reasonable for a generic mechanism.  But now all
messages consistently spell out 'subrepository', and double quote the name of
the repo.  I noticed the inconsistency in the change for the last commit.
2017-07-09 16:13:30 -04:00
Sean Farley
a83517063a tests: protect tests involving git ext::sh with git-ext-sh 2017-06-15 17:14:53 -07:00
Boris Feld
389d0518ad test: prepare tests for removing date aliases
In the next patch, I'm gonna removing the global command aliases that force
the epoch date but some tests either fail or their output change after that.
Instead I'm copying the needed aliases in the test files that will otherwise
change.

Update test-rebase-obsolete.t because a revision hash is based on the epoch
date after a 'commit --amend' and the output will change after removing date
aliases.

Update test-subrepo-git.t as the git subrepo doesn't use traditional date
mechanisms. I'm not sure that updating the git subrepo to support default-date
make sense. Add the commit alias to the test in order for making it pass after
removing the date aliases globally.
2017-05-22 19:28:47 +02:00
Simon Farnsworth
3622717b76 merge: add conflict labels to merge command
Now that we present the conflict labels in prompts, it's useful to have
better names than "local" and "other" for every command.
2016-10-07 08:51:50 -07:00
Simon Farnsworth
dfbb92b63b merge: use labels in subrepo merge
This is the last place that doesn't respect conflict labels in merge output.
Teach subrepos to use subrepo merge output too.
2016-10-08 01:25:28 -07:00
Matt Mackall
3291548f1c merge with stable 2016-06-09 13:47:42 -05:00
Danek Duvall
fd61c5191c tests-subrepo-git: use "f" to dump pwned.txt, for portability
Rather than sometimes using a complicated shell construct to dump pwned.txt
(if it wasn't expected to exist, but might, if something were broken) or
just cat (if it was expected to exist), just use the "f" utility, which
will be consistent in its behavior across different platforms.

Also make sure that *something* gets put into pwned.txt, even if we ended
up typoing the message variable.
2016-06-02 16:18:44 -07:00
Danek Duvall
aee88deefe tests-subrepo-git: emit a different "pwned" message based on the test
Having a single "pwned" message which may or may not be emitted during the
tests for CVE-2016-3068 leads to extra confusion.  Allow each test to emit
a more detailed message based on what the expectations are.

In both cases, we expect a version of git which has had the vulnerability
plugged, as well as a version of mercurial which also knows about
GIT_ALLOW_PROTOCOL.  For the first test, we make sure GIT_ALLOW_PROTOCOL is
unset, meaning that the ext-protocol subrepo should be ignored; if it
isn't, there's either a problem with mercurial or the installed copy of
git.

For the second test, we explicitly allow ext-protocol subrepos, which means
that the subrepo will be accessed and a message emitted confirming that
this was, in fact, our intention.
2016-05-27 15:20:03 -07:00
Danek Duvall
27b40ab5d7 tests-subrepo-git: make the "pwned" message output in a stable order
The "pwned" message from this test gets gets sent to stderr, and so may get
emitted in different places from run to run in the rest of mercurial's
output.  This patch forces the message to go to a specific file instead,
whose existence and contents we can examine at a stable point in the test's
execution.
2016-05-27 15:10:38 -07:00
Kevin Bullock
73ec31db86 subrepo: use unset instead of env -u to fix test on BSDs (issue5229) 2016-05-06 08:41:24 -05:00
Matt Harbison
4e1571628b test-subrepo-git: add globs for Windows 2016-04-15 22:23:34 -04:00
Matt Mackall
4a96519522 merge with stable 2016-03-29 12:29:00 -05:00
Mateusz Kwapich
e1c4c54543 subrepo: set GIT_ALLOW_PROTOCOL to limit git clone protocols (SEC)
CVE-2016-3068 (1/1)

Git's git-remote-ext remote helper provides an ext:: URL scheme that
allows running arbitrary shell commands. This feature allows
implementing simple git smart transports with a single shell shell
command. However, git submodules could clone arbitrary URLs specified
in the .gitmodules file. This was reported as CVE-2015-7545 and fixed
in git v2.6.1.

However, if a user directly clones a malicious ext URL, the git client
will still run arbitrary shell commands.

Mercurial is similarly effected. Mercurial allows specifying git
repositories as subrepositories. Git ext:: URLs can be specified as
Mercurial subrepositories allowing arbitrary shell commands to be run
on `hg clone ...`.


The Mercurial community would like to thank Blake Burkhart for
reporting this issue. The description of the issue is copied from
Blake's report.

This commit changes submodules to pass the GIT_ALLOW_PROTOCOL env
variable to git commands  with the same list of allowed protocols that
git submodule is using.

When the GIT_ALLOW_PROTOCOL env variable is already set, we just pass it
to git without modifications.
2016-03-20 21:52:21 -07:00
FUJIWARA Katsunori
bdf197db2e tests: make chunk header of external diff glob-ed for portability
Before this patch, some tests using external "diff" command via
extdiff extension fail on Solaris, because system standard "diff" (=
/usr/bin/diff) on Solaris always formats chunk header in the style
below:

  @@ -X.x +Y.y @@

even though "diff" on Linux sometimes omits ".x" and/or ".y" in it.

This patch makes chunk header of external diff glob-ed for portability
of tests, and adds check-code.py rules to detect such diff output in
tests.

This patch also changes "hg diff" output in test-subrepo-git to
simplify detection rules, even though it is certainly portable because
these lines are generated by "git" command.

This patch is a part of making tests using external "diff" portable,
and tests below aren't yet portable even after this patch.

  test-largefiles-update.t
  test-subrepo-deep-nested-change.t
2016-02-08 18:29:17 +09:00
Matt Harbison
d7467d5e8b tests: fix globs for Windows 2015-11-15 21:12:13 -05:00
Christian Delahousse
49f274e0e0 git-subrepos: revert respects specified location to save .orig files
This patch makes revert in git subrepos save .orig files where the user wants
them by using the cmdutil.origpath function.
2015-11-10 14:29:13 -08:00
Pierre-Yves David
f490dd76e1 test-subrepo-git: ignore pax_global_header when listing archive
d6f3cca7f3a5 is adding a new tar call but forgot to filter out the
pax_global_header file that some tar versions write. This is similar to what
happened in 686775e575f3.
2015-05-07 16:43:58 -07:00
Matt Harbison
9fe8bb732e archive: drop the leading '.' path component from the prefix (issue4634)
Unix utilities like tar will happily prefix the files it packs with './', but
annoyingly, Windows Explorer will not show these packed files when it opens the
archive.  Since there doesn't seem to be a point in including './' in the path
names, just drop it.  The default 'hg archive' prefix is the basename of the
archive, so specifying '.' allows for that default to be disabled completely.
2015-05-05 20:52:38 -04:00
Mathias De Maré
633c0af10d subrepo: correctly handle git subdirectory status change
'git diff-index' by default does not recurse into subdirectories
when changes are found. As a result, the directory is shown as changed,
rather than the files in this directory.
Adding '-r' results in recursing until the blobs themselves are checked.
2015-05-06 17:15:38 +02:00
Matt Harbison
7ae29b6407 archive: always use portable path component separators with subrepos
The previous behavior when archiving a subrepo 's' on Windows was to internally
name the file under it 's\file', due to the use of vfs.reljoin().  When printing
the file list from the archive on Windows or Linux, the file was named
's\\file'.  The archive extracted OK on Windows, but if the archive was brought
to a Linux system, it created a file named 's\file' instead of a directory 's'
containing 'file'.

*.zip format achives seemed not to have the problem, but this was definitely an
issue with *.tgz archives.

Largefiles actually got this right, but a test is added to keep this from
regressing.  The subrepo-deep-nested-change.t test was repurposed to archive to
a file, since there are several subsequent tests that archive to a directory.
The output change is losing the filesystem prefix '../archive_lf' and not
listing the directories 'sub1' and 'sub1/sub2'.
2015-05-04 22:33:29 -04:00
Siddharth Agarwal
c4e0365d23 util.checkcase: don't abort on broken symlinks
One case where that would happen is while trying to resolve a subrepo, if the
path to the subrepo was actually a broken symlink. This bug was exposed by an
hg-git test.
2015-05-03 12:49:15 -07:00
Mathias De Maré
3f5d166a19 subrepo: add include/exclude support for diffing git subrepos
Previously, git subrepos were ignored if any type of path selection
was done.
This can be solved by using subrepo status and filtering matching files.
2015-04-14 20:09:56 +02:00
Mathias De Maré
80df46375b tests: handle deleted .hg directory (git 2.2.0 and higher) (issue4585)
In git 2.2.0 and higher, removing files and directories is changed:
removing an object that does not exist returns success rather than failure.
As a result, even though .hg/hgrc does not exist, success is returned
and the .hg/ directory is removed.

To handle this correctly, use 'rm -rf' to allow successful removing
for all git versions.

The exact changeset where this was introduced in git:
1054af7d04aef64378d69a0496b45cdbf6a0bef2
wrapper.c: remove/unlink_or_warn: simplify, treat ENOENT as success
2015-04-02 08:18:33 +02:00
Mathias De Maré
5f319261ae subrepo: add status support for ignored and clean files in git subrepos 2015-03-09 22:14:09 +01:00
Matt Harbison
53cb50db7b subrepo: warn when adding already tracked files in gitsubrepo
This follows normal Mercurial rules, and the message is lifted from
workingctx.add().  The file is printed with abs() to be consistent with how it
is printed in workingctx, even though that is inconsistent with how added files
are printed in verbose mode.  Further, the 'already tracked' notifications come
after all of the files that are added are printed, like in Mercurial.

As a side effect, we now have the reject list to return to the caller, so that
'hg add' exits with the proper code.  It looks like an abort occurs if git fails
to add the file.  Prior to touching 'snake.python' in the test, this was the
result of attempting to add the file after a 'git rm':

    fatal: pathspec 'snake.python' did not match any files
    abort: git add error 128 in s (in subrepo s)

I'm not sure what happens when git is a deep subrepo, but the 'in s' and
'in subrepo s' from @annotatesubrepoerror are redundant here.  Maybe we should
stat the files before invoking git to catch this case and print out the prettier
hg message?  The other thing missing from workingctx.add() is the call to
scmutil.checkportable(), but that would need to borrow the parent's ui object.
2015-02-27 23:30:42 -05:00
Matt Harbison
62fe6a5d98 subrepo: don't exclude files in .hgignore when adding to git
The previous test gave a false success because only an hg-ignored pattern was
specified.  Therefore match.files() was empty, and it fell back to the files
unknown to git.  The simplest fix is to always consider what is unknown to git,
as well as anything specified explicitly.  Files that are ignored by git can
only be introduced by an explicit mention in match.files().
2015-02-26 15:53:54 -05:00
Mathias De Maré
50bc3c4ab5 subrepos: support adding files in git subrepos
This support includes correct matching, so includes,
excludes and patterns are all supported.
2015-02-24 08:49:22 +01:00
Mathias De Maré
6915ed3f3b subrepo: add 'cat' support for git subrepos
V2: use 'self._ctx.node()' instead of 'rev' in makefileobj.
As Matt Harbison mentioned, using 'rev' does not make sense,
since we'd be passing a git revision to the top-level
Mercurial repository.
2015-02-01 14:09:31 +01:00
Matt Harbison
12ec4872c6 subrepo: don't abort in add when non-hg subrepos are present (issue4513)
This change should have been part of a5602d49abba.
2015-01-27 20:57:43 -05:00
Mathias De Maré
d2e939ddb5 subrepo: correctly add newline for git subrepo diffs
Previously, git subrepo diffs did not have a newline at the end.
This caused multiple subrepo diffs to be joined on the same line.
Additionally, the command prompt after the diff still contained
a part of the diff.
2015-01-21 21:47:27 +01:00
FUJIWARA Katsunori
9c68e572c7 tests: discard useless "(glob)" in "reverting subrepo" lines 2015-01-22 00:10:26 +09:00
Matt Mackall
3c097d24cf test-subrepo-git: ignore global git config
This was causing a test failure for people with company-wide settings.
Still need a way to ignore local config.
2014-12-30 15:51:14 -06:00
Mathias De Maré
4aa7ae08d9 subrepo: add full revert support for git subrepos
Previously, revert was only possible if the '--no-backup'
switch was specified.
Now, to support backups, we explicitly go over all modified
files in the subrepo.
2014-12-28 10:42:25 +01:00
Mathias De Maré
873d3da688 tests: avoid git diffstat singular/plural output difference
'git diff --stat' output changed with regard to the amount
of changes/insertions/deletions shown.
In older git versions (1.7.7.6), output was shown as:
2 files changed, 2 insertions(+), 1 deletions(-)
In newer versions, output is shown as:
2 files changed, 2 insertions(+), 1 deletion(-)

This patch uses a regex to handle both cases.
2014-12-14 21:00:58 +01:00
Mathias De Maré
2f2a712a16 subrepo: add revert support without backup for git subrepos
Previously, git subrepos did not support reverting.
This change adds basic support for reverting
when '--no-backup' is specified.
A warning is given (and the current state is kept)
when a revert is done without the '--no-backup' flag.
2014-12-14 11:34:51 +01:00
Mathias De Maré
8c55f23d47 tests: allow more flexibility in git diffstat output
The output of 'git diff --stat' changed in git 1.7.10 and 1.7.11.
To ensure the tests work with earlier versions of git as well,
the output is now wrapped with a whitespace regex.
2014-12-13 09:45:00 +01:00
Mathias De Maré
60f4f56e86 subrepo: add partial diff support for git subrepos
So far, git subrepositories were silently ignored for diffs.
This patch adds support for git subrepositories,
with the remark that --include and --exclude are not supported.
If --include or --exclude are used, the subrepo is ignored.
2014-12-10 10:32:51 +01:00