sapling/tests/test-reflog.t
Durham Goode bd577925d9 reflog: adds a reflog extension to fb-hgext
Summary:
This adds an extension that tracks the locations of the working copy and
bookmarks over time. It's still a proof of concept, but I want to get it
deployed to start getting feedback.

Running `hg reflog` by default shows the previous locations of the working
copy (most recent first).

  ~/myrepo> hg reflog
  Previous locations of '.':
  35a5fcfee452  rebase -d master
  32eee5e2d406  up .^
  b5d6dab4f900  up foo -C

Specifying a bookmark name shows the locations of that bookmark over time.

  ~/myrepo> hg reflog foo
  Previous locations of 'foo':
  d1a696044ec0  rebase -d master
  35a5fcfee452  rebase -d master
  32eee5e2d406  book foo -f

--verbose will show more information about each entry.

  ~/myrepo> hg reflog foo -v
  Previous locations of 'foo':
  35a5fcfee452 -> d1a696044ec0 durham   2014-10-01 18:32:14  rebase -d master
  32eee5e2d406 -> 35a5fcfee452 durham   2014-10-01 17:28:54  rebase -d master
  000000000000 -> 32eee5e2d406 durham   2014-10-01 17:28:30  book foo -f

It's currently stored as a single .hg/reflog file that is append only. Each
entry can store an arbitrary number of hashes (like storing 2 hashes for a merge
state working copy), which means we could also potentially use this to track
heads in branches as well.

It also (sorta) works with '-T json' for machine readable output:

  ~/myrepo> hg reflog foo -T json
  [
   {
    "command": "up .^",
    "date": "2014-10-02 13:54:45",
    "newhashes": "474ff61d1a36",
    "oldhashes": "d1a696044ec0",
    "user": "durham  "
   },
   {
    "command": "book foo",
  ...
  ]

Test Plan: Added tests. Ran them.

Reviewers: sid0, pyd, mpm, davidsp, akushner

Differential Revision: https://phabricator.fb.com/D1592875
2014-10-02 14:04:54 -07:00

118 lines
2.7 KiB
Raku

$ extpath=$(dirname $TESTDIR)
$ cp $extpath/reflog.py $TESTTMP # use $TESTTMP substitution in message
$ cat >> $HGRCPATH << EOF
> [extensions]
> reflog=$TESTTMP/reflog.py
> EOF
$ hg init repo
$ cd repo
Test empty reflog
$ hg reflog
Previous locations of '.':
no recorded locations
$ hg reflog fakebookmark
Previous locations of 'fakebookmark':
no recorded locations
Test that working copy changes are tracked
$ echo a > a
$ hg commit -Aqm a
$ hg reflog
Previous locations of '.':
cb9a9f314b8b commit -Aqm a
$ echo b > a
$ hg commit -Aqm b
$ hg reflog
Previous locations of '.':
1e6c11564562 commit -Aqm b
cb9a9f314b8b commit -Aqm a
$ hg up 0
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ hg reflog
Previous locations of '.':
cb9a9f314b8b up 0
1e6c11564562 commit -Aqm b
cb9a9f314b8b commit -Aqm a
Test that bookmarks are tracked
$ hg book -r tip foo
$ hg reflog foo
Previous locations of 'foo':
1e6c11564562 book -r tip foo
$ hg book -f foo
$ hg reflog foo
Previous locations of 'foo':
cb9a9f314b8b book -f foo
1e6c11564562 book -r tip foo
$ hg up
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
updating bookmark foo
$ hg reflog foo
Previous locations of 'foo':
1e6c11564562 up
cb9a9f314b8b book -f foo
1e6c11564562 book -r tip foo
Test that bookmarks and working copy tracking is not mixed
$ hg reflog
Previous locations of '.':
1e6c11564562 up
cb9a9f314b8b up 0
1e6c11564562 commit -Aqm b
cb9a9f314b8b commit -Aqm a
Test verbose output
$ hg reflog -v
Previous locations of '.':
cb9a9f314b8b -> 1e6c11564562 * * up (glob)
1e6c11564562 -> cb9a9f314b8b * * up 0 (glob)
cb9a9f314b8b -> 1e6c11564562 * * commit -Aqm b (glob)
000000000000 -> cb9a9f314b8b * * commit -Aqm a (glob)
$ hg reflog -v foo
Previous locations of 'foo':
cb9a9f314b8b -> 1e6c11564562 * * up (glob)
1e6c11564562 -> cb9a9f314b8b * * book -f foo (glob)
000000000000 -> 1e6c11564562 * * book -r tip foo (glob)
Test JSON output
$ hg reflog -T json
[
{
"command": "up",
"date": "*", (glob)
"newhashes": "1e6c11564562",
"oldhashes": "cb9a9f314b8b",
"user": "*" (glob)
},
{
"command": "up 0",
"date": "*", (glob)
"newhashes": "cb9a9f314b8b",
"oldhashes": "1e6c11564562",
"user": "*" (glob)
},
{
"command": "commit -Aqm b",
"date": "*", (glob)
"newhashes": "1e6c11564562",
"oldhashes": "cb9a9f314b8b",
"user": "*" (glob)
},
{
"command": "commit -Aqm a",
"date": "*", (glob)
"newhashes": "cb9a9f314b8b",
"oldhashes": "000000000000",
"user": "*" (glob)
}
]