| 1 |
test sparse |
| 2 |
|
| 3 |
$ hg init myrepo |
| 4 |
$ cd myrepo |
| 5 |
$ cat >> $HGRCPATH <<EOF |
| 6 |
> [extensions] |
| 7 |
> sparse= |
| 8 |
> purge= |
| 9 |
> strip= |
| 10 |
> rebase= |
| 11 |
> EOF |
| 12 |
|
| 13 |
$ echo a > index.html |
| 14 |
$ echo x > data.py |
| 15 |
$ echo z > readme.txt |
| 16 |
$ cat > base.sparse <<EOF |
| 17 |
> [include] |
| 18 |
> *.sparse |
| 19 |
> EOF |
| 20 |
$ hg ci -Aqm 'initial' |
| 21 |
$ cat > webpage.sparse <<EOF |
| 22 |
> %include base.sparse |
| 23 |
> [include] |
| 24 |
> *.html |
| 25 |
> EOF |
| 26 |
$ hg ci -Aqm 'initial' |
| 27 |
|
| 28 |
Import a rules file against a 'blank' sparse profile |
| 29 |
|
| 30 |
$ cat > $TESTTMP/rules_to_import <<EOF |
| 31 |
> [include] |
| 32 |
> *.py |
| 33 |
> EOF |
| 34 |
$ hg debugsparse --import-rules $TESTTMP/rules_to_import |
| 35 |
$ ls -A |
| 36 |
.hg |
| 37 |
data.py |
| 38 |
|
| 39 |
$ hg debugsparse --reset |
| 40 |
$ rm .hg/sparse |
| 41 |
|
| 42 |
$ cat > $TESTTMP/rules_to_import <<EOF |
| 43 |
> %include base.sparse |
| 44 |
> [include] |
| 45 |
> *.py |
| 46 |
> EOF |
| 47 |
$ hg debugsparse --import-rules $TESTTMP/rules_to_import |
| 48 |
$ ls -A |
| 49 |
.hg |
| 50 |
base.sparse |
| 51 |
data.py |
| 52 |
webpage.sparse |
| 53 |
|
| 54 |
$ hg debugsparse --reset |
| 55 |
$ rm .hg/sparse |
| 56 |
|
| 57 |
Start against an existing profile; rules *already active* should be ignored |
| 58 |
|
| 59 |
$ hg debugsparse --enable-profile webpage.sparse |
| 60 |
$ hg debugsparse --include *.py |
| 61 |
$ cat > $TESTTMP/rules_to_import <<EOF |
| 62 |
> %include base.sparse |
| 63 |
> [include] |
| 64 |
> *.html |
| 65 |
> *.txt |
| 66 |
> [exclude] |
| 67 |
> *.py |
| 68 |
> EOF |
| 69 |
$ hg debugsparse --import-rules $TESTTMP/rules_to_import |
| 70 |
$ ls -A |
| 71 |
.hg |
| 72 |
base.sparse |
| 73 |
index.html |
| 74 |
readme.txt |
| 75 |
webpage.sparse |
| 76 |
$ cat .hg/sparse |
| 77 |
%include webpage.sparse |
| 78 |
[include] |
| 79 |
*.py |
| 80 |
*.txt |
| 81 |
[exclude] |
| 82 |
*.py |
| 83 |
|
| 84 |
$ hg debugsparse --reset |
| 85 |
$ rm .hg/sparse |
| 86 |
|
| 87 |
Same tests, with -Tjson enabled to output summaries |
| 88 |
|
| 89 |
$ cat > $TESTTMP/rules_to_import <<EOF |
| 90 |
> [include] |
| 91 |
> *.py |
| 92 |
> EOF |
| 93 |
$ hg debugsparse --import-rules $TESTTMP/rules_to_import -Tjson |
| 94 |
[ |
| 95 |
{ |
| 96 |
"exclude_rules_added": 0, |
| 97 |
"files_added": 0, |
| 98 |
"files_conflicting": 0, |
| 99 |
"files_dropped": 4, |
| 100 |
"include_rules_added": 1, |
| 101 |
"profiles_added": 0 |
| 102 |
} |
| 103 |
] |
| 104 |
|
| 105 |
$ hg debugsparse --reset |
| 106 |
$ rm .hg/sparse |
| 107 |
|
| 108 |
$ cat > $TESTTMP/rules_to_import <<EOF |
| 109 |
> %include base.sparse |
| 110 |
> [include] |
| 111 |
> *.py |
| 112 |
> EOF |
| 113 |
$ hg debugsparse --import-rules $TESTTMP/rules_to_import -Tjson |
| 114 |
[ |
| 115 |
{ |
| 116 |
"exclude_rules_added": 0, |
| 117 |
"files_added": 0, |
| 118 |
"files_conflicting": 0, |
| 119 |
"files_dropped": 2, |
| 120 |
"include_rules_added": 1, |
| 121 |
"profiles_added": 1 |
| 122 |
} |
| 123 |
] |
| 124 |
|
| 125 |
$ hg debugsparse --reset |
| 126 |
$ rm .hg/sparse |
| 127 |
|
| 128 |
$ hg debugsparse --enable-profile webpage.sparse |
| 129 |
$ hg debugsparse --include *.py |
| 130 |
$ cat > $TESTTMP/rules_to_import <<EOF |
| 131 |
> %include base.sparse |
| 132 |
> [include] |
| 133 |
> *.html |
| 134 |
> *.txt |
| 135 |
> [exclude] |
| 136 |
> *.py |
| 137 |
> EOF |
| 138 |
$ hg debugsparse --import-rules $TESTTMP/rules_to_import -Tjson |
| 139 |
[ |
| 140 |
{ |
| 141 |
"exclude_rules_added": 1, |
| 142 |
"files_added": 1, |
| 143 |
"files_conflicting": 0, |
| 144 |
"files_dropped": 1, |
| 145 |
"include_rules_added": 1, |
| 146 |
"profiles_added": 0 |
| 147 |
} |
| 148 |
] |
| 149 |
|
| 150 |
If importing results in no new rules being added, no refresh should take place! |
| 151 |
|
| 152 |
$ cat > $TESTTMP/trap_sparse_refresh.py <<EOF |
| 153 |
> from mercurial import error, sparse |
| 154 |
> def extsetup(ui): |
| 155 |
> def abort_refresh(*args, **kwargs): |
| 156 |
> raise error.Abort(b'sparse._refresh called!') |
| 157 |
> sparse.refreshwdir = abort_refresh |
| 158 |
> EOF |
| 159 |
$ cat >> $HGRCPATH <<EOF |
| 160 |
> [extensions] |
| 161 |
> trap_sparse_refresh=$TESTTMP/trap_sparse_refresh.py |
| 162 |
> EOF |
| 163 |
$ cat > $TESTTMP/rules_to_import <<EOF |
| 164 |
> [include] |
| 165 |
> *.py |
| 166 |
> EOF |
| 167 |
$ hg debugsparse --import-rules $TESTTMP/rules_to_import |
| 168 |
|
| 169 |
If an exception is raised during refresh, restore the existing rules again. |
| 170 |
|
| 171 |
$ cat > $TESTTMP/rules_to_import <<EOF |
| 172 |
> [exclude] |
| 173 |
> *.html |
| 174 |
> EOF |
| 175 |
$ hg debugsparse --import-rules $TESTTMP/rules_to_import |
| 176 |
abort: sparse._refresh called! |
| 177 |
[255] |
| 178 |
$ cat .hg/sparse |
| 179 |
%include webpage.sparse |
| 180 |
[include] |
| 181 |
*.py |
| 182 |
*.txt |
| 183 |
[exclude] |
| 184 |
*.py |