sapling/eden/scm/tests/test-hggit-external-sync.t

73 lines
1.4 KiB
Perl
Raw Normal View History

hggit: add a external-sync command that does the bare minimum Summary: For our HgExternalSync jobs that pull from git, we don't really use most of the bells and whistles of hggit. Notably, we don't care about bookmarks: we only ever pull master, we never update to it, we only ever look at `-r tip`. However, we do care about things that are actually much harder to fit in a world where we try to pretend the remote git repository is actually a hg repository we can pull from. Notably, we'd like to enforce limits on how many commits we pull (and convert) at a time, so that if we fall behind a little bit, we don't start falling even more behind by having to convert bigger and bigger batches of commits. If we're trying to pretend fetching from git and converting commits is actually a pull, then that seems harder to pull off (we'd need to somehow rewind the remote head we're pulling before importing it). So, this adds a new external-sync command to hggit that basically the bare minimum that we do need. It lets you specify a git remote and a head you care about, and import up to N commits from it. That's it — no bookmarks are updated or anything (but the git-mapfile is, of course). The only thing that changes is your commits. If you actually want to interact with your git repository on an ongoing basis as if it were a remote hg repository, this is completely useless, but that isn't what we actually do, so that should be OK. As part of this, I've modified a few other parts of git_handler to remove places where we called a `uri` `remote_name` (which is a bit confusing), and a place where we were asking for a `remote_name` parameter that I don't have here, but which we also didn't actually need (in `import_git_objects`). Reviewed By: farnz Differential Revision: D20836601 fbshipit-source-id: 96230e6e8269d0472404414948fd2f02aa98d79c
2020-04-06 17:33:37 +03:00
Load commonly used test logic
$ . "$TESTDIR/hggit/testutil"
$ setconfig hggit.mapsavefrequency=1
# Set up the git repo
$ cd "$TESTTMP"
$ git init -q gitrepo
hggit: add a external-sync command that does the bare minimum Summary: For our HgExternalSync jobs that pull from git, we don't really use most of the bells and whistles of hggit. Notably, we don't care about bookmarks: we only ever pull master, we never update to it, we only ever look at `-r tip`. However, we do care about things that are actually much harder to fit in a world where we try to pretend the remote git repository is actually a hg repository we can pull from. Notably, we'd like to enforce limits on how many commits we pull (and convert) at a time, so that if we fall behind a little bit, we don't start falling even more behind by having to convert bigger and bigger batches of commits. If we're trying to pretend fetching from git and converting commits is actually a pull, then that seems harder to pull off (we'd need to somehow rewind the remote head we're pulling before importing it). So, this adds a new external-sync command to hggit that basically the bare minimum that we do need. It lets you specify a git remote and a head you care about, and import up to N commits from it. That's it — no bookmarks are updated or anything (but the git-mapfile is, of course). The only thing that changes is your commits. If you actually want to interact with your git repository on an ongoing basis as if it were a remote hg repository, this is completely useless, but that isn't what we actually do, so that should be OK. As part of this, I've modified a few other parts of git_handler to remove places where we called a `uri` `remote_name` (which is a bit confusing), and a place where we were asking for a `remote_name` parameter that I don't have here, but which we also didn't actually need (in `import_git_objects`). Reviewed By: farnz Differential Revision: D20836601 fbshipit-source-id: 96230e6e8269d0472404414948fd2f02aa98d79c
2020-04-06 17:33:37 +03:00
$ cd gitrepo
$ echo commit1 > commit1
$ git add .
$ fn_git_commit -m 'commit1'
Clone the repo
$ cd "$TESTTMP"
$ hg clone -q -r master gitrepo hgrepo
Add more commits
$ cd "$TESTTMP/gitrepo"
$ echo commit2 > commit2
$ git add .
$ fn_git_commit -m 'commit2'
$ echo commit3 > commit3
$ git add .
$ fn_git_commit -m 'commit3'
$ echo commit4 > commit4
$ git add .
$ fn_git_commit -m 'commit4'
Pull one of them
$ cd "$TESTTMP/hgrepo"
$ hg log -r tip -T '{desc}\n'
commit1
$ hg external-sync "$TESTTMP/gitrepo" master 1
importing up to 1 commits from $TESTTMP/gitrepo in master
importing git objects into hg
imported 1 commits
$ hg log -r tip -T '{desc}\n'
commit2
Pull the rest
$ hg external-sync "$TESTTMP/gitrepo" master 3
importing up to 3 commits from $TESTTMP/gitrepo in master
importing git objects into hg
imported 2 commits
$ hg log -r tip -T '{desc}\n'
commit4
$ hg up tip
3 files updated, 0 files merged, 0 files removed, 0 files unresolved
(leaving bookmark master)
$ ls
commit1
commit2
commit3
commit4
Nothing left ot pull
$ hg external-sync "$TESTTMP/gitrepo" master 100
importing up to 100 commits from $TESTTMP/gitrepo in master
no changes found
imported 0 commits