Commit Graph

248 Commits

Author SHA1 Message Date
Siddharth Agarwal
9857ee8482 tests: stop filtering out bookmark output
The bookmark output has been stable since well before the oldest Mercurial we
support, 2.8.
2015-03-12 10:29:58 -07:00
Siddharth Agarwal
afdc4cc403 git_handler: don't store rename source if branch info is stored
Consider a Mercurial commit with hash 'h1'. Originally, if the only Mercurial
field stored is the branch info (which is stored in the commit message rather
than as an extra field), we'd store the rename source explicitly as a Git extra
field -- let's call the original exported hash 'g1'.

In Git, some operations throw all extra fields away. (One such example is a
rebase.) If such an operation happens, we'll be left with a frankencommit with
the branch info but without the rename source. Let's call this hash 'g2'. For a
setup where Git is the source of truth, let's say that this 'g2' frankencommit
is what gets pushed to the server.

When 'g2' is subsequently imported into Mercurial, we'd look at the fact that
it contains a Mercurial field in the commit message and believe that it was a
legacy commit from the olden days when all info was stored in the commit
message. In that case, in an attempt to preserve the hash, we wouldn't store
any extra rename source info, resulting in 'h1'. Then, when the commit is
re-exported to Git, we'd add the rename source again and produce 'g1' -- and
thus break bidirectionality.

Prevent this situation by not storing the rename source if we're adding branch
info to the commit message. Then for 'h1' we export as 'g2' directly and never
produce 'g1'.

What happens if we not only need to store branch info but also other extra
info, like renames? For 'h1' we'd produce 'g1', then it'd be rewritten on the
Git side to 'g2' throwing away all that extra information. 'g2' being
subsequently imported into Mercurial would produce a new hash, say 'h2'. That's
fine because the commit did get rewritten in Git. We unfortunately wouldn't
perform rename detection thinking that the commit is from Mercurial and had no
renames recorded there, but when the commit is re-exported to Git we'd export
it to 'g2' again. This at least preserves bidirectionality.
2015-02-26 22:14:44 -08:00
Siddharth Agarwal
50b09064ad test-renames.t: add tests for renaming a file out and replacing it with a submodule
Unlike the file to symlink transition discussed in the previous case, this case
works fine.
2015-02-26 18:00:36 -08:00
Siddharth Agarwal
6232b82c9f git_handler: handle case where file is renamed and replaced by a symlink
This edge case that rename detection introduces wasn't handled previously --
the file would be renamed but the symlink wouldn't be added.
2015-02-26 17:37:20 -08:00
Paul Chen
e0b24be7bc git_handler: Fix extra bookmark created after pushed to empty remote repo. 2015-02-21 14:49:43 +08:00
Mathias De Maré
62e84b3950 gitdirstate: avoid an abort when a .gitignore is missing
Deleting a .gitignore using 'rm' results in 'hg add' or 'hg status' aborting.
For example if the top-level .gitignore is removed:
  > abort: No such file or directory: .gitignore
This change avoids that by checking the presence of the .gitignore files.
2015-02-16 18:35:35 +01:00
Siddharth Agarwal
8db62b55cf git_handler: handle symlink <-> regular file transitions properly
See comment inline for explanation. Also add tests for this (the bug was masked
with rename detection disabled -- it only appeared with rename detection
enabled).
2014-12-30 13:25:55 -08:00
Siddharth Agarwal
7a8892e3fa tests: add further tests for gitlink <-> symlink and rename detection
There weren't any bugs here, but this is good to test.
2014-12-30 14:07:39 -08:00
Siddharth Agarwal
900d6b7203 tests: add tests for transitions to and from symlinks to files
This adds some test coverage for cases that are not buggy. There is a bug
lurking here, and an upcoming patch will extend these tests to cover those
cases too.
2014-12-30 12:26:10 -08:00
Augie Fackler
6efcd59b56 hg2git: audit path components during export (CVE-2014-9390)
A user recently got confused and managed to track and export a .git
directory, which confuses git and causes it to emit very odd
errors. For example, cloning one such repository (which has a symlink
for .git) produces this output from git:

  Cloning into 'git'...
  done.
  error: Updating '.git' would lose untracked files in it

and another (which has a .git directory checked in) produces this:

  Cloning into 'git'...
  done.
  error: Invalid path '.git/hooks/post-update'

If it ended there, that'd be fine, but this led to a line of
investigation that ended with CVE-2014-9390, so now git will block
checking these revisions out, so we should try to prevent
foot-shooting on our end. Since some servers (notably github) are
blocking trees that contain these entries, default to refusing to
export any path component that looks like it folds to .git. Since some
histories probably contain this already, we offer an escape hatch via
the config option git.blockdotgit that allows users to resume
foot-shooting behavior.
2014-11-23 19:06:21 -05:00
Siddharth Agarwal
10f98f06fa test-extra.t: fix for Mercurial 3.3+ 2014-12-29 11:18:03 -08:00
Siddharth Agarwal
e7b4906871 git_handler: mark source for rename info as Git or Mercurial
See inline comments for why the additional metadata needs to be stored.

This literally breaks all the hashes because of the additional metadata. The
changing of hashes is unfortunate but necessary to preserve bidirectionality.

While this could be broken up into multiple commits, there was no way to do
that while preserving bidirectionality. Following the principle that every
intermediate commit must result in a correct state, I decided to combine the
commits.
2014-12-02 14:17:09 -08:00
Siddharth Agarwal
9df74aef3e git_handler.get_files_changed: detect renames when asked to do so
We use Dulwich's rename detector to detect any renames over the specified
similarity threshold.

This isn't fully bidirectional yet -- when the commit is exported to Git
the hashes will no longer be the same. That's why that isn't tested here. In
upcoming patches we'll make sure it's bidirectional and will add the
corresponding tests.
2014-12-02 15:57:21 -08:00
Siddharth Agarwal
a6b1e5863c test-encoding: remove support for Git 1.7.x
Git 1.8.0 was released in late 2012. Given that we only support versions of
Mercurial released in 2014, it doesn't make sense to support versions of Git
this old.
2014-12-04 18:31:42 -08:00
Siddharth Agarwal
abfba0b8e3 git_handler.filter_min_date: support tag times for annotated tags
Previously we'd crash on annotated tags because they don't have a 'tag_time'
property.
2014-11-04 13:56:00 -08:00
Siddharth Agarwal
d1d7def3b9 tests: fix file modes 2014-10-29 19:34:36 -07:00
Siddharth Agarwal
c107b78504 gimport: support git.mindate 2014-10-29 19:37:23 -07:00
Siddharth Agarwal
b8dd01725f pull: support git.mindate 2014-10-29 19:37:10 -07:00
Siddharth Agarwal
079686eb01 git_handler: support wildcards for Git branch name matching
This is quite similar to syntax Git supports. In the future maybe core
Mercurial could be extended to support this, but I think this independently
makes sense in hg-git.
2014-10-31 11:14:35 -07:00
Siddharth Agarwal
e23ddbd959 test-hg-tags-invalid: add a test for tag with space in it
There was previously an attempt to handle this but no test coverage.
2014-10-29 13:28:39 -07:00
Siddharth Agarwal
9cc8a9705d test-bookmark-workflow: drop check for Mercurial < 2.1
We only support Mercurial >= 2.8.
2014-10-13 19:10:38 -07:00
Siddharth Agarwal
53fad749ea test-extra: add some more rename tests 2014-08-31 14:23:57 -07:00
Siddharth Agarwal
ed8599fcd4 git_handler: export hg extra metadata as git extra metadata (issue121)
We export new git commits with hg extra metadata stored as git extra fields.
We also ensure that parsing old commits doesn't break.
2014-08-31 14:01:07 -07:00
Siddharth Agarwal
0685b87e70 git_handler: support extracting metadata from Git extra fields
Git has a well-hidden notion of extra fields. They aren't accessible from the
CLI, but Dulwich can create them. They're a better place to store Mercurial's
extra metadata than the commit message.

An upcoming patch will switch hg-git to saving the metadata in the Git extra
fields. This commit:
(a) prepares for that
(b) extracts other Git extra fields so that commits from Git with such fields
    roundtrip correctly
2014-08-31 06:49:18 -07:00
Siddharth Agarwal
73ef101f82 tests: add support for inline python
An upcoming patch will include an inline python test. tests/heredoctest.py is
copied over from the Mercurial repository.
2014-08-31 06:27:46 -07:00
Augie Fackler
ec5ffb1707 test-extra.t: use a templater format that's portable back to hg 2.8.2 2014-08-31 09:37:28 -04:00
Siddharth Agarwal
553598f445 git_handler: store hg extra data in git deterministically by sorting it
Previously, we'd iterate over the extra elements in arbitrary order. We now
sort the elements and store them in deterministic order.

Without sorting, the included test fails half the time.
2014-08-31 05:13:39 -07:00
Siddharth Agarwal
706ef1547d tests: add test to ensure hg rename and extra metadata roundtrips
We didn't actually have a test for this until now.
2014-08-30 09:29:20 -07:00
Augie Fackler
61c4c39b9a tests: adapt for hg 3.1 output changes 2014-08-23 13:05:28 -04:00
Siddharth Agarwal
29901229f3 tests: fix further breakage due to upstream output changes
Mercurial changesets 355cfc5dc0f1 and 02e6c82cb015 added messages when
bookmarks are activated and deactivated, respectively.
2014-05-26 18:37:09 -07:00
Siddharth Agarwal
d0ee6b199a tests: fix breakage caused by Mercurial changes
Mercurial commit 1ecf7fef14e2 added a new message to `hg resolve` with no more
unresolved files.
2014-05-19 19:52:22 -07:00
Takumi IINO
7dcd72400d gignore: remove illegal components (issue92)
mercurial can't ignore .hg direcotry.
2014-04-16 22:04:26 +09:00
Siddharth Agarwal
c39a11100a test-bookmark-workflow: introduce tests for incoming bookmarks
An upcoming patch will change bookmark discovery significantly. These tests
make sure nothing major regresses.
2014-05-08 19:49:50 -07:00
Siddharth Agarwal
f8423175b8 test-git-submodules: replace hg cat with hg manifest
Mercurial commit a6d634896102 added support for hg cat across subrepositories.
That caused these tests to break. Fix this by using hg manifest instead.
2014-05-08 13:53:36 -07:00
Augie Fackler
53d4df5863 tests: add some extra filters for new output
Tests pass on both my Mac and Linux machine, so I feel moderately confident
that this is portable.
2014-03-25 15:04:11 -04:00
Siddharth Agarwal
c188adb4b9 hg2git: in _init_dirs, store keys without leading '/' (issue103)
Previously, whenever a tree that wasn't the root ('') was stored, we'd prepend
a '/' to it. Then, when we'd try retrieving the entry, we'd do so without the
leading '/'. This caused data loss because existing tree entries were dropped
on the floor. Fix that by only adding '/' if we're adding to a non-empty
initial path.

This wasn't detected in tests because most of them deal only with files in the
root and not ones in subdirectories.
2014-03-25 11:11:04 -07:00
Siddharth Agarwal
3e13ddc73e safebranchrevs: handle changelog having no commits
The usage of getattr was unsafe. Use hgutil.safehasattr instead.
util.safehasattr has been around since Mercurial 2.0.

This also fixes the formerly disabled test in test-pull.t.
2014-03-04 23:20:50 -08:00
Siddharth Agarwal
8117eb614e test-pull.t: add test for no-op pull 2014-03-04 16:30:12 -08:00
Siddharth Agarwal
bf45b40ca3 git_handler.fetch: only import commits reachable from requested heads
Previously we'd attempt to import every single reachable commit in the Git
object store.

The test adds another branch to the Git repo and doesn't import it until much
later. Previously we'd import it when we ran `hg -R hgrepo pull -r beta`. Now
we won't.
2014-03-04 16:23:11 -08:00
Siddharth Agarwal
759062fbfd git_handler.fetch: actually return number of heads added or removed
The return value as implemented in git_handler.fetch was pretty bogus. It used
to return the number of values that changed in the 'refs/heads/' namespace,
regardless of whether multiple values in there point to the same Mercurial
commit, or whether particular heads were even imported. Fix all of that by
using the actual heads in the changelog, just like vanilla Mercurial.

The test output changes demonstrate examples where the code was buggy.
2014-03-04 16:05:19 -08:00
Siddharth Agarwal
e41aded84e git_handler: base 'no changes found' message on commits, not on heads
Since Mercurial is commit-oriented, the 'no changes found' message really
should rely on what new commits are in the repo, not on new heads. This also
makes an upcoming patch much simpler.

Since everything around this code is completely broken anyway, writing a test
for this that doesn't trigger other bugs is close to impossible. An upcoming
patch will include tests.

The test output change is for an empty clone -- the output is precisely how
vanilla Mercurial treats an empty clone.
2014-03-04 15:43:54 -08:00
Siddharth Agarwal
89c409af60 verify: add new command to verify the contents of a Mercurial rev
Since the Git to Mercurial conversion process is incremental, it's at risk of
missing files, or recording files the wrong way, or recording the wrong commit
metadata. Add a command called 'gverify' that can verify the contents of a
particular Mercurial rev against the corresponding Git commit.

Currently, this is limited to checking file names, flags and contents, but this
can be made as robust as desired. Further additions will probably require
refactoring git_handler.py a bit though.

This function is pretty fast: on a Linux machine with a warm cache, verifying a
repository with around 50,000 files takes just 20 seconds. There is scope for
further improvement through parallelization, but conducting tree walks in
parallel is non-trivial with the current worker infrastructure in Mercurial.
2014-02-26 14:19:24 -08:00
Siddharth Agarwal
bbfc3bf8b0 overlayrevlog: handle root commits correctly
Previously, we'd try to access commit.parents[0] and fail. Now, check for
commit.parents being empty and return what Mercurial thinks is a repository
root in that case.
2014-02-25 00:23:12 -08:00
Siddharth Agarwal
7291240d87 tests: upgrade run-tests.py
This is the version in Mercurial rev 8f2c4360fa44, plus a patch to make
--with-hg work for system hg (sent upstream). Importantly, this gets us the
hash seed randomization we need for bugs like the one fixed by the parent
commit to be detected.
2014-02-19 21:49:06 -08:00
Siddharth Agarwal
d7dbce79bd hg2git: call _handle_subrepos when .hgsubstate is removed
Now that _handle_subrepos can handle .hgsubstate being removed, we should use
it for that.

The test changes make sure that the SHAs roundtrip.
2014-02-12 22:55:16 -08:00
Siddharth Agarwal
fdc1c44809 test-git-submodules.t: add further tests
We now also test:
- removing one submodule but not all of them
- replacing a submodule with a file
- replacing a file with a submodule
2014-02-12 16:49:51 -08:00
Siddharth Agarwal
8d0c4fe9f2 git_handler: fix hgsubstate generation
Before this patch, in the git to hg conversion, .hgsubstate once created is
never deleted, even if no submodules are any longer present. This is broken
state, as shown by the test for which the SHA changes. Fix that by looking at
the diff instead of just what submodules are present.

Since 'gitlinks' now contains *changed* gitlinks, not *all* gitlinks, it no
longer makes sense to gate gitmodules checks on that.

This patch simply demonstrates that the test was broken; an upcoming patch will
introduce more tests.

Bonus: this also makes the import process faster because we no longer need to
walk the entire tree to collect gitlinks.

This will cause the SHAs of repos that have submodules added and then removed
to change.
2014-02-14 15:44:50 -08:00
Siddharth Agarwal
a06bbdeeac git_handler: don't bail on multiple octopus merges in succession
Consider two octopus merges, one of which is a child of the other. Without this
patch, get_git_parents() called on the second octopus merge checks that each p1
is neither in the middle of an octopus merge nor the end of it. Since the end
of the first octopus merge is a p1 of the second one, this asserts.

Change the sanity check to only make sure that p1 is not in the middle of an
octopus merge.
2014-02-11 22:13:34 -08:00
Augie Fackler
ea43a55ef9 tests: fix output expectations from 3ff09f0 2013-12-15 15:25:31 -05:00
Augie Fackler
0de600a5da test-subrepos.t: hide output from newer hg versions about active bookmarks 2013-12-14 12:00:09 -05:00