tweakdefaults already overrides amend, rebase and graft to update the commit date
to the current time when it creates new commits.
This extends this to also give the same behavior to histedit.
stash | |
ryanmce |
Restricted Project |
tweakdefaults already overrides amend, rebase and graft to update the commit date
to the current time when it creates new commits.
This extends this to also give the same behavior to histedit.
New unit test added.
Lint OK |
Unit Tests OK |
Path | Packages | |||
---|---|---|---|---|
M | hgext3rd/tweakdefaults.py (17 lines) | |||
M | tests/test-smartlog-obsolete.t (2 lines) | |||
M | tests/test-tweakdefaults.t (35 lines) |
Commit | Local | Parents | Author | Summary | Date |
---|---|---|---|---|---|
ff9435f666d9 | 3556 | 07648c8cd7ac | Mark Thomas | tweakdefaults: make histedit update dates of commits it edits | Aug 23 2017, 12:24 PM |
hg histgrep renamed from grep | hg histgrep renamed from grep | ||||
Config:: | Config:: | ||||
[tweakdefaults] | [tweakdefaults] | ||||
# default destination used by pull --rebase / --update | # default destination used by pull --rebase / --update | ||||
defaultdest = '' | defaultdest = '' | ||||
# whether to keep the commit date when doing amend / graft / rebase | # whether to keep the commit date when doing amend / graft / rebase / | ||||
# histedit | |||||
amendkeepdate = False | amendkeepdate = False | ||||
graftkeepdate = False | graftkeepdate = False | ||||
rebasekeepdate = False | rebasekeepdate = False | ||||
histeditkeepdate = False | |||||
# whether to allow or disable some commands | # whether to allow or disable some commands | ||||
allowbranch = True | allowbranch = True | ||||
allowfullrepohistgrep = False | allowfullrepohistgrep = False | ||||
allowmerge = True | allowmerge = True | ||||
allowrollback = True | allowrollback = True | ||||
allowtags = True | allowtags = True | ||||
wrapcommand(commands.table, 'tags', tagscmd) | wrapcommand(commands.table, 'tags', tagscmd) | ||||
wrapcommand(commands.table, 'graft', graftcmd) | wrapcommand(commands.table, 'graft', graftcmd) | ||||
try: | try: | ||||
fbamendmodule = extensions.find('fbamend') | fbamendmodule = extensions.find('fbamend') | ||||
opawareamend = markermetadatawritingcommand(ui, amendcmd, 'amend') | opawareamend = markermetadatawritingcommand(ui, amendcmd, 'amend') | ||||
wrapcommand(fbamendmodule.cmdtable, 'amend', opawareamend) | wrapcommand(fbamendmodule.cmdtable, 'amend', opawareamend) | ||||
except KeyError: | except KeyError: | ||||
pass | pass | ||||
try: | |||||
histeditmodule = extensions.find('histedit') | |||||
wrapfunction(histeditmodule, 'commitfuncfor', histeditcommitfuncfor) | |||||
except KeyError: | |||||
pass | |||||
# wrapped createmarkers knows how to write operation-aware | # wrapped createmarkers knows how to write operation-aware | ||||
# metadata (e.g. 'amend', 'rebase' and so forth) | # metadata (e.g. 'amend', 'rebase' and so forth) | ||||
wrapfunction(obsolete, 'createmarkers', _createmarkers) | wrapfunction(obsolete, 'createmarkers', _createmarkers) | ||||
# bookmark -D is an alias to strip -B | # bookmark -D is an alias to strip -B | ||||
entry = wrapcommand(commands.table, 'bookmarks', bookmarkcmd) | entry = wrapcommand(commands.table, 'bookmarks', bookmarkcmd) | ||||
entry[1].insert(3, ('D', 'strip', None, | entry[1].insert(3, ('D', 'strip', None, | ||||
def amendcmd(orig, ui, repo, *pats, **opts): | def amendcmd(orig, ui, repo, *pats, **opts): | ||||
if (not opts.get("date") | if (not opts.get("date") | ||||
and not opts.get("to") | and not opts.get("to") | ||||
and not ui.configbool('tweakdefaults', 'amendkeepdate')): | and not ui.configbool('tweakdefaults', 'amendkeepdate')): | ||||
opts["date"] = currentdate() | opts["date"] = currentdate() | ||||
return orig(ui, repo, *pats, **opts) | return orig(ui, repo, *pats, **opts) | ||||
def histeditcommitfuncfor(orig, repo, src): | |||||
origcommitfunc = orig(repo, src) | |||||
def commitfunc(**kwargs): | |||||
if not repo.ui.configbool('tweakdefaults', 'histeditkeepdate'): | |||||
kwargs['date'] = util.makedate(time.time()) | |||||
origcommitfunc(**kwargs) | |||||
return commitfunc | |||||
def log(orig, ui, repo, *pats, **opts): | def log(orig, ui, repo, *pats, **opts): | ||||
# 'hg log' defaults to -f | # 'hg log' defaults to -f | ||||
# All special uses of log (--date, --branch, etc) will also now do follow. | # All special uses of log (--date, --branch, etc) will also now do follow. | ||||
if not opts.get('rev') and not opts.get('all'): | if not opts.get('rev') and not opts.get('all'): | ||||
opts['follow'] = True | opts['follow'] = True | ||||
return orig(ui, repo, *pats, **opts) | return orig(ui, repo, *pats, **opts) | ||||
$ cat >> $HGRCPATH << EOF | $ cat >> $HGRCPATH << EOF | ||||
> [extensions] | > [extensions] | ||||
> fbamend=$TESTDIR/../hgext3rd/fbamend | > fbamend=$TESTDIR/../hgext3rd/fbamend | ||||
> histedit= | > histedit= | ||||
> inhibit=$TESTDIR/../hgext3rd/inhibit.py | > inhibit=$TESTDIR/../hgext3rd/inhibit.py | ||||
> rebase= | > rebase= | ||||
> smartlog=$TESTDIR/../hgext3rd/smartlog.py | > smartlog=$TESTDIR/../hgext3rd/smartlog.py | ||||
> tweakdefaults=$TESTDIR/../hgext3rd/tweakdefaults.py | > tweakdefaults=$TESTDIR/../hgext3rd/tweakdefaults.py | ||||
> [tweakdefaults] | |||||
> histeditkeepdate = true | |||||
> [experimental] | > [experimental] | ||||
> evolution = createmarkers, allowunstable | > evolution = createmarkers, allowunstable | ||||
> allowdivergence = on | > allowdivergence = on | ||||
> [ui] | > [ui] | ||||
> interactive = true | > interactive = true | ||||
> EOF | > EOF | ||||
$ mkcommit() { | $ mkcommit() { | ||||
> echo $1 > $1 | > echo $1 > $1 |
$ . "$TESTDIR/histedit-helpers.sh" | |||||
$ cat >> $HGRCPATH << EOF | $ cat >> $HGRCPATH << EOF | ||||
> [extensions] | > [extensions] | ||||
> tweakdefaults=$TESTDIR/../hgext3rd/tweakdefaults.py | > tweakdefaults=$TESTDIR/../hgext3rd/tweakdefaults.py | ||||
> fbamend=$TESTDIR/../hgext3rd/fbamend | > fbamend=$TESTDIR/../hgext3rd/fbamend | ||||
> rebase= | > rebase= | ||||
> histedit= | |||||
> [experimental] | > [experimental] | ||||
> updatecheck=noconflict | > updatecheck=noconflict | ||||
> EOF | > EOF | ||||
Setup repo | Setup repo | ||||
$ hg init repo | $ hg init repo | ||||
$ cd repo | $ cd repo | ||||
$ echo test_2 > rebase_source | $ echo test_2 > rebase_source | ||||
$ hg commit -Aqm "source commit for rebase" | $ hg commit -Aqm "source commit for rebase" | ||||
$ hg bookmark rebase_source_test_2 | $ hg bookmark rebase_source_test_2 | ||||
$ hg rebase -q -s rebase_source_test_2 -d rebase_dest_test_2 --config tweakdefaults.rebasekeepdate=True | $ hg rebase -q -s rebase_source_test_2 -d rebase_dest_test_2 --config tweakdefaults.rebasekeepdate=True | ||||
$ hg log -l 2 -T "{date} {rev}\n" | $ hg log -l 2 -T "{date} {rev}\n" | ||||
0.00 15 | 0.00 15 | ||||
0.00 14 | 0.00 14 | ||||
Test histedit date when tweakdefaults.histeditkeepdate is set | |||||
$ hg bookmark histedit_test | |||||
$ echo test_1 > histedit_1 | |||||
$ hg commit -Aqm "commit 1 for histedit" | |||||
$ echo test_2 > histedit_2 | |||||
$ hg commit -Aqm "commit 2 for histedit" | |||||
$ echo test_3 > histedit_3 | |||||
$ hg commit -Aqm "commit 3 for histedit" | |||||
$ hg histedit 16 --commands - --config tweakdefaults.histeditkeepdate=True 2>&1 <<EOF| fixbundle | |||||
> pick 16 | |||||
> pick 18 | |||||
> pick 17 | |||||
> EOF | |||||
[1] | |||||
$ hg log -l 3 -T "{date} {rev} {desc}\n" | |||||
0.00 18 commit 2 for histedit | |||||
0.00 17 commit 3 for histedit | |||||
0.00 16 commit 1 for histedit | |||||
Test histedit date when tweakdefaults.histeditkeepdate is not set | |||||
$ hg histedit 16 --commands - 2>&1 <<EOF| fixbundle | |||||
> pick 16 | |||||
> pick 18 | |||||
> pick 17 | |||||
> EOF | |||||
[1] | |||||
$ hg log -l 2 -T "{rev} {desc}\n" -d "yesterday to today" | |||||
18 commit 3 for histedit | |||||
17 commit 2 for histedit | |||||
Test reuse message flag by taking message from previous commit | Test reuse message flag by taking message from previous commit | ||||
$ cd ../.. | $ cd ../.. | ||||
$ hg up -q hyphen-book | $ hg up -q hyphen-book | ||||
$ touch afile | $ touch afile | ||||
$ hg add afile | $ hg add afile | ||||
$ hg commit -M 2 | $ hg commit -M 2 | ||||
$ hg log --template {desc} -r . | $ hg log --template {desc} -r . | ||||
b (no-eol) | b (no-eol) | ||||
HG: branch 'foo' | HG: branch 'foo' | ||||
HG: bookmark 'hyphen-book' | HG: bookmark 'hyphen-book' | ||||
HG: changed afile | HG: changed afile | ||||
Test non-remotenames use of pull --rebase and --update requires --dest | Test non-remotenames use of pull --rebase and --update requires --dest | ||||
$ cd $TESTTMP | $ cd $TESTTMP | ||||
$ hg clone repo clone | $ hg clone repo clone | ||||
updating to branch default | updating to branch default | ||||
9 files updated, 0 files merged, 0 files removed, 0 files unresolved | 12 files updated, 0 files merged, 0 files removed, 0 files unresolved | ||||
$ cd clone | $ cd clone | ||||
$ hg pull --rebase | $ hg pull --rebase | ||||
abort: you must use a bookmark with tracking or manually specify a destination for the rebase | abort: you must use a bookmark with tracking or manually specify a destination for the rebase | ||||
(set up tracking with `hg book <name> -t <destination>` or manually supply --dest / -d) | (set up tracking with `hg book <name> -t <destination>` or manually supply --dest / -d) | ||||
[255] | [255] | ||||
$ hg pull --update | $ hg pull --update | ||||
abort: you must specify a destination for the update | abort: you must specify a destination for the update | ||||
(use `hg pull --update --dest <destination>`) | (use `hg pull --update --dest <destination>`) |