Mercurial > hg
view tests/test-git-interop.t @ 44651:00e0c5c06ed5
pycompat: change argv conversion semantics
Use of os.fsencode() to convert Python's sys.argv back to bytes
was not correct because it isn't the logically inverse operation
from what CPython was doing under the hood.
This commit changes the logic for doing the str -> bytes
conversion. This required a separate implementation for
POSIX and Windows.
The Windows behavior is arguably not ideal. The previous
behavior on Windows was leading to failing tests, such as
test-http-branchmap.t, which defines a utf-8 branch name
via a command argument. Previously, Mercurial's argument
parser looked to be receiving wchar_t bytes in some cases.
After this commit, behavior on Windows is compatible with
Python 2, where CPython did not implement `int wmain()` and
Windows was performing a Unicode to ANSI conversion on the
wchar_t native command line.
Arguably better behavior on Windows would be for Mercurial to
preserve the original Unicode sequence coming from Python and
to wrap this in a bytes-like type so we can round trip safely.
But, this would be new, backwards incompatible behavior. My
goal for this commit was to converge Mercurial behavior on
Python 3 on Windows to fix busted tests. And I believe I was
successful, as this commit fixes 9 tests on my Windows
machine and 14 tests in the AWS CI environment!
Differential Revision: https://phab.mercurial-scm.org/D8337
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 28 Mar 2020 12:18:58 -0700 |
parents | 02c47b74366c |
children | 572f98a6f6af |
line wrap: on
line source
#require pygit2 Setup: $ GIT_AUTHOR_NAME='test'; export GIT_AUTHOR_NAME > GIT_AUTHOR_EMAIL='test@example.org'; export GIT_AUTHOR_EMAIL > GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0000"; export GIT_AUTHOR_DATE > GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"; export GIT_COMMITTER_NAME > GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"; export GIT_COMMITTER_EMAIL > GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"; export GIT_COMMITTER_DATE > count=10 > gitcommit() { > GIT_AUTHOR_DATE="2007-01-01 00:00:$count +0000"; > GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE" > git commit "$@" >/dev/null 2>/dev/null || echo "git commit error" > count=`expr $count + 1` > } Test auto-loading extension works: $ mkdir nogit $ cd nogit $ mkdir .hg $ echo git >> .hg/requires $ hg status abort: repository specified git format in .hg/requires but has no .git directory [255] $ git init Initialized empty Git repository in $TESTTMP/nogit/.git/ This status invocation shows some hg gunk because we didn't use `hg init --git`, which fixes up .git/info/exclude for us. $ hg status ? .hg/cache/git-commits.sqlite ? .hg/cache/git-commits.sqlite-shm ? .hg/cache/git-commits.sqlite-wal ? .hg/requires $ cd .. Now globally enable extension for the rest of the test: $ echo "[extensions]" >> $HGRCPATH > echo "git=" >> $HGRCPATH Make a new repo with git: $ mkdir foo $ cd foo $ git init Initialized empty Git repository in $TESTTMP/foo/.git/ Ignore the .hg directory within git: $ echo .hg >> .git/info/exclude $ echo alpha > alpha $ git add alpha $ gitcommit -am 'Add alpha' $ echo beta > beta $ git add beta $ gitcommit -am 'Add beta' $ echo gamma > gamma $ git status On branch master Untracked files: (use "git add <file>..." to include in what will be committed) gamma nothing added to commit but untracked files present (use "git add" to track) Without creating the .hg, hg status fails: $ hg status abort: no repository found in '$TESTTMP/foo' (.hg not found)! [255] But if you run hg init --git, it works: $ hg init --git $ hg id --traceback 3d9be8deba43 tip master $ hg status ? gamma Log works too: $ hg log changeset: 1:3d9be8deba43 bookmark: master tag: tip user: test <test@example.org> date: Mon Jan 01 00:00:11 2007 +0000 summary: Add beta changeset: 0:c5864c9d16fb user: test <test@example.org> date: Mon Jan 01 00:00:10 2007 +0000 summary: Add alpha and bookmarks: $ hg bookmarks * master 1:3d9be8deba43 diff even works transparently in both systems: $ echo blah >> alpha $ git diff diff --git a/alpha b/alpha index 4a58007..faed1b7 100644 --- a/alpha +++ b/alpha @@ -1* +1,2 @@ (glob) alpha +blah $ hg diff --git diff --git a/alpha b/alpha --- a/alpha +++ b/alpha @@ -1,1 +1,2 @@ alpha +blah Remove a file, it shows as such: $ rm alpha $ hg status ! alpha ? gamma Revert works: $ hg revert alpha --traceback $ hg status ? gamma $ git status On branch master Untracked files: (use "git add <file>..." to include in what will be committed) gamma nothing added to commit but untracked files present (use "git add" to track) Add shows sanely in both: $ hg add gamma $ hg status A gamma $ hg files alpha beta gamma $ git ls-files alpha beta gamma $ git status On branch master Changes to be committed: (use "git restore --staged <file>..." to unstage) new file: gamma forget does what it should as well: $ hg forget gamma $ hg status ? gamma $ git status On branch master Untracked files: (use "git add <file>..." to include in what will be committed) gamma nothing added to commit but untracked files present (use "git add" to track) clean up untracked file $ rm gamma hg log FILE $ echo a >> alpha $ hg ci -m 'more alpha' --traceback --date '1583522787 18000' $ echo b >> beta $ hg ci -m 'more beta' $ echo a >> alpha $ hg ci -m 'even more alpha' $ hg log -G alpha @ changeset: 4:6626247b7dc8 : bookmark: master : tag: tip : user: test <test> : date: Thu Jan 01 00:00:00 1970 +0000 : summary: even more alpha : o changeset: 2:a1983dd7fb19 : user: test <test> : date: Fri Mar 06 14:26:27 2020 -0500 : summary: more alpha : o changeset: 0:c5864c9d16fb user: test <test@example.org> date: Mon Jan 01 00:00:10 2007 +0000 summary: Add alpha $ hg log -G beta o changeset: 3:d8ee22687733 : user: test <test> : date: Thu Jan 01 00:00:00 1970 +0000 : summary: more beta : o changeset: 1:3d9be8deba43 | user: test <test@example.org> ~ date: Mon Jan 01 00:00:11 2007 +0000 summary: Add beta hg annotate $ hg annotate alpha 0: alpha 2: a 4: a $ hg annotate beta 1: beta 3: b Files in subdirectories. TODO: case-folding support, make this `A` instead of `a`. $ mkdir a $ echo "This is file mu." > a/mu $ hg ci -A -m 'Introduce file a/mu' adding a/mu Both hg and git agree a/mu is part of the repo $ git ls-files a/mu alpha beta $ hg files a/mu alpha beta hg and git status both clean $ git status On branch master nothing to commit, working tree clean $ hg status node|shortest works correctly $ hg log -T '{node}\n' | sort 3d9be8deba43482be2c81a4cb4be1f10d85fa8bc 6626247b7dc8f231b183b8a4761c89139baca2ad a1983dd7fb19cbd83ad5a1c2fc8bf3d775dea12f ae1ab744f95bfd5b07cf573baef98a778058537b c5864c9d16fb3431fe2c175ff84dc6accdbb2c18 d8ee22687733a1991813560b15128cd9734f4b48 $ hg log -r ae1ab744f95bfd5b07cf573baef98a778058537b --template "{shortest(node,1)}\n" ae