felipec / git-remote-hg

Transparent bidirectional bridge between Git and Mercurial for Git
GNU General Public License v2.0
369 stars 87 forks source link

Git commit ID (SHA-1 hash) is not consistent between the committing repository and others #73

Open CheukLeung opened 6 years ago

CheukLeung commented 6 years ago

Hey,

I am using the latest git-remote-hg and Git 2.18.0. If I make a commit on a hg repository cloned with git-remote-hg and push it back to remote, the commit ID from Git would not be usable by other people using the same repository.

The following is how I can reproduced it:

$ git clone hg::/tmp/hg-git/testrepo/ testrepo-git
Cloning into 'testrepo-git'...
warning: You appear to have cloned an empty repository.
$ cd testrepo-git/
$ touch a && git add a && git commit -m "Add a"
[master (root-commit) a328f58] Add a
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 a

$ git push
To hg::/tmp/hg-git/testrepo/
 * [new branch]      master -> master
$ git rev-parse HEAD
a328f582f9c0764814e48f4a957466fd86e7c4de
$ cd ..
$ git clone hg::/tmp/hg-git/testrepo/ testrepo-git-2
Cloning into 'testrepo-git-2'...
$ cd testrepo-git-2/ && git rev-parse HEAD
57508268690601d470e5aa29a0e6004508d8df73

The hash from the committing repository would not be updated even after pulling, and if another repository is using git-remote-hg for commit and push, it gets even more messier. I can reproduce it with 3 repositories and only 2 commits as below:

testrepo-git$ git log --oneline 
3cff113 (HEAD -> master, origin/master, origin/branches/default, refs/hg/origin/branches/default, refs/hg/origin/bookmarks/master) Add b
a328f58 Add a

testrepo-git-2$ git log --oneline 
a8ac55c (HEAD -> master, origin/master, origin/HEAD, refs/hg/origin/bookmarks/master) Add b
5750826 (origin/branches/default, refs/hg/origin/branches/default) Add a

testrepo-git-3$ git log --oneline 
4b311a5 (HEAD -> master, origin/master, origin/branches/default, origin/HEAD, refs/hg/origin/branches/default, refs/hg/origin/bookmarks/master) Add b
5750826 Add a

This means referencing using the Git commit ID is almost impossible, and it also make the hg repository impossible to be used as submodule in the Git repository, due to how git is referencing the ID for the submodule version.

catskul commented 5 years ago

did you ever resolve/find a work around for this issue?

felipec commented 5 years ago

The following is how I can reproduced it:

hg init /tmp/hg-git/testrepo &&
git clone -q hg::/tmp/hg-git/testrepo testrepo-git-1 &&
(cd testrepo-git-1 &&
 touch a && git add a && git commit -q -m "Add a" &&
 git push -q
) &&
git clone -q hg::/tmp/hg-git/testrepo testrepo-git-2 &&
git --git-dir=testrepo-git-1/.git/ rev-parse master &&
git --git-dir=testrepo-git-2/.git/ rev-parse master

I modified your steps a little bit, and I don't see the same problem. Maybe in your case HEAD is pointing to another ref?

I get:

warning: You appear to have cloned an empty repository.
3b3c1ee66e17361cf3e96156275b37dc3974c8a5
3b3c1ee66e17361cf3e96156275b37dc3974c8a5

Please try with the latest release (v0.4). Also, check that the output of git cat-file -p master is exactly the same in both repositories. The difference should give you a clue.