sapling/tests/test-fb-hgext-sparse-profiles.t
Martijn Pieters bf9eb9018e sparse: add the option to hide certain profiles
Summary:
Some profiles are not for general consumption; they are usually profiles aimed at CI subsystems or similar. These can be hidden from listings by default using a `hidden` key.

The value of the key doesn't matter but can be used to explain why it is hidden.

Reviewed By: quark-zju

Differential Revision: D7433781

fbshipit-source-id: 877cd8698d50dc64cec8da706ab005e1fd786de4
2018-04-13 21:51:39 -07:00

613 lines
15 KiB
Perl

test sparse
$ hg init myrepo
$ cd myrepo
$ cat > .hg/hgrc <<EOF
> [extensions]
> sparse=$TESTDIR/../hgext/fbsparse.py
> purge=
> strip=
> rebase=
> EOF
$ echo a > index.html
$ echo x > data.py
$ echo z > readme.txt
$ cat > webpage.sparse <<EOF
> [metadata]
> title: frontend sparse profile
> [include]
> *.html
> EOF
$ cat > backend.sparse <<EOF
> [metadata]
> title: backend sparse profile
> [include]
> *.py
> EOF
$ hg ci -Aqm 'initial'
$ hg sparse --include '*.sparse'
Verify enabling a single profile works
$ hg sparse --enable-profile webpage.sparse
$ ls
backend.sparse
index.html
webpage.sparse
Verify enabling two profiles works
$ hg sparse --enable-profile backend.sparse
$ ls
backend.sparse
data.py
index.html
webpage.sparse
Verify disabling a profile works
$ hg sparse --disable-profile webpage.sparse
$ ls
backend.sparse
data.py
webpage.sparse
Verify error checking includes filename and line numbers
$ cat > broken.sparse <<EOF
> # include section omitted
> [exclude]
> *.html
> /absolute/paths/are/ignored
> [include]
> EOF
$ hg add broken.sparse
$ hg ci -m 'Adding a broken file'
$ hg sparse --enable-profile broken.sparse
warning: sparse profile cannot use paths starting with /, ignoring /absolute/paths/are/ignored, in broken.sparse:4
abort: A sparse file cannot have includes after excludes in broken.sparse:5
[255]
$ hg strip .
0 files updated, 0 files merged, 1 files removed, 0 files unresolved
saved backup bundle to $TESTTMP/myrepo/.hg/strip-backup/* (glob)
Verify that a profile is updated across multiple commits
$ cat > webpage.sparse <<EOF
> [metadata]
> title: frontend sparse profile
> [include]
> *.html
> EOF
$ cat > backend.sparse <<EOF
> [metadata]
> title: backend sparse profile
> [include]
> *.py
> *.txt
> EOF
$ echo foo >> data.py
$ hg ci -m 'edit profile'
$ ls
backend.sparse
data.py
readme.txt
webpage.sparse
$ hg up -q 0
$ ls
backend.sparse
data.py
webpage.sparse
$ hg up -q 1
$ ls
backend.sparse
data.py
readme.txt
webpage.sparse
Introduce a conflicting .hgsparse change
$ hg up -q 0
$ cat > backend.sparse <<EOF
> [metadata]
> title: Different backend sparse profile
> [include]
> *.html
> EOF
$ echo bar >> data.py
$ hg ci -qAm "edit profile other"
$ ls
backend.sparse
index.html
webpage.sparse
Verify conflicting merge pulls in the conflicting changes
$ hg merge 1
temporarily included 1 file(s) in the sparse checkout for merging
merging backend.sparse
merging data.py
warning: conflicts while merging backend.sparse! (edit, then use 'hg resolve --mark')
warning: conflicts while merging data.py! (edit, then use 'hg resolve --mark')
0 files updated, 0 files merged, 0 files removed, 2 files unresolved
use 'hg resolve' to retry unresolved file merges or 'hg update -C .' to abandon
[1]
$ rm *.orig
$ ls
backend.sparse
data.py
index.html
webpage.sparse
Verify resolving the merge removes the temporarily unioned files
$ cat > backend.sparse <<EOF
> [metadata]
> title: backend sparse profile
> [include]
> *.html
> *.txt
> EOF
$ hg resolve -m backend.sparse
$ cat > data.py <<EOF
> x
> foo
> bar
> EOF
$ hg resolve -m data.py
(no more unresolved files)
$ hg ci -qAm "merge profiles"
$ ls
backend.sparse
index.html
readme.txt
webpage.sparse
$ hg cat -r . data.py
x
foo
bar
Verify stripping refreshes dirstate
$ hg strip -q -r .
$ ls
backend.sparse
index.html
webpage.sparse
Verify rebase conflicts pulls in the conflicting changes
$ hg up -q 1
$ ls
backend.sparse
data.py
readme.txt
webpage.sparse
$ hg rebase -d 2
rebasing 1:e7901640ca22 "edit profile"
temporarily included 1 file(s) in the sparse checkout for merging
merging backend.sparse
merging data.py
warning: conflicts while merging backend.sparse! (edit, then use 'hg resolve --mark')
warning: conflicts while merging data.py! (edit, then use 'hg resolve --mark')
unresolved conflicts (see hg resolve, then hg rebase --continue)
[1]
$ rm *.orig
$ ls
backend.sparse
data.py
index.html
webpage.sparse
Verify resolving conflict removes the temporary files
$ cat > backend.sparse <<EOF
> [include]
> *.html
> *.txt
> EOF
$ hg resolve -m backend.sparse
$ cat > data.py <<EOF
> x
> foo
> bar
> EOF
$ hg resolve -m data.py
(no more unresolved files)
continue: hg rebase --continue
$ hg rebase -q --continue
$ ls
backend.sparse
index.html
readme.txt
webpage.sparse
$ hg cat -r . data.py
x
foo
bar
Test checking out a commit that does not contain the sparse profile. The
warning message can be suppressed by setting missingwarning = false in
[sparse] section of your config:
$ hg sparse --reset
$ hg rm *.sparse
$ hg commit -m "delete profiles"
$ hg up -q ".^"
$ hg sparse --enable-profile backend.sparse
$ ls
index.html
readme.txt
$ hg up tip | grep warning
warning: sparse profile 'backend.sparse' not found in rev 42b23bc43905 - ignoring it
[1]
$ ls
data.py
index.html
readme.txt
$ hg sparse --disable-profile backend.sparse | grep warning
warning: sparse profile 'backend.sparse' not found in rev 42b23bc43905 - ignoring it
[1]
$ cat >> .hg/hgrc <<EOF
> [sparse]
> missingwarning = false
> EOF
$ hg sparse --enable-profile backend.sparse
$ cd ..
Test file permissions changing across a sparse profile change
$ hg init sparseperm
$ cd sparseperm
$ cat > .hg/hgrc <<EOF
> [extensions]
> sparse=$TESTDIR/../hgext/fbsparse.py
> EOF
$ touch a b
$ cat > .hgsparse <<EOF
> a
> EOF
$ hg commit -Aqm 'initial'
$ chmod a+x b
$ hg commit -qm 'make executable'
$ cat >> .hgsparse <<EOF
> b
> EOF
$ hg commit -qm 'update profile'
$ hg up -q 0
$ hg sparse --enable-profile .hgsparse
$ hg up -q 2
$ ls -l b
-rwxr-xr-x* b (glob)
$ cd ..
Test profile discovery
$ hg init sparseprofiles
$ cd sparseprofiles
$ cat > .hg/hgrc <<EOF
> [extensions]
> sparse=$TESTDIR/../hgext/fbsparse.py
> EOF
$ mkdir -p profiles/foo profiles/bar
$ touch profiles/README.txt
$ touch profiles/foo/README
$ cat > profiles/foo/spam <<EOF
> %include profiles/bar/eggs
> [metadata]
> title: Profile that only includes another
> EOF
$ cat > profiles/bar/eggs <<EOF
> [metadata]
> title: Base profile including the profiles directory
> description: This is a base profile, you really want to include this one
> if you want to be able to edit profiles. In addition, this profiles has
> some metadata.
> foo = bar baz and a whole
> lot more.
> team: me, myself and I
> [include]
> profiles
> EOF
$ cat > profiles/foo/monty <<EOF
> [metadata]
> hidden: this profile is deliberatly hidden from listings
> [include]
> eric_idle
> john_cleese
> [exclude]
> guido_van_rossum
> EOF
$ touch profiles/bar/python
$ mkdir hidden
$ cat > hidden/outsidesparseprofile <<EOF
> A non-empty file to show that a sparse profile has an impact in terms of
> file count and bytesize.
> EOF
$ hg add -q profiles hidden
$ hg commit -qm 'created profiles and some hidden data'
$ hg sparse --enable-profile profiles/foo/spam
$ hg sparse list
symbols: * = active profile, ~ = transitively included
~ profiles/bar/eggs - Base profile including the profiles directory
* profiles/foo/spam - Profile that only includes another
$ hg sparse list -T json
[
{
"active": "included",
"metadata": {"description": "This is a base profile, you really want to include this one\nif you want to be able to edit profiles. In addition, this profiles has\nsome metadata.", "foo": "bar baz and a whole\nlot more.", "team": "me, myself and I", "title": "Base profile including the profiles directory"},
"path": "profiles/bar/eggs"
},
{
"active": "active",
"metadata": {"title": "Profile that only includes another"},
"path": "profiles/foo/spam"
}
]
$ cat >> .hg/hgrc <<EOF
> [sparse]
> profile_directory = profiles/
> EOF
$ hg sparse list
symbols: * = active profile, ~ = transitively included
~ profiles/bar/eggs - Base profile including the profiles directory
profiles/bar/python
* profiles/foo/spam - Profile that only includes another
$ hg sparse list -T json
[
{
"active": "included",
"metadata": {"description": "This is a base profile, you really want to include this one\nif you want to be able to edit profiles. In addition, this profiles has\nsome metadata.", "foo": "bar baz and a whole\nlot more.", "team": "me, myself and I", "title": "Base profile including the profiles directory"},
"path": "profiles/bar/eggs"
},
{
"active": "inactive",
"metadata": {},
"path": "profiles/bar/python"
},
{
"active": "active",
"metadata": {"title": "Profile that only includes another"},
"path": "profiles/foo/spam"
}
]
The current working directory plays no role in listing profiles:
$ mkdir otherdir
$ cd otherdir
$ hg sparse list
symbols: * = active profile, ~ = transitively included
~ profiles/bar/eggs - Base profile including the profiles directory
profiles/bar/python
* profiles/foo/spam - Profile that only includes another
$ cd ..
Profiles are loaded from the manifest, so excluding a profile directory should
not hamper listing.
$ hg sparse --exclude profiles/bar
$ hg sparse list
symbols: * = active profile, ~ = transitively included
~ profiles/bar/eggs - Base profile including the profiles directory
profiles/bar/python
* profiles/foo/spam - Profile that only includes another
Hidden profiles only show up when we use the --verbose switch:
$ hg sparse list --verbose
symbols: * = active profile, ~ = transitively included
~ profiles/bar/eggs - Base profile including the profiles directory
profiles/bar/python
profiles/foo/monty
* profiles/foo/spam - Profile that only includes another
The metadata section format can have errors, but those are only listed as
warnings:
$ cat > profiles/foo/errors <<EOF
> [metadata]
> indented line but no current key active
> not an option line, there is no delimiter
> EOF
$ hg add -q profiles
$ hg commit -qm 'Broken profile added'
$ hg sparse list
symbols: * = active profile, ~ = transitively included
warning: sparse profile [metadata] section indented lines that do not belong to a multi-line entry, ignoring, in profiles/foo/errors:2
warning: sparse profile [metadata] section does not appear to have a valid option definition, ignoring, in profiles/foo/errors:3
~ profiles/bar/eggs - Base profile including the profiles directory
profiles/bar/python
profiles/foo/errors
* profiles/foo/spam - Profile that only includes another
We can look at invididual profiles:
$ hg sparse explain profiles/bar/eggs
profiles/bar/eggs
Base profile including the profiles directory
"""""""""""""""""""""""""""""""""""""""""""""
This is a base profile, you really want to include this one if you want to be
able to edit profiles. In addition, this profiles has some metadata.
Size impact compared to a full checkout
=======================================
file count 7 (87.50%)
Additional metadata
===================
foo bar baz and a whole lot more.
team me, myself and I
Inclusion rules
===============
.hg*
profiles
$ hg sparse explain profiles/bar/eggs -T json
[
{
"excludes": [],
"includes": [".hg*", "profiles"],
"metadata": {"description": "This is a base profile, you really want to include this one\nif you want to be able to edit profiles. In addition, this profiles has\nsome metadata.", "foo": "bar baz and a whole\nlot more.", "team": "me, myself and I", "title": "Base profile including the profiles directory"},
"path": "profiles/bar/eggs",
"profiles": [],
"stats": {"filecount": 7, "filecountpercentage": 87.5}
}
]
$ hg sparse explain profiles/bar/eggs -T json --verbose
[
{
"excludes": [],
"includes": [".hg*", "profiles"],
"metadata": {"description": "This is a base profile, you really want to include this one\nif you want to be able to edit profiles. In addition, this profiles has\nsome metadata.", "foo": "bar baz and a whole\nlot more.", "team": "me, myself and I", "title": "Base profile including the profiles directory"},
"path": "profiles/bar/eggs",
"profiles": [],
"stats": {"filecount": 7, "filecountpercentage": 87.5, "totalsize": 608}
}
]
$ hg sparse explain profiles/bar/eggs
profiles/bar/eggs
Base profile including the profiles directory
"""""""""""""""""""""""""""""""""""""""""""""
This is a base profile, you really want to include this one if you want to be
able to edit profiles. In addition, this profiles has some metadata.
Size impact compared to a full checkout
=======================================
file count 7 (87.50%)
Additional metadata
===================
foo bar baz and a whole lot more.
team me, myself and I
Inclusion rules
===============
.hg*
profiles
$ hg sparse explain profiles/bar/eggs --verbose
profiles/bar/eggs
Base profile including the profiles directory
"""""""""""""""""""""""""""""""""""""""""""""
This is a base profile, you really want to include this one if you want to be
able to edit profiles. In addition, this profiles has some metadata.
Size impact compared to a full checkout
=======================================
file count 7 (87.50%)
total size 608 bytes
Additional metadata
===================
foo bar baz and a whole lot more.
team me, myself and I
Inclusion rules
===============
.hg*
profiles
$ hg sparse explain profiles/bar/eggs profiles/foo/monty profiles/nonsuch
The profile profiles/nonsuch was not found
profiles/bar/eggs
Base profile including the profiles directory
"""""""""""""""""""""""""""""""""""""""""""""
This is a base profile, you really want to include this one if you want to be
able to edit profiles. In addition, this profiles has some metadata.
Size impact compared to a full checkout
=======================================
file count 7 (87.50%)
Additional metadata
===================
foo bar baz and a whole lot more.
team me, myself and I
Inclusion rules
===============
.hg*
profiles
profiles/foo/monty
(untitled)
""""""""""
Size impact compared to a full checkout
=======================================
file count 7 (87.50%)
Additional metadata
===================
hidden this profile is deliberatly hidden from listings
Inclusion rules
===============
eric_idle
john_cleese
Exclusion rules
===============
guido_van_rossum
$ hg sparse explain profiles/bar/eggs -T "{path}\n{metadata.title}\n{stats.filecount}\n"
profiles/bar/eggs
Base profile including the profiles directory
7
We can list the files in a profile with the hg sparse files command:
$ hg sparse files profiles/bar/eggs
profiles/README.txt
profiles/bar/eggs
profiles/bar/python
profiles/foo/README
profiles/foo/errors
profiles/foo/monty
profiles/foo/spam
$ hg sparse files profiles/bar/eggs **/README **/README.*
profiles/README.txt
profiles/foo/README