sapling/eden/scm/tests/test-debugdynamicconfig.t
Muir Manders 1caeb25d0a status: enable rust status in more tests
Summary:
These tests just needed to switch to a modern, non-revlog repo format.

Remaining tests using the old status have the same problem, but are trickier to migrate due more complicated client/server interactions.

Reviewed By: quark-zju

Differential Revision: D42748903

fbshipit-source-id: 979720cff4e72de586c90d922694d4d88c130b2f
2023-01-31 12:25:37 -08:00

290 lines
7.6 KiB
Perl

#chg-compatible
$ configure modernclient
$ hg help > /dev/null
Outside of repo the dynamic config gets written to a known global spot.
$ cat $TESTTMP/.cache/edenscm/hgrc.dynamic
# version=4.4.2* (glob)
# reponame=no_repo
# canary=None
# username=
# Generated by `hg debugdynamicconfig` - DO NOT MODIFY
$ export HG_TEST_DYNAMICCONFIG="$TESTTMP/test_hgrc"
$ cat > test_hgrc <<EOF
> [section]
> key=value
> EOF
debugdumpdynamicconfig works without a repo
$ hg debugdumpdynamicconfig
[section]
key=value
$ hg debugdumpdynamicconfig section.key
value
Create a repo
$ newclientrepo client
Verify it can be manually generated
$ hg debugdynamicconfig
$ cat .hg/hgrc.dynamic
# version=4.4.2* (glob)
# reponame=reponame-default
# canary=None
# username=
# Generated by `hg debugdynamicconfig` - DO NOT MODIFY
[section]
key=value
$ hg config section.key
value
Verify it can be automatically synchronously generated
$ rm .hg/hgrc.dynamic
$ hg config section.key
value
$ cat .hg/hgrc.dynamic
# version=4.4.2* (glob)
# reponame=client_server
# canary=None
# username=
# Generated by `hg debugdynamicconfig` - DO NOT MODIFY
[section]
key=value
#if no-windows
$ f -m .hg/hgrc.dynamic
.hg/hgrc.dynamic: mode=644
#endif
Verify it can be automatically asynchronously regenerated
$ cat > $TESTTMP/test_hgrc <<EOF
> [section]
> key=value
> [section2]
> key2=value2
> EOF
$ hg config section2.key2 --config configs.generationtime=30 # No regen, because too soon
[1]
$ sleep 1
$ hg status --config configs.generationtime=1 # Regen, because lower time limit
$ sleep 0.5 # Time for background process to complete
$ hg config section2.key2
value2
$ cat .hg/hgrc.dynamic
# version=4.4.2* (glob)
# reponame=reponame-default
# canary=None
# username=
# Generated by `hg debugdynamicconfig` - DO NOT MODIFY
[section]
key=value
[section2]
key2=value2
Verify mtime is updated even if no change is made
$ hg debugsh -c "import stat, os; ui.write('%s\n' % os.stat(os.path.join('.hg', 'hgrc.dynamic'))[stat.ST_MTIME])" > $TESTTMP/mtime1
$ hg status --config configs.generationtime=60 # No regen, because high time limit
$ hg debugsh -c "import stat, os; ui.write('%s\n' % os.stat(os.path.join('.hg', 'hgrc.dynamic'))[stat.ST_MTIME])" > $TESTTMP/mtime2
$ [ "$(cat $TESTTMP/mtime1)" = "$(cat $TESTTMP/mtime2)" ]
$ sleep 1
$ hg status --config configs.generationtime=1 # Regen, because low time limit
$ hg debugsh -c "import stat, os; ui.write('%s\n' % os.stat(os.path.join('.hg', 'hgrc.dynamic'))[stat.ST_MTIME])" > $TESTTMP/mtime3
$ [ "$(cat $TESTTMP/mtime3)" = "$(cat $TESTTMP/mtime2)" ]
[1]
Verify we generate and load from a shared repo
$ cd ..
$ enable share
$ newclientrepo shared
$ cd ..
$ hg share shared shared_copy --configfile shared/.hg/hgrc --traceback --config devel.collapse-traceback=false
updating working directory
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ cd shared_copy
- Test the case where sharedpath ends in newlines.
$ echo >> .hg/sharedpath
$ echo >> .hg/sharedpath
$ hg debugdynamicconfig
$ test -f .hg/hgrc.dynamic
[1]
$ cat ../shared/.hg/hgrc.dynamic
# version=4.4.2* (glob)
# reponame=reponame-default
# canary=None
# username=
# Generated by `hg debugdynamicconfig` - DO NOT MODIFY
[section]
key=value
[section2]
key2=value2
$ hg config section.key
value
Verify we regenerate configs if the Mercurial version differs
$ cat > ../shared/.hg/hgrc.dynamic <<EOF
> # version=1
> [section3]
> key3=value3
> EOF
$ hg config section3.key3
[1]
$ hg config section.key
value
$ cat ../shared/.hg/hgrc.dynamic
# version=4.4.2* (glob)
# reponame=shared_server
# canary=None
# username=
# Generated by `hg debugdynamicconfig` - DO NOT MODIFY
[section]
key=value
[section2]
key2=value2
Verify we don't regenerate configs if the Mercurial version hasn't changed
$ cat >> ../shared/.hg/hgrc.dynamic <<EOF
> [section3]
> key3=value3
> EOF
$ hg config section3.key3
value3
Verify configs.allowedlocations limits config loading to the allowed locations
$ cat >> .hg/hgrc <<EOF
> %include hgrc1
> %include hgrc2
> %include hgrc3
> [configs]
> validatedynamicconfig=True
> EOF
$ cat >> .hg/hgrc1 <<EOF
> [zz_section]
> key=foo
> [zz_other_section]
> other_key=other_foo
> EOF
$ cat >> .hg/hgrc2 <<EOF
> [zz_section]
> key=bar
> [zz_other_section]
> other_key=other_bar
> EOF
$ hg config --debug | grep ': zz_'
$TESTTMP/shared_copy/.hg/hgrc2:4: zz_other_section.other_key=other_bar
$TESTTMP/shared_copy/.hg/hgrc2:2: zz_section.key=bar
$ hg config --debug --config "configs.allowedlocations=hgrc1 .hgrc" | grep ': zz_'
$TESTTMP/shared_copy/.hg/hgrc1:4: zz_other_section.other_key=other_foo
$TESTTMP/shared_copy/.hg/hgrc1:2: zz_section.key=foo
$ hg config --debug --config "configs.allowedlocations=hgrc2 .hgrc" | grep ': zz_'
$TESTTMP/shared_copy/.hg/hgrc2:4: zz_other_section.other_key=other_bar
$TESTTMP/shared_copy/.hg/hgrc2:2: zz_section.key=bar
$ hg config --debug --config "configs.allowedlocations=hgrc3 .hgrc" | grep ': zz_'
[1]
$ hg config --debug --config "configs.allowedlocations=hgrc3 .hgrc" --config "configs.allowedconfigs=zz_section.key .hgrc" | grep 'zz_section\.'
--config: configs.allowedconfigs=zz_section.key .hgrc
$TESTTMP/shared_copy/.hg/hgrc2:2: zz_section.key=bar
Verify we load dynamicconfigs during clone
$ cd $TESTTMP
$ export HG_TEST_DYNAMICCONFIG="$TESTTMP/test_hgrc"
$ cat > test_hgrc <<EOF
> [hooks]
> pretxnclose = printf "Hook ran!\n"
> EOF
Clear the cached, non-repo dynamic config
$ rm -rf $TESTTMP/.cache
$ cat > good_hgrc <<EOF
> [hooks]
> pretxnclose = printf "Hook ran!\n"
> [foo]
> bar=True
> EOF
$ hg clone test:server client2 --configfile $TESTTMP/good_hgrc
fetching lazy changelog
populating main commit graph
fetching selected remote bookmarks
Hook ran!
updating to branch default
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
Hook ran!
$ cat client2/.hg/hgrc.dynamic
# version=4.4.2* (glob)
# reponame=reponame-default
# canary=None
# username=
# Generated by `hg debugdynamicconfig` - DO NOT MODIFY
[hooks]
pretxnclose=printf "Hook ran!\n"
Verify hgrc.dynamic is updated even if the original command is outside the repo
$ echo "[junk_on_the_end]" >> client2/.hg/hgrc.dynamic
$ sleep 1
$ hg -R client2 status --config configs.generationtime=1
$ sleep 1
$ cat client2/.hg/hgrc.dynamic
# version=4.4.2* (glob)
# reponame=reponame-default
# canary=None
# username=
# Generated by `hg debugdynamicconfig` - DO NOT MODIFY
[hooks]
pretxnclose=printf "Hook ran!\n"
$ cd client2
#if no-osx
Verify fake timestamps dont crash
$ touch -d tomorrow .hg/hgrc.dynamic
$ hg log -r tip --config configs.generationtime=1
commit: 000000000000
user:
date: Thu Jan 01 00:00:00 1970 +0000
#endif
Verify read-only permissions dont block commands from succeeding due to
hgrc.dynamic write errors.
$ echo > .hg/hgrc.dynamic
$ chmod a-w .hg/hgrc.dynamic
$ hg log -r tip
commit: 000000000000
user:
date: Thu Jan 01 00:00:00 1970 +0000
$ chmod u+w .hg/hgrc.dynamic
$ chmod a-w .hg/
$ hg log -r tip
commit: 000000000000
user:
date: Thu Jan 01 00:00:00 1970 +0000
#if no-windows
$ chmod u+w .hg/
$ rm -f .hg/hgrc.dynamic
$ chmod u-w .hg/
$ hg log -r tip
hg: parse errors: required config not found at $TESTTMP/client2/.hg/hgrc.dynamic
[255]
#endif