From 7b859c681d43c0cb67deea009ead4e19f55d01cd Mon Sep 17 00:00:00 2001 From: Mateusz Kwapich Date: Fri, 17 Feb 2017 16:01:02 +0000 Subject: [PATCH] whereami: add extension Summary: This command will allow us to expose simple api to all automation checking working copy parent. It's meant to be overridden by our wrapper to read the dirsate directly without shelling out to hg (see D4454504 ) Test Plan: see tests Reviewers: #mercurial, durham, rmcelroy Reviewed By: rmcelroy Subscribers: mjpieters Differential Revision: https://phabricator.intern.facebook.com/D4454502 Signature: t1:4454502:1485441135:09902c6437a7af55dfa5c97e3165681de687231f --- hgext3rd/whereami.py | 18 ++++++++++++++++++ tests/test-whereami.t | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 hgext3rd/whereami.py create mode 100644 tests/test-whereami.t diff --git a/hgext3rd/whereami.py b/hgext3rd/whereami.py new file mode 100644 index 0000000000..6f8b9b2e6e --- /dev/null +++ b/hgext3rd/whereami.py @@ -0,0 +1,18 @@ +from mercurial import cmdutil +from mercurial.node import hex, nullid + +cmdtable = {} +command = cmdutil.command(cmdtable) +testedwith = 'ships-with-fb-hgext' + +@command('whereami') +def whereami(ui, repo, *args, **opts): + """output the current working directory parents + + Outputs the hashes of current working directory parents separated + by newline. + """ + parents = repo.dirstate.parents() + ui.status('%s\n' % hex(parents[0])) + if parents[1] != nullid: + ui.status('%s\n' % hex(parents[1])) diff --git a/tests/test-whereami.t b/tests/test-whereami.t new file mode 100644 index 0000000000..5c1dde24f9 --- /dev/null +++ b/tests/test-whereami.t @@ -0,0 +1,38 @@ +Test whereami + + $ hg init repo1 + $ cd repo1 + $ cat > .hg/hgrc < [extensions] + > whereami=$(dirname $TESTDIR)/hgext3rd/whereami.py + > EOF + + $ hg whereami + 0000000000000000000000000000000000000000 + + $ echo a > a + $ hg add a + $ hg commit -m a + + $ hg whereami + cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b + + $ echo b > b + $ hg add b + $ hg commit -m b + + $ hg up ".^" + 0 files updated, 0 files merged, 1 files removed, 0 files unresolved + + $ echo c > c + $ hg add c + $ hg commit -m c + created new head + + $ hg merge 1 + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved + (branch merge, don't forget to commit) + + $ hg whereami + d36c0562f908c692f5204d606d4ff3537d41f1bf + d2ae7f538514cd87c17547b0de4cea71fe1af9fb