sapling/tests/test-fb-hgext-diff-since-last-submit.t
Mark Thomas 0ba172a19e arcdiff: add lastsubmitted revsetpredicate
Summary:
Add a new revsetpredicate, `lastsubmitted(set)`, which maps commits to the last
version that was submitted to phabricator.

Note that this will fail if any commit doesn't have a diff associated with it,
or if the last submitted commit is not in the local repository.

Reviewed By: quark-zju

Differential Revision: D9282952

fbshipit-source-id: 9de8e3196197b2ed106779bb2f58b1f208525e91
2018-08-14 19:27:41 -07:00

167 lines
5.2 KiB
Perl

Load extensions
$ cat >> $HGRCPATH << EOF
> [extensions]
> arcconfig=$TESTDIR/../hgext/extlib/phabricator/arcconfig.py
> arcdiff=
> EOF
Diff with no revision
$ hg init repo
$ cd repo
$ touch foo
$ hg add foo
$ hg ci -qm 'No rev'
$ hg diff --since-last-submit
abort: local changeset is not associated with a differential revision
[255]
$ hg log -r 'lastsubmitted(.)' -T '{node} {desc}\n'
abort: local changeset is not associated with a differential revision
[255]
Fake a diff
$ echo bleet > foo
$ hg ci -qm 'Differential Revision: https://phabricator.fb.com/D1'
$ hg diff --since-last-submit
abort: no .arcconfig found
[255]
$ hg log -r 'lastsubmitted(.)' -T '{node} {desc}\n'
abort: no .arcconfig found
[255]
Prep configuration
$ echo '{}' > .arcrc
$ echo '{"config" : {"default" : "https://a.com/api"}, "hosts" : {"https://a.com/api/" : { "user" : "testuser", "cert" : "garbage_cert"}}}' > .arcconfig
Now progressively test the response handling for variations of missing data
$ cat > $TESTTMP/mockduit << EOF
> [{}]
> EOF
$ HG_ARC_CONDUIT_MOCK=$TESTTMP/mockduit hg diff --since-last-submit
Error calling graphql: Unexpected graphql response format
abort: unable to determine previous changeset hash
[255]
$ HG_ARC_CONDUIT_MOCK=$TESTTMP/mockduit hg log -r 'lastsubmitted(.)' -T '{node} {desc}\n'
Error calling graphql: Unexpected graphql response format
abort: unable to determine previous changeset hash
[255]
$ cat > $TESTTMP/mockduit << EOF
> [{"data": {"query": [{"results": {"nodes": [{
> "number": 1,
> "diff_status_name": "Needs Review",
> "differential_diffs": {"count": 3},
> "is_landing": false,
> "created_time": 123,
> "updated_time": 222
> }]}}]}}]
> EOF
$ HG_ARC_CONDUIT_MOCK=$TESTTMP/mockduit hg diff --since-last-submit
abort: unable to determine previous changeset hash
[255]
$ HG_ARC_CONDUIT_MOCK=$TESTTMP/mockduit hg log -r 'lastsubmitted(.)' -T '{node} {desc}\n'
abort: unable to determine previous changeset hash
[255]
$ cat > $TESTTMP/mockduit << EOF
> [{"data": {"query": [{"results": {"nodes": [{
> "number": 1,
> "diff_status_name": "Needs Review",
> "is_landing": false,
> "created_time": 123,
> "updated_time": 222
> }]}}]}}]
> EOF
$ HG_ARC_CONDUIT_MOCK=$TESTTMP/mockduit hg diff --since-last-submit
abort: unable to determine previous changeset hash
[255]
$ HG_ARC_CONDUIT_MOCK=$TESTTMP/mockduit hg log -r 'lastsubmitted(.)' -T '{node} {desc}\n'
abort: unable to determine previous changeset hash
[255]
This is the case when the diff is up to date with the current commit;
there is no diff since what was landed.
$ cat > $TESTTMP/mockduit << EOF
> [{"data": {"query": [{"results": {"nodes": [{
> "number": 1,
> "diff_status_name": "Needs Review",
> "latest_active_diff": {
> "local_commit_info": {
> "nodes": [
> {"property_value": "{\"lolwut\": {\"time\": 0, \"commit\": \"2e6531b7dada2a3e5638e136de05f51e94a427f4\"}}"}
> ]
> }
> },
> "differential_diffs": {"count": 1},
> "is_landing": false,
> "created_time": 123,
> "updated_time": 222
> }]}}]}}]
> EOF
$ HG_ARC_CONDUIT_MOCK=$TESTTMP/mockduit hg diff --since-last-submit
$ HG_ARC_CONDUIT_MOCK=$TESTTMP/mockduit hg log -r 'lastsubmitted(.)' -T '{node} {desc}\n'
2e6531b7dada2a3e5638e136de05f51e94a427f4 Differential Revision: https://phabricator.fb.com/D1
This is the case when the diff points at our parent commit, we expect to
see the bleet text show up. There's a fake hash that I've injected into
the commit list returned from our mocked phabricator; it is present to
assert that we order the commits consistently based on the time field.
$ cat > $TESTTMP/mockduit << EOF
> [{"data": {"query": [{"results": {"nodes": [{
> "number": 1,
> "diff_status_name": "Needs Review",
> "latest_active_diff": {
> "local_commit_info": {
> "nodes": [
> {"property_value": "{\"lolwut\": {\"time\": 0, \"commit\": \"88dd5a13bf28b99853a24bddfc93d4c44e07c6bd\"}}"}
> ]
> }
> },
> "differential_diffs": {"count": 1},
> "is_landing": false,
> "created_time": 123,
> "updated_time": 222
> }]}}]}}]
> EOF
$ HG_ARC_CONDUIT_MOCK=$TESTTMP/mockduit hg diff --since-last-submit --nodates
diff -r 88dd5a13bf28 -r 2e6531b7dada foo
--- a/foo
+++ b/foo
@@ -0,0 +1,1 @@
+bleet
$ HG_ARC_CONDUIT_MOCK=$TESTTMP/mockduit hg log -r 'lastsubmitted(.)' -T '{node} {desc}\n'
88dd5a13bf28b99853a24bddfc93d4c44e07c6bd No rev
$ HG_ARC_CONDUIT_MOCK=$TESTTMP/mockduit hg diff --since-last-submit-2o
Phabricator rev: 88dd5a13bf28b99853a24bddfc93d4c44e07c6bd
Local rev: 2e6531b7dada2a3e5638e136de05f51e94a427f4 (.)
Changed: foo
| ...
| +bleet
Make a new commit on top, and then use -r to look at the previous commit
$ echo other > foo
$ hg commit -m "Other commmit"
$ HG_ARC_CONDUIT_MOCK=$TESTTMP/mockduit hg diff --since-last-submit --nodates -r 2e6531b
diff -r 88dd5a13bf28 -r 2e6531b7dada foo
--- a/foo
+++ b/foo
@@ -0,0 +1,1 @@
+bleet
$ HG_ARC_CONDUIT_MOCK=$TESTTMP/mockduit hg log -r 'lastsubmitted(2e6531b)' -T '{node} {desc}\n'
88dd5a13bf28b99853a24bddfc93d4c44e07c6bd No rev