[
  {
    "path": "CHANGELOG",
    "content": "2025-07-18  v3.6.14 only one important fix:\n\n                    detect HEAD name in admin repo (don't require it be \"master\")\n\n2023-07-14  v3.6.13 only one important fix:\n\n                    remove the \"description\" file on new repos, to fix a bug\n                    created by an optimisation made 6 years ago in 3.6.8 (and\n                    was caught only in 2022 or so!)\n\n2020-08-04  v3.6.12 mirroring terminology changes\n\n                    install script can now modify #! lines when using a custom\n                    perl executable\n\n                    'config' user command allows for config values with spaces\n                    in them\n\n                    finally added notes in \"t/README\" on testing http mode and\n                    mirroring, with pre-build helpers for Fedora and Manjaro\n\n                    ...plus various bug fixes\n\n2019-01-08  v3.6.11 fix security issue in 'rsync' (bundle helper); see commit\n                    5df2b81 for more\n\n2018-09-30  v3.6.10 fix up boo-boo caused by previous release; see mails on\n                    list for details\n\n2018-08-07  v3.6.9  prevent racy access to repos in process of migration to\n                    gitolite\n\n                    'info' learns new '-p' option to show only physical repos\n                    (as opposed to wild repos)\n\n2018-07-12  v3.6.8  fix bug when deleting *all* hooks for a repo\n\n                    allow trailing slashes in repo names\n\n                    make pre-receive hook driver bail on non-zero exit of a\n                    pre-receive hook\n\n                    allow templates in gitolite.conf (new feature)\n\n                    various optimiations\n\n2017-07-02  v3.6.7  allow repo-specific hooks to be organised into\n                    subdirectories, and allow the multi-hook driver to be\n                    placed in some other location of your choice\n\n                    allow simple test code to be embedded within the\n                    gitolite.conf file; see contrib/utils/testconf for how.\n                    (This goes on the client side, not on the server)\n\n                    allow syslog \"facility\" to be changed, from the default of\n                    'local0'\n\n                    allow @group names in config values to be expanded; it is\n                    replaced with a space separated list of members\n\n2016-09-08  v3.6.6  simple but important fix for a future perl deprecation\n                    (perl will be removing \".\" from @INC in 5.24)\n\n                    'perms' now requires a '-c' to activate batch mode\n                    (should not affect interactive use but check your scripts\n                    perhaps?)\n\n                    gitolite setup now accepts a '-m' option to supply a\n                    custom message (useful when it is used by a script)\n\n2016-02-20  v3.6.5  allow creator check to be bypassed during mirroring\n\n                    handle new style ssh fingerprinting correctly (thanks to\n                    Robin Johnson)\n\n                    allow pre-auto-gc as a repo-specific hook\n\n                    optimise mirror pushes for heavily used repos\n\n                    create-with-reference trigger: on repo creation, setup\n                    objects/info/alternates for a server side alternate object\n                    store.\n\n                    'mirror status all all' prints a list of repos that have\n                    *some* error, which is arguably more useful for further\n                    action/processing\n\n                    allow incrementally adding more repo-specific hooks\n\n2015-11-01  v3.6.4  a ref-create bug in wild repos was fixed\n\n                    some contrib code related to AD integration, and to\n                    redmine user aliases\n\n                    teach Alias.pm a few new tricks\n\n                    remove a race condition in 'create' command that affected\n                    the 'default roles' setting\n\n                    make 'who-pushed' more efficient (local push logs, and\n                    'tip search')\n\n                    'gitolite query-rc' learns '-d' ('--dump') option\n\n2015-04-26  v3.6.3  allow limited use of 'git config' using the new 'config'\n                    command\n\n                    accept openssh 6.8's new fingerprint output format\n\n                    (finally!) allow limited symlinks within ~/repositories;\n                    see commit 8e36230 for details\n\n                    perms command now lists available roles\n\n                    minor backward compat breakage: 'perms -l repo' no longer\n                    works; see 'perms -h' for new usage\n\n                    allow gitolite-shell to be used as $SHELL (experts only;\n                    no support, no docs; see commit 9cd1e37 for details)\n\n                    help with 'git push --signed' using a post-receive hook to\n                    adopt push certs into 'refs/push-certs'; for details see\n                    contrib/hooks/repo-specific/save-push-signatures\n\n                    new 'transparent proxy' feature for git repos; see\n                    src/lib/Gitolite/Triggers/TProxy.pm for details\n\n2014-11-10  v3.6.2  disable ../ everywhere (see mailing list thread for\n                    details)\n\n                    VREF/NAME_NC -- like VREF/NAME but for new commits only.\n                    Details within src/VREF/NAME_NC.\n\n                    allow gitolite.conf to be tested locally; details within\n                    contrib/utils/gitolite-local\n\n2014-06-22  v3.6.1  experimental rc format convertor for \"<= 3.3\" users who\n                    have already upgraded the *code* to \">= v3.4\".  Program is\n                    in contrib/utils.\n\n                    giving shell access to a few users got a lot easier (see\n                    comments in the rc file).\n\n                    allow logging to syslog as well (see comments in the rc\n                    file)\n\n                    new 'motd' command\n\n                    redis caching redone and now in core; see\n                    http://gitolite.com/gitolite/cache.html\n\n2014-05-09  v3.6    (cool stuff) the access command can now help you debug\n                    your rules / understand how a specific access decision was\n                    arrived at.\n\n                    mirroring: since mirroring is asynchronous (by default\n                    anyway), when a 'git push --mirror' fails, you may not\n                    know it unless you look in the log file on the server.\n                    Now gitolite captures the info and -- if the word 'fatal'\n                    appears anywhere within it, it saves the entire output and\n                    prints it to STDERR for anyone who reads or writes the\n                    repo on the *master* server, until the error condition\n                    clears up.\n\n                    mirroring: allow 'nosync' slaves -- no attempt to\n                    automatically push to these slaves will be made.  Instead,\n                    you have to manually (or via cron, etc) trigger pushes.\n\n                    (backward compat breakage) the old v2 syntax for\n                    specifying gitweb owner and description is no longer\n                    supported.\n\n                    macros now allow strings as arguments (thanks to Jason\n                    Donenfeld for the idea/problem).\n\n                    the 'info' command can print in JSON format if asked to.\n\n                    repo-specific hooks: now you can specify more than one,\n                    and gitolite runs all of them in sequence.\n\n                    new trigger 'expand-deny-messages' to show more details\n                    when access is denied.\n\n                    git-annex support is finally in master, yaaay!\n\n                    new 'readme' command, modelled after 'desc'.  Apparently\n                    gitweb can use a README.html file in the *bare* repo\n                    directory -- who knew!\n\n2013-10-14  v3.5.3  catch undefined groupnames (when possible)\n\n                    mirroring: async push to slaves\n\n                    (some portability fixes)\n\n                    (a couple of contrib scripts - querying IPA based LDAP\n                    servers for group membership, and user key management)\n\n                    allow groups in subconf files (this *may* slow down\n                    compilation in extreme cases)\n\n                    make adding repo-specific hooks easier (see cust.mkd or\n                    cust.html online for docs)\n\n                    smart http now supports git 1.8.2 and above (which changed\n                    the protocol requirements a wee bit)\n\n2013-07-10  v3.5.2  allow ENV vars to be set from repo options, for use in\n                    triggers and hooks\n\n                    bug-fix: the new set-default-roles feature was being\n                    invoked on every run of \"perms\" and overriding it!\n\n2013-03-24  v3.5    (2 minor backward compat breakages)\n                    1.  'DEFAULT_ROLE_PERMS' replaced by per repo\n                        'default.roles' option\n                    2.  'gitolite list-memberships' now requires a '-r' or a\n                        '-u' flag\n\n                    new 'gitolite owns' command (thanks to Kevin Pulo)\n\n2013-03-05  v3.4    new rc file format makes it much easier to enable specific\n                    features\n\n2012-12-29  v3.3    bug fix: gl-perms propagation to slaves broke sometime\n                    after v3.2 (so if you're only picking up tagged releases\n                    you're OK)\n\n                    the \"D\" command now allows rm/unlock to be totally\n                    disabled\n\n                    new trigger: update-gitweb-daemon-from-options; another\n                    way to update gitweb and daemon access lists\n\n                    new 'create' command for explicit wild repo creation, and\n                    new AutoCreate trigger to control auto-creation\n\n                    allow simple macros in conf file\n\n2012-11-14  v3.2    major efficiency boost for large setups\n\n                    optional support for multi-line pubkeys; see\n                    src/triggers/post-compile/ssh-authkeys-split\n\n                    bug fix for not creating gl-conf when repo para has only\n                    config lines and no access rules\n\n                    new 'bg' trigger command to put long jobs started from a\n                    trigger into background\n\n                    %GL_REPO and %GL_CREATOR now work for 'option's also\n\n                    test suite now much more BSD friendly\n\n2012-10-05  v3.1    (security) fix path traversal on wild repos\n\n                    new %GL_CREATOR variable for git-config lines\n\n                    rsync command to create and send bundles automagically\n\n                    migrated 'who-pushed'\n\n                    logical expressions on refexes!!!\n\n2012-06-27  v3.04   documentation graduated and moved out of parents house :)\n\n                    new trigger for 'repo specific umask'\n\n                    new 'list-dangling-repos' command\n\n                    new LOCAL_CODE rc var; allow admin specified programs to\n                    override system-installed ones\n\n                    new 'upstream' trigger-cum-command to maintain local\n                    copies of external repos\n\n                    new 'sudo' command\n\n                    minor backward compat breakage in 'gitolite query-rc'\n\n                    'perms' command can now create repo if needed\n\n                    migrated 'symbolic-ref' command\n\n                    'gitolite setup --hooks-only'\n\n2012-05-23  v3.03   fix major bug that allowed an admin to get a shell\n\n2012-05-20  v3.02   packaging instructions fixed up and smoke tested\n\n                    make it easier to give some users a full shell\n\n                    allow aliasing a repo to another name\n\n                    simulate POST_CREATE for new normal (non-wild) repos\n\n                    (just for kicks) a VREF that allows for voting on changes\n                    to a branch\n\n                    bug fix: smart http was not running PRE_ and POST_GIT\n                    triggers\n\n                    htpasswd migrated\n\n2012-04-29  v3.01   mostly BSD and Solaris compat\n                    also fork command added\n\n2012-04-18  v3.0    first release to \"master\"\n                    This is a compete rewrite of gitolite; please see\n                    documentation before upgrading.\n"
  },
  {
    "path": "CONTRIBUTING",
    "content": "Go to http://gitolite.com/gitolite/index.html#contactsupport for information on\ncontacting me, the mailing list, and IRC channel.  *Unless you are reporting\nwhat you think is a security issue, I prefer you send to the mailing list,\nnot to me directly.*\n\nPlease DO NOT send messages via github's \"issues\" system, linkedin\ncomments/discussion, stackoverflow questions, google+, and any other Web 3.0\n\"coolness\". (The issues system does have an email interface, but it is not a\nsubstitute for email. I can't cc anyone else when I want to, for instance.\nWell I can, but any response the original requester then makes using the\nwebsite will not get cc-d to the person I cc-d).\n\nPlease send patches *via email*, not as github pull requests. Again, if you\nthink it's a security issue, send it directly to my gmail address, but\notherwise please send it to the mailing list, so others can see it and comment\non it.\n\nThe preferred format is the files created by git-format-patch, as attachments.\nHowever, if your repo has a public clone URL, you can make a new branch just\nfor this fix, and send the repo URL and branch name to the mailing list.\n\n(If you do send me a github pull request, I may take it if it's a trivial\npatch, but otherwise I'll ask you to close the pull request, then read\nthis URL for how to send me the patch.)\n"
  },
  {
    "path": "COPYING",
    "content": "                    GNU GENERAL PUBLIC LICENSE\n                       Version 2, June 1991\n\n Copyright (C) 1989, 1991 Free Software Foundation, Inc.,\n 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The licenses for most software are designed to take away your\nfreedom to share and change it.  By contrast, the GNU General Public\nLicense is intended to guarantee your freedom to share and change free\nsoftware--to make sure the software is free for all its users.  This\nGeneral Public License applies to most of the Free Software\nFoundation's software and to any other program whose authors commit to\nusing it.  (Some other Free Software Foundation software is covered by\nthe GNU Lesser General Public License instead.)  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthis service if you wish), that you receive source code or can get it\nif you want it, that you can change the software or use pieces of it\nin new free programs; and that you know you can do these things.\n\n  To protect your rights, we need to make restrictions that forbid\nanyone to deny you these rights or to ask you to surrender the rights.\nThese restrictions translate to certain responsibilities for you if you\ndistribute copies of the software, or if you modify it.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must give the recipients all the rights that\nyou have.  You must make sure that they, too, receive or can get the\nsource code.  And you must show them these terms so they know their\nrights.\n\n  We protect your rights with two steps: (1) copyright the software, and\n(2) offer you this license which gives you legal permission to copy,\ndistribute and/or modify the software.\n\n  Also, for each author's protection and ours, we want to make certain\nthat everyone understands that there is no warranty for this free\nsoftware.  If the software is modified by someone else and passed on, we\nwant its recipients to know that what they have is not the original, so\nthat any problems introduced by others will not reflect on the original\nauthors' reputations.\n\n  Finally, any free program is threatened constantly by software\npatents.  We wish to avoid the danger that redistributors of a free\nprogram will individually obtain patent licenses, in effect making the\nprogram proprietary.  To prevent this, we have made it clear that any\npatent must be licensed for everyone's free use or not licensed at all.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                    GNU GENERAL PUBLIC LICENSE\n   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n\n  0. This License applies to any program or other work which contains\na notice placed by the copyright holder saying it may be distributed\nunder the terms of this General Public License.  The \"Program\", below,\nrefers to any such program or work, and a \"work based on the Program\"\nmeans either the Program or any derivative work under copyright law:\nthat is to say, a work containing the Program or a portion of it,\neither verbatim or with modifications and/or translated into another\nlanguage.  (Hereinafter, translation is included without limitation in\nthe term \"modification\".)  Each licensee is addressed as \"you\".\n\nActivities other than copying, distribution and modification are not\ncovered by this License; they are outside its scope.  The act of\nrunning the Program is not restricted, and the output from the Program\nis covered only if its contents constitute a work based on the\nProgram (independent of having been made by running the Program).\nWhether that is true depends on what the Program does.\n\n  1. You may copy and distribute verbatim copies of the Program's\nsource code as you receive it, in any medium, provided that you\nconspicuously and appropriately publish on each copy an appropriate\ncopyright notice and disclaimer of warranty; keep intact all the\nnotices that refer to this License and to the absence of any warranty;\nand give any other recipients of the Program a copy of this License\nalong with the Program.\n\nYou may charge a fee for the physical act of transferring a copy, and\nyou may at your option offer warranty protection in exchange for a fee.\n\n  2. You may modify your copy or copies of the Program or any portion\nof it, thus forming a work based on the Program, and copy and\ndistribute such modifications or work under the terms of Section 1\nabove, provided that you also meet all of these conditions:\n\n    a) You must cause the modified files to carry prominent notices\n    stating that you changed the files and the date of any change.\n\n    b) You must cause any work that you distribute or publish, that in\n    whole or in part contains or is derived from the Program or any\n    part thereof, to be licensed as a whole at no charge to all third\n    parties under the terms of this License.\n\n    c) If the modified program normally reads commands interactively\n    when run, you must cause it, when started running for such\n    interactive use in the most ordinary way, to print or display an\n    announcement including an appropriate copyright notice and a\n    notice that there is no warranty (or else, saying that you provide\n    a warranty) and that users may redistribute the program under\n    these conditions, and telling the user how to view a copy of this\n    License.  (Exception: if the Program itself is interactive but\n    does not normally print such an announcement, your work based on\n    the Program is not required to print an announcement.)\n\nThese requirements apply to the modified work as a whole.  If\nidentifiable sections of that work are not derived from the Program,\nand can be reasonably considered independent and separate works in\nthemselves, then this License, and its terms, do not apply to those\nsections when you distribute them as separate works.  But when you\ndistribute the same sections as part of a whole which is a work based\non the Program, the distribution of the whole must be on the terms of\nthis License, whose permissions for other licensees extend to the\nentire whole, and thus to each and every part regardless of who wrote it.\n\nThus, it is not the intent of this section to claim rights or contest\nyour rights to work written entirely by you; rather, the intent is to\nexercise the right to control the distribution of derivative or\ncollective works based on the Program.\n\nIn addition, mere aggregation of another work not based on the Program\nwith the Program (or with a work based on the Program) on a volume of\na storage or distribution medium does not bring the other work under\nthe scope of this License.\n\n  3. You may copy and distribute the Program (or a work based on it,\nunder Section 2) in object code or executable form under the terms of\nSections 1 and 2 above provided that you also do one of the following:\n\n    a) Accompany it with the complete corresponding machine-readable\n    source code, which must be distributed under the terms of Sections\n    1 and 2 above on a medium customarily used for software interchange; or,\n\n    b) Accompany it with a written offer, valid for at least three\n    years, to give any third party, for a charge no more than your\n    cost of physically performing source distribution, a complete\n    machine-readable copy of the corresponding source code, to be\n    distributed under the terms of Sections 1 and 2 above on a medium\n    customarily used for software interchange; or,\n\n    c) Accompany it with the information you received as to the offer\n    to distribute corresponding source code.  (This alternative is\n    allowed only for noncommercial distribution and only if you\n    received the program in object code or executable form with such\n    an offer, in accord with Subsection b above.)\n\nThe source code for a work means the preferred form of the work for\nmaking modifications to it.  For an executable work, complete source\ncode means all the source code for all modules it contains, plus any\nassociated interface definition files, plus the scripts used to\ncontrol compilation and installation of the executable.  However, as a\nspecial exception, the source code distributed need not include\nanything that is normally distributed (in either source or binary\nform) with the major components (compiler, kernel, and so on) of the\noperating system on which the executable runs, unless that component\nitself accompanies the executable.\n\nIf distribution of executable or object code is made by offering\naccess to copy from a designated place, then offering equivalent\naccess to copy the source code from the same place counts as\ndistribution of the source code, even though third parties are not\ncompelled to copy the source along with the object code.\n\n  4. You may not copy, modify, sublicense, or distribute the Program\nexcept as expressly provided under this License.  Any attempt\notherwise to copy, modify, sublicense or distribute the Program is\nvoid, and will automatically terminate your rights under this License.\nHowever, parties who have received copies, or rights, from you under\nthis License will not have their licenses terminated so long as such\nparties remain in full compliance.\n\n  5. You are not required to accept this License, since you have not\nsigned it.  However, nothing else grants you permission to modify or\ndistribute the Program or its derivative works.  These actions are\nprohibited by law if you do not accept this License.  Therefore, by\nmodifying or distributing the Program (or any work based on the\nProgram), you indicate your acceptance of this License to do so, and\nall its terms and conditions for copying, distributing or modifying\nthe Program or works based on it.\n\n  6. Each time you redistribute the Program (or any work based on the\nProgram), the recipient automatically receives a license from the\noriginal licensor to copy, distribute or modify the Program subject to\nthese terms and conditions.  You may not impose any further\nrestrictions on the recipients' exercise of the rights granted herein.\nYou are not responsible for enforcing compliance by third parties to\nthis License.\n\n  7. If, as a consequence of a court judgment or allegation of patent\ninfringement or for any other reason (not limited to patent issues),\nconditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot\ndistribute so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you\nmay not distribute the Program at all.  For example, if a patent\nlicense would not permit royalty-free redistribution of the Program by\nall those who receive copies directly or indirectly through you, then\nthe only way you could satisfy both it and this License would be to\nrefrain entirely from distribution of the Program.\n\nIf any portion of this section is held invalid or unenforceable under\nany particular circumstance, the balance of the section is intended to\napply and the section as a whole is intended to apply in other\ncircumstances.\n\nIt is not the purpose of this section to induce you to infringe any\npatents or other property right claims or to contest validity of any\nsuch claims; this section has the sole purpose of protecting the\nintegrity of the free software distribution system, which is\nimplemented by public license practices.  Many people have made\ngenerous contributions to the wide range of software distributed\nthrough that system in reliance on consistent application of that\nsystem; it is up to the author/donor to decide if he or she is willing\nto distribute software through any other system and a licensee cannot\nimpose that choice.\n\nThis section is intended to make thoroughly clear what is believed to\nbe a consequence of the rest of this License.\n\n  8. If the distribution and/or use of the Program is restricted in\ncertain countries either by patents or by copyrighted interfaces, the\noriginal copyright holder who places the Program under this License\nmay add an explicit geographical distribution limitation excluding\nthose countries, so that distribution is permitted only in or among\ncountries not thus excluded.  In such case, this License incorporates\nthe limitation as if written in the body of this License.\n\n  9. The Free Software Foundation may publish revised and/or new versions\nof the General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\nEach version is given a distinguishing version number.  If the Program\nspecifies a version number of this License which applies to it and \"any\nlater version\", you have the option of following the terms and conditions\neither of that version or of any later version published by the Free\nSoftware Foundation.  If the Program does not specify a version number of\nthis License, you may choose any version ever published by the Free Software\nFoundation.\n\n  10. If you wish to incorporate parts of the Program into other free\nprograms whose distribution conditions are different, write to the author\nto ask for permission.  For software which is copyrighted by the Free\nSoftware Foundation, write to the Free Software Foundation; we sometimes\nmake exceptions for this.  Our decision will be guided by the two goals\nof preserving the free status of all derivatives of our free software and\nof promoting the sharing and reuse of software generally.\n\n                            NO WARRANTY\n\n  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\nFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN\nOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\nPROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\nOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\nMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS\nTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE\nPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\nREPAIR OR CORRECTION.\n\n  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\nREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\nINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\nOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\nTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\nYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\nPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\nPOSSIBILITY OF SUCH DAMAGES.\n"
  },
  {
    "path": "README.markdown",
    "content": "Gitolite README\n===============\n\n## about this README\n\n**(Github-users: click the \"wiki\" link before sending me anything via github.)**\n\n**This is a minimal README for gitolite**, so you can quickly get started with:\n\n*   installing gitolite on a fresh userid on a Unix(-like) machine, using ssh\n*   learning enough to do some basic access control\n\n**For anything more, you need to look at the complete documentation, at:\n<http://gitolite.com/gitolite>**.  Please go there for what/why/how, concepts,\nbackground, troubleshooting, more details on what is covered here, advanced\nfeatures not covered here, migration from older gitolite, running gitolite\nover http (rather than ssh), and many more topics.\n\n<!-- --------------------------------------------------------------------- -->\n\n## Assumptions\n\n*   You are familiar with:\n    *   OS: at least one Unix-like OS\n    *   ssh: ssh, ssh keys, ssh authorized keys file\n    *   git: basic use of git, bare and non-bare remotes\n\n*   You are setting up a fresh, ssh-based, installation of gitolite on a Unix\n    machine of some sort.\n\n*   You have root access, or someone has created a userid called \"git\" for you\n    to use and given you a password for it.  This is a brand new userid (or\n    you have deleted everything but `.bashrc` and similar files to make it\n    look like one!)\n\n*   If your server is not connected to the internet, you know how to clone the\n    gitolite source code by using some in-between server or \"git bundle\".\n\n<!-- --------------------------------------------------------------------- -->\n\n## Installation and setup\n\n### server requirements\n\n*   any unix system\n*   sh\n*   git 1.6.6 or later\n*   perl 5.8.8 or later\n*   openssh 5.0 or later\n*   a dedicated userid to host the repos (in this document, we assume it is\n    \"git\", but it can be anything; substitute accordingly)\n*   this user id does NOT currently have any ssh pubkey-based access\n    *   ideally, this user id has shell access ONLY by \"su - git\" from some\n        other userid on the same server (this ensure minimal confusion for ssh\n        newbies!)\n\n### steps to install\n\nFirst, prepare the ssh key:\n\n*   login to \"git\" on the server\n*   make sure `~/.ssh/authorized_keys` is empty or non-existent\n*   make sure your ssh public key from your workstation has been copied as\n    $HOME/YourName.pub\n\nNext, install gitolite by running these commands:\n\n    git clone https://github.com/sitaramc/gitolite\n    mkdir -p $HOME/bin\n    gitolite/install -to $HOME/bin\n\nFinally, setup gitolite with yourself as the administrator:\n\n    gitolite setup -pk YourName.pub\n\nIf the last command doesn't run perhaps \"bin\" is not in your \"PATH\". You can\neither add it, or just run:\n\n    $HOME/bin/gitolite setup -pk YourName.pub\n\nIf you get any other errors please refer to the online documentation whose URL\nwas given at the top of this file.\n\n## adding users and repos\n\n*Do NOT add new repos or users manually on the server.*  Gitolite users,\nrepos, and access rules are maintained by making changes to a special repo\ncalled \"gitolite-admin\" and *pushing* those changes to the server.\n\nTo administer your gitolite installation, start by doing this on your\nworkstation (if you have not already done so):\n\n    git clone git@host:gitolite-admin\n\n>   -------------------------------------------------------------------------\n\n>   **NOTE: if you are asked for a password, something went wrong.**.  Go hit\n>   the link for the complete documentation earlier in this file.\n\n>   -------------------------------------------------------------------------\n\nNow if you \"cd gitolite-admin\", you will see two subdirectories in it: \"conf\"\nand \"keydir\".\n\nTo add new users alice, bob, and carol, obtain their public keys and add them\nto \"keydir\" as alice.pub, bob.pub, and carol.pub respectively.\n\nTo add a new repo \"foo\" and give different levels of access to these\nusers, edit the file \"conf/gitolite.conf\" and add lines like this:\n\n    repo foo\n        RW+         =   alice\n        RW          =   bob\n        R           =   carol\n\nOnce you have made these changes, do something like this:\n\n    git add conf\n    git add keydir\n    git commit -m \"added foo, gave access to alice, bob, carol\"\n    git push\n\nWhen the push completes, gitolite will add the new users to\n`~/.ssh/authorized_keys` on the server, as well as create a new, empty, repo\ncalled \"foo\".\n\n## help for your users\n\nOnce a user has sent you their public key and you have added them as\nspecified above and given them access, you have to tell them what URL to\naccess their repos at.  This is usually \"git clone git@host:reponame\"; see\nman git-clone for other forms.\n\n**NOTE**: again, if they are asked for a password, something is wrong.\n\nIf they need to know what repos they have access to, they just have to run\n\"ssh git@host info\".\n\n## access rule examples\n\nGitolite's access rules are very powerful.  The simplest use was already\nshown above.  Here is a slightly more detailed example:\n\n    repo foo\n        RW+                     =   alice\n        -   master              =   bob\n        -   refs/tags/v[0-9]    =   bob\n        RW                      =   bob\n        RW  refs/tags/v[0-9]    =   carol\n        R                       =   dave\n\nHere's what these example rules say:\n\n  * alice can do anything to any branch or tag -- create, push,\n    delete, rewind/overwrite etc.\n\n  * bob can create or fast-forward push any branch whose name does\n    not start with \"master\" and create any tag whose name does not\n    start with \"v\"+digit.\n\n  * carol can create tags whose names start with \"v\"+digit.\n\n  * dave can clone/fetch.\n\nPlease see the main documentation linked above for all the gory details, as\nwell as more features and examples.\n\n## groups\n\nGitolite allows you to group users or repos for convenience.  Here's an\nexample that creates two groups of users:\n\n    @staff      =   alice bob carol\n    @interns    =   ashok\n\n    repo secret\n        RW      =   @staff\n\n    repo foss\n        RW+     =   @staff\n        RW      =   @interns\n\nGroup lists accumulate.  The following two lines have the same effect as\nthe earlier definition of @staff above:\n\n    @staff      =   alice bob\n    @staff      =   carol\n\nYou can also use group names in other group names:\n\n    @all-devs   =   @staff @interns\n\nFinally, @all is a special group name that is often convenient to use if\nyou really mean \"all repos\" or \"all users\".\n\n## commands\n\nUsers can run certain commands remotely, using ssh.  Running\n\n    ssh git@host help\n\nprints a list of available commands.\n\nThe most commonly used command is \"info\".  All commands respond to a\nsingle argument of \"-h\" with suitable information.\n\nIf you have shell on the server, you have a lot more commands available to\nyou; try running \"gitolite help\".\n\n<!-- --------------------------------------------------------------------- -->\n\n## LICENSE\n\n# contact and support\n\nPlease see <http://gitolite.com/gitolite/#contactsupport> for mailing list and IRC\ninfo.\n\n# license\n\nThe gitolite software is copyright Sitaram Chamarty and is licensed under the\nGPL v2; please see the file called COPYING in the source distribution.\n\nPlease see <http://gitolite.com/gitolite/#license> for more.\n\n>   -------------------------------------------------------------------------\n\n>   **NOTE**: GIT is a trademark of Software Freedom Conservancy and my use of\n>   \"Gitolite\" is under license.\n\n>   -------------------------------------------------------------------------\n"
  },
  {
    "path": "check-g2-compat",
    "content": "#!/usr/bin/perl\n\nuse Cwd;\n\nmy $h  = $ENV{HOME};\nmy $rc = \"$h/.gitolite.rc\";\nmy %count;\n\nintro();\n\nmsg( FATAL => \"no rc file found; do you even *have* g2 running?\" ) if not -f $rc;\ndo $rc;\nunless ( $return = do $rc ) {\n    msg( FATAL => \"couldn't parse $rc: $@\" ) if $@;\n    msg( FATAL   => \"couldn't do $rc: $!\" ) unless defined $return;\n    msg( WARNING => \"couldn't run $rc\" )    unless $return;\n}\n\nprint \"checking rc file...\\n\";\nrc_basic();\nrest_of_rc();\nprint \"\\n\";\n\nprint \"checking conf file(s)...\\n\";\nconf();\nprint \"\\n\";\n\nprint \"checking repos...\\n\";\nrepo();\nprint \"\\n\";\n\nprint \"...all done...\\n\";\n\n# ----------------------------------------------------------------------\n\nsub intro {\n    msg( INFO => \"This program only checks for uses that make the new g3 completely unusable\" );\n    msg( ''   => \"or that might end up giving *more* access to someone if migrated as-is.\" );\n    msg( ''   => \"It does NOT attempt to catch all the differences described in the docs.\" );\n    msg( '', '' );\n    msg( INFO => \"'see docs' usually means the pre-migration checklist in\" );\n    msg( '',  => \"'g2migr.html'; to get there, start from the main migration\" );\n    msg( '',  => \"page at http://gitolite.com/gitolite/migr.html\" );\n    msg( '', '' );\n}\n\nsub rc_basic {\n    msg( FATAL => \"GL_ADMINDIR in the wrong place -- aborting; see docs\" ) if $GL_ADMINDIR ne \"$h/.gitolite\";\n    msg( NOTE => \"GL_ADMINDIR is in the right place; assuming you did not mess with\" );\n    msg( '', \"GL_CONF, GL_LOGT, GL_KEYDIR, and GL_CONF_COMPILED\" );\n    msg( FATAL => \"REPO_BASE in the wrong place -- aborting; see docs\" ) if $REPO_BASE ne \"$h/repositories\" and $REPO_BASE ne \"repositories\";\n# ( abs or rel both ok)\n}\n\nsub rest_of_rc {\n    msg( SEVERE  => \"GIT_PATH found; see docs\" )                          if $GIT_PATH;\n    msg( SEVERE  => \"GL_ALL_INCLUDES_SPECIAL found; see docs\" )           if $GL_ALL_INCLUDES_SPECIAL;\n    msg( SEVERE  => \"GL_NO_CREATE_REPOS not yet implemented\" )            if $GL_NO_CREATE_REPOS;\n    msg( SEVERE  => \"rsync not yet implemented\" )                         if $RSYNC_BASE;\n    msg( WARNING => \"ADMIN_POST_UPDATE_CHAINS_TO found; see docs\" )       if $ADMIN_POST_UPDATE_CHAINS_TO;\n    msg( WARNING => \"GL_NO_DAEMON_NO_GITWEB found; see docs\" )            if $GL_NO_DAEMON_NO_GITWEB;\n    msg( WARNING => \"GL_NO_SETUP_AUTHKEYS found; see docs\" )              if $GL_NO_SETUP_AUTHKEYS;\n    msg( WARNING => \"UPDATE_CHAINS_TO found; see docs\" )                  if $UPDATE_CHAINS_TO;\n    msg( WARNING => \"GL_ADC_PATH found; see docs\" )                       if $GL_ADC_PATH;\n    msg( WARNING => \"non-default GL_WILDREPOS_PERM_CATS found\" ) if $GL_WILDREPOS_PERM_CATS ne 'READERS WRITERS';\n}\n\nsub conf {\n    chdir($h);\n    chdir($GL_ADMINDIR);\n\n    my $conf = `find . -name \"*.conf\" | xargs cat`;\n    msg( \"SEVERE\", \"NAME rules; see docs\" )                    if $conf =~ m(NAME/);\n    msg( \"SEVERE\", \"subconf command in admin repo; see docs\" ) if $conf =~ m(NAME/conf/fragments);\n    msg( \"SEVERE\", \"mirroring used; see docs\" )                if $conf =~ m(config +gitolite\\.mirror\\.);\n}\n\nsub repo {\n    chdir($h);\n    chdir($REPO_BASE);\n    my @creater = `find . -name gl-creater`;\n    if (@creater) {\n        msg( WARNING => \"found \" . scalar(@creater) . \" gl-creater files; see docs\" );\n    }\n\n    my @perms = `find . -name gl-perms | xargs egrep -l -w R\\\\|RW`;\n    if (@perms) {\n        msg( WARNING => \"found \" . scalar(@perms) . \" gl-perms files with R or RW; see docs\" );\n    }\n}\n\nsub msg {\n    my ( $type, $text ) = @_;\n    print \"$type\" if $type;\n    print \"\\t$text\\n\";\n    exit 1 if $type eq 'FATAL';\n\n    $count{$type}++ if $type;\n}\n"
  },
  {
    "path": "contrib/commands/compile-1",
    "content": "#!/usr/bin/perl -s\nuse strict;\nuse warnings;\n\n# DESCRIPTION:\n\n#   This program is meant to re-compile the access rules (and 'config' or\n#   'option' lines) of exactly ONE actual repo (i.e., not a repo group or a\n#   repo pattern).\n\n# MOTIVATION:\n\n#   Fedora has a huge number of repos, as well as lot of churn in permissions.\n#   The combination of having a large conf *and* frequent compiles were not\n#   working out, hence this solution.  Not sure if any others have such a\n#   situation, so it's a standalone program, separate from \"core\" gitolite,\n#   shipped in \"contrib\" instead of \"src\".\n\n# SETUP:\n\n#   It expects to run as a gitolite sub-command, which means you will need to\n#   copy it from contrib to src/commands, or the equivalent location inside\n#   LOCAL_CODE; see non-core.html in the docs for details.\n\n# INVOCATION:\n\n#   It takes one argument: the name of a file that contains the new ruleset\n#   you want to use.  (This cannot be STDIN or \"-\" or something).\n\n#   example:\n#\n#       gitolite compile-1 <file-containing-rules-for-exactly-one-repo>\n\n# WARNING:\n\n#   If the main gitolite.conf changes significantly (specifically, if the\n#   number of effective rules in it increase quite a bit), you may have to run\n#   this command on ALL repos to update their individual gl-conf files.\n#\n#   (TBD: explain this in more concrete terms)\n\n# ----------------------------------------------------------------------\n# THERE IS NO ERROR CHECKING ON THE WARNING ABOVE, NOR ON THE ASSUMPTIONS AND\n# REQUIREMENTS BELOW.  PLEASE USE CAREFULLY!\n# ----------------------------------------------------------------------\n\n# ASSUMPTIONS/REQUIREMENTS:\n\n#   The file given must contain exactly one 'repo' line, with exactly one repo\n#   name, followed by the rules, configs, and options for that repo in the\n#   normal gitolite.conf syntax.\n\n#   The file must not have any group definitions, though it may use group\n#   definitions already setup in the main gitolite.conf file.\n\n#   Rules for this repo need not be already defined in the main gitolite.conf.\n#   If they are, they will cease to have any effect once you run this command\n#   - only the rules you supply in the file passed to this command will apply,\n#   and they will be considered to be placed at the end of gitolite.conf.\n\n#   If the repo does not exist, it must be first created using:\n#\n#       GL_USER=admin gitolite create <reponame>\n#\n#   where <reponame> is the gitolite-style name (i.e., \"foo\", not \"foo.git\" or\n#   \"~/repositories/foo\" or \"~/repositories/foo.git\")\n#\n#   This, of course, requires the main gitolite.conf to have the following\n#   lines at the top:\n#\n#       repo [A-Za-z].*\n#           C   =   admin\n\n#   Any change to the main gitolite.conf is followed by a full 'gitolite\n#   compile'; i.e., ~/.gitolite/conf/gitolite.conf-compiled.pm, the main\n#   \"compiled\" conf file, is consistent with the latest gitolite.conf.\n\nuse 5.10.0;\nuse Data::Dumper;\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Rc;\nuse Gitolite::Common;\nuse Gitolite::Conf;\nuse Gitolite::Conf::Store;\nuse Gitolite::Conf::Sugar;\n\nmy ($cf, $repo) = args();       # conffile from @ARGV, repo from first line of conffile\nmy $startseq = getseq();        # get the starting sequence number by looking in the (common) compiled conf file\nparse_and_store($cf, $repo);    # parse the ruleset and write out just the gl-conf file\n                                # (this is the only part that uses core gitolite functions)\nupdate_seq($repo, $startseq);   # update gl-conf with adjusted sequence numbers\n\nexit 0;\n\n# ----------------------------------------------------------------------\n\nsub args {\n    my $cf = shift @ARGV or _die \"need conffile\";\n    $cf = $ENV{PWD} . \"/\" . $cf unless $cf =~ m(^/);\n\n    my $t = slurp($cf);\n    _die \"bad conf file\" unless $t =~ /^\\s*repo\\s+(\\S+)\\s*$/m;\n    my $repo = $1;\n\n    return ($cf, $repo);\n}\n\nsub getseq {\n    my @main_cc = slurp \"$rc{GL_ADMIN_BASE}/conf/gitolite.conf-compiled.pm\";\n    my $max = 0;\n    for (@main_cc) {\n        $max = $1 if m/^ +(\\d+),$/ and $max < $1;\n    }\n\n    return $max;\n}\n\nsub parse_and_store {\n    my ($cf, $repo) = @_;\n\n    parse(sugar($cf));\n    _chdir( $rc{GL_REPO_BASE} );\n    Gitolite::Conf::Store::store_1($repo);\n}\n\nsub update_seq {\n    my ($repo, $startseq) = @_;\n\n    _chdir(\"$rc{GL_REPO_BASE}/$repo.git\");\n    my $text = slurp(\"gl-conf\");\n\n    $startseq+=1000;\n    # just for safety, in case someone adds a few rules to the main conf later, but neglects to update repo confs\n\n    $text =~ s/^( +)(\\d+),$/\"$1\" . ($2+$startseq) . \",\"/gme;\n\n    _print(\"gl-conf\", $text);\n}\n"
  },
  {
    "path": "contrib/commands/ukm",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Rc;\nuse Gitolite::Common;\nuse Gitolite::Easy;\n\n=for usage\nUsage for this command is not that simple. Please read the full\ndocumentation in\nhttps://github.com/sitaramc/gitolite-doc/blob/master/docs/contrib/ukm.mkd\nor online at http://gitolite.com/gitolite/contrib/ukm.html.\n=cut\n\nusage() if @ARGV and $ARGV[0] eq '-h';\n\n# Terms used in this file.\n# pubkeypath: the (relative) filename of a public key starting from\n#   gitolite-admin/keydir. Examples: alice.pub, foo/bar/alice.pub,\n#   alice@home.pub, foo/alice@laptop.pub. You get more examples, if you\n#   replace \"alice\" by \"bob@example.com\".\n# userid: computed from a pubkeypath by removing any directory\n#   part, the '.pub' extension and the \"old-style\" @NAME classifier.\n#   The userid identifies a user in the gitolite.conf file.\n# keyid: an identifier for a key given on the command line.\n#   If the script is called by one of the super_key_managers, then the\n#   keyid is the pubkeypath without the '.pub' extension. Otherwise it\n#   is the userid for a guest.\n#   The keyid is normalized to lowercase letters.\n\nmy $rb = $rc{GL_REPO_BASE};\nmy $ab = $rc{GL_ADMIN_BASE};\n\n# This will be the subdirectory under \"keydir\" in which the guest\n# keys will be stored. To prevent denial of service, this directory\n# should better start with 'zzz'.\n# The actual value can be set through the GUEST_DIRECTORY resource.\n# WARNING: If this value is changed you must understand the consequences.\n#          There will be no support if guestkeys_dir is anything else than\n#          'zzz/guests'.\nmy $guestkeys_dir = 'zzz/guests';\n\n# A guest key cannot have arbitrary names (keyid). Only keys that do *not*\n# match $forbidden_guest_pattern are allowed. Super-key-managers can add\n# any keyid.\n\n# This is the directory for additional keys of a self key manager.\nmy $selfkeys_dir = 'zzz/self';\n# There is no flexibility for selfkeys. One must specify a keyid that\n# matches the regular expression '^@[a-z0-9]+$'. Note that all keyids\n# are transformed to lowercase before checking.\nmy $required_self_pattern = qr([a-z0-9]+);\nmy $selfkey_management = 0; # disable selfkey managment\n\n# For guest key managers the keyid must pass two tests.\n#   1) It must match the $required_guest_pattern regular expression.\n#   2) It must not match the $forbidden_guest_pattern regular expression.\n# Default for $forbidden_guest_pattern is qr(.), i.e., every keyid is\n# forbidden, or in other words, only the gitolite-admin can manage keys.\n# Default for $required_guest_pattern is such that the keyid must look\n# like an email address, i.e. must have exactly one @ and at least one\n# dot after the @.\n# Just setting 'ukm' => 1 in .gitolite.rc only allows the super-key-managers\n# (i.e., only the gitolite admin(s)) to manage keys.\nmy $required_guest_pattern =\n    qr(^[0-9a-z][-0-9a-z._+]*@[-0-9a-z._+]+[.][-0-9a-z._+]+$);\nmy $forbidden_guest_pattern = qr(.);\n\ndie \"The command 'ukm' is not enabled.\\n\" if ! $rc{'COMMANDS'}{'ukm'};\n\nmy $km = $rc{'UKM_CONFIG'};\nif(ref($km) eq 'HASH') {\n    # If not set we only allow keyids that look like emails\n    my $rgp = $rc{'UKM_CONFIG'}{'REQUIRED_GUEST_PATTERN'} || '';\n    $required_guest_pattern = qr(^($rgp)$) if $rgp;\n    $forbidden_guest_pattern = $rc{'UKM_CONFIG'}{'FORBIDDEN_GUEST_PATTERN'}\n                            || $forbidden_guest_pattern;\n    $selfkey_management = $rc{'UKM_CONFIG'}{'SELFKEY_MANAGEMENT'} || 0;\n}\n\n# get the actual userid\nmy $gl_user = $ENV{GL_USER};\nmy $super_key_manager = is_admin(); # or maybe is_super_admin() ?\n\n# save arguments for later\nmy $operation = shift || 'list';\nmy $keyid     = shift || '';\n$keyid = lc $keyid; # normalize to lowercase ids\n\nmy ($zop, $zfp, $zselector, $zuser) = get_pending($gl_user);\n# The following will only be true if a selfkey manager logs in to\n# perform a pending operation.\nmy $pending_self = ($zop ne '');\n\ndie \"You are not a key manager.\\n\"\n    unless $super_key_manager || $pending_self\n           || in_group('guest-key-managers')\n           || in_group('self-key-managers');\n\n# Let's deal with the pending user first. The only allowed operations\n# that are to confirm the add operation with the random code\n# that must be provided via stdin or to undo a pending del operation.\nif ($pending_self) {\n    pending_user($gl_user, $zop, $zfp, $zselector, $zuser);\n    exit;\n}\n\nmy @available_operations = ('list','add','del');\ndie \"unknown ukm subcommand: $operation\\n\"\n    unless grep {$operation eq $_} @available_operations;\n\n# get to the keydir\n_chdir(\"$ab/keydir\");\n\n# Note that the program warns if it finds a fingerprint that maps to\n# different userids.\nmy %userids = (); # mapping from fingerprint to userid\nmy %fingerprints = (); # mapping from pubkeypath to fingerprint\nmy %pubkeypaths = (); # mapping from userid to pubkeypaths\n                      # note that the result is a list of pubkeypaths\n\n# Guest keys are managed by people in the @guest-key-managers group.\n# They can only add/del keys in the $guestkeys_dir directory. In fact,\n# the guest key manager $gl_user has only access to keys inside\n# %guest_pubkeypaths.\nmy %guest_pubkeypaths = (); # mapping from userid to pubkeypath for $gl_user\n\n# Self keys are managed by people in the @self-key-managers group.\n# They can only add/del keys in the $selfkeys_dir directory. In fact,\n# the self key manager $gl_user has only access to keys inside\n# %self_pubkeypaths.\nmy %self_pubkeypaths = ();\n\n# These are the keys that are managed by a super key manager.\nmy @all_pubkeypaths = `find . -type f -name \"*.pub\" 2>/dev/null | sort`;\n\nfor my $pubkeypath (@all_pubkeypaths) {\n    chomp($pubkeypath);\n    my $fp = fingerprint($pubkeypath);\n    $fingerprints{$pubkeypath} = $fp;\n    my $userid = get_userid($pubkeypath);\n    my ($zop, $zfp, $zselector, $zuser) = get_pending($userid);\n    $userid = $zuser if $zop;\n    if (! defined $userids{$fp}) {\n        $userids{$fp} = $userid;\n    } else {\n        warn \"key $fp is used for different user ids\\n\"\n            unless $userids{$fp} eq $userid;\n    }\n    push @{$pubkeypaths{$userid}}, $pubkeypath;\n    if ($pubkeypath =~ m|^./$guestkeys_dir/([^/]+)/[^/]+\\.pub$|) {\n        push @{$guest_pubkeypaths{$userid}}, $pubkeypath if $gl_user eq $1;\n    }\n    if ($pubkeypath =~ m|^./$selfkeys_dir/([^/]+)/[^/]+\\.pub$|) {\n        push @{$self_pubkeypaths{$userid}}, $pubkeypath if $gl_user eq $1;\n    }\n}\n\n###################################################################\n# do stuff according to the operation\n###################################################################\n\nif ( $operation eq 'list' ) {\n    list_pubkeys();\n    print \"\\n\\n\";\n    exit;\n}\n\ndie \"keyid required\\n\" unless $keyid;\ndie \"Not allowed to use '..' in keyid.\\n\" if $keyid =~ /\\.\\./;\n\nif ( $operation eq 'add' ) {\n    if ($super_key_manager) {\n        add_pubkey($gl_user, \"$keyid.pub\", safe_stdin());\n    } elsif (selfselector($keyid)) {\n        add_self($gl_user, $keyid, safe_stdin());\n    } else {\n        # assert ingroup('guest-key-managers');\n        add_guest($gl_user, $keyid, safe_stdin());\n    }\n} elsif ( $operation eq 'del' ) {\n    if ($super_key_manager) {\n        del_super($gl_user, \"$keyid.pub\");\n    } elsif (selfselector($keyid)) {\n        del_self($gl_user, $keyid);\n    } else {\n        # assert ingroup('guest-key-managers');\n        del_guest($gl_user, $keyid);\n    }\n}\n\nexit;\n\n\n###################################################################\n# only function definitions are following\n###################################################################\n\n# make a temp clone and switch to it\nour $TEMPDIR;\nBEGIN { $TEMPDIR = `mktemp -d -t tmp.XXXXXXXXXX`; chomp($TEMPDIR) }\nEND { my $err = $?; `/bin/rm -rf $TEMPDIR`; $? = $err; }\n\nsub cd_temp_clone {\n    chomp($TEMPDIR);\n    hushed_git( \"clone\", \"$rb/gitolite-admin.git\", \"$TEMPDIR/gitolite-admin\" );\n    chdir(\"$TEMPDIR/gitolite-admin\");\n    my $ip = $ENV{SSH_CONNECTION};\n    $ip =~ s/ .*//;\n    my ($zop, $zfp, $zselector, $zuser) = get_pending($ENV{GL_USER});\n    my $email = $zuser;\n    $email .= '@' . $ip  unless $email =~ m(@);\n    my $name = $zop ? \"\\@$zselector\" : $zuser;\n    # Record the keymanager in the gitolite-admin repo as author of the change.\n    hushed_git( \"config\", \"user.email\", \"$email\" );\n    hushed_git( \"config\", \"user.name\",  \"'$name from $ip'\" );\n}\n\n# compute the fingerprint from the full path of a pubkey file\nsub fingerprint {\n    my ($fp, $output) = ssh_fingerprint_file(shift);\n    # Do not print the output of $output to an untrusted destination.\n    die \"does not seem to be a valid pubkey\\n\" unless $fp;\n    return $fp;\n}\n\n\n# Read one line from STDIN and return it.\n#  If no data is available on STDIN after one second, the empty string\n# is returned.\n# If there is more than one line or there was an error in reading, the\n# function dies.\nsub safe_stdin {\n    use IO::Select;\n    my $s=IO::Select->new(); $s->add(\\*STDIN);\n    return '' unless $s->can_read(1);\n    my $data;\n    my $ret = read STDIN, $data, 4096;\n    # current pubkeys are approx 400 bytes so we go a little overboard\n    die \"could not read pubkey data\" . ( defined($ret) ? \"\" : \": $!\" ) . \"\\n\"\n        unless $ret;\n    die \"pubkey data seems to have more than one line\\n\" if $data =~ /\\n./;\n    return $data;\n}\n\n# call git, be quiet\nsub hushed_git {\n    system(\"git \" . join(\" \", @_) . \">/dev/null 2>/dev/null\");\n}\n\n# Extract the userid from the full path of the pubkey file (relative\n# to keydir/ and including the '.pub' extension.\nsub get_userid {\n    my ($u) = @_; # filename of pubkey relative to keydir/.\n    $u =~ s(.*/)();                # foo/bar/baz.pub -> baz.pub\n    $u =~ s/(\\@[^.]+)?\\.pub$//;    # baz.pub, baz@home.pub -> baz\n    return $u;\n}\n\n# Extract the @selector part from the full path of the pubkey file\n# (relative to keydir/ and including the '.pub' extension).\n# If there is no @selector part, the empty string is returned.\n# We also correctly extract the selector part from pending keys.\nsub get_selector {\n    my ($u) = @_; # filename of pubkey relative to keydir/.\n    $u =~ s(.*/)();                # foo/bar/baz.pub -> baz.pub\n    $u =~ s(\\.pub$)();             # baz@home.pub -> baz@home\n    return $1 if $u =~ m/.\\@($required_self_pattern)$/; # baz@home -> home\n    my ($zop, $zfp, $zselector, $zuser) = get_pending($u);\n    # If $u was not a pending key, then $zselector is the empty string.\n    return $zselector;\n}\n\n# Extract fingerprint, operation, selector, and true userid from a\n# pending userid.\nsub get_pending {\n    my ($gl_user) = @_;\n    return ($1, $2, $3, $4)\n       if ($gl_user=~/^zzz-(...)-([0-9a-f]{32})-($required_self_pattern)-(.*)/);\n    return ('', '', '', $gl_user)\n}\n\n# multiple / and are simplified to one / and the path is made relative\nsub sanitize_pubkeypath {\n    my ($pubkeypath) = @_;\n    $pubkeypath =~ s|//|/|g; # normalize path\n    $pubkeypath =~ s,\\./,,g; # remove './' from path\n    return './'.$pubkeypath; # Don't allow absolute paths.\n}\n\n# This function is only relavant for guest key managers.\n# It returns true if the pattern is OK and false otherwise.\nsub required_guest_keyid {\n    local ($_) = @_;\n    /$required_guest_pattern/ and ! /$forbidden_guest_pattern/;\n}\n\n# The function takes a $keyid as input and returns the keyid with the\n# initial @ stripped if everything is fine. It aborts with an error if\n# selfkey management is not enabled or the function is called for a\n# non-self-key-manager.\n# If the required selfkey pattern is not matched, it returns an empty string.\n# Thus the function can be used to check whether a given keyid is a\n# proper selfkeyid.\nsub selfselector {\n    my ($keyid) = @_;\n    return '' unless $keyid =~ m(^\\@($required_self_pattern)$);\n    $keyid = $1;\n    die \"selfkey management is not enabled\\n\" unless $selfkey_management;\n    die \"You are not a selfkey manager.\\n\" if ! in_group('self-key-managers');\n    return $keyid;\n}\n\n# Return the number of characters reserved for the userid field.\nsub userid_width {\n    my ($paths) = @_;\n    my (%pkpaths) = %{$paths};\n    my (@userid_lengths) = sort {$a <=> $b} (map {length($_)} keys %pkpaths);\n    @userid_lengths ? $userid_lengths[-1] : 0;\n}\n\n# List the keys given by a reference to a hash.\n# The regular expression $re is used to remove the initial part of the\n# keyid and replace it by what is matched inside the parentheses.\n# $format and $width are used for pretty printing\nsub list_keys {\n    my ($paths, $tokeyid, $format, $width) = @_;\n    my (%pkpaths) = %{$paths};\n    for my $userid (sort keys %pkpaths) {\n        for my $pubkeypath (sort @{$pkpaths{$userid}}) {\n            my $fp = $fingerprints{$pubkeypath};\n            my $userid = $userids{$fp};\n            my $keyid = &{$tokeyid}($pubkeypath);\n            printf $format,$fp,$userid,$width+1-length($userid),\"\",$keyid\n                if ($super_key_manager\n                    || required_guest_keyid($keyid)\n                    || $keyid=~m(^\\@));\n        }\n    }\n}\n\n# Turn a pubkeypath into a keyid for super-key-managers, guest-keys,\n# and self-keys.\nsub superkeyid {\n    my ($keyid) = @_;\n    $keyid =~ s(\\.pub$)();\n    $keyid =~ s(^\\./)();\n    return $keyid;\n}\n\nsub guestkeyid {\n    my ($keyid) = @_;\n    $keyid =~ s(\\.pub$)();\n    $keyid =~ s(^.*/)();\n    return $keyid;\n}\n\nsub selfkeyid {\n    my ($keyid) = @_;\n    $keyid =~ s(\\.pub$)();\n    $keyid =~ s(^.*/)();\n    my ($zop, $zfp, $zselector, $zuser) = get_pending($keyid);\n    return \"\\@$zselector (pending $zop)\" if $zop;\n    $keyid =~ s(.*@)(@);\n    return $keyid;\n}\n\n###################################################################\n\n# List public keys managed by the respective user.\n# The fingerprints, userids and keyids are printed.\n# keyids are shown in a form that can be used for add and del\n# subcommands. \nsub list_pubkeys {\n    print \"Hello $gl_user, you manage the following keys:\\n\";\n    my $format = \"%-47s %s%*s%s\\n\";\n    my $width = 0;\n    if ($super_key_manager) {\n        $width = userid_width(\\%pubkeypaths);\n        $width = 6 if $width < 6; # length(\"userid\")==6\n        printf $format, \"fingerprint\", \"userid\", ($width-5), \"\", \"keyid\";\n        list_keys(\\%pubkeypaths, , \\&superkeyid, $format, $width);\n    } else {\n        my $widths = $selfkey_management?userid_width(\\%self_pubkeypaths):0;\n        my $widthg = userid_width(\\%guest_pubkeypaths);\n        $width = $widths > $widthg ? $widths : $widthg; # maximum width\n        return unless $width; # there are no keys\n        $width = 6 if $width < 6; # length(\"userid\")==6\n        printf $format, \"fingerprint\", \"userid\", ($width-5), \"\", \"keyid\";\n        list_keys(\\%self_pubkeypaths, \\&selfkeyid, $format, $width)\n            if $selfkey_management;\n        list_keys(\\%guest_pubkeypaths, \\&guestkeyid,  $format, $width);\n    }\n}\n\n\n###################################################################\n\n# Add a public key for the user $gl_user.\n# $pubkeypath is the place where the new key will be stored.\n# If the file or its fingerprint already exists, the operation is\n# rejected.\nsub add_pubkey {\n    my ( $gl_user, $pubkeypath, $keymaterial ) = @_;\n    if(! $keymaterial) {\n        print STDERR \"Please supply the new key on STDIN.\\n\";\n        print STDERR \"Try something like this:\\n\";\n        print STDERR \"cat FOO.pub | ssh GIT\\@GITOLITESERVER ukm add KEYID\\n\";\n        die \"missing public key data\\n\";\n    }\n    # clean pubkeypath a bit\n    $pubkeypath = sanitize_pubkeypath($pubkeypath);\n    # Check that there is not yet something there already.\n    die \"cannot override existing key\\n\" if $fingerprints{$pubkeypath};\n\n    my $userid = get_userid($pubkeypath);\n    # Super key managers shouldn't be able to add a that leads to\n    # either an empty userid or to a userid that starts with @.\n    #\n    # To avoid confusion, all keyids for super key managers must be in\n    # a full path format. Having a public key of the form\n    # gitolite-admin/keydir/@foo.pub might be confusing and might lead\n    # to other problems elsewhere.\n    die \"cannot add key that starts with \\@\\n\" if (!$userid) || $userid=~/^@/;\n\n    cd_temp_clone();\n    _chdir(\"keydir\");\n    $pubkeypath =~ m((.*)/); # get the directory part\n    _mkdir($1);\n    _print($pubkeypath, $keymaterial);\n    my $fp = fingerprint($pubkeypath);\n\n    # Maybe we are adding a selfkey.\n    my ($zop, $zfp, $zselector, $zuser) = get_pending($userid);\n    my $user = $zop ? \"$zuser\\@$zselector\" : $userid;\n    $userid = $zuser;\n    # Check that there isn't a key with the same fingerprint under a\n    # different userid.\n    if (defined $userids{$fp}) {\n        if ($userid ne $userids{$fp}) {\n            print STDERR \"Found  $fp $userids{$fp}\\n\" if $super_key_manager;\n            print STDERR \"Same key is already available under another userid.\\n\";\n            die \"cannot add key\\n\";\n        } elsif ($zop) {\n            # Because of the way a key is confirmed with ukm, it is\n            # impossible to confirm the initial key of the user as a\n            # new selfkey. (It will lead to the function list_pubkeys\n            # instead of pending_user_add, because the gl_user will\n            # not be that of a pending user.) To avoid confusion, we,\n            # therefore, forbid to add the user's initial key\n            # altogether.\n            # In fact, we here also forbid to add any key for that\n            # user that is already in the system.\n            die \"You cannot add a key that already belongs to you.\\n\";\n        }\n    } else {# this fingerprint does not yet exist\n        my @paths = @{$pubkeypaths{$userid}} if defined $pubkeypaths{$userid};\n        if (@paths) {# there are already keys for $userid\n            if (grep {$pubkeypath eq $_} @paths) {\n                print STDERR \"The keyid is already present. Nothing changed.\\n\";\n            } elsif ($super_key_manager) {\n                # It's OK to add new selfkeys, but here we are in the case\n                # of adding multiple keys for guests. That is forbidden.\n                print STDERR \"Adding new public key for $userid.\\n\";\n            } elsif ($pubkeypath =~ m(^\\./$guestkeys_dir/)) {\n                # Arriving here means we are about to add a *new*\n                # guest key, because the fingerprint is not yet\n                # existing. This would be for an already existing\n                # userid (added by another guest key manager). Since\n                # that effectively means to (silently) add an\n                # additional key for an existing user, it must be\n                # forbidden.\n                die \"cannot add another public key for an existing user\\n\";\n            }\n        }\n    }\n    exit if (`git status -s` eq ''); # OK to add identical keys twice\n    hushed_git( \"add\", \".\" ) and die \"git add failed\\n\";\n    hushed_git( \"commit\", \"-m\", \"'ukm add $gl_user $userid\\n\\n$fp'\" )\n        and die \"git commit failed\\n\";\n    system(\"gitolite push >/dev/null 2>/dev/null\") and die \"git push failed\\n\";\n}\n\n# Guest key managers should not be allowed to add directories or\n# multiple keys via the @domain mechanism, since this might allow\n# another guest key manager to give an attacker access to another\n# user's repositories.\n#\n# Example: Alice adds bob.pub for bob@example.org. David adds eve.pub\n# (where only Eve but not Bob has the private key) under the keyid\n# bob@example.org@foo. This basically gives Eve the same rights as\n# Bob.\nsub add_guest {\n    my ( $gl_user, $keyid, $keymaterial ) = @_;\n    die \"keyid not allowed: '$keyid'\\n\"\n        if $keyid =~ m(@.*@) or $keyid =~ m(/) or !required_guest_keyid($keyid);\n    add_pubkey($gl_user, \"$guestkeys_dir/$gl_user/$keyid.pub\", $keymaterial);\n}\n\n# Add a new selfkey for user $gl_user.\nsub add_self {\n    my ( $gl_user, $keyid, $keymaterial ) = @_;\n    my $selector = \"\";\n    $selector = selfselector($keyid); # might return empty string\n    die \"keyid not allowed: $keyid\\n\" unless $selector;\n\n    # Check that the new selector is not already in use even not in a\n    # pending state.\n    die \"keyid already in use: $keyid\\n\"\n        if grep {selfkeyid($_)=~/^\\@$selector( .*)?$/} @{$self_pubkeypaths{$gl_user}};\n    # generate new pubkey create fingerprint\n    system(\"ssh-keygen -N '' -q -f \\\"$TEMPDIR/session\\\" -C $gl_user\");\n    my $sessionfp = fingerprint(\"$TEMPDIR/session.pub\");\n    $sessionfp =~ s/://g;\n    my $user = \"zzz-add-$sessionfp-$selector-$gl_user\";\n    add_pubkey($gl_user, \"$selfkeys_dir/$gl_user/$user.pub\", $keymaterial);\n    print `cat \"$TEMPDIR/session.pub\"`;\n}\n\n###################################################################\n\n\n# Delete a key of user $gl_user.\nsub del_pubkey {\n    my ($gl_user, $pubkeypath) = @_;\n    $pubkeypath = sanitize_pubkeypath($pubkeypath);\n    my $fp = $fingerprints{$pubkeypath};\n    die \"key not found\\n\" unless $fp;\n    cd_temp_clone();\n    chdir(\"keydir\");\n    hushed_git( \"rm\", \"$pubkeypath\" ) and die \"git rm failed\\n\";\n    my $userid = get_userid($pubkeypath);\n    hushed_git( \"commit\", \"-m\", \"'ukm del $gl_user $userid\\n\\n$fp'\" )\n        and die \"git commit failed\\n\";\n    system(\"gitolite push >/dev/null 2>/dev/null\") and die \"git push failed\\n\";\n}\n\n# $gl_user is a super key manager. This function aborts if the\n# superkey manager tries to remove his last key.\nsub del_super {\n    my ($gl_user, $pubkeypath) = @_;\n    $pubkeypath = sanitize_pubkeypath($pubkeypath);\n    die \"You are not managing the key $keyid.\\n\"\n        unless grep {$_ eq $pubkeypath} @all_pubkeypaths;\n    my $userid = get_userid($pubkeypath);\n    if ($gl_user eq $userid) {\n        my @paths = @{$pubkeypaths{$userid}};\n        die \"You cannot delete your last key.\\n\"\n            if scalar(grep {$userid eq get_userid($_)} @paths)<2;\n    }\n    del_pubkey($gl_user, $pubkeypath);\n}\n\nsub del_guest {\n    my ($gl_user, $keyid) = @_;\n    my $pubkeypath = sanitize_pubkeypath(\"$guestkeys_dir/$gl_user/$keyid.pub\");\n    my $userid = get_userid($pubkeypath);\n    # Check whether $gl_user actually manages $keyid.\n    my @paths = ();\n    @paths = @{$guest_pubkeypaths{$userid}}\n        if defined $guest_pubkeypaths{$userid};\n    die \"You are not managing the key $keyid.\\n\"\n        unless grep {$_ eq $pubkeypath} @paths;\n    del_pubkey($gl_user, $pubkeypath);\n}\n\n# Delete a selfkey of $gl_user. The first delete is a preparation of\n# the deletion and only a second call will actually delete the key. If\n# the second call is done with the key that is scheduled for deletion,\n# it is basically undoing the previous del call. This last case is\n# handled in function pending_user_del.\nsub del_self {\n    my ($gl_user, $keyid) = @_;\n    my $selector = selfselector($keyid); # might return empty string\n    die \"keyid not allowed: '$keyid'\\n\" unless $selector;\n\n    # Does $gl_user actually manage that keyid?\n    # All (non-pending) selfkeys have an @selector part in their pubkeypath.\n    my @paths = @{$self_pubkeypaths{$gl_user}};\n    die \"You are not managing the key $keyid.\\n\"\n        unless grep {$selector eq get_selector($_)} @paths;\n\n    cd_temp_clone();\n    _chdir(\"keydir\");\n    my $fp = '';\n    # Is it the first or the second del call? It's the second call, if\n    # there is a scheduled-for-deletion or scheduled-for-addition\n    # selfkey which has the given keyid as a selector part.\n    @paths = grep {\n        my ($zop, $zfp, $zselector, $zuser) = get_pending(get_userid($_));\n        $zselector eq $selector\n    } @paths;\n    if (@paths) {# start actual deletion of the key (second call)\n        my $pubkeypath = $paths[0];\n        $fp = fingerprint($pubkeypath);\n        my ($zop, $zf, $zs, $zu) = get_pending(get_userid($pubkeypath));\n        $zop = $zop eq 'add' ? 'undo-add' : 'confirm-del';\n        hushed_git(\"rm\", \"$pubkeypath\") and die \"git rm failed\\n\";\n        hushed_git(\"commit\", \"-m\", \"'ukm $zop $gl_user\\@$selector\\n\\n$fp'\")\n            and die \"git commit failed\\n\";\n        system(\"gitolite push >/dev/null 2>/dev/null\")\n            and die \"git push failed\\n\";\n        print STDERR \"pending keyid deleted: \\@$selector\\n\";\n        return;\n    }\n    my $oldpubkeypath = \"$selfkeys_dir/$gl_user/$gl_user\\@$selector.pub\";\n    # generate new pubkey and create fingerprint to get a random number\n    system(\"ssh-keygen -N '' -q -f \\\"$TEMPDIR/session\\\" -C $gl_user\");\n    my $sessionfp = fingerprint(\"$TEMPDIR/session.pub\");\n    $sessionfp =~ s/://g;\n    my $user = \"zzz-del-$sessionfp-$selector-$gl_user\";\n    my $newpubkeypath = \"$selfkeys_dir/$gl_user/$user.pub\";\n\n    # A key for gitolite access that is in authorized_keys and not\n    # existing in the expected place under keydir/ should actually not\n    # happen, but one never knows.\n    die \"key not available\\n\" unless -r $oldpubkeypath;\n\n    # For some strange reason the target key already exists.\n    die \"cannot override existing key\\n\" if -e $newpubkeypath;\n\n    $fp = fingerprint($oldpubkeypath);\n    print STDERR \"prepare deletion of key \\@$selector\\n\";\n    hushed_git(\"mv\", \"$oldpubkeypath\", \"$newpubkeypath\")\n        and die \"git mv failed\\n\";\n    hushed_git(\"commit\", \"-m\", \"'ukm prepare-del $gl_user\\@$selector\\n\\n$fp'\")\n        and die \"git commit failed\\n\";\n    system(\"gitolite push >/dev/null 2>/dev/null\")\n        and die \"git push failed\\n\";\n}\n\n###################################################################\n# Adding a selfkey should be done as follows.\n#\n#   cat newkey.pub | ssh git@host ukm add @selector > session\n#   cat session | ssh -i newkey git@host ukm\n#\n# The provided random data will come from a newly generated ssh key\n# whose fingerprint will be stored in $gl_user. So we compute the\n# fingerprint of the data that is given to us. If it doesn't match the\n# fingerprint, then something went wrong and the confirm operation is\n# forbidden, in fact, the pending key will be removed from the system.\nsub pending_user_add {\n    my ($gl_user, $zfp, $zselector, $zuser) = @_;\n    my $oldpubkeypath = \"$selfkeys_dir/$zuser/$gl_user.pub\";\n    my $newpubkeypath = \"$selfkeys_dir/$zuser/$zuser\\@$zselector.pub\";\n\n    # A key for gitolite access that is in authorized_keys and not\n    # existing in the expected place under keydir/ should actually not\n    # happen, but one never knows.\n    die \"key not available\\n\" unless -r $oldpubkeypath;\n\n    my $keymaterial = safe_stdin();\n    # If there is no keymaterial (which corresponds to a session key\n    # for the confirm-add operation), logging in to this key, removes\n    # it from the system.\n    my $session_key_not_provided = '';\n    if (!$keymaterial) {\n        $session_key_not_provided = \"missing session key\";\n    } else {\n        _print(\"$TEMPDIR/session.pub\", $keymaterial);\n        my $sessionfp = fingerprint(\"$TEMPDIR/session.pub\");\n        $sessionfp =~ s/://g;\n        $session_key_not_provided = \"session key not accepted\"\n            unless ($zfp eq $sessionfp)\n    }\n    my $fp = fingerprint($oldpubkeypath);\n    if ($session_key_not_provided) {\n        print STDERR \"$session_key_not_provided\\n\";\n        print STDERR \"pending keyid deleted: \\@$zselector\\n\";\n        hushed_git(\"rm\", \"$oldpubkeypath\") and die \"git rm failed\\n\";\n        hushed_git(\"commit\", \"-m\", \"'ukm del $zuser\\@$zselector\\n\\n$fp'\")\n            and die \"git commit failed\\n\";\n        system(\"gitolite push >/dev/null 2>/dev/null\")\n            and die \"git push failed\\n\";\n        return;\n    }\n\n    # For some strange reason the target key already exists.\n    die \"cannot override existing key\\n\" if -e $newpubkeypath;\n\n    print STDERR \"pending keyid added: \\@$zselector\\n\";\n    hushed_git(\"mv\", \"$oldpubkeypath\", \"$newpubkeypath\")\n        and die \"git mv failed\\n\";\n    hushed_git(\"commit\", \"-m\", \"'ukm confirm-add $zuser\\@$zselector\\n\\n$fp'\")\n        and die \"git commit failed\\n\";\n    system(\"gitolite push >/dev/null 2>/dev/null\")\n        and die \"git push failed\\n\";\n}\n\n# To delete a key, one must first bring the key into a pending state\n# and then truely delete it with another key. In case, the login\n# happens with the pending key (implemented below), it means that the\n# delete operation has to be undone.\nsub pending_user_del {\n    my ($gl_user, $zfp, $zselector, $zuser) = @_;\n    my $oldpubkeypath = \"$selfkeys_dir/$zuser/$gl_user.pub\";\n    my $newpubkeypath = \"$selfkeys_dir/$zuser/$zuser\\@$zselector.pub\";\n    print STDERR \"undo pending deletion of keyid \\@$zselector\\n\";\n    # A key for gitolite access that is in authorized_keys and not\n    # existing in the expected place under keydir/ should actually not\n    # happen, but one never knows.\n    die \"key not available\\n\" unless -r $oldpubkeypath;\n    # For some strange reason the target key already exists.\n    die \"cannot override existing key\\n\" if -e $newpubkeypath;\n    my $fp = fingerprint($oldpubkeypath);\n    hushed_git(\"mv\", \"$oldpubkeypath\", \"$newpubkeypath\")\n        and die \"git mv failed\\n\";\n    hushed_git(\"commit\", \"-m\", \"'ukm undo-del $zuser\\@$zselector\\n\\n$fp'\")\n        and die \"git commit failed\\n\";\n}\n\n# A user whose key is in pending state cannot do much. In fact,\n# logging in as such a user simply takes back the \"bringing into\n# pending state\", i.e. a key scheduled for adding is remove and a key\n# scheduled for deletion is brought back into its properly added state.\nsub pending_user {\n    my ($gl_user, $zop, $zfp, $zselector, $zuser) = @_;\n    cd_temp_clone();\n    _chdir(\"keydir\");\n    if ($zop eq 'add') {\n        pending_user_add($gl_user, $zfp, $zselector, $zuser);\n    } elsif ($zop eq 'del') {\n        pending_user_del($gl_user, $zfp, $zselector, $zuser);\n    } else {\n        die \"unknown operation\\n\";\n    }\n    system(\"gitolite push >/dev/null 2>/dev/null\")\n        and die \"git push failed\\n\";\n}\n"
  },
  {
    "path": "contrib/hooks/repo-specific/save-push-signatures",
    "content": "#!/bin/sh\n\n# ----------------------------------------------------------------------\n# post-receive hook to adopt push certs into 'refs/push-certs'\n\n# Collects the cert blob on push and saves it, then, if a certain number of\n# signed pushes have been seen, processes all the \"saved\" blobs in one go,\n# adding them to the special ref 'refs/push-certs'.  This is done in a way\n# that allows searching for all the certs pertaining to one specific branch\n# (thanks to Junio Hamano for this idea plus general brainstorming).\n\n# The \"collection\" happens only if $GIT_PUSH_CERT_NONCE_STATUS = OK; again,\n# thanks to Junio for pointing this out; see [1]\n#\n# [1]: https://groups.google.com/forum/#!topic/gitolite/7cSrU6JorEY\n\n# WARNINGS:\n#   Does not check that GIT_PUSH_CERT_STATUS = \"G\".  If you want to check that\n#   and FAIL the push, you'll have to write a simple pre-receive hook\n#   (post-receive is not the place for that; see 'man githooks').\n#\n#   Gitolite users: failing the hook cannot be done as a VREF because git does\n#   not set those environment variables in the update hook.  You'll have to\n#   write a trivial pre-receive hook and add that in.\n\n# Relevant gitolite doc links:\n#   repo-specific environment variables\n#       http://gitolite.com/gitolite/dev-notes.html#appendix-1-repo-specific-environment-variables\n#   repo-specific hooks\n#       http://gitolite.com/gitolite/non-core.html#repo-specific-hooks\n#       http://gitolite.com/gitolite/cookbook.html#v36-variation-repo-specific-hooks\n\n# Environment:\n#   GIT_PUSH_CERT_NONCE_STATUS should be \"OK\" (as mentioned above)\n#\n#   GL_OPTIONS_GPC_PENDING (optional; defaults to 1).  This is the number of\n#   git push certs that should be waiting in order to trigger the post\n#   processing.  You can set it within gitolite like so:\n#\n#       repo foo bar    # or maybe just 'repo @all'\n#           option ENV.GPC_PENDING = 5\n\n# Setup:\n#   Set up this code as a post-receive hook for whatever repos you need to.\n#   Then arrange to have the environment variable GL_OPTION_GPC_PENDING set to\n#   some number, as shown above.  (This is only required if you need it to be\n#   greater than 1.)  It could of course be different for different repos.\n#   Also see \"Invocation\" section below.\n\n# Invocation:\n#   Normally via git (see 'man githooks'), once it is setup as a post-receive\n#   hook.\n#\n#   However, if you set the \"pending\" limit high, and want to periodically\n#   \"clean up\" pending certs without necessarily waiting for the counter to\n#   trip, do the following (untested):\n#\n#       RB=$(gitolite query-rc GL_REPO_BASE)\n#       for r in $(gitolite list-phy-repos)\n#       do\n#           cd $RB/$repo.git\n#           unset GL_OPTIONS_GPC_PENDING    # if it is set higher up\n#           hooks/post-receive post_process\n#       done\n#\n#   That will take care of it.\n\n# Using without gitolite:\n#   Just set GL_OPTIONS_GPC_PENDING within the script (maybe read it from git\n#   config).  Everything else is independent of gitolite.\n\n# ----------------------------------------------------------------------\n# make it work on BSD also (but NOT YET TESTED on FreeBSD!)\nuname_s=`uname -s`\nif [ \"$uname_s\" = \"Linux\" ]\nthen\n    _lock() { flock \"$@\"; }\nelse\n    _lock() { lockf -k \"$@\"; }\n    # I'm assuming other BSDs also have this; I only have FreeBSD.\nfi\n\n# ----------------------------------------------------------------------\n# standard stuff\ndie() { echo \"$@\" >&2; exit 1; }\nwarn() { echo \"$@\" >&2; }\n\n# ----------------------------------------------------------------------\n# if there are no arguments, we're running as a \"post-receive\" hook\nif [ -z \"$1\" ]\nthen\n    # ignore if it may be a replay attack\n    [ \"$GIT_PUSH_CERT_NONCE_STATUS\" = \"OK\" ] || exit 1\n    # I don't think \"exit 1\" does anything in a post-receive anyway, so that's\n    # just a symbolic gesture!\n\n    # note the lock file used\n    _lock .gpc.lock $0 cat_blob\n\n    # if you want to initiate the post-processing ONLY from outside (for\n    # example via cron), comment out the next line.\n    exec $0 post_process\nfi\n\n# ----------------------------------------------------------------------\n# the 'post_process' part; see \"Invocation\" section in the doc at the top\nif [ \"$1\" = \"post_process\" ]\nthen\n    # this is the same lock file as above\n    _lock .gpc.lock $0 count_and_rotate $$\n\n    [ -d git-push-certs.$$ ] || exit 0\n\n    # but this is a different one\n    _lock .gpc.ref.lock $0 update_ref $$\n\n    exit 0\nfi\n\n# ----------------------------------------------------------------------\n# other values for \"$1\" are internal use only\n\nif [ \"$1\" = \"cat_blob\" ]\nthen\n    mkdir -p git-push-certs\n    git cat-file blob $GIT_PUSH_CERT > git-push-certs/$GIT_PUSH_CERT\n    echo $GIT_PUSH_CERT >> git-push-certs/.blob.list\nfi\n\nif [ \"$1\" = \"count_and_rotate\" ]\nthen\n    count=$(ls git-push-certs | wc -l)\n    if test $count -ge ${GL_OPTIONS_GPC_PENDING:-1}\n    then\n        # rotate the directory\n        mv git-push-certs git-push-certs.$2\n    fi\nfi\n\nif [ \"$1\" = \"update_ref\" ]\nthen\n    # use a different index file for all this\n    GIT_INDEX_FILE=push_certs_index; export GIT_INDEX_FILE\n\n    # prepare the special ref to receive commits\n    # historically this hook put the certs in a ref named refs/push-certs\n    # however, git does *NOT* replicate single-level refs\n    # trying to push them explicitly causes this error:\n    # remote: error: refusing to create funny ref 'refs/push-certs' remotely\n    # https://lore.kernel.org/git/robbat2-20211115T063838-612792475Z@orbis-terrarum.net/\n    #\n    # As a good-enough solution, use the namespace of meta/ for the refs.\n    # This is already used in other systems:\n    # - kernel.org refs/meta/cgit\n    # - gerrit refs/meta/config\n    # - GitBlit reflog: refs/meta/gitblit https://www.gitblit.com/administration.html#H12\n    # - cc-utils refs/meta/ci\n    # - JGit refs/meta/push-certs https://www.ibm.com/docs/en/radfws/9.6.1?topic=SSRTLW_9.6.1/org.eclipse.egit.doc/help/JGit/New_and_Noteworthy/4.1/4.1.htm\n    #\n    # To migrate from old to new, for each repo:\n    # git update-ref refs/meta/push-certs refs/push-certs\n    PUSH_CERTS_EXTRA_REFS='' PUSH_CERTS='' # These vars will be populated after checks.\n    # others vars are temp\n    _OLD_PUSH_CERTS=refs/push-certs\n    _NEW_PUSH_CERTS=refs/meta/push-certs\n    _OLD_PUSH_CERTS_EXISTS=0\n    _NEW_PUSH_CERTS_EXISTS=0\n    git show-ref --verify --quiet -- \"$_OLD_PUSH_CERTS\" && _OLD_PUSH_CERTS_EXISTS=1\n    git show-ref --verify --quiet -- \"$_NEW_PUSH_CERTS\" && _NEW_PUSH_CERTS_EXISTS=1\n    case \"${_OLD_PUSH_CERTS_EXISTS}${_NEW_PUSH_CERTS_EXISTS}\" in\n        # neither or new only:\n        # let's push to the NEW name only\n        '00'|'01') PUSH_CERTS=$_NEW_PUSH_CERTS ;;\n        # old-only: stick to the same, the migration is opt-in\n        '10') PUSH_CERTS=$_OLD_PUSH_CERTS ;;\n        # Both: Push to the old name, duplicate to the new name\n        '11') PUSH_CERTS=$_OLD_PUSH_CERTS PUSH_CERTS_EXTRA_REFS=$_NEW_PUSH_CERTS ;;\n    esac\n    # cleanup vars\n    unset _OLD_PUSH_CERTS_EXISTS _NEW_PUSH_CERTS_EXISTS _OLD_PUSH_CERTS _NEW_PUSH_CERTS\n\n    if git rev-parse -q --verify $PUSH_CERTS >/dev/null\n    then\n        git read-tree $PUSH_CERTS\n    else\n        git read-tree --empty\n        T=$(git write-tree)\n        C=$(echo 'start' | git commit-tree $T)\n        for _ref in $PUSH_CERTS $PUSH_CERTS_EXTRA_REFS ; do\n            git update-ref \"${_ref}\" \"${C}\"\n        done\n    fi\n\n    # for each cert blob...\n    for b in `cat git-push-certs.$2/.blob.list`\n    do\n        cf=git-push-certs.$2/$b\n\n        # it's highly unlikely that the blob got GC-ed already but write it\n        # back anyway, just in case\n        B=$(git hash-object -w $cf)\n\n        # bit of a sanity check\n        [ \"$B\" = \"$b\" ] || warn \"this should not happen: $B is not equal to $b\"\n\n        # for each ref described within the cert, update the index\n        for ref in `cat $cf | egrep '^[a-f0-9]+ [a-f0-9]+ refs/' | cut -f3 -d' '`\n        do\n            git update-index --add --cacheinfo 100644,$b,$ref\n            # we're using the ref name as a \"fake\" filename, so people can,\n            # for example, 'git log refs/push-certs -- refs/heads/master', to\n            # see all the push certs pertaining to the master branch.  This\n            # idea came from Junio Hamano, the git maintainer (I certainly\n            # don't deal with git plumbing enough to have thought of it!)\n        done\n\n        T=$(git write-tree)\n        C=$( git commit-tree -p $PUSH_CERTS $T < $cf )\n        for _ref in $PUSH_CERTS $PUSH_CERTS_EXTRA_REFS ; do\n            git update-ref \"${_ref}\" \"${C}\"\n        done\n\n        rm -f $cf\n    done\n    rm -f git-push-certs.$2/.blob.list\n    rmdir git-push-certs.$2\nfi\n"
  },
  {
    "path": "contrib/lib/Apache/gitolite.conf",
    "content": "# Apache Gitolite smart-http install Active Directory Authentication\n\n# Author: Jonathan Gray\n\n# It is assumed you already have mod_ssl, mod_ldap, & mod_authnz configured for apache\n# It is also assumed you are disabling http on port 80 and requiring the use of https on port 443\n\n# Boiler plate configuration from the smart-http deployment documentation script\n# Adjust paths if you use something other than the default\nSetEnv GIT_PROJECT_ROOT /var/www/gitolite-home/repositories\nScriptAlias /git/ /var/www/gitolite-home/gitolite-source/src/gitolite-shell/\nScriptAlias /gitmob/ /var/www/gitolite-home/gitolite-source/src/gitolite-shell/\nSetEnv GITOLITE_HTTP_HOME /var/www/gitolite-home\n# WARNING: do not add a trailing slash to the value of GITOLITE_HTTP_HOME\nSetEnv GIT_HTTP_EXPORT_ALL\n \n# Setup LDAP trusted root certificate from your domain\nLDAPTrustedGlobalCert CA_BASE64 /etc/httpd/conf.d/domain.ca.cer\n\n# In case you havn't setup proper SSL certificates in ssl.conf, go ahead and do it here to save headache later with git\nSSLCertificateFile /etc/httpd/conf.d/gitolite.server.crt\nSSLCertificateKeyFile /etc/httpd/conf.d/gitolite.server.key\nSSLCertificateChainFile /etc/httpd/conf.d/DigiCertCA.crt\n \n<Location /git>\n        Order deny,allow\n\t# In case you want to restrict access to a given ip/subnet\n        #Allow from my.ip.range/cidr\n        #Deny from All\n        AuthType Basic\n        AuthName \"Git\"\n        AuthBasicProvider ldap\n        AuthUserFile /dev/null\n        AuthzLDAPAuthoritative on\n        AuthLDAPURL ldaps://AD.DC1.local:3269 AD.DC2.local:3269 AD.DC3.local:3269/?sAMAccountName?sub\n        AuthLDAPBindDN git@domain.local\n        AuthLDAPBindPassword super.secret.password\n        AuthLDAPGroupAttributeIsDN on\n \n\t# You must use one of the two following approaches to handle authentication via active directory\n\t\n        # Require membership in the gitolite users group in AD\n        # The ldap-filter option is used to handle nested groups on the AD server rather than multiple calls to traverse from apache\n        # Require ldap-filter memberof:1.2.840.113556.1.4.1941:=cn=Gitolite Users,ou=Security Groups,dc=domain,dc=local\n\n\t# Alternatively, require a valid user account only since you're going to control authorization in gitolite anyway\n\tRequire valid-user\n</Location>\n"
  },
  {
    "path": "contrib/lib/Gitolite/Triggers/RedmineUserAlias.pm",
    "content": "package Gitolite::Triggers::RedmineUserAlias;\n\nuse Gitolite::Rc;\nuse Gitolite::Common;\nuse Gitolite::Conf::Load;\n\nuse strict;\nuse warnings;\n\n# aliasing a redmine username to a more user-friendly one\n# ----------------------------------------------------------------------\n\n=for usage\n\nWhy:\n\n    Redmine creates users like \"redmine_alice_123\"; we want the users to just\n    see \"alice\" instead of that.\n\nAssumption:\n\n*   Redmine does not allow duplicates in the middle bit; i.e., you can't\n    create redmine_alice_123 and redmine_alice_456 also.\n\nHow:\n\n*   add this code as lib/Gitolite/Triggers/RedmineUserAlias.pm to your\n    site-local code directory; see this link for how:\n\n        http://gitolite.com/gitolite/non-core.html#locations\n\n*   add the following to the rc file, just before the ENABLE section (don't\n    forget the trailing comma):\n\n        INPUT   =>  [ 'RedmineUserAlias::input' ],\n\nNotes:\n\n*   http mode has not been tested and will not be.  If someone has the time to\n    test it and make it work please let me know.\n\n*   not tested with mirroring.\n\nQuote:\n\n*   \"All that for what is effectively one line of code.  I need a life\".\n\n=cut\n\nsub input {\n    $ARGV[0] or _die \"no username???\";\n    $ARGV[0] =~ s/^redmine_(\\S+)_\\d+$/$1/;\n}\n\n1;\n"
  },
  {
    "path": "contrib/t/ukm.t",
    "content": "#!/usr/bin/perl\n\n# Call like this:\n# TSH_VERBOSE=1 TSH_ERREXIT=1 HARNESS_ACTIVE=1 GITOLITE_TEST=y prove t/ukm.t\n\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Common;\nuse Gitolite::Test;\n\n# basic tests using ssh\n# ----------------------------------------------------------------------\n\nmy $bd = `gitolite query-rc -n GL_BINDIR`;\nmy $h  = $ENV{HOME};\nmy $ab = `gitolite query-rc -n GL_ADMIN_BASE`;\nmy $pd = \"$bd/../t/keys\"; # source for pubkeys\numask 0077;\n\n_mkdir( \"$h/.ssh\", 0700 ) if not -d \"$h/.ssh\";\n\ntry \"plan 204\";\n\n\n# Reset everything.\n# Only admin and u1, u2, and u3 keys are available initially\n# Keys u4, u5, and u6 are used as guests later.\n# For easy access, we put the keys into ~/.ssh/, though.\ntry \"\n    rm -f $h/.ssh/authorized_keys; ok or die 1\n    cp $pd/u[1-6]* $h/.ssh; ok or die 2\n    cp $pd/admin*  $h/.ssh; ok or die 3\n    cp $pd/config  $h/.ssh; ok or die 4\n        cat $h/.ssh/config\n        perl s/%USER/$ENV{USER}/\n        put $h/.ssh/config\n    mkdir             $ab/keydir; ok or die 5\n    cp $pd/u[1-3].pub $ab/keydir; ok or die 6\n    cp $pd/admin.pub  $ab/keydir; ok or die 7\n\";\n\n# Put the keys into ~/.ssh/authorized_keys\nsystem(\"gitolite ../triggers/post-compile/ssh-authkeys\");\n\n# enable user key management in a simple form.\n# Guest key managers can add keyids looking like email addresses, but\n# cannot add emails containing example.com or hemmecke.org.\nsystem(\"sed -i \\\"s/.*ENABLE =>.*/'UKM_CONFIG'=>{'FORBIDDEN_GUEST_PATTERN'=>'example.com|hemmecke.org'}, ENABLE => ['ukm',/\\\" $h/.gitolite.rc\");\n\n# super-key-managers can add/del any key\n# super-key-managers should in fact agree with people having write\n# access to gitolite-admin repo.\n# guest-key-managers can add/del guest keys\nconfreset; confadd '\n    @guest-key-managers = u2 u3\n    @creators = u2 u3\n    repo pub/CREATOR/..*\n        C   =   @creators\n        RW+ =   CREATOR\n        RW  =   WRITERS\n        R   =   READERS\n';\n\n# Populate the gitolite-admin/keydir in the same way as it was used for\n# the initialization of .ssh/authorized_keys above.\ntry \"\n    mkdir             keydir; ok or die 8\n    cp $pd/u[1-3].pub keydir; ok or die 9;\n    cp $pd/admin.pub  keydir; ok or die 10;\n    git add conf keydir; ok\n    git commit -m ukm; ok; /master.* ukm/\n\";\n\n# Activate new config data.\ntry \"PUSH admin; ok; gsh; /master -> master/; !/FATAL/\" or die text();\n\n# Check whether the above setup yields the expected behavior for ukm.\n# The admin is super-key-manager, thus can manage every key.\ntry \"\n    ssh admin ukm; ok; /Hello admin, you manage the following keys:/\n                       / admin +admin/\n                       / u1 +u1/\n                       / u2 +u2/\n                       / u3 +u3/\n\";\n\n# u1 isn't a key manager, so shouldn't be above to manage keys.\ntry \"ssh u1 ukm; !ok; /FATAL: You are not a key manager./\";\n\n# u2 and u3 are guest key managers, but don't yet manage any key.\ntry \"ssh u2 ukm; ok\"; cmp \"Hello u2, you manage the following keys:\\n\\n\\n\";\ntry \"ssh u3 ukm; ok\"; cmp \"Hello u3, you manage the following keys:\\n\\n\\n\";\n\n\n###################################################################\n# Unknows subkommands abort ukm.\ntry \"ssh u2 ukm fake; !ok; /FATAL: unknown ukm subcommand: fake/\";\n\n\n###################################################################\n# Addition of keys.\n\n# If no data is provided on stdin, we don't block, but rather timeout\n# after one second and abort the program.\ntry \"ssh u2 ukm add u4\\@example.org; !ok; /FATAL: missing public key data/\";\n\n# If no keyid is given, we cannot add a key.\ntry \"ssh u2 ukm add; !ok; /FATAL: keyid required/\";\n\ntry \"\n    DEF ADD = cat $pd/%1.pub|ssh %2 ukm add %3\n    DEF ADDOK = ADD %1 %2 %3; ok\n    DEF ADDNOK = ADD %1 %2 %3; !ok\n    DEF FP = ADDNOK u4 u2 %1\n    DEF FORBIDDEN_PATTERN = FP %1; /FATAL: keyid not allowed:/\n\";\n\n# Neither a guest key manager nor a super key manager can add keys that have\n# double dot in their keyid. This is hardcoded to forbid paths with .. in it.\ntry \"\n    ADDNOK u4 u2    u4\\@hemmecke..org; /Not allowed to use '..' in keyid./\n    ADDNOK u4 admin u4\\@hemmecke..org; /Not allowed to use '..' in keyid./\n    ADDNOK u4 admin ./../.myshrc;      /Not allowed to use '..' in keyid./\n\";\n\n# guest-key-managers can only add keys that look like emails.\ntry \"\n    FORBIDDEN_PATTERN u4\n    FORBIDDEN_PATTERN u4\\@example\n    FORBIDDEN_PATTERN u4\\@foo\\@example.org\n\n    # No support for 'old style' multiple keys.\n    FORBIDDEN_PATTERN u4\\@example.org\\@foo\n\n    # No path delimiter in keyid\n    FORBIDDEN_PATTERN foo/u4\\@example.org\n\n    # Certain specific domains listed in FORBIDDEN_GUEST_PATTERN are forbidden.\n    # Note that also u4\\@example-com would be rejected, because MYDOMAIN\n    # contains a regular expression --> I don't care.\n    FORBIDDEN_PATTERN u4\\@example.com\n    FORBIDDEN_PATTERN u4\\@hemmecke.org\n\";\n\n# Accept one guest key.\ntry \"ADDOK u4 u2 u4\\@example.org\";\ntry \"ssh u2 ukm; ok; /Hello u2, you manage the following keys:/\n                     / u4\\@example.org *u4\\@example.org/\";\n\n# Various ways how a key must be rejected.\ntry \"\n    # Cannot add the same key again.\n    ADDNOK u4 u2 u4\\@example.org; /FATAL: cannot override existing key/\n\n    # u2 can also not add u4.pub under another keyid\n    ADDNOK u4 u2 u4\\@example.net; /FATAL: cannot add key/\n         /Same key is already available under another userid./\n\n    # u2 can also not add another key under the same keyid.\n    ADDNOK u5 u2 u4\\@example.org; /FATAL: cannot override existing key/\n\n    # Also u3 cannot not add another key under the same keyid.\n    ADDNOK u5 u3 u4\\@example.org\n         /FATAL: cannot add another public key for an existing user/\n\n    # And u3 cannot not add u4.pub under another keyid.\n    ADDNOK u4 u3 u4\\@example.net; /FATAL: cannot add key/\n         /Same key is already available under another userid./\n\n    # Not even the admin can add the same key u4 under a different userid.\n    ADDNOK u4 admin u4\\@example.net; /FATAL: cannot add key/\n         /Same key is already available under another userid./\n         /Found  .* u4\\@example.org/\n\n    # Super key managers cannot add keys that start with @.\n    # We don't care about @ in the dirname, though.\n    ADDNOK u4 admin foo/\\@ex.net; /FATAL: cannot add key that starts with \\@/\n    ADDNOK u4 admin foo/\\@ex;     /FATAL: cannot add key that starts with \\@/\n    ADDNOK u4 admin     \\@ex.net; /FATAL: cannot add key that starts with \\@/\n    ADDNOK u4 admin     \\@ex;     /FATAL: cannot add key that starts with \\@/\n\";\n\n# But u3 can add u4.pub under the same keyid.\ntry \"ADDOK u4 u3 u4\\@example.org\";\n\ntry \"ssh u3 ukm; ok; /Hello u3, you manage the following keys:/\n                     / u4\\@example.org *u4\\@example.org/\";\n\n# The admin can add multiple keys for the same userid.\ntry \"\n    ADDOK u5 admin u4\\@example.org\n    ADDOK u5 admin u4\\@example.org\\@home\n    ADDOK u5 admin laptop/u4\\@example.org\n    ADDOK u5 admin laptop/u4\\@example.org\\@home\n\";\n\n# And admin can also do this for other guest key managers. Note,\n# however, that the gitolite-admin must be told where the\n# GUEST_DIRECTORY is. But he/she could find out by cloning the\n# gitolite-admin repository and adding the same key directly.\ntry \"\n    ADDOK u5 admin zzz/guests/u2/u4\\@example.org\\@foo\n    ADDOK u6 admin zzz/guests/u3/u6\\@example.org\n\";\n\ntry \"ssh admin ukm; ok\"; cmp \"Hello admin, you manage the following keys:\nfingerprint                                     userid         keyid\na4:d1:11:1d:25:5c:55:9b:5f:91:37:0e:44:a5:a5:f2 admin          admin\n00:2c:1f:dd:a3:76:5a:1e:c4:3c:01:15:65:19:a5:2e u1             u1\n69:6f:b5:8a:f5:7b:d8:40:ce:94:09:a2:b8:95:79:5b u2             u2\n26:4b:20:24:98:a4:e4:a5:b9:97:76:9a:15:92:27:2d u3             u3\n78:cf:7e:2b:bf:18:58:54:23:cc:4b:3d:7e:f4:63:79 u4\\@example.org laptop/u4\\@example.org\n78:cf:7e:2b:bf:18:58:54:23:cc:4b:3d:7e:f4:63:79 u4\\@example.org laptop/u4\\@example.org\\@home\n78:cf:7e:2b:bf:18:58:54:23:cc:4b:3d:7e:f4:63:79 u4\\@example.org u4\\@example.org\n78:cf:7e:2b:bf:18:58:54:23:cc:4b:3d:7e:f4:63:79 u4\\@example.org u4\\@example.org\\@home\n8c:a6:c0:a5:71:85:0b:89:d3:08:97:22:ae:95:e1:bb u4\\@example.org zzz/guests/u2/u4\\@example.org\n78:cf:7e:2b:bf:18:58:54:23:cc:4b:3d:7e:f4:63:79 u4\\@example.org zzz/guests/u2/u4\\@example.org\\@foo\n8c:a6:c0:a5:71:85:0b:89:d3:08:97:22:ae:95:e1:bb u4\\@example.org zzz/guests/u3/u4\\@example.org\nfc:0f:eb:52:7a:d2:35:da:89:96:f5:15:0e:85:46:e7 u6\\@example.org zzz/guests/u3/u6\\@example.org\n\\n\\n\";\n\n# Now, u2 has two keys in his directory, but u2 can manage only one of\n# them, since the one added by the admin has two @ in it. Thus the key\n# added by admin is invisible to u2.\ntry \"ssh u2 ukm; ok\"; cmp \"Hello u2, you manage the following keys:\nfingerprint                                     userid         keyid\n8c:a6:c0:a5:71:85:0b:89:d3:08:97:22:ae:95:e1:bb u4\\@example.org u4\\@example.org\n\\n\\n\";\n\n# Since admin added key u6@example.org to the directory of u2, u2 is\n# also able to see it and, in fact, to manage it.\ntry \"ssh u3 ukm; ok\"; cmp \"Hello u3, you manage the following keys:\nfingerprint                                     userid         keyid\n8c:a6:c0:a5:71:85:0b:89:d3:08:97:22:ae:95:e1:bb u4\\@example.org u4\\@example.org\nfc:0f:eb:52:7a:d2:35:da:89:96:f5:15:0e:85:46:e7 u6\\@example.org u6\\@example.org\n\\n\\n\";\n\n###################################################################\n# Deletion of keys.\ntry \"\n    DEF DEL = ssh %1 ukm del %2\n    DEF DELOK  = DEL %1 %2; ok\n    DEF DELNOK = DEL %1 %2; !ok\n    DEF DELNOMGR = DELNOK %1 %2; /FATAL: You are not managing the key /\n\";\n\n# Deletion requires a keyid.\ntry \"ssh u3 ukm del; !ok; /FATAL: keyid required/\";\n\n# u3 can, of course, not remove any unmanaged key.\ntry \"DELNOMGR u3 u2\";\n\n# But u3 can delete u4@example.org and u6@example.org. This will, of course,\n# not remove the key u4@example.org that u2 manages.\ntry \"\n    DELOK u3 u4\\@example.org\n    DELOK u3 u6\\@example.org\n\";\n\n# After having deleted u4@example.org, u3 cannot remove it again,\n# even though, u2 still manages that key.\ntry \"DELNOMGR u3 u4\\@example.org\";\n\n# Of course a super-key-manager can remove any (existing) key.\ntry \"\n    DELOK  admin zzz/guests/u2/u4\\@example.org\n    DELNOK admin zzz/guests/u2/u4\\@example.org\n        /FATAL: You are not managing the key zzz/guests/u2/u4\\@example.org./\n    DELNOK admin zzz/guests/u2/u4\\@example.org\\@x\n        /FATAL: You are not managing the key zzz/guests/u2/u4\\@example.org./\n    DELOK  admin zzz/guests/u2/u4\\@example.org\\@foo\n\";\n\n# As the admin could do that via pushing to the gitolite-admin manually,\n# it's also allowed to delete even non-guest keys.\ntry \"DELOK admin u3\";\n\n# Let's clean the environment again.\ntry \"\n    DELOK admin laptop/u4\\@example.org\\@home\n    DELOK admin laptop/u4\\@example.org\n    DELOK admin        u4\\@example.org\\@home\n    DELOK admin        u4\\@example.org\n    ADDOK u3 admin u3\n \";\n\n# Currently the admin has just one key. It cannot be removed.\n# But after adding another key, deletion should work fine.\ntry \"\n    DELNOK admin admin; /FATAL: You cannot delete your last key./\n    ADDOK u6 admin second/admin; /Adding new public key for admin./\n    DELOK admin admin\n    DELNOK u6 admin; /FATAL: You are not managing the key admin./\n    DELNOK u6 second/admin; /FATAL: You cannot delete your last key./\n    ADDOK admin u6 admin; /Adding new public key for admin./\n    DELOK u6 second/admin\n\";\n\n###################################################################\n# Selfkey management.\n\n# If self key management is not switched on in the .gitolite.rc file,\n# it's not allowed at all.\ntry \"ssh u2 ukm add \\@second; !ok; /FATAL: selfkey management is not enabled/\";\n\n# Let's enable it.\nsystem(\"sed -i \\\"/'UKM_CONFIG'=>/s/=>{/=>{'SELFKEY_MANAGEMENT'=>1,/\\\" $h/.gitolite.rc\");\n\n# And add self-key-managers to gitolite.conf\n# chdir(\"../gitolite-admin\") or die \"in `pwd`, could not cd ../g-a\";\ntry \"glt pull admin origin master; ok\";\nput \"|cut -c5- > conf/gitolite.conf\", '\n    repo gitolite-admin\n        RW+ = admin\n    repo testing\n        RW+ = @all\n    @guest-key-managers = u2 u3\n    @self-key-managers = u1 u2\n    @creators = u2 u3\n    repo pub/CREATOR/..*\n        C   =   @creators\n        RW+ =   CREATOR\n        RW  =   WRITERS\n        R   =   READERS\n';\ntry \"\n    git add conf keydir; ok\n    git commit -m selfkey; ok; /master.* selfkey/\n\";\ntry \"PUSH admin; ok; gsh; /master -> master/; !/FATAL/\" or die text();\n\n# Now we can start with the tests.\n\n# Only self key managers are allowed to use selfkey management.\n# See variable @self-key-managers.\ntry \"ssh u3 ukm add \\@second; !ok; /FATAL: You are not a selfkey manager./\";\n\n# Cannot add keyid that are not alphanumeric.\ntry \"ssh u1 ukm add \\@second-key; !ok; /FATAL: keyid not allowed:/\";\n\n# Add a second key for u1, but leave it pending by not feeding in the\n# session key. The new user can login, but he/she lives under a quite\n# random gl_user name and thus is pretty much excluded from everything\n# except permissions given to @all. If this new id calls ukm without\n# providing the session key, this (pending) key is automatically\n# removed from the system.\n# If a certain keyid is in the system, then it cannot be added again.\ntry \"\n    ADDOK u4 u1 \\@second\n    ssh admin ukm; ok; /u1     zzz/self/u1/zzz-add-[a-z0-9]{32}-second-u1/\n    ssh u1    ukm; ok; /u1     \\@second .pending add./\n    ADDNOK u4 u1 \\@second; /FATAL: keyid already in use: \\@second/\n    ssh u4    ukm; ok; /pending keyid deleted: \\@second/\n    ssh admin ukm; ok; !/zzz/; !/second/\n\";\n\n# Not providing a proper ssh public key will abort. Providing a good\n# ssh public key, which is not a session key makes the key invalid.\n# The key will, therefore, be deleted by this operation.\ntry \"\n    ADDOK u4 u1 \\@second\n    echo fake|ssh u4 ukm; !ok; /FATAL: does not seem to be a valid pubkey/\n    cat $pd/u5.pub | ssh u4 ukm; ok;\n        /session key not accepted/\n        /pending keyid deleted: \\@second/\n\";\n\n# True addition of a new selfkey is done via piping it to a second ssh\n# call that uses the new key to call ukm. Note that the first ssh must\n# have completed its job before the second ssh is able to successfully\n# log in. This can be done via sleep or via redirecting to a file and\n# then reading from it.\ntry \"\n    # ADDOK u4 u1 \\@second | (sleep 2; ssh u4 ukm); ok\n    ADD u4 u1 \\@second > session; ok\n    cat session | ssh u4 ukm; ok;  /pending keyid added: \\@second/\n\";\n\n# u1 cannot add his/her initial key, since that key can never be\n# confirmed via ukm, so it is forbidden altogether. In fact, u1 is not\n# allowed to add any key twice.\ntry \"\n    ADDNOK u1 u1 \\@first\n       /FATAL: You cannot add a key that already belongs to you./\n    ADDNOK u4 u1 \\@first\n       /FATAL: You cannot add a key that already belongs to you./\n\";\n\n# u1 also can add more keys, but not under an existing keyid. That can\n# be done by any of his/her identities (here we choose u4).\ntry \"\n    ADDNOK u5 u1 \\@second; /FATAL: keyid already in use: \\@second/\n    ADD u5 u4 \\@third > session; ok\n    cat session | ssh u5 ukm; ok;  /pending keyid added: \\@third/\n\";\n\n# u2 cannot add the same key, but is allowed to use the same name (@third).\ntry \"\n    ADDNOK u5 u2 \\@third; /FATAL: cannot add key/\n        /Same key is already available under another userid./\n    ADD u6 u2 \\@third > session; ok\n    cat session | ssh u6 ukm; ok;  /pending keyid added: \\@third/\n\";\n\n# u6 can schedule his/her own key for deletion, but cannot actually\n# remove it. Trying to do so results in bringing back the key. Actual\n# deletion must be confirmed by another key.\ntry \"\n    ssh u6 ukm del \\@third; /prepare deletion of key \\@third/\n    ssh u2 ukm; ok; /u2     \\@third .pending del./\n    ssh u6 ukm; ok; /undo pending deletion of keyid \\@third/\n    ssh u6 ukm del \\@third; /prepare deletion of key \\@third/\n    ssh u2 ukm del \\@third; ok;  /pending keyid deleted: \\@third/\n\";\n\n# While in pending-deletion state, it's forbidden to add another key\n# with the same keyid. It's also forbidden to add a key with the same\n# fingerprint as the to-be-deleted key).\n# A new key under another keyid, is OK.\ntry \"\n    ssh u1 ukm del \\@third; /prepare deletion of key \\@third/\n    ADDNOK u4 u1 \\@third; /FATAL: keyid already in use: \\@third/\n    ADDNOK u5 u1 \\@fourth;\n        /FATAL: You cannot add a key that already belongs to you./\n    ADD u6 u1 \\@fourth > session; ok\n    ssh u1 ukm; ok;\n        /u1     \\@second/\n        /u1     \\@fourth .pending add./\n        /u1     \\@third .pending del./\n\";\n# We can remove a pending-for-addition key (@fourth) by logging in\n# with a non-pending key. Trying to do anything with key u5 (@third)\n# will just bring it back to its normal state, but not change the\n# state of any other key. As already shown above, using u6 (@fourth)\n# without a proper session key, would remove it from the system.\n# Here we want to demonstrate that key u1 can delete u6 immediately.\ntry \"ssh u1 ukm del \\@fourth; /pending keyid deleted: \\@fourth/\";\n\n# The pending-for-deletion key @third can also be removed via the u4\n# (@second) key.\ntry \"ssh u4 ukm del \\@third; ok; /pending keyid deleted: \\@third/\";\n\n# Non-existing selfkeys cannot be deleted.\ntry \"ssh u4 ukm del \\@x; !ok; /FATAL: You are not managing the key \\@x./\";\n"
  },
  {
    "path": "contrib/triggers/IP-check",
    "content": "#!/bin/bash\n\n# Check an IP before allowing access.\n\n# This is also a generic example of how to add arbitrary checks at the PRE_GIT\n# stage, in order to control fetch/clone as well, not just push operations\n# (VREFs, in contrast, only work for pushes).\n\n# Notice how repo-specific information is being passed to this code (bullet 3\n# below).  For more on that, see:\n# https://gitolite.com/gitolite/dev-notes#appendix-1-repo-specific-environment-variables\n\n# Instructions:\n\n#   1.  put this in an appropriate triggers directory (read about non-core\n#       code at http://gitolite.com/gitolite/non-core for more on this; the\n#       cookbook may also help here).\n\n#   2.  add a line:\n#           PRE_GIT => [ 'IP-check' ],\n#       just before the \"ENABLE\" line in the rc file\n\n#   3.  add a line like this to the \"repo ...\" section in gitolite.conf:\n#           option ENV.IP_allowed   =   1.2.3.0/24\n#       take care that this expression is valid, in the sense that passing it\n#       to 'ipcalc -n' will return the part before the \"/\".  I.e., in this\n#       example, 'ipcalc -n 1.2.3.0/24' should (and does) return 1.2.3.0.\n\n# ----\n\n[ -n \"$GL_OPTION_IP_allowed\" ] || exit 0\n\nexpected=${GL_OPTION_IP_allowed%/*}\n    mask=${GL_OPTION_IP_allowed#*/}\n\ncurrent_ip=${SSH_CONNECTION%% *}\n\neval `ipcalc -n $current_ip/$mask`\n\n[ \"$expected\" == \"$NETWORK\" ] && exit 0\n\necho >&2 \"IP $current_ip does not match allowed block $GL_OPTION_IP_allowed\"\nexit 1\n"
  },
  {
    "path": "contrib/triggers/file_mirror",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# Use an external (non-gitolite) mirror to backup gitolite repos.  They will\n# be automatically kept uptodate as people push to your gitolite server.  If\n# your server should die and you create a new one, you can quickly and easily\n# get everything back from the external mirror with a few simple commands.\n\n#       -------------------------------------------------------------\n#       SEE WARNINGS/CAVEATS AND INSTRUCTIONS AT THE END OF THIS FILE\n#       -------------------------------------------------------------\n\n# ----------------------------------------------------------------------\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Easy;\n\nmy ( $trigger, $repo, $dummy, $op ) = @ARGV;\nexit 0 unless $trigger eq 'POST_GIT' or $trigger eq 'POST_CREATE';\nexit 0 if     $trigger eq 'POST_GIT' and $op ne 'W';\n\nchdir(\"$rc{GL_REPO_BASE}/$repo.git\") or _die \"chdir failed: $!\\n\";\n\nmy %config = config( $repo, \"gitolite-options\\\\.mirror\\\\.extcopy\" );\nfor my $copy ( values %config ) {\n    _do($copy);\n\n    # processing one copy is sufficient for restoring!\n    last if $trigger eq 'POST_CREATE';\n}\n\n# in shell, that would be something like:\n#   gitolite git-config -r $repo gitolite-options\\\\.mirror\\\\.extcopy | cut -f3 | while read copy\n#   do\n#       ...\n\n# ----------------------------------------------------------------------\n\nsub _do {\n    my $url = shift;\n\n    if ( $trigger eq 'POST_CREATE' ) {\n        # brand new repo just created; needs to be populated from mirror\n\n        # For your urls you will need a way to somehow query the server and\n        # ask if the repo is present; it's upto you how you do it.\n        my $path = $url;\n        $path =~ s(^file://)();\n        return unless -d $path;\n\n        # now fetch.  Maybe we can put a \"-q\" in there?\n        system( \"git\", \"fetch\", $url, \"+refs/*:refs/*\" );\n\n    } elsif ( $trigger eq 'POST_GIT' ) {\n        # someone just pushed; we need to update our mirrors\n\n        # need to create the repo on the mirror.  Again, it's upto you how you\n        # make sure there's a repo on the mirror that can receive the push.\n        make_repo($url);    # in case it doesn't already exist\n\n        # now push\n        system( \"git\", \"push\", \"--mirror\", $url );\n    }\n}\n\nsub make_repo {\n    my $url = shift;\n    # in this example, the URL is 'file:///...'; for other urls, presumably\n    # the url tells you enough about how to *create* a repo.\n\n    my $path = $url;\n    $path =~ s(^file://)();\n    return if -d $path;\n    system( \"git\", \"init\", \"--bare\", $path );\n}\n\n__END__\n\nWARNINGS\n--------\n\n1.  THIS IS SAMPLE CODE.  You will AT LEAST have to customise the _do() and\n    make_repo() functions above based on what your remote URLs are.  For\n    example, I don't even know how to create a repo from the command line if\n    your external store is, say, github!\n\n2.  THIS DOES NOT WORK FOR WILD REPOs.  It can be made to work, with a few\n    extra steps to backup and restore the \"gl-perms\" and \"gl-creator\" files.\n\n    \"Left as an exercise for the reader!\"\n\nDESIGN NOTES\n------------\n\nThis is really just a combination of \"upstream\" (see src/triggers/upstream)\nand mirroring (gitolite mirroring does allow a copy to be non-gitolite, as\nlong as the ssh stuff is done the same way).\n\nThe main difference is that gitolite mirroring expects peers to all talk ssh,\nwhereas this method lets you use other protocols.  Specifically, since this\nwhole thing was started off by someone wanting to put his repos on s3\n(apparently jgit can talk to s3 directly), you can modify the two functions to\ndeal with whatever remote server you have.\n\nLANGUAGE\n--------\n\nThis doesn't have to be in perl.  Shell equivalent for the only gitolite\nspecific code is supplied; the rest of the code is fairly straightforward.\n\nSETUP\n-----\n\n1.  Put this code into your LOCAL_CODE directory under \"triggers\"; see\n    non-core.html for details.\n\n2.  Add these lines to your rc file, just before the ENABLE line.  (I'm\n    assuming a v3.4 or later installation here).\n\n        POST_CREATE => [ 'file_mirror' ],\n        POST_GIT => [ 'file_mirror' ],\n\n3.  Backup your rc file, since you may have other changes in it that you'll\n    want to preserve.\n\n4.  Do something like this in your gitolite.conf file:\n\n        repo @all\n            option mirror.extcopy-1    =   file:///tmp/he1/%GL_REPO.git\n            option mirror.extcopy-2    =   file:///tmp/he2/%GL_REPO.git\n\n    As you can see, since this is just for demo/test, we're using a couple of\n    temp directories to serve as our \"remotes\" using the file:// protocol.\n\n5.  Do a one-time manual sync of all the repos (subsequent syncs happen on\n    each push):\n\n        gitolite list-phy-repos | xargs -I xx gitolite trigger POST_GIT xx admin W\n\n    (This is a little trick we're playing on the trigger stuff, but it should\n    work fine.  Just make sure that, if you have other things in your POST_GIT\n    trigger list, they're not affected in some way.  'gitolite query-rc\n    POST_GIT' will tell you what else you have.)\n\nThat takes care of the \"setup\" and \"regular backup\".\n\nRESTORE\n-------\n\n1.  Install gitolite normally.  You'll get the usual two repos.\n\n2.  Restore the previously backed up rc file to replace the default one that\n    gitolite created.  At the very least, the rc file should have the\n    POST_CREATE and POST_GIT entries.\n\n        ---------------------------------------------------------\n        IF YOU FORGET THIS STEP, NASTY THINGS WILL HAPPEN TO YOU!\n        ---------------------------------------------------------\n\n3.  Clone the admin repo from one of your backup servers to some temp dir.  In\n    our example,\n\n        git clone /tmp/he1/gitolite-admin.git old-ga\n\n4.  'cd' to that clone and force push to your *new* admin repo:\n\n        cd old-ga\n        git push -f admin:gitolite-admin\n\nThat's it.  As each repo gets created by the admin push, they'll get populated\nby the backed up stuff due to the POST_CREATE trigger.\n"
  },
  {
    "path": "contrib/utils/ad_groups.sh",
    "content": "#!/bin/bash\n\n# author derived from: damien.nozay@gmail.com\n# author: Jonathan Gray\n\n# Given a username,\n# Provides a space-separated list of groups that the user is a member of.\n#\n# see http://gitolite.com/gitolite/conf.html#getting-user-group-info-from-ldap\n# GROUPLIST_PGM => /path/to/ldap_groups.sh\n\n# Be sure to add your domain CA to the trusted certificates in /etc/openldap/ldap.conf using the TLS_CACERT option or you'll get certificate validation errors\n\nldaphost='ldap://AD.DC1.local:3268,ldap://AD.DC2.local:3268,ldap://AD.DC3.local:3268'\nldapuser='git@domain.local'\nldappass='super.secret.password'\nbinddn='dc=domain,dc=local'\nusername=$1;\n\n# I don't assume your users share a common OU, so I search the entire domain\nldap_groups() {\n        # Go fetch the full user CN as it could be anywhere inside the DN\n        usercn=$(\n                ldapsearch -ZZ -H ${ldaphost} -D ${ldapuser} -w ${ldappass} -b ${binddn} -LLL -o ldif-wrap=no \"(sAMAccountName=${username})\" \\\n                | grep \"^dn:\" \\\n                | perl -pe 's|dn: (.*?)|\\1|'\n        )\n\n        # Using a proprietary AD extension, let the AD Controller resolve all nested group memberships\n        # http://ddkonline.blogspot.com/2010/05/how-to-recursively-get-group-membership.html\n        # Also, substitute spaces in AD group names for '_' since gitolite expects a space separated list\n        echo $(\n                ldapsearch -ZZ -H ${ldaphost} -D ${ldapuser} -w ${ldappass} -b ${binddn} -LLL -o ldif-wrap=no \"(member:1.2.840.113556.1.4.1941:=${usercn})\" \\\n                | grep \"^dn:\" \\\n                | perl -pe 's|dn: CN=(.*?),.*|\\1|' \\\n                | sed 's/ /_/g'\n        )\n}\n\nldap_groups $@\n"
  },
  {
    "path": "contrib/utils/gitolite-local",
    "content": "#!/bin/bash\n\n# ----------------------------------------------------------------------\n# change these lines to suit\ntestconf=$HOME/GITOLITE-TESTCONF\ngitolite_url=https://github.com/sitaramc/gitolite\n    # change it to something local for frequent use\n    # gitolite_url=file:///tmp/gitolite.git\n\n# ----------------------------------------------------------------------\n# Usage: gitolite-local <options>\n#\n# Test your gitolite.conf rule lists on your LOCAL machine (without even\n# pushing to the server!)\n#\n# (one-time)\n#\n#   1.  put this code somewhere in your $PATH if you wish\n#   2.  edit the line near the top of the script if you want to use some other\n#       directory than the default, for \"testconf\".\n#   2.  prepare the \"testconf\" directory by running:\n#           gitolite-local prep\n#\n# (lather, rinse, repeat)\n#\n#   1.  edit the conf (see notes below for more)\n#           gitolite-local edit\n#   2.  compile the conf\n#           gitolite-local compile\n#   3.  check permissions using \"info\" command:\n#           gitolite-local info USERNAME\n#   4.  check permissions using \"access\" command:\n#           gitolite-local access <options for gitolite access command>\n#   5.  clone, fetch, and push if you like!\n#           gitolite-local clone <username> <reponame> <other options for clone>\n#           gitolite-local fetch <username> <options for fetch>\n#           gitolite-local push  <username> <options for push>\n#\n# note on editing the conf: you don't have to use the edit command; you can\n# also directly edit '.gitolite/conf/gitolite.conf' in the 'testconf'\n# directory.  You'll need to do that if your gitolite conf consists of more\n# than just one file (like if you have includes, etc.)\n#\n# note on the clone command: most of the options won't work for clone, unless\n# git is ok with them being placed *after* the repo name.\n\n# ----------------------------------------------------------------------\ndie() { echo \"$@\" >&2; exit 1; }\nusage() { perl -lne 'print substr($_, 2) if /^# Usage/../^$/' < $0; exit 1; }\n[ -z \"$1\" ] && usage\n\n# ----------------------------------------------------------------------\nif [ $1 == prep ]\nthen\n    set -e\n\n    [ -d $testconf ] && die \"directory '$testconf' already exists\"\n\n    mkdir $testconf\n    cd $testconf\n\n    export HOME=$PWD\n\n    echo getting gitolite source...\n    git clone $gitolite_url gitolite\n    echo\n\n    echo installing gitolite...\n    gitolite/install >/dev/null\n    echo\n\n    echo setting up gitolite...\n    export PATH=$PWD/gitolite/src:$PATH\n    gitolite setup -a admin\n    echo\n\n    exit 0\nfi\n\nod=$PWD\ncd $testconf\nexport HOME=$PWD\nexport PATH=$PWD/gitolite/src:$PATH\n\nif [ $1 = edit ]\nthen\n    editor=${EDITOR:-vim}\n    $editor .gitolite/conf/gitolite.conf\nelif [ $1 = compile ]\nthen\n    gitolite compile\nelif [ $1 = compile+ ]\nthen\n    gitolite compile\\; gitolite trigger POST_COMPILE\nelif [ $1 = info ]\nthen\n    shift\n    user=$1\n    shift\n\n    GL_USER=$user gitolite info \"$@\"\nelif [ $1 = access ]\nthen\n    shift\n\n    gitolite access \"$@\"\nelif [ $1 = clone ]\nthen\n    shift\n    export G3T_USER=$1\n    shift\n\n    cd $od\n    export GL_BINDIR=$HOME/gitolite/t\n        # or you could do it the long way, using 'gitolite query-rc GL_BINDIR'\n    repo=$1; shift\n    git clone --upload-pack=$GL_BINDIR/gitolite-upload-pack file:///$repo \"$@\"\nelif [ $1 = fetch ]\nthen\n    shift\n    export G3T_USER=$1\n    shift\n\n    cd $od\n    export GL_BINDIR=$HOME/gitolite/t\n    git fetch --upload-pack=$GL_BINDIR/gitolite-upload-pack \"$@\"\nelif [ $1 = push ]\nthen\n    shift\n    export G3T_USER=$1\n    shift\n\n    cd $od\n    export GL_BINDIR=$HOME/gitolite/t\n    git push --receive-pack=$GL_BINDIR/gitolite-receive-pack \"$@\"\nfi\n"
  },
  {
    "path": "contrib/utils/ipa_groups.pl",
    "content": "#!/usr/bin/env perl\n#\n# ipa_groups.pl\n#\n# See perldoc for usage\n#\nuse Net::LDAP;\nuse Net::LDAP::Control::Paged;\nuse Net::LDAP::Constant qw(LDAP_CONTROL_PAGED);\nuse strict;\nuse warnings;\n\nmy $usage = <<EOD;\nUsage: $0 \\$uid\nThis script returns a list of groups that \\$uid is a member of\nEOD\n\nmy $uid = shift or die $usage;\n\n## CONFIG SECTION\n\n# If you want to do plain-text LDAP, then set ldap_opts to an empty hash and\n# then set protocols of ldap_hosts to ldap://\nmy @ldap_hosts = [\n  'ldaps://auth-ldap-001.prod.example.net',\n  'ldaps://auth-ldap-002.prod.example.net',\n];\nmy %ldap_opts = (\n    verify => 'require',\n    cafile => '/etc/pki/tls/certs/prod.example.net_CA.crt'\n);\n\n# Base DN to search\nmy $base_dn = 'dc=prod,dc=example,dc=net';\n\n# User for binding to LDAP server with\nmy $user = 'uid=svc_gitolite_bind,cn=sysaccounts,cn=etc,dc=prod,dc=example,dc=net';\nmy $pass = 'reallysecurepasswordstringhere';\n\n## Below variables should not need to be changed under normal circumstances\n\n# OU where groups are located. Anything return that is not within this OU is\n# removed from results. This OU is static on FreeIPA so will only need updating\n# if you want to support other LDAP servers. This is a regex so can be set to\n# anything you want (E.G '.*').\nmy $groups_ou = qr/cn=groups,cn=accounts,${base_dn}$/;\n\n# strip path - if you want to return the full path of the group object then set\n# this to 0\nmy $strip_group_paths = 1;\n\n# Number of seconds before timeout (for each query)\nmy $timeout=5;\n\n# user object class\nmy $user_oclass = 'person';\n\n# group attribute\nmy $group_attrib = 'memberOf';\n\n## END OF CONFIG SECTION\n\n# Catch timeouts here\n$SIG{'ALRM'} = sub {\n  die \"LDAP queries timed out\";\n};\n\nalarm($timeout);\n\n# try each server until timeout is reached, has very fast failover if a server\n# is totally unreachable\nmy $ldap = Net::LDAP->new(@ldap_hosts, %ldap_opts) ||\n  die \"Error connecting to specified servers: $@ \\n\";\n\nmy $mesg = $ldap->bind(\n    dn       => $user,\n    password => $pass\n);\n\nif ($mesg->code()) {\n  die (\"error:\",      $mesg->code(),\"\\n\",\n       \"error name: \",$mesg->error_name(),\"\\n\",\n       \"error text: \",$mesg->error_text(),\"\\n\");\n}\n\n# How many LDAP query results to grab for each paged round\n# Set to under 1000 to limit load on LDAP server\nmy $page = Net::LDAP::Control::Paged->new(size => 500);\n\n# @queries is an array or array references. We initially fill it up with one\n# arrayref (The first LDAP search) and then add more during the execution.\n# First start by resolving the group.\nmy @queries = [ ( base    => $base_dn,\n                  filter  => \"(&(objectClass=${user_oclass})(uid=${uid}))\",\n                  control => [ $page ],\n) ];\n\n# array to store groups matching $groups_ou\nmy @verified_groups;\n\n# Loop until @queries is empty...\nforeach my $queryref (@queries) {\n\n  # set cookie for paged querying\n  my $cookie;\n  alarm($timeout);\n  while (1) {\n    # Perform search\n    my $mesg = $ldap->search( @{$queryref} );\n\n    foreach my $entry ($mesg->entries) {\n      my @groups = $entry->get_value($group_attrib);\n      # find any groups matching $groups_ou  regex and push onto $verified_groups array\n      foreach my $group (@groups) {\n        if ($group =~ /$groups_ou/) {\n          push @verified_groups, $group;\n        }\n      }\n    }\n\n    # Only continue on LDAP_SUCCESS\n    $mesg->code and last;\n\n    # Get cookie from paged control\n    my($resp)  = $mesg->control(LDAP_CONTROL_PAGED) or last;\n    $cookie    = $resp->cookie or last;\n\n    # Set cookie in paged control\n    $page->cookie($cookie);\n  } # END: while(1)\n\n  # Reset the page control for the next query\n  $page->cookie(undef);\n\n  if ($cookie) {\n    # We had an abnormal exit, so let the server know we do not want any more\n    $page->cookie($cookie);\n    $page->size(0);\n    $ldap->search( @{$queryref} );\n    # Then die\n    die(\"LDAP query unsuccessful\");\n  }\n\n} # END: foreach my $queryref (...)\n\n# we're assuming that the group object looks something like\n# cn=name,cn=groups,cn=accounts,dc=X,dc=Y and there are no ',' chars in group\n# names\nif ($strip_group_paths) {\n  for (@verified_groups) { s/^cn=([^,]+),.*$/$1/g };\n}\n\nforeach my $verified (@verified_groups) {\n  print $verified . \"\\n\";\n}\n\nalarm(0);\n\n__END__\n\n=head1 NAME\n\nipa_groups.pl\n\n=head2 VERSION\n\n0.1.1\n\n=head2 DESCRIPTION\n\nConnects to one or more FreeIPA-based LDAP servers in a first-reachable fashion and returns a newline separated list of groups for a given uid. Uses memberOf attribute and thus supports nested groups.\n\n=head2 AUTHOR\n\nRichard Clark <rclark@telnic.org>\n\n=head2 FreeIPA vs Generic LDAP\n\nThis script uses regular LDAP, but is focussed on support for FreeIPA, where users and groups are generally contained within single OUs, and memberOf attributes within the user object are enumerated with a recursive list of groups that the user is a member of.\n\nIt is mostly impossible to provide generic out of the box LDAP support due to varying schemas, supported extensions and overlays between implementations.\n\n=head2 CONFIGURATION\n\n=head3  LDAP Bind Account \n\nTo setup an LDAP bind user in FreeIPA, create a svc_gitolite_bind.ldif file along the following lines:\n\n    dn: uid=svc_gitolite_bind,cn=sysaccounts,cn=etc,dc=prod,dc=example,dc=net\n    changetype: add\n    objectclass: account\n    objectclass: simplesecurityobject\n    uid: svc_gitolite_bind\n    userPassword: reallysecurepasswordstringhere\n    passwordExpirationTime: 20150201010101Z\n    nsIdleTimeout: 0\n\nThen create the service account user, using ldapmodify authenticating as the the directory manager account (or other acccount with appropriate privileges to the sysaccounts OU):\n\n    $ ldapmodify -h auth-ldap-001.prod.example.net -Z -x -D \"cn=Directory Manager\" -W -f svc_gitolite_bind.ldif\n\n=head3 Required Configuration\n\nThe following variables within the C<## CONFIG SECTION ##> need to be configured before the script will work.\n\nC<@ldap_hosts> - Should be set to an array of URIs or hosts to connect to. Net::LDAP will attempt to connect to each host in this list and stop on the first reachable server. The example shows TLS-supported URIs, if you want to use plain-text LDAP then set the protocol part of the URI to LDAP:// or just provide hostnames as this is the default behavior for Net::LDAP.\n\nC<%ldap_opts> - To use LDAP-over-TLS, provide the CA certificate for your LDAP servers. To use plain-text LDAP, then empty this hash of it's values or provide other valid arguments to Net::LDAP.\n\nC<%base_dn> - This can either be set to the 'true' base DN for your directory, or alternatively you can set it the the OU that your users are located in (E.G cn=users,cn=accounts,dc=prod,dc=example,dc=net).\n\nC<$user> - Provide the full Distinguished Name of your directory bind account as configured above.\n\nC<$pass> - Set to password of your directory bind account as configured above.\n\n=head3 Optional Configuration\n\nC<$groups_ou> - By default this is a regular expression matching the default groups OU. Any groups not matching this regular expression are removed from the search results. This is because FreeIPA enumerates non-user type groups (E.G system, sudoers, policy and other types) within the memberOf attribute. To change this behavior, set C<$groups_ou> to a regex matching anything you want (E.G: '.*').\n\nC<$strip_group_paths> - If this is set to perl boolean false (E.G '0') then groups will be returned in DN format. Default is true, so just the short/CN value is returned.\n\nC<$timeout> - Number of seconds to wait for an LDAP query before determining that it has failed and trying the next server in the list. This does not affect unreachable servers, which are failed immediately.\n\nC<$user_oclass> - Object class of the user to search for.\n\nC<$group_attrib> - Attribute to search for within the user object that denotes the membership of a group.\n\n=cut\n\n"
  },
  {
    "path": "contrib/utils/ldap_groups.sh",
    "content": "#!/bin/bash\n\n# author: damien.nozay@gmail.com\n\n# Given a username,\n# Provides a space-separated list of groups that the user is a member of.\n#\n# see http://gitolite.com/gitolite/conf.html#getting-user-group-info-from-ldap\n# GROUPLIST_PGM => /path/to/ldap_groups.sh\n\nldap_groups() {\n    username=$1;\n    # this relies on openldap / pam_ldap to be configured properly on your\n    # system. my system allows anonymous search.\n    echo $(\n        ldapsearch -x -LLL \"(&(objectClass=posixGroup)(memberUid=${username}))\" cn \\\n        | grep \"^cn\" \\\n        | cut -d' ' -f2\n    );\n}\n\nldap_groups $@\n"
  },
  {
    "path": "contrib/utils/rc-format-v3.4",
    "content": "#!/usr/bin/perl\n\n# help with rc file format change at v3.4 -- help upgrade v3 rc files from\n# v3.3 and below to the new v3.4 and above format\n\n# once you upgrade gitolite past 3.4, you may want to use the new rc file\n# format, because it's really much nicer (just to recap: the old format will\n# still work, in fact internally the new format gets converted to the old\n# format before actually being used.  However, the new format makes it much\n# easier to enable and disable features).\n\n# PLEASE SEE WARNINGS BELOW\n\n# this program helps you upgrade your rc file.\n\n# STEPS\n#   cd gitolite-source-repo-clone\n#   contrib/utils/upgrade-rc33 /path/to/old.gitolite.rc > new.gitolite.rc\n\n# WARNINGS\n#   make sure you also READ ALL ERROR/WARNING MESSAGES GENERATED\n#   make sure you EXAMINE THE FILE AND CHECK THAT EVERYTHING LOOKS GOOD before using it\n#   be especially careful about\n#       variables which contains single/double quotes or other special characters\n#       variables that stretch across multiple lines\n#       features which take arguments (like 'renice')\n#       new features you've enabled which don't exist in the default rc\n\n# ----------------------------------------------------------------------\n\nuse strict;\nuse warnings;\nuse 5.10.0;\nuse Cwd;\nuse Data::Dumper;\n$Data::Dumper::Terse    = 1;\n$Data::Dumper::Indent   = 1;\n$Data::Dumper::Sortkeys = 1;\n\nBEGIN {\n    $ENV{HOME} = getcwd;\n    $ENV{HOME} .= \"/.home.rcupgrade.$$\";\n    mkdir $ENV{HOME} or die \"mkdir '$ENV{HOME}': $!\\n\";\n}\n\nEND {\n    system(\"rm -rf ./.home.rcupgrade.$$\");\n}\n\nuse lib \"./src/lib\";\nuse Gitolite::Rc;\n{\n    no warnings 'redefine';\n    sub Gitolite::Common::gl_log { }\n}\n\n# ----------------------------------------------------------------------\n\n# everything happens inside a fresh v3.6.1+ gitolite clone; no other\n# directories are used.\n\n# the old rc file to be migrated is somewhere *else* and is supplied as a\n# command line argument.\n\n# ----------------------------------------------------------------------\n\nmy $oldrc = shift or die \"need old rc filename as arg-1\\n\";\n\n{\n\n    package rcup;\n    do $oldrc;\n}\n\nmy %oldrc;\n{\n    no warnings 'once';\n    %oldrc = %rcup::RC;\n}\n\ndelete $rcup::{RC};\n{\n    my @extra = sort keys %rcup::;\n    warn \"**** WARNING ****\\nyou have variables declared outside the %RC hash; you must handle them manually\\n\" if @extra;\n}\n\n# this is the new rc text being built up\nmy $newrc = glrc('default-text');\n\n# ----------------------------------------------------------------------\n\n# default disable all features in newrc\nmap { disable( $_, 'sq' ) } (qw(help desc info perms writable ssh-authkeys git-config daemon gitweb));\n# map { disable($_, '') } (qw(GIT_CONFIG_KEYS));\n\nset_s('HOSTNAME');\nset_s( 'UMASK',               'num' );\nset_s( 'GIT_CONFIG_KEYS',     'sq' );\nset_s( 'LOG_EXTRA',           'num' );\nset_s( 'DISPLAY_CPU_TIME',    'num' );\nset_s( 'CPU_TIME_WARN_LIMIT', 'num' );\nset_s('SITE_INFO');\n\nset_s('LOCAL_CODE');\n\nif ( $oldrc{WRITER_CAN_UPDATE_DESC} ) {\n    die \"tell Sitaram he changed the default rc too much\" unless $newrc =~ /rc variables used by various features$/m;\n    $newrc =~ s/(rc variables used by various features\\n)/$1\\n    # backward compat\\n        WRITER_CAN_UPDATE_DESC      =>  1,\\n/;\n\n    delete $oldrc{WRITER_CAN_UPDATE_DESC};\n}\n\nif ( $oldrc{ROLES} ) {\n    my $t = '';\n    for my $r ( sort keys %{ $oldrc{ROLES} } ) {\n        $t .= ( \" \" x 8 ) . $r . ( \" \" x ( 28 - length($r) ) ) . \"=>  1,\\n\";\n    }\n    $newrc =~ s/(ROLES *=> *\\{\\n).*?\\n( *\\},)/$1$t$2/s;\n\n    delete $oldrc{ROLES};\n}\n\nif ( $oldrc{DEFAULT_ROLE_PERMS} ) {\n    warn \"DEFAULT_ROLE_PERMS has been replaced by per repo option\\nsee http://gitolite.com/gitolite/wild.html\\n\";\n    delete $oldrc{DEFAULT_ROLE_PERMS};\n}\n\n# the following is a bit like the reverse of what the new Rc.pm does...\n\nfor my $l ( split /\\n/, $Gitolite::Rc::non_core ) {\n    next if $l =~ /^ *#/ or $l !~ /\\S/;\n\n    my ( $name, $where, $module ) = split ' ', $l;\n    $module = $name if $module eq '.';\n    ( $module = $name ) .= \"::\" . lc($where) if $module eq '::';\n\n    # if you find $module as an element of $where, enable $name\n    enable($name) if miw( $module, $where );\n}\n\n# now deal with commands\nif ( $oldrc{COMMANDS} ) {\n    for my $c ( sort keys %{ $oldrc{COMMANDS} } ) {\n        if ( $oldrc{COMMANDS}{$c} == 1 ) {\n            enable($c);\n            # we don't handle anything else right (and so far only git-annex\n            # is affected, as far as I remember)\n\n            delete $oldrc{COMMANDS}{$c};\n        }\n    }\n}\n\nprint $newrc;\n\nfor my $w (qw(INPUT POST_COMPILE PRE_CREATE ACCESS_1 POST_GIT PRE_GIT ACCESS_2 POST_CREATE SYNTACTIC_SUGAR)) {\n    delete $oldrc{$w} unless scalar( @{ $oldrc{$w} } );\n}\ndelete $oldrc{COMMANDS} unless scalar keys %{ $oldrc{COMMANDS} };\n\nexit 0 unless %oldrc;\n\nwarn \"the following parts of the old rc were NOT converted:\\n\";\nprint STDERR Dumper \\%oldrc;\n\n# ----------------------------------------------------------------------\n\n# set scalars that the new file defaults to \"commented out\"\nsub set_s {\n    my ( $key, $type ) = @_;\n    $type ||= '';\n    return unless exists $oldrc{$key};\n\n    # special treatment for UMASK\n    $oldrc{$key} = substr( \"00\" . sprintf( \"%o\", $oldrc{$key} ), -4 ) if ( $key eq 'UMASK' );\n\n    $newrc =~ s/# $key /$key   /;    # uncomment if needed\n    if ( $type eq 'num' ) {\n        $newrc =~ s/$key ( *=> *).*/$key $1$oldrc{$key},/;\n    } elsif ( $type eq 'sq' ) {\n        $newrc =~ s/$key ( *=> *).*/$key $1'$oldrc{$key}',/;\n    } else {\n        $newrc =~ s/$key ( *=> *).*/$key $1\"$oldrc{$key}\",/;\n    }\n\n    delete $oldrc{$key};\n}\n\nsub disable {\n    my ( $key, $type ) = @_;\n    if ( $type eq 'sq' ) {\n        $newrc =~ s/^( *)'$key'/$1# '$key'/m;\n    } else {\n        $newrc =~ s/^( *)$key\\b/$1# $key/m;\n    }\n}\n\nsub enable {\n    my $key = shift;\n    $newrc =~ s/^( *)# *'$key'/$1'$key'/m;\n    return if $newrc =~ /^ *'$key'/m;\n    $newrc =~ s/(add new commands here.*\\n)/$1            '$key',\\n/;\n}\n\nsub miw {\n    my ( $m, $w ) = @_;\n    return 0 unless $oldrc{$w};\n    my @in = @{ $oldrc{$w} };\n    my @out = grep { !/^$m$/ } @{ $oldrc{$w} };\n    $oldrc{$w} = \\@out;\n    return not scalar(@in) == scalar(@out);\n}\n"
  },
  {
    "path": "contrib/utils/testconf",
    "content": "#!/bin/bash\n\n# this is meant to be run on your *client* (where you edit and commit files\n# in a gitolite-admin *working* repo), not on the gitolite server.\n#\n# TO USE\n# ======\n\n# To use this, first upgrade gitolite to the latest on the server; you need at\n# least v3.6.7.\n#\n# Then, on the client:\n#\n#   1.  copy this file (contrib/utils/testconf in the latest gitolite) to\n#       somewhere in your $PATH\n#   2.  modify the following lines if you wish (default should be fine for\n#       most people):\n\n    # a semi-permanent area to play in (please delete it manually if you want to start afresh).\n    testconf=$HOME/GITOLITE-TESTCONF\n    # the gitolite source code\n    gitolite_url=https://github.com/sitaramc/gitolite\n\n#   3.  go to your gitolite-admin clone and make suitable changes; see example\n#       below.  No need to push to the server, yet.\n#   4.  run 'testconf`\n#\n# CAVEAT: include files are not handled the same way gitolite parsing handles\n# them -- we just cat all the conf files together, in sorted order.\n#\n# If the tests ran OK, push your changes to the server as usual.\n\n# EXAMPLE changes to gitolite.conf\n# ================================\n# Say you have these rules in the conf file:\n#\n#     repo foo\n#         R       =   u1\n#         RW      =   u2\n#         RW+     =   u3\n#\n# To create test code for this, add the following lines to the conf file.\n#\n#     =begin testconf\n#     # you can put arbitrary bash code here, but a simple example follows\n#\n#     ok() { \"$@\" && echo ok || echo \"not ok ($*)\"; }\n#     nok() { ! \"$@\" && echo ok || echo \"not ok ($*)\"; }\n#\n#     ok gitolite access -q foo u1 R\n#     nok gitolite access -q foo u1 W\n#\n#     ok gitolite access -q foo u2 W\n#     nok gitolite access -q foo u2 +\n#\n#     ok gitolite access -q foo u3 +\n#     =end\n#\n# Note that you can actually put in any bash code between the 'begin' and\n# 'end' lines; the above is just a useful sample/template.\n#\n# Because of the 'begin' and 'end' lines, gitolite will ignore those lines\n# when processing the conf file ON THE SERVER.\n#\n# (optional) TAP compliance\n# =========================\n# if you add a line 'echo 1..5' (in this case, since there are 5 ok/nok lines;\n# you will certainly have more) to the top the file, you can run\n#\n#   prove `which testconf`\n#\n# which will give you a much nicer output.  The only issue is if you have\n# include files, you will need to put that in the file whose name is sorted\n# first!\n#\n# Using a non-default \".gitolite.rc\"\n# ==================================\n#\n# If your conf needs a non-default `~/.gitolite.rc`, copy the file you need as\n# \"testconf.gitolite.rc\" in the root directory of the gitolite-admin clone\n# where you are running \"testconf\".  (Whether you commit this file to the\n# gitolite-admin repo, or keep it local/untracked, is your call).\n\n# ----------------------------------------------------------------------\nod=$PWD\n\n# prep\n\nmkdir -p $testconf\ncd $testconf\n\nexport HOME=$PWD\nexport PATH=$PWD/gitolite/src:$PATH\n\n[ -d gitolite ] || {\n\n    echo getting gitolite source...\n    git clone $gitolite_url gitolite\n    echo\n\n    echo installing gitolite...\n    gitolite/install >/dev/null\n    echo\n\n    echo setting up gitolite...\n    gitolite setup -a admin\n    echo\n\n}\n\n# copy conf from $od\n\nrm -rf           $testconf/.gitolite/conf\nmkdir -p         $testconf/.gitolite/conf\ncp -a $od/conf/* $testconf/.gitolite/conf/\n\n# copy rc from $od, if it exists\n[ -f $od/testconf.gitolite.rc ] && cp $od/testconf.gitolite.rc $testconf/.gitolite.rc\n\n# compile+\n\ngitolite compile\ngitolite trigger POST_COMPILE\n\n# snarf bits of code from conf files and run them\n\ncat `find $testconf/.gitolite/conf -type f -name \"*.conf\" | sort` |\n    perl -ne '\n        print if /^=begin testconf$/ .. /^=end$/ and not /^=(begin|end)/;\n    ' | /bin/bash\n"
  },
  {
    "path": "contrib/vim/indent/gitolite.vim",
    "content": "\" Vim indent file\n\" Language:\tgitolite configuration\n\" URL:\t\thttps://github.com/sitaramc/gitolite/blob/master/contrib/vim/indent/gitolite.vim\n\"\t(https://raw.githubusercontent.com/sitaramc/gitolite/master/contrib/vim/indent/gitolite.vim)\n\" Maintainer:\tSitaram Chamarty <sitaramc@gmail.com>\n\" (former Maintainer:\tTeemu Matilainen <teemu.matilainen@iki.fi>)\n\" Last Change:\t2017 Oct 05\n\nif exists(\"b:did_indent\")\n  finish\nendif\nlet b:did_indent = 1\n\nsetlocal autoindent\nsetlocal indentexpr=GetGitoliteIndent()\nsetlocal indentkeys=o,O,*<Return>,!^F,=repo,\\\",=\n\n\" Only define the function once.\nif exists(\"*GetGitoliteIndent\")\n  finish\nendif\n\nlet s:cpo_save = &cpo\nset cpo&vim\n\nfunction! GetGitoliteIndent()\n  let prevln = prevnonblank(v:lnum-1)\n  let pline = getline(prevln)\n  let cline = getline(v:lnum)\n\n  if cline =~ '^\\s*\\(C\\|R\\|RW\\|RW+\\|RWC\\|RW+C\\|RWD\\|RW+D\\|RWCD\\|RW+CD\\|-\\)[ \\t=]'\n    return shiftwidth()\n  elseif cline =~ '^\\s*config\\s'\n    return shiftwidth()\n  elseif cline =~ '^\\s*option\\s'\n    return shiftwidth()\n  elseif pline =~ '^\\s*repo\\s' && cline =~ '^\\s*\\(#.*\\)\\?$'\n    return shiftwidth()\n  elseif cline =~ '^\\s*#'\n    return indent(prevln)\n  elseif cline =~ '^\\s*$'\n    return -1\n  else\n    return 0\n  endif\nendfunction\n\nlet &cpo = s:cpo_save\nunlet s:cpo_save\n"
  },
  {
    "path": "contrib/vim/syntax/gitolite.vim",
    "content": "\" Vim syntax file\n\" Language:\tgitolite configuration\n\" URL:\t\thttps://github.com/sitaramc/gitolite/blob/master/contrib/vim/syntax/gitolite.vim\n\"\t(https://raw.githubusercontent.com/sitaramc/gitolite/master/contrib/vim/syntax/gitolite.vim)\n\" Maintainer:\tSitaram Chamarty <sitaramc@gmail.com>\n\" (former Maintainer:\tTeemu Matilainen <teemu.matilainen@iki.fi>)\n\" Last Change:\t2017 Oct 05\n\nif exists(\"b:current_syntax\")\n  finish\nendif\n\nlet s:cpo_save = &cpo\nset cpo&vim\n\n\" this seems to be the best way, for now.\nsyntax sync fromstart\n\n\" ---- common stuff\n\nsyn match   gitoliteGroup           '@\\S\\+'\n\nsyn match   gitoliteComment         '#.*' contains=gitoliteTodo\nsyn keyword gitoliteTodo            TODO FIXME XXX NOT contained\n\n\" ---- main section\n\n\" catch template-data syntax appearing outside template-data section\nsyn match   gitoliteRepoError       '^\\s*repo.*='\nsyn match   gitoliteRepoError       '^\\s*\\S\\+\\s*='  \" this gets overridden later when first word is a perm, don't worry\n\n\" normal gitolite group and repo lines\nsyn match   gitoliteGroupLine       '^\\s*@\\S\\+\\s*=\\s*\\S.*$' contains=gitoliteGroup,gitoliteComment\nsyn match   gitoliteRepoLine        '^\\s*repo\\s\\+[^=]*$' contains=gitoliteRepo,gitoliteGroup,gitoliteComment\nsyn keyword gitoliteRepo            repo contained\n\nsyn keyword gitoliteSpecialRepo     CREATOR\n\n\" normal gitolite rule lines\nsyn match   gitoliteRuleLine        '^\\s*\\(-\\|C\\|R\\|RW+\\?C\\?D\\?\\)\\s[^#]*' contains=gitoliteRule,gitoliteCreateRule,gitoliteDenyRule,gitoliteRefex,gitoliteUsers,gitoliteGroup\nsyn match   gitoliteRule            '\\(^\\s*\\)\\@<=\\(-\\|C\\|R\\|RW+\\?C\\?D\\?\\)\\s\\@=' contained\nsyn match   gitoliteRefex           '\\(^\\s*\\(-\\|R\\|RW+\\?C\\?D\\?\\)\\s\\+\\)\\@<=\\S.\\{-}\\(\\s*=\\)\\@=' contains=gitoliteSpecialRefex\nsyn match   gitoliteSpecialRefex    'NAME/'\nsyn match   gitoliteSpecialRefex    '/USER/'\nsyn match   gitoliteCreateRule      '\\(^\\s*C\\s.*=\\s*\\)\\@<=\\S[^#]*[^# ]' contained contains=gitoliteGroup\nsyn match   gitoliteDenyRule        '\\(^\\s*-\\s.*=\\s*\\)\\@<=\\S[^#]*[^# ]' contained\n\n\" normal gitolite config (and similar) lines\nsyn match   gitoliteConfigLine      '^\\s*\\(config\\|option\\|include\\|subconf\\)\\s[^#]*' contains=gitoliteConfigKW,gitoliteConfigKey,gitoliteConfigVal,gitoliteComment\nsyn keyword gitoliteConfigKW        config option include subconf contained\nsyn match   gitoliteConfigKey       '\\(\\(config\\|option\\)\\s\\+\\)\\@<=[^ =]*' contained\nsyn match   gitoliteConfigVal       '\\(=\\s*\\)\\@<=\\S.*' contained\n\n\" ---- template-data section\n\nsyn region  gitoliteTemplateLine    matchgroup=PreProc start='^=begin template-data$' end='^=end$' contains=gitoliteTplRepoLine,gitoliteTplRoleLine,gitoliteGroup,gitoliteComment,gitoliteTplError\n\nsyn match   gitoliteTplRepoLine     '^\\s*repo\\s\\+\\S.*=.*' contained contains=gitoliteTplRepo,gitoliteTplTemplates,gitoliteGroup\nsyn keyword gitoliteTplRepo         repo contained\nsyn match   gitoliteTplTemplates    '\\(=\\s*\\)\\@<=\\S.*' contained contains=gitoliteGroup,gitoliteComment\n\nsyn match   gitoliteTplRoleLine     '^\\s*\\S\\+\\s*=\\s*.*' contained contains=gitoliteTplRole,gitoliteGroup,gitoliteComment\nsyn match   gitoliteTplRole         '\\S\\+\\s*='he=e-1 contained\n\n\" catch normal gitolite rules appearing in template-data section\nsyn match   gitoliteTplError        '^\\s*repo[^=]*$' contained\nsyn match   gitoliteTplError        '^\\s*\\(-\\|R\\|RW+\\?C\\?D\\?\\)\\s'he=e-1 contained\nsyn match   gitoliteTplError        '^\\s*\\(config\\|option\\|include\\|subconf\\)\\s'he=e-1 contained\nsyn match   gitoliteTplError        '^\\s*@\\S\\+\\s*=' contained contains=NONE\n\nhi def link gitoliteGroup           Identifier\nhi def link gitoliteComment         Comment\nhi def link gitoliteTodo            ToDo\nhi def link gitoliteRepoError       Error\nhi def link gitoliteGroupLine       PreProc\nhi def link gitoliteRepo            Keyword\nhi def link gitoliteSpecialRepo     PreProc\nhi def link gitoliteRule            Keyword\nhi def link gitoliteCreateRule      PreProc\nhi def link gitoliteDenyRule        WarningMsg\nhi def link gitoliteRefex           Constant\nhi def link gitoliteSpecialRefex    PreProc\nhi def link gitoliteConfigKW        Keyword\nhi def link gitoliteConfigKey       Identifier\nhi def link gitoliteConfigVal       String\nhi def link gitoliteTplRepo         Keyword\nhi def link gitoliteTplTemplates    Constant\nhi def link gitoliteTplRole         Constant\nhi def link gitoliteTplError        Error\n\nlet b:current_syntax = \"gitolite\"\n\nlet &cpo = s:cpo_save\nunlet s:cpo_save\n"
  },
  {
    "path": "convert-gitosis-conf",
    "content": "#!/usr/bin/perl -w\n#\n# migrate gitosis.conf to gitolite.conf format\n#\n# Based on gl-conf-convert by: Sitaram Chamarty\n# Rewritten by: Behan Webster <behanw@websterwood.com>\n#\n\nuse strict;\nuse warnings;\n\nif (not @ARGV and -t or @ARGV and $ARGV[0] eq '-h') {\n    print \"Usage:\\n    gl-conf-convert < gitosis.conf > gitolite.conf\\n(please see the documentation for details)\\n\";\n    exit 1;\n}\n\nmy @comments = ();\nmy $groupname;\nmy %groups;\nmy $reponame;\nmy %repos;\n\nwhile (<>)\n{\n    # not supported\n    if (/^repositories *=/ or /^map /) {\n        print STDERR \"not supported: $_\";\n        s/^/NOT SUPPORTED: /;\n        print;\n        next;\n    }\n\n    # normalise whitespace to help later regexes\n    chomp;\n    s/\\s+/ /g;\n    s/ ?= ?/ = /;\n    s/^ //;\n    s/ $//;\n\n    if (/^\\s*$/ and @comments > 1) {\n        @{$repos{$reponame}{comments}} = @comments if $reponame;\n        @{$groups{$groupname}{comments}} = @comments if $groupname;\n        @comments = ();\n    } elsif (/^\\s*#/) {\n        push @comments, $_;\n    } elsif (/^\\[repo\\s+(.*?)\\]$/) {\n        $groupname = '';\n        $reponame = $1;\n        $reponame =~ s/\\.git$//;\n    } elsif (/^\\[gitosis\\]$/) {\n        $groupname = '';\n        $reponame = '@all';\n    } elsif (/^gitweb\\s*=\\s*yes/i) {\n        push @{$repos{$reponame}{R}}, 'gitweb';\n    } elsif (/^daemon\\s*=\\s*yes/i) {\n        push @{$repos{$reponame}{R}}, 'daemon';\n    } elsif (/^description\\s*=\\s*(.+?)$/) {\n        $repos{$reponame}{desc} = $1;\n    } elsif (/^owner\\s*=\\s*(.+?)$/) {\n        $repos{$reponame}{owner} = $1;\n    } elsif (/^\\[group\\s+(.*)\\]$/) {\n        $reponame = '';\n        $groupname = $1;\n    } elsif (/^members\\s*=\\s*(.*)/) {\n        push @{$groups{$groupname}{users}}, map {s/\\@([^.]+)$/_$1/g; $_} split(' ', $1);\n    } elsif (/^write?able\\s*=\\s*(.*)/) {\n        foreach my $repo (split(' ', $1)) {\n            $repo =~ s/\\.git$//;\n            push @{$repos{$repo}{RW}}, \"\\@$groupname\";\n        }\n    } elsif (/^readonly\\s*=\\s*(.*)/) {\n        foreach my $repo (split(' ', $1)) {\n            $repo =~ s/\\.git$//;\n            push @{$repos{$repo}{R}}, \"\\@$groupname\";\n        }\n    }\n}\n\n#use Data::Dumper;\n#print Dumper(\\%repos);\n#print Dumper(\\%groups);\n\n# Groups\nprint \"#\\n# Groups\\n#\\n\\n\";\nforeach my $grp (sort keys %groups) {\n    next unless @{$groups{$grp}{users}};\n    printf join(\"\\n\", @{$groups{$grp}{comments}}).\"\\n\" if $groups{$grp}{comments};\n    printf \"\\@%-19s = %s\\n\", $grp, join(' ', @{$groups{$grp}{users}});\n}\n\n# Gitweb\nprint \"\\n#\\n# Gitweb\\n#\\n\\n\";\nforeach my $repo (sort keys %repos) {\n    if ($repos{$repo}{desc}) {\n        @{$repos{$repo}{R}} = grep(!/^gitweb$/, @{$repos{$repo}{R}});\n        print $repo;\n        print \" \\\"$repos{$repo}{owner}\\\"\" if $repos{$repo}{owner};\n        print \" = \\\"$repos{$repo}{desc}\\\"\\n\";\n    }\n}\n\n# Repos\nprint \"\\n#\\n# Repos\\n#\\n\";\nforeach my $repo (sort keys %repos) {\n    print \"\\n\";\n    printf join(\"\\n\", @{$repos{$repo}{comments}}).\"\\n\" if $repos{$repo}{comments};\n    #if ($repos{$repo}{desc}) {\n    #    @{$repos{$repo}{R}} = grep(!/^gitweb$/, @{$repos{$repo}{R}});\n    #}\n    print \"repo\\t$repo\\n\";\n    foreach my $access (qw(RW+ RW R)) {\n        next unless $repos{$repo}{$access};\n        my @keys;\n        foreach my $key (@{$repos{$repo}{$access}}) {\n            if ($key =~ /^\\@(.*)/) {\n                next unless defined $groups{$1} and @{$groups{$1}{users}};\n            }\n            push @keys, $key;\n        }\n        printf \"\\t$access\\t= %s\\n\", join(' ', @keys) if @keys;\n    }\n    #if ($repos{$repo}{desc}) {\n    #    print $repo;\n    #    print \" \\\"$repos{$repo}{owner}\\\"\" if $repos{$repo}{owner};\n    #    print \" = \\\"$repos{$repo}{desc}\\\"\\n\";\n    #}\n}\n"
  },
  {
    "path": "install",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# Clearly you don't need a program to make one measly symlink, but the git\n# describe command involved in generating the VERSION string is a bit fiddly.\n\nuse Getopt::Long;\nuse FindBin;\nuse Config;\n\n# meant to be run from the root of the gitolite tree, one level above 'src'\nBEGIN { $ENV{GL_BINDIR} = $FindBin::RealBin . \"/src\"; }\nBEGIN { $ENV{GL_LIBDIR} = \"$ENV{GL_BINDIR}/lib\"; }\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Common;\n\n=for usage\nUsage (from gitolite clone directory):\n\n    ./install\n        to run gitolite using an absolute or relative path, for example\n        'src/gitolite' or '/full/path/to/this/dir/src/gitolite'\n\n    ./install -ln [<dir>]\n        to symlink just the gitolite executable to some <dir> that is in\n        $PATH.  <dir> defaults to $HOME/bin if <dir> not specified.  <dir> is\n        assumed to exist; gitolite will not create it.\n\n        Please provide a full path, not a relative path.\n\n    ./install -to <dir>\n        to copy the entire 'src' directory to <dir>.  If <dir> is not in\n        $PATH, use the full path to run gitolite commands.\n\n        Please provide a full path, not a relative path.\n\n    <perl-executable> ./install -to <dir>\n        to copy the entire 'src' directory to <dir>, but will replace\n        all of the shebangs with the path to <perl-executable>.  This\n        is a way to force gitolite to use some perl that is not\n        installed at /usr/bin/perl.\n\nSimplest use, if $HOME/bin exists and is in $PATH, is:\n\n    git clone https://github.com/sitaramc/gitolite\n    gitolite/install -ln\n\n    # now run setup\n    gitolite setup -pk /path/to/YourName.pub\n=cut\n\nmy ( $to, $ln, $help, $quiet );\n\nGetOptions(\n    'to=s' => \\$to,\n    'ln:s' => \\$ln,\n    'help|h'    => \\$help,\n    'quiet|q'    => \\$quiet,\n);\nusage() if $to and $ln or $help;\n$ln = \"$ENV{HOME}/bin\" if defined($ln) and not $ln;\nfor my $d ($ln, $to) {\n    next unless $d;    # ignore empty values\n    unless ( $d =~ m(^/) ) {\n        print STDERR \"FATAL: please use an absolute path, not a relative path\\n\";\n        usage();\n    }\n    if ( not -d $d ) {\n        print STDERR \"FATAL: '$d' does not exist.\\n\";\n        usage();\n    }\n}\n\nchdir($ENV{GL_BINDIR});\nmy $version = `git describe --tags --long --dirty=-dt 2>/dev/null`;\nunless ($version =~ /^v\\d/) {\n    print STDERR \"git describe failed; cannot deduce version number\\n\";\n    $version = \"(unknown)\";\n}\n\nif ($to) {\n    _mkdir($to);\n    system(\"cp -RpP * $to\");\n    _print( \"$to/VERSION\", $version );\n\n    # Replace shebangs if necessary.\n    my $thisperl = $Config{perlpath};\n    if ($thisperl ne '/usr/bin/perl') {\n        system(\"cd $to; grep -r -l /usr/bin/perl | xargs perl -pi -e 's(^#!/usr/bin/perl)(#!$thisperl)'\");\n    }\n} elsif ($ln) {\n    ln_sf( $ENV{GL_BINDIR}, \"gitolite\", $ln );\n    _print( \"VERSION\", $version );\n} else {\n    say \"use the following full path for gitolite:\";\n    say \"\\t$ENV{GL_BINDIR}/gitolite\";\n    _print( \"VERSION\", $version );\n}\n"
  },
  {
    "path": "src/VREF/COUNT",
    "content": "#!/bin/sh\n\n# gitolite VREF to count number of changed/new files in a push\n\n# see gitolite docs for what the first 7 arguments mean\n\n# inputs:\n#   arg-8 is a number\n#   arg-9 is optional, and can be \"NEWFILES\"\n# outputs (STDOUT)\n#   arg-7 if the number of changed (or new, if arg-9 supplied) files is > arg-8\n#   otherwise nothing\n# exit status:\n#   always 0\n\ndie() { echo \"$@\" >&2; exit 1; }\n[ -z \"$8\" ] && die \"not meant to be run manually\"\n\nnewsha=$3\noldtree=$4\nnewtree=$5\nrefex=$7\n\nmax=$8\n\nnf=\n[ \"$9\" = \"NEWFILES\" ] && nf='--diff-filter=A'\n# NO_SIGNOFF implies NEWFILES\n[ \"$9\" = \"NO_SIGNOFF\" ] && nf='--diff-filter=A'\n\n# count files against all the other commits in the system not just $oldsha\n# (why?  consider what is $oldtree when you create a new branch, or what is\n# $oldsha when you update an old feature branch from master and then push it\ncount=`git log --name-only $nf --format=%n $newtree --not --all | grep . | sort -u | perl -ne '}{print \"$.\"'`\n\n[ $count -gt $max ] && {\n    # count has been exceeded.  If $9 was NO_SIGNOFF there's still a chance\n    # for redemption -- if the top commit has a proper signed-off by line\n    [ \"$9\" = \"NO_SIGNOFF\" ] && {\n        author_email=$(git log --format=%ae -1 $newsha)\n        git cat-file -p $newsha |\n            egrep -i >/dev/null \"^ *$count +new +files +signed-off by: *$author_email *$\" && exit 0\n        echo $refex top commit message should include the text \\'$count new files signed-off by: $author_email\\'\n        exit 0\n    }\n    echo -n $refex \"(too many \"\n    [ -n \"$nf\" ] && echo -n \"new \" || echo -n \"changed \"\n    echo \"files in this push)\"\n}\n\nexit 0\n"
  },
  {
    "path": "src/VREF/EMAIL-CHECK",
    "content": "#!/usr/bin/perl\n\n# gitolite VREF to check if all *new* commits have author == pusher\n\n#                       THIS IS NOT READY TO USE AS IS\n#                       ------------------------------\n#           you MUST change the 'email_ok()' sub to suit *YOUR* site's\n#           gitolite username -> author email mapping!\n\n# See bottom of the program for important philosophical notes.\n\nuse strict;\nuse warnings;\n\n# mapping between gitolite userid and correct email address is encapsulated in\n# this subroutine; change as you like\nsub email_ok {\n    my ($author_email) = shift;\n    my $expected_email = \"$ENV{GL_USER}\\@atc.tcs.com\";\n    return $author_email eq $expected_email;\n}\n\nmy ( $ref, $old, $new ) = @ARGV;\nfor my $rev (`git log --format=\"%ae\\t%h\\t%s\" $new --not --all`) {\n    chomp($rev);\n    my ( $author_email, $hash, $subject ) = split /\\t/, $rev;\n\n    # again, we use the trick that a vref can just choose to die instead of\n    # passing back a vref, having it checked, etc., if it's more convenient\n    die \"$ENV{GL_USER}, you can't push $hash authored by $author_email\\n\" . \"\\t(subject of commit was $subject)\\n\"\n      unless email_ok($author_email);\n}\n\nexit 0;\n\n__END__\n\nThe following discussion is for people who want to enforce this check on ALL\ntheir developers (i.e., not just the newbies).\n\nDoing this breaks the \"D\" in \"DVCS\", forcing all your developers to work to a\ncentralised model as far as pushes are concerned.  It prevents amending\nsomeone else's commit and pushing (this includes rebasing, cherry-picking, and\nso on, which are all impossible now).  It also makes *any* off-line\ncollabaration between two developers useless, because neither of them can push\nthe result to the server.\n\nPHBs should note that validating the committer ID is NOT the same as reviewing\nthe code and running QA/tests on it.  If you're not reviewing/QA-ing the code,\nit's probably worthless anyway.  Conversely, if you *are* going to review the\ncode and run QA/tests anyway, then you don't really need to validate the\nauthor email!\n\nIn a DVCS, if you *pushed* a series of commits, you have -- in some sense --\nsigned off on them.  The most formal way to \"sign\" a series is to tack on and\npush a gpg-signed tag, although most people don't go that far.  Gitolite's log\nfiles are designed to preserve that accountability to *some* extent, though;\nsee contrib/adc/who-pushed for an admin defined command that quickly and\neasily tells you who *pushed* a particular commit.\n\nAnyway, the point is that the only purpose of this script is to\n\n  * pander to someone who still has not grokked *D*VCS\n          OR\n  * tick off an item in some stupid PHB's checklist\n\n"
  },
  {
    "path": "src/VREF/FILETYPE",
    "content": "#!/bin/sh\n\n# gitolite VREF to find autogenerated files\n\n# *completely* site specific; use it as an illustration of what can be done\n# with gitolite VREFs if you wish\n\n# see gitolite docs for what the first 7 arguments mean\n\n# inputs:\n#   arg-8 is currently only one possible value: AUTOGENERATED\n# outputs (STDOUT)\n#   arg-7 if any files changed in the push look like they were autogenerated\n#   otherwise nothing\n# exit status:\n#   always 0\n\ndie() { echo \"$@\" >&2; exit 1; }\n[ -z \"$8\" ] && die \"not meant to be run manually\"\n\nnewsha=$3\noldtree=$4\nnewtree=$5\nrefex=$7\n\noption=$8\n\n[ \"$option\" = \"AUTOGENERATED\" ] && {\n    # currently we only look for \".java\" programs with the string \"Generated\n    # by the protocol buffer compiler.  DO NOT EDIT\" in them.\n\n    git log --name-only $nf --format=%n $newtree --not --all |\n        grep . |\n        sort -u |\n        grep '\\.java$' |\n    while read fn\n    do\n        git show \"$newtree:$fn\" | egrep >/dev/null \\\n            'Generated by the protocol buffer compiler. +DO NOT EDIT' ||\n            continue\n\n        echo $refex\n        exit 0\n    done\n}\n"
  },
  {
    "path": "src/VREF/MAX_NEWBIN_SIZE",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# gitolite VREF to check max size of new binary files\n\n# see gitolite docs for what the first 7 arguments mean\n\n# inputs:\n#   arg-8 is a number\n# outputs (STDOUT)\n#   arg-7 if any new binary files exist that are greater in size than arg-8\n#   *and* there is no \"signed-off by\" line for such a file in the top commit\n#   message.\n#\n#   Otherwise nothing\n# exit status:\n#   always 0\n\ndie \"not meant to be run manually\" unless $ARGV[7];\n\nmy ( $newsha, $oldtree, $newtree, $refex, $max ) = @ARGV[ 2, 3, 4, 6, 7 ];\n\nexit 0 if $newsha eq '0000000000000000000000000000000000000000';\n\n# / (.*) +\\| Bin 0 -> (\\d+) bytes/\n\nchomp( my $author_email = `git log --format=%ae -1 $newsha` );\nmy $msg = `git cat-file -p $newsha`;\n$msg =~ s/\\t/ /g;    # makes our regexes simpler\n\nfor my $newbin (`git diff --stat=999,999 $oldtree $newtree | grep Bin.0.-`) {\n    next unless $newbin =~ /^ (.*) +\\| +Bin 0 -> (\\d+) bytes/;\n    my ( $f, $s ) = ( $1, $2 );\n    next if $s <= $max;\n\n    next if $msg =~ /^ *$f +signed-off by: *$author_email *$/mi;\n\n    print \"$refex $f is larger than $max\";\n}\n\nexit 0\n"
  },
  {
    "path": "src/VREF/MERGE-CHECK",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# gitolite VREF to check if there are any merge commits in the current push.\n\n# THIS IS DEMO CODE; please read all comments below as well as\n# doc/vref.mkd before trying to use this.\n\n# usage in conf/gitolite.conf goes like this:\n\n#       -   VREF/MERGE-CHECK/master     =   @all\n#       # reject only if the merge commit is being pushed to the master branch\n#       -   VREF/MERGE-CHECK            =   @all\n#       # reject merge commits to any branch\n\nmy $ref    = $ARGV[0];\nmy $oldsha = $ARGV[1];\nmy $newsha = $ARGV[2];\nmy $refex  = $ARGV[6];\n\n# The following code duplicates some code from parse_conf_line() and some from\n# check_ref().  This duplication is the only thing that is preventing me from\n# removing the \"M\" permission code from 'core' gitolite and using this\n# instead.  However, it does demonstrate how you would do this if you had to\n# create any other similar features, for example someone wanted \"no non-merge\n# first-parent\", which is far too specific for me to add to 'core'.\n\n# -- begin duplication --\nmy $branch_refex = $ARGV[7] || '';\nif ($branch_refex) {\n    $branch_refex =~ m(^refs/) or $branch_refex =~ s(^)(refs/heads/);\n} else {\n    $branch_refex = 'refs/.*';\n}\nexit 0 unless $ref =~ /^$branch_refex/;\n# -- end duplication --\n\n# we can't run this check for tag creation or new branch creation, because\n# 'git log' does not deal well with $oldsha = '0' x 40.\nif ( $oldsha eq \"0\" x 40 or $newsha eq \"0\" x 40 ) {\n    print STDERR \"ref create/delete ignored for purposes of merge-check\\n\";\n    exit 0;\n}\n\nmy $ret = `git rev-list -n 1 --merges $oldsha..$newsha`;\nprint \"$refex FATAL: merge commits not allowed\\n\" if $ret =~ /./;\n\nexit 0;\n"
  },
  {
    "path": "src/VREF/NAME_NC",
    "content": "#!/bin/sh\n\n# ----------------------------------------------------------------------\n# VREF/NAME_NC\n#   Like VREF/NAME, but only considers \"new commits\" -- i.e., commits that\n#   don't already exist in the repo as part of some other ref.\n\n# ----------------------------------------------------------------------\n# WHY\n#   VREF/NAME doesn't deal well with tag creation (or new branch creation),\n#   since then all files in the project look like they are being created (due\n#   to comparison with an empty tree).\n\n#   Use this instead of VREF/NAME when you need to make that distinction.\n\nnewsha=$3\n\n[ $newsha = \"0000000000000000000000000000000000000000\" ] && {\n    echo \"we don't currently handle deletions\" >&2\n    exit 1\n}\n\ngit log --name-only --format=%n $newsha --not --all |\n    sort -u | grep . | sed -e 's.^.VREF/NAME_NC/.'\n\n# ----------------------------------------------------------------------\n# OTHER NOTES\n#   The built-in NAME does have a wee bit of a performance advantage.  I plan\n#   to ignore this until someone notices this enough to be a problem :)\n#\n#   I could explain it here at least, but I fear that any explanation will\n#   only add to the already rampant confusion about how VREFs work.  I'm not\n#   rocking THAT boat again, sorry!\n"
  },
  {
    "path": "src/VREF/VOTES",
    "content": "#!/bin/sh\n\n# gitolite VREF to count votes before allowing pushes to certain branches.\n\n# This approximates gerrit's voting (but it is SHA based; I believe Gerrit is\n# more \"changeset\" based).  Here's how it works:\n\n# - A normal developer \"bob\" proposes changes to master by pushing a commit to\n#   \"pers/bob/master\", then informs the voting members by email.\n\n# - Some or all of the voting members fetch and examine the commit.  If they\n#   approve, they \"vote\" for the commit like so.  For example, say voting\n#   member \"alice\" fetched bob's proposed commit into \"bob-master\" on her\n#   clone, then tested or reviewed it.  She would approve it by running:\n#       git push origin bob-master:votes/alice/master\n\n# - Once enough votes have been tallied (hopefully there is normal team\n#   communication that says \"hey I approved your commit\", or it can be checked\n#   by 'git ls-remote origin' anyway), Bob, or any developer, can push the\n#   same commit (same SHA) to master and the push will succeed.\n\n# - Finally, a \"trusted\" developer can push a commit to master without\n#   worrying about the voting restriction at all.\n\n# The config for this example would look like this:\n\n#   repo foo\n#       # allow personal branches (to submit proposed changes)\n#       RW+ pers/USER/          =   @devs\n#       -   pers/               =   @all\n#\n#       # allow only voters to vote\n#       RW+ votes/USER/         =   @voters\n#       -   votes/              =   @all\n#\n#       # normal access rules go here; should allow *someone* to push master\n#       RW+                     =   @devs\n#\n#       # 2 votes required to push master, but trusted devs don't have this restriction\n#       RW+ VREF/VOTES/2/master =   @trusted-devs\n#       -   VREF/VOTES/2/master =   @devs\n\n# Note: \"2 votes required to push master\" means at least 2 refs matching\n# \"votes/*/master\" have the same SHA as the one currently being pushed.\n\n# ----------------------------------------------------------------------\n\n# see gitolite docs for what the first 7 arguments mean\n\n# inputs:\n#   arg-8 is a number; see below\n#   arg-9 is a simple branch name (i.e., \"master\", etc).  Currently this code\n#   does NOT do vote counting for branch names with more than one component\n#   (like foo/bar).\n# outputs (STDOUT)\n#   nothing\n# exit status:\n#   always 0\n\ndie() { echo \"$@\" >&2; exit 1; }\n[ -z \"$8\" ] && die \"not meant to be run manually\"\n\nref=$1\nnewsha=$3\nrefex=$7\nvotes_needed=$8\nbranch=$9\n\n# nothing to do if the branch being pushed is not \"master\" (using our example)\n[ \"$ref\" = \"refs/heads/$branch\" ] || exit 0\n\n# find how many votes have come in\nvotes=`git for-each-ref refs/heads/votes/*/$branch | grep -c $newsha`\n\n# send back a vref if we don't have the minimum votes needed.  For trusted\n# developers this will invoke the RW+ rule and pass anyway, but for others it\n# will invoke the \"-\" rule and fail.\n[ $votes -ge $votes_needed ] || echo $refex \"require at least $votes_needed votes to push $branch\"\n\nexit 0\n"
  },
  {
    "path": "src/VREF/lock",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Common;\n\n# gitolite VREF to lock and unlock (binary) files.  Requires companion command\n# 'lock' to be enabled; see doc/locking.mkd for details.\n\n# ----------------------------------------------------------------------\n\n# see gitolite docs for what the first 7 arguments mean\n\ndie \"not meant to be run manually\" unless $ARGV[6];\n\nmy $ff = \"$ENV{GL_REPO_BASE}/$ENV{GL_REPO}.git/gl-locks\";\nexit 0 unless -f $ff;\n\nour %locks;\nmy $t = slurp($ff);\neval $t;\n_die \"do '$ff' failed with '$@', contact your administrator\" if $@;\n\nmy ( $oldtree, $newtree, $refex ) = @ARGV[ 3, 4, 6 ];\n\nfor my $file (`git diff --name-only $oldtree $newtree`) {\n    chomp($file);\n\n    if ( $locks{$file} and $locks{$file}{USER} ne $ENV{GL_USER} ) {\n        print \"$refex '$file' locked by '$locks{$file}{USER}'\";\n        last;\n    }\n}\n\nexit 0\n"
  },
  {
    "path": "src/VREF/partial-copy",
    "content": "#!/bin/sh\n\n# push updated branches back to the \"main\" repo.\n\n# This must be run as the *last* VREF, though it doesn't matter what\n# permission you give to it\n\ndie() { echo \"$@\" >&2; exit 1; }\n\nrepo=$GL_REPO\nuser=$GL_USER\nref=$1          # we're running like an update hook\nold=$2\nnew=$3\n\n# never send any STDOUT back, to avoid looking like a ref.  If we fail, git\n# will catch it by our exit code\nexec >&2\n\nmain=`git config --file $GL_REPO_BASE/$repo.git/config --get gitolite.partialCopyOf`;\n[ -z \"$main\" ] && exit 0\n\nrand=$$\nexport GL_BYPASS_ACCESS_CHECKS=1\n\nif [ \"$new\" = \"0000000000000000000000000000000000000000\" ]\nthen\n    # special case for deleting a ref (this is why it is important to put this\n    # VREF as the last one; if we got this far he is allowed to delete it)\n    git push -f $GL_REPO_BASE/$main.git :$ref || die \"FATAL: failed to delete $ref\"\n\n    exit 0\nfi\n\ngit push -f $GL_REPO_BASE/$main.git $new:refs/partial/br-$rand || die \"FATAL: failed to send $new\"\n\ncd $GL_REPO_BASE/$main.git\ngit update-ref -d refs/partial/br-$rand\ngit update-ref $ref $new $old || die \"FATAL: update-ref for $ref failed\"\n\nexit 0\n"
  },
  {
    "path": "src/VREF/refex-expr",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# see bottom of this file for instructons and IMPORTANT WARNINGS!\n# ----------------------------------------------------------------------\n\nmy $rule = $ARGV[7];\ndie \"\\n\\nFATAL: GL_REFEX_EXPR_ doesn't exist\\n(your admin probably forgot the rc file change needed for this to work)\\n\\n\"\n  unless exists $ENV{ \"GL_REFEX_EXPR_\" . $rule };\nmy $res = $ENV{ \"GL_REFEX_EXPR_\" . $rule } || 0;\nprint \"$ARGV[6] ($res)\\n\" if $res;\n\nexit 0;\n\n__END__\n\n------------------------------------------------------------------------\nIMPORTANT WARNINGS:\n  * has not been tested heavily\n      * SO PLEASE TEST YOUR SPECIFIC USE CASE THOROUGHLY!\n      * read the NOTES section below\n  * syntax and semantics are to be considered beta and may change as I find\n    better use cases\n------------------------------------------------------------------------\n\nRefex expressions, like VREFs, are best used as additional \"deny\" rules, to\ndeny combinations that the normal ruleset cannot detect.\n\nTo enable this, uncomment 'refex-expr' in the ENABLE list in the rc file.\n\nIt allows you to say things like \"don't allow users u3 and u4 to change the\nMakefile in the master branch\" (i.e., they can change any other file in\nmaster, or the Makefile in any other branch, but not that specific combo).\n\n    repo foo\n        RW+                                 =   u1 u2   # line 1\n\n        RW+ master                          =   u3 u4   # line 2\n        RW+                                 =   u3 u4   # line 3\n        RW+ VREF/NAME/Makefile              =   u3 u4   # line 4\n        -   master and VREF/NAME/Makefile   =   u3 u4   # line 5\n\nLine 5 is a \"refex expression\".  Here are the rules:\n\n  * for each refex in the expression (\"master\" and \"VREF/NAME/Makefile\" in\n    this example), a count is kept of the number of times the EXACT refex was\n    matched and allowed in the *normal* rules (here, lines 2 and 4) during\n    this push.\n\n  * the expression is evaluated based on these counts.  0 is false, and\n    any non-zero is true (see more examples later).  The truth value of the\n    expression determines whether the refex expression matched.\n\n    You can use any logical or arithmetic expression using refexes as operands\n    and using these operators:\n\n        not and or xor + - == -lt -gt -eq -le -ge -ne\n\n    Parens are not allowed.  Precedence is as you might expect for those\n    operators.  It's actually perl that is evaluating it (you can guess what\n    the '-lt' etc., get translated to) so if in doubt, check 'man perlop'.\n\n  * the refexes that form the terms of the expression (in this case, lines 2\n    and 4) MUST come before the expression itself (i.e., line 5).\n\n  * note the words \"EXACT refex was matched\" above.\n\n    Let's say you add \"u3\" to line 1.  Then the refex expression in line 5\n    would never match for u3.  This is because line 1 prevents line 2 from\n    matching (being more general *and* appearing earlier), so the count for\n    the \"master\" refex would be 0.  If \"master\" is 0 (false), then \"master and\n    <anything>\" is also false.\n\n    (Same thing is you swap lines 2 and 3; i.e., put the \"RW+ = ...\" before\n    the \"RW+ master = ...\").\n\n    Put another way, the terms in the refex expression are refexes, not refs.\n    Merely pushing the master branch does not mean the count for \"master\"\n    increases; it has to *match* on a line that has \"master\" as the refex.\n\nHere are some more examples:\n\n  * user u2 is allowed to push either 'doc/' or 'src/' but not both\n\n        repo    foo\n            RW+                         =   u1 u2 u3\n\n            RW+ VREF/NAME/doc/                      =   u2\n            RW+ VREF/NAME/src/                      =   u2\n            -   VREF/NAME/doc/ and VREF/NAME/src/   =   u2\n\n  * user u3 is allowed to push at most 2 files to conf/\n\n        repo    foo\n            RW+                         =   u1 u2 u3\n\n            RW+ VREF/NAME/conf/         =   u3\n            -   VREF/NAME/conf/ -gt 2   =   u3\n"
  },
  {
    "path": "src/commands/1plus1",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# import LOCK_*\nuse Fcntl qw(:flock);\n\nmy $lockbase      = shift;    # suggested: $GL_REPO_BASE/$GL_REPO.git/.gl-mirror-push-lock.$COPY_NAME\nmy @cmd_plus_args = @ARGV;    # the actual 'gitolite mirror ...' command\n@ARGV = ();\n\n# ----------------------------------------------------------------------\n\nopen( my $fhrun, \">\", \"$lockbase.run\" ) or die \"open '$lockbase.run' failed: $!\";\nif ( flock( $fhrun, LOCK_EX | LOCK_NB ) ) {\n    # got run lock; you're good to go\n\n    system(@cmd_plus_args);\n\n    flock( $fhrun, LOCK_UN );\n    exit 0;\n}\n\n# \"run\" lock failed; someone is already running the command\n\nopen( my $fhqueue, \">\", \"$lockbase.queue\" ) or die \"open '$lockbase.queue' failed: $!\";\nif ( flock( $fhqueue, LOCK_EX | LOCK_NB ) ) {\n    # got queue lock, now block waiting for \"run\" lock\n    flock( $fhrun, LOCK_EX );\n    # got run lock, so take yourself out of \"queue\" state, then run\n    flock( $fhqueue, LOCK_UN );\n\n    system(@cmd_plus_args);\n\n    flock( $fhrun, LOCK_UN );\n    exit 0;\n}\n\n# \"queue\" lock also failed; someone is running AND someone is queued; we can go home\nsay STDERR \"INFO: nothing to do/queue; '$lockbase' already running and 1 in queue\";\nexit 0;\n"
  },
  {
    "path": "src/commands/D",
    "content": "#!/bin/sh\n\n# ----------------------------------------------------------------------\n# ADMINISTRATOR NOTES:\n# ----------------------------------------------------------------------\n\n# - set TRASH_CAN in the rc if you don't like the default.  It should be\n#   relative to GL_REPO_BASE or an absolute value.  It should also be on the\n#   same filesystem as GL_REPO_BASE, otherwise the 'mv' will take too long.\n\n# - you could set TRASH_SUFFIX also but I recomend you leave it as it is\n\n# - run a cron job to delete old repos based on age (the TRASH_SUFFIX has a\n#   timestamp); your choice how/how often you do that\n\n# - you can completely disable the 'rm' command by setting an rc variable\n#   called D_DISABLE_RM to \"1\".\n# ----------------------------------------------------------------------\n\n# ----------------------------------------------------------------------\n# Usage:    ssh git@host D <subcommand> <argument>\n#\n# The whimsically named \"D\" command deletes repos (\"D\" is a counterpart to the\n# \"C\" permission which lets you create repos.  Which also means that, just\n# like \"C\", it only works for wild repos).\n#\n# There are two kinds of deletions: 'rm' removes a repo completely, while\n# 'trash' moves it to a trashcan which can be recovered later (upto a time\n# limit that your admin will tell you).\n#\n# The 'rm', 'lock', and 'unlock' subcommands:\n#     Initially, all repos are \"locked\" against 'rm'.  The correct sequence is\n#         ssh git@host D unlock repo\n#         ssh git@host D rm repo\n#     Since the initial condition is always locked, the \"lock\" command is\n#     rarely used but it is there if you want it.\n#\n# The 'trash', 'list-trash', and 'restore' subcommands:\n#     You can 'trash' a repo, which moves it to a special place:\n#         ssh git@host D trash repo\n#     You can then 'list-trash'\n#         ssh git@host D list-trash\n#     which prints something like\n#         repo/2012-04-11_05:58:51\n#     allowing you to restore by saying\n#         ssh git@host D restore repo/2012-04-11_05:58:51\n\ndie() { echo \"$@\" >&2; exit 1; }\nusage() { perl -lne 'print substr($_, 2) if /^# Usage/../^$/' < $0; exit 1; }\n[ -z \"$1\" ] && usage\n[ \"$1\" = \"-h\" ] && usage\n[ \"$1\" != \"list-trash\" ] && [ -z \"$2\" ] && usage\n[ -z \"$GL_USER\" ] && die GL_USER not set\n\n# ----------------------------------------------------------------------\ncmd=$1\nrepo=$2\n# ----------------------------------------------------------------------\nRB=`gitolite query-rc GL_REPO_BASE`;            cd $RB\nTRASH_CAN=`gitolite query-rc TRASH_CAN`;        tcan=Trash;                     TRASH_CAN=${TRASH_CAN:-$tcan}\nTRASH_SUFFIX=`gitolite query-rc TRASH_SUFFIX`;  tsuf=`date +%Y-%m-%d_%H:%M:%S`; TRASH_SUFFIX=${TRASH_SUFFIX:-$tsuf}\n# ----------------------------------------------------------------------\n\nowner_or_die() {\n    gitolite owns \"$repo\" || die You are not authorised\n}\n\n# ----------------------------------------------------------------------\n\nif [ \"$cmd\" = \"rm\" ]\nthen\n\n    gitolite query-rc -q D_DISABLE_RM && die \"sorry, 'unlock' and 'rm' are disabled\"\n\n    owner_or_die\n    [ -f $repo.git/gl-rm-ok ] || die \"'$repo' is locked!\"\n    rm -rf $repo.git\n    echo \"'$repo' is now gone!\"\n\nelif [ \"$cmd\" = \"lock\" ]\nthen\n\n    owner_or_die\n    rm -f $repo.git/gl-rm-ok\n    echo \"'$repo' is now locked\"\n\nelif [ \"$cmd\" = \"unlock\" ]\nthen\n\n    gitolite query-rc -q D_DISABLE_RM && die \"sorry, 'unlock' and 'rm' are disabled\"\n\n    owner_or_die\n    touch $repo.git/gl-rm-ok\n    echo \"'$repo' is now unlocked\"\n\nelif [ \"$cmd\" = \"trash\" ]\nthen\n\n    owner_or_die\n    mkdir -p $TRASH_CAN/$repo 2>/dev/null || die \"failed creating directory in trashcan\"\n    [ -d $TRASH_CAN/$repo/$TRASH_SUFFIX ] && die \"try again in a few seconds...\"\n    mv $repo.git $TRASH_CAN/$repo/$TRASH_SUFFIX\n    echo \"'$repo' moved to trashcan\"\n\nelif [ \"$cmd\" = \"list-trash\" ]\nthen\n\n    cd $TRASH_CAN 2>/dev/null || exit 0\n    find . -name gl-creator | sort | while read t\n    do\n        owner=\n        owner=`cat \"$t\"`\n        [ \"$owner\" = \"$GL_USER\" ] && dirname $t\n    done | cut -c3-\n\nelif [ \"$cmd\" = \"restore\" ]\nthen\n\n    owner=\n    owner=`cat $TRASH_CAN/$repo/gl-creator 2>/dev/null`\n    [ \"$owner\" = \"$GL_USER\" ] || die \"'$repo' is not yours!\"\n\n    cd $TRASH_CAN\n    realrepo=`dirname $repo`\n    [ -d $RB/$realrepo.git ] && die \"'$realrepo' already exists\"\n    mv $repo $RB/$realrepo.git\n    echo \"'$repo' restored to '$realrepo'\"\n\nelse\n    die \"unknown subcommand '$cmd'\"\nfi\n"
  },
  {
    "path": "src/commands/access",
    "content": "#!/usr/bin/perl -s\nuse strict;\nuse warnings;\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Rc;\nuse Gitolite::Common;\nuse Gitolite::Conf::Load;\n\nour ( $q, $s, $h );    # quiet, show, help\n\n=for usage\nUsage:  gitolite access [-q|-s] <repo> <user> <perm> <ref>\n\nPrint access rights for arguments given.  The string printed has the word\nDENIED in it if access was denied.  With '-q', returns only an exit code\n(shell truth, not perl truth -- 0 is success).  For '-s', see below.\n\n  - repo: mandatory\n  - user: mandatory\n  - perm: defauts to '+'.  Valid values: R, W, +, C, D, M\n  - ref:  defauts to 'any'.  See notes below\n\nNotes:\n  - ref: something like 'master', or 'refs/tags/v1.0', or even a VREF if you\n    know what they look like.\n\n    The 'any' ref is special -- it ignores deny rules, thus simulating\n    gitolite's behaviour during the pre-git access check (see 'deny-rules'\n    section in rules.html for details).\n\n  - batch mode: see src/triggers/post-compile/update-git-daemon-access-list\n    for a good example that shows how to test several repos in one invocation.\n    This is orders of magnitude faster than running the command multiple\n    times; you'll notice if you have more than a hundred or so repos.\n\n  - '-s' shows the rules (conf file name, line number, and rule) that were\n    considered and how they fared.\n\n  - you can also test the ability to create wild repos if you set GL_USER to\n    the username and use ^C as the permission to check for.\n=cut\n\nusage() if not @ARGV >= 2 or $h;\n\nmy ( $repo, $user, $aa, $ref ) = @ARGV;\n# default access is '+'\n$aa  ||= '+';\n# default ref is 'any'\n$ref ||= 'any';\n# fq the ref if needed\n$ref =~ s(^)(refs/heads/) if $ref and $ref ne 'any' and $ref !~ m(^(refs|VREF)/);\n_die \"invalid perm\" if not( $aa and $aa =~ /^(R|W|\\+|C|D|M|\\^C)$/ );\n_die \"invalid ref name\" if not( $ref and $ref =~ $REF_OR_FILENAME_PATT );\n\nmy $ret = '';\n\nif ( $repo ne '%' and $user ne '%' ) {\n    # single repo, single user; no STDIN\n    $ret = access( $repo, $user, adjust_aa($repo, $aa), $ref );\n\n    show($ret) if $s;\n\n    # adjust for fallthru in VREFs\n    $ret =~ s/DENIED by fallthru/allowed by fallthru/ if $ref =~ m(^VREF/);\n\n    if ( $ret =~ /DENIED/ ) {\n        print \"$ret\\n\" unless $q;\n        exit 1;\n    }\n\n    print \"$ret\\n\" unless $q;\n    exit 0;\n}\n\n$repo = '' if $repo eq '%';\n$user = '' if $user eq '%';\n\n_die \"'-q' and '-s' meaningless in pipe mode\" if $q or $s;\n@ARGV = ();\nwhile (<>) {\n    my @in = split;\n    my $r  = $repo || shift @in;\n    my $u  = $user || shift @in;\n    $ret = access( $r, $u, adjust_aa($r, $aa), $ref );\n    print \"$r\\t$u\\t$ret\\n\";\n}\n\nsub adjust_aa {\n    my ($repo, $aa) = @_;\n    $aa = 'W' if $aa eq 'C' and not option($repo, 'CREATE_IS_C');\n    $aa = '+' if $aa eq 'D' and not option($repo, 'DELETE_IS_D');\n    $aa = 'W' if $aa eq 'M' and not option($repo, 'MERGE_CHECK');\n    return $aa;\n}\n\nsub show {\n    my $ret = shift;\n    die \"repo already exists; ^C won't work\\n\" if $ret =~ /DENIED by existence/;\n\n    my $in = $rc{RULE_TRACE} or die \"this should not happen! $ret\";\n\n    print STDERR \"legend:\";\n    print STDERR \"\n    d => skipped deny rule due to ref unknown or 'any',\n    r => skipped due to refex not matching,\n    p => skipped due to perm (W, +, etc) not matching,\n    D => explicitly denied,\n    A => explicitly allowed,\n    F => fallthru; access denied for normal refs, allowed for VREFs\n\n\";\n\n    my %rule_info = read_ri($in);    # get rule info data for all traced rules\n                                     # this means conf filename, line number, and content of the line\n\n    # the rule-trace info is a set of pairs of a number plus a string.  Only\n    # the last character in a string is valid (and has meanings shown above).\n    # At the end there may be a final 'f'\n    my @in = split ' ', $in;\n    while (@in) {\n        $in = shift @in;\n        if ( $in =~ /^\\d+$/ ) {\n            my $res = shift @in or die \"this should not happen either!\";\n            my $m = chop($res);\n            printf \"  %s %20s:%-6s %s\\n\", $m,\n                                          $rule_info{$in}{fn},\n                                          $rule_info{$in}{ln},\n                                          $rule_info{$in}{cl};\n        } elsif ( $in eq 'F' ) {\n            printf \"  %s %20s\\n\", $in, \"(fallthru)\";\n        } else {\n            die \"and finally, this also should not happen!\";\n        }\n    }\n    print \"\\n\";\n}\n\nsub read_ri {\n    my %rules = map { $_ => 1 } $_[0] =~ /(\\d+)/g;\n    # contains a series of rule numbers, each of which we must search in\n    # $GL_ADMIN_BASE/.gitolite/conf/rule_info\n\n    my %rule_info;\n    for ( slurp( $ENV{GL_ADMIN_BASE} . \"/conf/rule_info\" ) ) {\n        my ( $r, $f, $l ) = split ' ', $_;\n        next unless $rules{$r};\n        $rule_info{$r}{fn} = $f;\n        $rule_info{$r}{ln} = $l;\n        $rule_info{$r}{cl} = conf_lines( $f, $l );\n\n        # a wee bit of optimisation, in case the rule_info file is huge and\n        # what we want is up near the beginning\n        delete $rules{$r};\n        last unless %rules;\n    }\n    return %rule_info;\n}\n\n{\n    my %conf_lines;\n\n    sub conf_lines {\n        my ( $file, $line ) = @_;\n        $line--;\n\n        unless ( $conf_lines{$file} ) {\n            $conf_lines{$file} = [ slurp( $ENV{GL_ADMIN_BASE} . \"/conf/$file\" ) ];\n            chomp( @{ $conf_lines{$file} } );\n        }\n        return $conf_lines{$file}[$line];\n    }\n}\n"
  },
  {
    "path": "src/commands/compile-template-data",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# read template data to produce gl-perms and gl-repo-groups files in each\n# $repo dir.  Create the repo if needed, using the wild repos create logic\n# (with a \"creator\" of \"gitolite-admin\"!), though they're not really wild\n# repos.\n\n# see rule-templates.html in the gitolite documentation site.\n\n# pure text manipulation (and very little of that!), no git or gitolite\n# functions, no access checks, no possibility of a performance drama (or at\n# least not a *complex* performance drama)\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Rc;\nuse Gitolite::Common;\nuse Gitolite::Conf::Load;\nuse Gitolite::Conf::Store;\n\nmy $rb = $rc{GL_REPO_BASE};\n\n@ARGV = `find $rc{GL_ADMIN_BASE}/conf -type f -name \"*.conf\" | sort`; chomp(@ARGV);\n# we don't see the files in the exact same order that gitolite compile sees\n# them, but we don't need to, for the data we are interested in (as long as\n# you don't break up one repo's data across multiple files!)\n\n# XXX We also potentially see more; a conf file may be in the directory, but\n# not pulled in via an 'include' or 'subconf', so it doesn't exist as far as\n# 'gitolite compile' is concerned, but here we *do* pull it in.\n\nmy $repos = '';\nmy $perms = '';\nmy $list = '';  # list of templates to apply\nmy $lip = '';   # line in progress\nwhile (<>) {\n    chomp;\n    next unless /^=begin template-data$/ .. /^=end$/ and not /^=(begin|end)/;\n\n    next unless /\\S/;\n    next if /^\\s*#/;\n\n    s/\\t/ /g;   # all the same to us\n\n    # handle continuation lines (backslash as last character)\n    if (/\\\\$/) {\n        s/\\\\$//;\n        $lip .= $_;\n        next;\n    }\n    $_ = $lip . $_;\n    $lip = '';\n\n    _warn(\"bad line: $_\"), next if m([^ \\w.\\@/=-]);    # silently ignore lines that have characters we don't need\n    if (/^\\s*repo\\s+(\\S.*)=\\s*(\\S.*)$/) {\n        flush($repos, $list, $perms);\n        $repos = $1;\n        $perms = '';\n        $list = $2;\n\n    } elsif (/^\\s*(\\S+)\\s*=\\s*(\\S.*)$/) {\n        $perms .= \"$1 = $2\\n\";\n    } else {\n        # probably a blank line or a comment line.  If not, well *shrug*\n    }\n}\nflush($repos, $list, $perms);\n\nsub flush {\n    my ($r, $l, $p) = @_;\n    return unless $r and $l and $p;\n    $l =~ s/\\s+/ /g;\n\n    my @r = split ' ', $r;\n    while (@r) {\n        my $r1 = shift @r;\n        if ($r1 =~ m(^@)) {\n            my @g = @{ Gitolite::Conf::Load::list_members($r1) };\n            _warn \"undefined group '$r1'\" unless @g;\n            unshift @r, @g;\n            next;\n        }\n\n        flush_1($r1, $l, $p);\n    }\n}\nsub flush_1 {\n    my ($repo, $list, $perms) = @_;\n\n    # beware of wild characters!\n    return unless $repo =~ $REPONAME_PATT;\n\n    if (not -d \"$rb/$repo.git\") {\n        new_wild_repo( $repo, 'gitolite-admin', 'template-data' );\n    }\n\n    _print(\"$rb/$repo.git/gl-repo-groups\", $list);\n\n    _print(\"$rb/$repo.git/gl-perms\", $perms);\n}\n"
  },
  {
    "path": "src/commands/config",
    "content": "#!/usr/bin/perl\nuse 5.10.0;\n\n# ---- WARNING ----\n\n# If your site makes a distinction between \"right to push the admin repo\" and\n# \"right to run arbitrary commands on the server\" (i.e., if not all of your\n# \"admins\" have shell access to the server), this is a security risk. If that\n# is the case, DO NOT ENABLE THIS COMMAND.\n\n# ----------------------------------------------------------------------\n# gitolite command to allow \"git config\" on repos (with some restrictions)\n\n# (Not to be confused with the 'git-config' command, which is used only in\n# server-side scripts, not remotely.)\n\n# setup:\n#   1.  Enable the command by adding it to the COMMANDS section in the ENABLE\n#       list in the rc file.  (Have you read the warning above?)\n#\n#   2.  Specify configs allowed to be changed by the user.  This is a space\n#       separated regex list.  For example:\n\n#           repo ...\n#               ... (various rules) ...\n#               option user-configs = hook\\..* foo.bar[0-9].*\n\nuse strict;\nuse warnings;\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Easy;\nuse Gitolite::Common;\n\n# ----------------------------------------------------------------------\n# usage\n\n=for usage\nUsage:    ssh git@host config <repo> [git config options]\n\nRuns \"git config\" in the repo.  Only the following 3 syntaxes are supported\n(see 'man git-config'):\n\n          --add name value\n      --get-all name\n    --unset-all name\n         --list\n\nYour administrator should tell you what keys are allowed for the \"name\".\n=cut\n\n# ----------------------------------------------------------------------\n# arg checks\n\nmy %nargs = qw(\n          --add 3\n      --get-all 2\n    --unset-all 2\n         --list 1\n     );\n\nusage() if not @ARGV or $ARGV[0] eq '-h';\n\nmy $repo = shift;\n\nmy $op = shift;\nusage() unless $op and exists $nargs{$op};\n\n# ----------------------------------------------------------------------\n# authorisation checks\n\ndie \"sorry, you are not authorised\\n\" unless\n    owns($repo)\n        or\n    ( ( $op eq '--get-all' or $op eq '--list' )\n        ? can_read($repo)\n        : ( can_write($repo) and option( $repo, 'writer-is-owner' ) )\n    );\n\n# ----------------------------------------------------------------------\n# key validity checks\n\nunless ($op eq '--list') {\n    my $key = shift;\n\n    my $val = '';\n    $val = join(\" \", @ARGV) if @ARGV;\n    # values with spaces embedded get flattened by sshd when it passes\n    # SSH_ORIGINAL_COMMAND to gitolite.  In this specific instance, we will\n    # pretend we know what the user meant, and join up the last 1+ args into\n    # one space-separated arg.\n\n    my $user_configs = option( $repo, 'user-configs' );\n    # this is a space separated list of allowed config keys\n    my @validkeys = split( ' ', ( $user_configs || '' ) );\n    my @matched = grep { $key =~ /^$_$/i } @validkeys;\n    _die \"config '$key' not allowed\\n\" if ( @matched < 1 );\n\n    @ARGV = ($key);\n    push @ARGV, $val if $val;\n}\n\n# ----------------------------------------------------------------------\n# go!\n\nunshift @ARGV, $op;\nusage() unless @ARGV == $nargs{$op};\n\n_chdir(\"$rc{GL_REPO_BASE}/$repo.git\");\n_system( \"git\", \"config\", @ARGV );\n"
  },
  {
    "path": "src/commands/create",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Rc;\nuse Gitolite::Common;\nuse Gitolite::Conf::Load;\nuse Gitolite::Conf::Store;\n\n=for usage\ncreate -- create a wild repo.\n\nUsage:\n    ssh git@host create <repo>\n=cut\n\nusage() if @ARGV != 1 or $ARGV[0] eq '-h';\n\n$ENV{GL_USER} or _die \"GL_USER not set\";\n\nmy $repo = shift;\n_die \"invalid repo '$repo'\" unless $repo =~ $REPONAME_PATT;\n\nmy $ret = access( $repo, $ENV{GL_USER}, '^C', 'any' );\n_die \"repo already exists or you are not authorised to create it\" if $ret =~ /DENIED/;\n\nnew_wild_repo( $repo, $ENV{GL_USER}, 'create' );\ngl_log( 'create', $repo, $ENV{GL_USER}, 'create' );\n"
  },
  {
    "path": "src/commands/creator",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Rc;\nuse Gitolite::Common;\nuse Gitolite::Conf::Load;\n\n=for usage\nUsage:  gitolite creator [-n] <reponame> [<username>]\n\nPrint the creator name for the repo.  A '-n' suppresses the newline.\n\nWhen an optional username is supplied, it checks if the user is the creator of\nthe repo and returns an exit code (shell truth, 0 for success) instead of\nprinting anything, which makes it possible to do this in shell:\n\n    if gitolite creator someRepo someUser\n    then\n        ...\n=cut\n\nusage() if not @ARGV or $ARGV[0] eq '-h';\nmy $nl = \"\\n\";\nif ( $ARGV[0] eq '-n' ) {\n    $nl = '';\n    shift;\n}\nmy $repo = shift;\nmy $user = shift || '';\n\nmy $creator = '';\n$creator = creator($repo) if not repo_missing($repo);\nif ($user) {\n    exit 0 if $creator eq $user;\n    exit 1;\n}\nreturn ( $creator eq $user ) if $user;\nprint \"$creator$nl\";\n"
  },
  {
    "path": "src/commands/desc",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Easy;\n\n=for usage\nUsage:    ssh git@host desc <repo>\n          ssh git@host desc <repo> <description string>\n\nShow or set description for repo.  You need to have write access to the repo\nand the 'writer-is-owner' option must be set for the repo, or it must be a\nuser-created ('wild') repo and you must be the owner.\n=cut\n\nusage() if not @ARGV or @ARGV < 1 or $ARGV[0] eq '-h';\n\nmy $repo = shift;\nmy $text = join( \" \", @ARGV );\nmy $file = 'description';\n\n#<<<\n_die \"you are not authorized\" unless\n    ( not $text and can_read($repo) )   or\n    (     $text and owns($repo) )       or\n    (     $text and can_write($repo)    and ( $rc{WRITER_CAN_UPDATE_DESC} or option( $repo, 'writer-is-owner' ) ) );\n#>>>\n\n$text\n  ? textfile( file => $file, repo => $repo, text => $text )\n  : print textfile( file => $file, repo => $repo );\n\n__END__\n\nkernel.org needs 'desc' to be available to people who have \"RW\" or above, not\njust the \"creator\".  In fact they need it for non-wild repos so there *is* no\ncreator.  To accommodate this, we created the WRITER_CAN_UPDATE_DESC rc\nvariable.\n\nHowever, that has turned out to be a bit of a blunt instrument for people with\ndifferent types of wild repos -- they don't want to apply this to all of them.\nIt seems easier to do this as an option, so you may have it for one set of\n\"repo ...\" and not have it for others.  And if you want it for the whole\nsystem you'd just put it under \"repo @all\".\n\nThe new 'writer-is-owner' option is meant to cover desc, readme, and any other\nrepo-specific text file, so it's also a blunt instrument, though in a\ndifferent dimension :-)\n"
  },
  {
    "path": "src/commands/fork",
    "content": "#!/bin/sh\n\n# Usage:    ssh git@host fork <repo1> <repo2>\n#\n# Forks repo1 to repo2.  You must have read permissions on repo1, and create\n# (\"C\") permissions for repo2, which of course must not exist.\n#\n# A fork is functionally the same as cloning repo1 to a client and pushing it\n# to a new repo2.  It's just a little more efficient, not just in network\n# traffic but because it uses git clone's \"-l\" option to share the object\n# store also, so it is likely to be almost instantaneous, regardless of how\n# big the repo actually is.\n\ndie() { echo \"$@\" >&2; exit 1; }\nusage() { perl -lne 'print substr($_, 2) if /^# Usage/../^$/' < $0; exit 1; }\n[ -z \"$1\" ] && usage\n[ \"$1\" = \"-h\" ] && usage\n[ -z \"$GL_USER\" ] && die GL_USER not set\n\n# ----------------------------------------------------------------------\nfrom=$1; shift\nto=$1; shift\n[ -z \"$to\" ] && usage\n\ngitolite access -q \"$from\" $GL_USER R any || die \"'$from' does not exist or you are not allowed to read it\"\ngitolite access -q \"$to\"   $GL_USER ^C any || die \"'$to' already exists or you are not allowed to create it\"\n\n# ----------------------------------------------------------------------\n# IMPORTANT NOTE: checking whether someone can create a repo is done as above.\n# However, make sure that the env var GL_USER is set, and that too to the same\n# value as arg-2 of the access command), otherwise it won't work.\n\n# Ideally, you'll leave such code to me.  There's a reason ^C is not listed in\n# the help message for 'gitolite access'.\n# ----------------------------------------------------------------------\n\n# clone $from to $to\ngit clone --bare -l $GL_REPO_BASE/$from.git $GL_REPO_BASE/$to.git\n[ $? -ne 0 ] && exit 1\n\necho \"$from forked to $to\" >&2\n\n# fix up creator, default role permissions (gl-perms), and hooks\ncd $GL_REPO_BASE/$to.git\necho $GL_USER > gl-creator\n\ngitolite query-rc -q LOCAL_CODE && ln -sf `gitolite query-rc LOCAL_CODE`/hooks/common/* hooks\nln -sf `gitolite query-rc GL_ADMIN_BASE`/hooks/common/* hooks\n\n# record where you came from\necho \"$from\" > gl-forked-from\n\n# cache control, if rc says caching is on\ngitolite query-rc -q CACHE && perl -I$GL_LIBDIR -MGitolite::Cache -e \"cache_control('flush', '$to')\";\n\n# trigger post_create\ngitolite trigger POST_CREATE $to $GL_USER fork\n"
  },
  {
    "path": "src/commands/git-annex-shell",
    "content": "#!/usr/bin/perl\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Easy;\n\n# This command requires unrestricted arguments, so add it to the ENABLE list\n# like this:\n#   'git-annex-shell ua',\n\n# This requires git-annex version 20111016 or newer. Older versions won't\n# be secure.\n\nuse strict;\nuse warnings;\n\n# ignore @ARGV and look at the original unmodified command\nmy $cmd = $ENV{SSH_ORIGINAL_COMMAND};\n\n# Expect commands like:\n#   git-annex-shell 'configlist' '/~/repo'\n#   git-annex-shell 'configlist' '/repo'\n#   git-annex-shell 'sendkey' '/~/repo' 'key'\n# The parameters are always single quoted, and the repo path is always\n# the second parameter.\n# Further parameters are not validated here (see below).\ndie \"bad git-annex-shell command: $cmd\"\n  unless $cmd =~ m#^(git-annex-shell '\\w+' ')/(?:\\~/)?([0-9a-zA-Z][0-9a-zA-Z._\\@/+-]*)('( .*|))$#;\nmy $start = $1;\nmy $repo  = $2;\nmy $end   = $3;\n$repo =~ s/\\.git$//;\ndie \"I dont like some of the characters in $repo\\n\" unless $repo =~ $Gitolite::Rc::REPONAME_PATT;\ndie \"I dont like absolute paths in $cmd\\n\" if $repo =~ /^\\//;\ndie \"I dont like '..' paths in $cmd\\n\"     if $repo =~ /\\.\\./;\n\n# Modify $cmd, fixing up the path to the repo to include GL_REPO_BASE.\nmy $newcmd = \"$start$rc{GL_REPO_BASE}/$repo$end\";\n\n# Rather than keeping track of which git-annex-shell commands\n# require write access and which are readonly, we tell it\n# when readonly access is needed.\nif ( can_write($repo) ) {\n} elsif ( can_read($repo) ) {\n    $ENV{GIT_ANNEX_SHELL_READONLY} = 1;\n} else {\n    die \"$repo $ENV{GL_USER} DENIED\\n\";\n}\n# Further limit git-annex-shell to safe commands (avoid it passing\n# unknown commands on to git-shell)\n$ENV{GIT_ANNEX_SHELL_LIMITED} = 1;\n\n# Note that $newcmd does *not* get evaluated by the unix shell.\n# Instead it is passed as a single parameter to git-annex-shell for\n# it to parse and handle the command. This is why we do not need to\n# fully validate $cmd above.\nGitolite::Common::gl_log( $ENV{SSH_ORIGINAL_COMMAND} );\nexec \"git-annex-shell\", \"-c\", $newcmd;\n\n__END__\n\nINSTRUCTIONS... (NEED TO BE VALIDATED BY SOMEONE WHO KNOWS GIT-ANNEX WELL).\n\nbased on http://git-annex.branchable.com/tips/using_gitolite_with_git-annex/\nONLY VARIATIONS FROM THAT PAGE ARE WRITTEN HERE.\n\nsetup\n\n  * in the ENABLE list in the rc file, add an entry like this:\n        'git-annex-shell ua',\n\nThat should be it; everything else should be as in that page.\n"
  },
  {
    "path": "src/commands/git-config",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nuse Getopt::Long;\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Rc;\nuse Gitolite::Common;\nuse Gitolite::Conf::Load;\n\n=for usage\nUsage:  gitolite git-config [-n] [-q] [-r] <repo> <key|pattern>\n\nPrint git config keys and values for the given repo.  The key is either a full\nkey, or, if '-r' is supplied, a regex that is applied to all available keys.\n\n    -q          exit code only (shell truth; 0 is success)\n    -n          suppress trailing newline when used as key (not pattern)\n    -r          treat key as regex pattern (unanchored)\n    -ev         print keys with empty values also (see below)\n\nExamples:\n    gitolite git-config repo gitweb.owner\n    gitolite git-config -q repo gitweb.owner\n    gitolite git-config -r repo gitweb\n\nNotes:\n\n1.  When the key is treated as a pattern, prints:\n\n        reponame<tab>key<tab>value<newline>\n\n    Otherwise the output is just the value.\n\n2.  By default, keys with empty values (specified as \"\" in the conf file) are\n    treated as non-existant.  Using '-ev' will print those keys also.  Note\n    that this only makes sense when the key is treated as a pattern, where\n    such keys are printed as:\n\n        reponame<tab>key<tab><newline>\n\n3.  Finally, see the advanced use section of 'gitolite access -h' -- you can\n    do something similar here also:\n\n        gitolite list-phy-repos | gitolite git-config -r % gitweb\\\\. | cut -f1 > ~/projects.list\n=cut\n\nusage() if not @ARGV;\n\nmy ( $help, $nonl, $quiet, $regex, $ev ) = (0) x 5;\nGetOptions(\n    'n'  => \\$nonl,\n    'q'  => \\$quiet,\n    'r'  => \\$regex,\n    'h'  => \\$help,\n    'ev' => \\$ev,\n) or usage();\n\nmy ( $repo, $key ) = @ARGV;\nusage() unless $key;\n\nmy $ret = '';\n\nif ( $repo ne '%' and $key ne '%' ) {\n    # single repo, single key; no STDIN\n    $key = \"^\\Q$key\\E\\$\" unless $regex;\n\n    $ret = git_config( $repo, $key, $ev );\n\n    # if the key is not a regex, it should match at most one item\n    _die \"found more than one entry for '$key'\" if not $regex and scalar( keys %$ret ) > 1;\n\n    # unlike access, there's nothing to print if we don't find any matching keys\n    exit 1 unless %$ret;\n\n    if ($regex) {\n        map { print \"$repo\\t$_\\t\" . $ret->{$_} . \"\\n\" } sort keys %$ret unless $quiet;\n    } else {\n        map { print $ret->{$_} . ( $nonl ? \"\" : \"\\n\" ) } sort keys %$ret unless $quiet;\n    }\n    exit 0;\n}\n\n$repo = '' if $repo eq '%';\n$key  = '' if $key eq '%';\n\n_die \"'-q' doesn't go with using a pipe\" if $quiet;\n@ARGV = ();\nwhile (<>) {\n    my @in = split;\n    my $r  = $repo || shift @in;\n    my $k  = $key || shift @in;\n    $k = \"^\\Q$k\\E\\$\" unless $regex;\n    $ret = git_config( $r, $k, $ev );\n    next unless %$ret;\n    map { print \"$r\\t$_\\t\" . $ret->{$_} . \"\\n\" } sort keys %$ret;\n}\n"
  },
  {
    "path": "src/commands/help",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Rc;\nuse Gitolite::Common;\n\n=for usage\nUsage:  ssh git@host help       # via ssh\n        gitolite help           # directly on server command line\n\nPrints a list of custom commands available at this gitolite installation.\n\nEach command has (or should have!) its own help, accessed by passing it the\n'-h' option; e.g., \"gitolite access -h\".\n\nNOTE: These commands are found in the commands subdirectory (see the page on\n\"core and non-core gitolite\" in the documentation).  Gitolite also has some\nbuilt-in commands; run just \"gitolite\", with no arguments, to see those.\n=cut\n\nusage() if @ARGV;\n\nprint greeting();\n\nmy $user = $ENV{GL_USER} || '';\nprint \"list of \" . ( $user ? \"remote\" : \"gitolite\" ) . \" commands available:\\n\\n\";\n\nmy %list = ( list_x( $ENV{GL_BINDIR} ), list_x( $rc{LOCAL_CODE} || '' ) );\nfor ( sort keys %list ) {\n    print \"\\t$list{$_}\" if $ENV{D};\n    print \"\\t$_\\n\" if not $user or $rc{COMMANDS}{$_};\n}\n\nprint \"\\n\";\nprint \"$rc{SITE_INFO}\\n\" if $rc{SITE_INFO};\n\nexit 0;\n\n# ------------------------------------------------------------------------------\nsub list_x {\n    my $d = shift;\n    return unless $d;\n    return unless -d \"$d/commands\";\n    _chdir \"$d/commands\";\n    return map { $_ => $d } grep { -x $_ } map { chomp; s(^./)(); $_ } `find . -type f -o -type l|sort`;\n}\n"
  },
  {
    "path": "src/commands/htpasswd",
    "content": "#!/usr/bin/perl\n\nuse strict;\nuse warnings;\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Rc;\nuse Gitolite::Common;\n\n=for usage\nUsage:  ssh git@host htpasswd\n\nSets your htpasswd, assuming your admin has enabled it.\n\n(Admins: You need to add HTPASSWD_FILE to the rc file, pointing to an\nexisting, writable, but possibly an initially empty, file, as well as adding\n'htpasswd' to the ENABLE list).\n=cut\n\n# usage and sanity checks\nusage() if @ARGV and $ARGV[0] eq '-h';\n$ENV{GL_USER} or _die \"GL_USER not set\";\nmy $htpasswd_file = $rc{HTPASSWD_FILE} || '';\ndie \"htpasswd not enabled\\n\" unless $htpasswd_file;\ndie \"$htpasswd_file doesn't exist or is not writable\\n\" unless -w $htpasswd_file;\n\n# prompt\n$|++;\nprint <<EOFhtp;\nPlease type in your new htpasswd at the prompt.  You only have to type it once.\n\nNOTE THAT THE PASSWORD WILL BE ECHOED, so please make sure no one is\nshoulder-surfing, and make sure you clear your screen as well as scrollback\nhistory after you're done (or close your terminal instance).\n\nEOFhtp\nprint \"new htpasswd: \";\n\n# get the password and run htpasswd\nmy $password = <>;\n$password =~ s/[\\n\\r]*$//;\ndie \"empty passwords are not allowed\\n\" unless $password;\nmy $res = system( \"htpasswd\", \"-mb\", $htpasswd_file, $ENV{GL_USER}, $password );\ndie \"htpasswd command seems to have failed with return code: $res.\\n\" if $res;\n"
  },
  {
    "path": "src/commands/info",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nuse Getopt::Long;\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Rc;\nuse Gitolite::Common;\nuse Gitolite::Conf::Load;\n\n=for args\nUsage:  gitolite info [-lc] [-ld] [-json] [<repo name pattern>]\n\nList all existing repos you can access, as well as repo name patterns (see\n\"wild repos\") you have any kind of access to.\n\n    '-lc'       lists creators as an additional field at the end.\n    '-ld'       lists description as an additional field at the end.\n    '-json'     produce JSON output instead of normal output\n    '-p'        limits output to physical repos only (no wild repo regexes!)\n\nThe optional pattern is an unanchored regex that will limit the repos\nsearched, in both cases.  It might speed up things a little if you have more\nthan a few thousand repos.\n=cut\n\n# these are globals\nmy ( $lc, $ld, $json, $p, $patt ) = args();\nmy %out;    # holds info to be json'd\n\n$ENV{GL_USER} or _die \"GL_USER not set\";\nif ($json) {\n    greeting(\\%out);\n} else {\n    print greeting();\n}\n\nprint_patterns() unless $p;     # repos he can create for himself\nprint_phy_repos();              # repos already created\n\nif ( $rc{SITE_INFO} ) {\n    $json\n      ? $out{SITE_INFO} = $rc{SITE_INFO}\n      : print \"\\n$rc{SITE_INFO}\\n\";\n}\n\nprint JSON::to_json( \\%out, { utf8 => 1, pretty => 1 } ) if $json;\n\n# ----------------------------------------------------------------------\n\nsub args {\n    my ( $lc, $ld, $json, $p, $patt ) = ( '', '', '', '' );\n    my $help = '';\n\n    GetOptions(\n        'lc'   => \\$lc,\n        'ld'   => \\$ld,\n        'json' => \\$json,\n        'p'    => \\$p,\n        'h'    => \\$help,\n    ) or usage();\n\n    usage() if @ARGV > 1 or $help;\n    $patt = shift @ARGV || '.';\n\n    require JSON if $json;\n\n    return ( $lc, $ld, $json, $p, $patt );\n}\n\nsub print_patterns {\n    my ( $repos, @aa );\n\n    my $lm = \\&Gitolite::Conf::Load::list_members;\n\n    # find repo patterns only, call them with ^C flag included\n    @$repos = grep { !/$REPONAME_PATT/ } map { /^@/ ? @{ $lm->($_) } : $_ } @{ lister_dispatch('list-repos')->() };\n    @aa = qw(R W ^C);\n    listem( $repos, '', '', @aa );\n    # but squelch the 'lc' and 'ld' flags for these\n}\n\nsub print_phy_repos {\n    my ( $repos, @aa );\n\n    # now get the actual repos and get R or W only\n    _chdir( $rc{GL_REPO_BASE} );\n    $repos = list_phy_repos(1);\n    @aa    = qw(R W);\n    listem( $repos, $lc, $ld, @aa );\n}\n\nsub listem {\n    my ( $repos, $lc, $ld, @aa ) = @_;\n    my @list;\n    my $mlr = 0;    # max length of reponame\n    my $mlc = 0;    # ...and creator\n    for my $repo (@$repos) {\n        next unless $repo =~ /$patt/;\n        my $creator = '';\n        my $desc    = '';\n        my $perm    = '';\n        $creator = creator($repo) if $lc;\n\n        if ($ld) {\n            # use config value first, else 'description' file as second choice\n            my $k = 'gitweb.description';\n            my $d = \"$ENV{GL_REPO_BASE}/$repo.git/description\";\n            $desc = git_config( $repo, $k )->{$k} || '';\n            if ( !$desc and -r $d ) {\n                $desc = slurp($d);\n                chomp($desc);\n            }\n        }\n\n        for my $aa (@aa) {\n            my $ret = access( $repo, $ENV{GL_USER}, $aa, 'any' );\n            $perm .= ( $ret =~ /DENIED/ ? \"  \" : \" $aa\" );\n        }\n        $perm =~ s/\\^//;\n        next unless $perm =~ /\\S/;\n\n        if ($json) {\n            $out{repos}{$repo}{creator}     = $creator if $lc;\n            $out{repos}{$repo}{description} = $desc    if $ld;\n            $out{repos}{$repo}{perms}       = _hash($perm);\n        } else {\n            $mlr = length($repo) if ( $lc or $ld ) and $mlr < length($repo);\n            $mlc = length($creator) if $lc and $ld and $mlc < length($creator);\n            push @list, [ $perm, $repo, $creator, $desc ];\n        }\n    }\n    return if $json;\n\n    my $fmt = \"%s\\t%-${mlr}s\\t%-${mlc}s\\t%s\\n\";\n    map { s/\\t\\t/\\t/; s/\\s*$/\\n/; print } map { sprintf $fmt, @$_ } @list;\n}\n\nsub _hash {\n    my $in = shift;\n    my %out = map { $_ => 1 } ( $in =~ /(\\S)/g );\n    return \\%out;\n}\n"
  },
  {
    "path": "src/commands/list-dangling-repos",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Common;\nuse Gitolite::Conf::Load;\n\n=for usage\nUsage:  gitolite list-dangling-repos\n\nList all existing repos that no one can access remotely any more.  They could\nbe normal repos that were taken out of \"repo\" statements in the conf file, or\nwildcard repos whose matching \"wild\" pattern was taken out or changed so it no\nlonger matches.\n\nI would advise caution if you use this as a basis for deleting repos from the\nfile system.  A bug in this program could cause you to lose important data!\n=cut\n\nusage() if @ARGV and $ARGV[0] eq '-h';\n\n# get the two lists we need.  %repos is the list of repos in \"repo\" statements\n# in the conf file.  %phy_repos is the list of actual repos on disk.  Our job\n# is to cull %phy_repos of all keys that have a matching key in %repos, where\n# \"matching\" means \"string equal\" or \"regex match\".\nmy %repos = map { chomp; $_ => 1 } `gitolite list-repos`;\nfor my $r ( grep /^@/, keys %repos ) {\n    map { chomp; $repos{$_} = 1; } `gitolite list-members $r`;\n}\nmy %phy_repos = map { chomp; $_ => 1 } `gitolite list-phy-repos`;\n\n# Remove exact matches.  But for repo names like \"gtk+\", you could have\n# collapsed this into the next step (the regex match).\nfor my $pr ( keys %phy_repos ) {\n    next unless exists $repos{$pr};\n    delete $repos{$pr};\n    delete $phy_repos{$pr};\n}\n\n# Remove regex matches.\nfor my $pr ( keys %phy_repos ) {\n    my $matched = 0;\n    my $pr2     = Gitolite::Conf::Load::generic_name($pr);\n    for my $r ( keys %repos ) {\n        if ( $pr =~ /^$r$/ or $pr2 =~ /^$r$/ ) {\n            $matched = 1;\n            next;\n        }\n    }\n    delete $phy_repos{$pr} if $matched;\n}\n\n# what's left in %phy_repos are dangling repos.\nprint join( \"\\n\", sort keys %phy_repos ), \"\\n\";\n"
  },
  {
    "path": "src/commands/lock",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nuse Getopt::Long;\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Rc;\nuse Gitolite::Common;\nuse Gitolite::Conf::Load;\n\n# gitolite command to lock and unlock (binary) files and deal with locks.\n\n=for usage\nUsage:  ssh git@host lock -l      <repo> <file>     # lock a file\n        ssh git@host lock -u      <repo> <file>     # unlock a file\n        ssh git@host lock --break <repo> <file>     # break someone else's lock\n        ssh git@host lock -ls     <repo>            # list locked files for repo\n\nSee doc/locking.mkd for other details.\n=cut\n\nusage() if not @ARGV or $ARGV[0] eq '-h';\n$ENV{GL_USER} or _die \"GL_USER not set\";\n\nmy $op = '';\n$op = 'lock'   if $ARGV[0] eq '-l';\n$op = 'unlock' if $ARGV[0] eq '-u';\n$op = 'break'  if $ARGV[0] eq '--break';\n$op = 'list'   if $ARGV[0] eq '-ls';\nusage() if not $op;\nshift;\n\nmy $repo = shift;\n_die \"You are not authorised\" if access( $repo, $ENV{GL_USER}, 'W', 'any' ) =~ /DENIED/;\n_die \"You are not authorised\" if $op eq 'break' and access( $repo, $ENV{GL_USER}, '+', 'any' ) =~ /DENIED/;\n\nmy $file = shift || '';\nusage() if $op ne 'list' and not $file;\n\n_chdir( $ENV{GL_REPO_BASE} );\n_chdir(\"$repo.git\");\n\n_die \"aborting, file '$file' not found in any branch\" if $file and not object_exists($file);\n\nmy $ff = \"gl-locks\";\n\nif ( $op eq 'lock' ) {\n    f_lock( $repo, $file );\n} elsif ( $op eq 'unlock' ) {\n    f_unlock( $repo, $file );\n} elsif ( $op eq 'break' ) {\n    f_break( $repo, $file );\n} elsif ( $op eq 'list' ) {\n    f_list($repo);\n}\n\n# ----------------------------------------------------------------------\n# For a given path, return 1 if object exists in any branch, 0 if not.\n# This is to prevent locking invalid objects.\n\nsub object_exists {\n    my $file = shift;\n\n    my @branches = `git for-each-ref refs/heads '--format=%(refname)'`;\n    foreach my $b (@branches) {\n        chomp($b);\n        system(\"git cat-file -e $b:$file 2>/dev/null\") or return 1;\n        # note that with system(), the return value is \"shell truth\", so\n        # you check for success with \"or\", not \"and\"\n    }\n    return 0;    # report object not found\n}\n\n# ----------------------------------------------------------------------\n# everything below assumes we have already chdir'd to \"$repo.git\".  Also, $ff\n# is used as a global.\n\nsub f_lock {\n    my ( $repo, $file ) = @_;\n\n    my %locks = get_locks();\n    _die \"'$file' locked by '$locks{$file}{USER}' since \" . localtime( $locks{$file}{TIME} ) if $locks{$file}{USER};\n    $locks{$file}{USER} = $ENV{GL_USER};\n    $locks{$file}{TIME} = time;\n    put_locks(%locks);\n}\n\nsub f_unlock {\n    my ( $repo, $file ) = @_;\n\n    my %locks = get_locks();\n    _die \"'$file' not locked by '$ENV{GL_USER}'\" if ( $locks{$file}{USER} || '' ) ne $ENV{GL_USER};\n    delete $locks{$file};\n    put_locks(%locks);\n}\n\nsub f_break {\n    my ( $repo, $file ) = @_;\n\n    my %locks = get_locks();\n    _die \"'$file' was not locked\" unless $locks{$file};\n    push @{ $locks{BREAKS} }, time . \" $ENV{GL_USER} $locks{$file}{USER} $locks{$file}{TIME} $file\";\n    delete $locks{$file};\n    put_locks(%locks);\n}\n\nsub f_list {\n    my $repo = shift;\n\n    my %locks = get_locks();\n    print \"\\n# locks held:\\n\\n\";\n    map { print \"$locks{$_}{USER}\\t$_\\t(\" . scalar( localtime( $locks{$_}{TIME} ) ) . \")\\n\" } grep { $_ ne 'BREAKS' } sort keys %locks;\n    print \"\\n# locks broken:\\n\\n\";\n    for my $b ( @{ $locks{BREAKS} } ) {\n        my ( $when, $who, $whose, $how_old, $what ) = split ' ', $b;\n        print \"$who\\t$what\\t(\" . scalar( localtime($when) ) . \")\\t(locked by $whose at \" . scalar( localtime($how_old) ) . \")\\n\";\n    }\n}\n\nsub get_locks {\n    if ( -f $ff ) {\n        our %locks;\n\n        my $t = slurp($ff);\n        eval $t;\n        _die \"do '$ff' failed with '$@', contact your administrator\" if $@;\n\n        return %locks;\n    }\n    return ();\n}\n\nsub put_locks {\n    my %locks = @_;\n\n    use Data::Dumper;\n    $Data::Dumper::Indent   = 1;\n    $Data::Dumper::Sortkeys = 1;\n\n    my $dumped_data = Data::Dumper->Dump( [ \\%locks ], [qw(*locks)] );\n    _print( $ff, $dumped_data );\n}\n"
  },
  {
    "path": "src/commands/mirror",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nmy $tid;\n\nBEGIN {\n    $tid = $ENV{GL_TID} || 0;\n    delete $ENV{GL_TID};\n}\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Rc;\nuse Gitolite::Common;\nuse Gitolite::Conf::Load;\n\n=for usage\nUsage 1:    gitolite mirror push <copy> <repo>\n            gitolite mirror status <copy> <repo>\n            gitolite mirror status all <repo>\n            gitolite mirror status all all\nUsage 2:    ssh git@master-server mirror push <copy> <repo>\n            ssh git@master-server mirror status <copy> <repo>\n\nForces a push of one repo to one copy.\n\nUsage 1 is directly on the master server.  Nothing is checked; if the copy\naccepts it, the push happens, even if the copy is not in any copies\noption.  This is how you do delayed or lagged pushes to servers that do not\nneed real-time updates or have bandwidth/connectivity issues.\n\nUsage 2 can be initiated by *any* user who has *any* gitolite access to the\nmaster server, but it checks that the copy is in one of the copies options\nbefore doing the push.\n\nMIRROR STATUS: The usage examples above show what can be done.  The 'status\nall <repo>' usage checks the status of all the copies defined for the given\nrepo.  The 'status all all' usage is special, in that it only prints a list of\nrepos that have *some* error, instead of dumping all the error info itself.\n\nSERVER LIST: 'gitolite mirror list master <reponame>' and 'gitolite mirror\nlist copies <reponame>' will show you the name of the master server, and list\nthe copy servers, for the repo.  They only work on the server command line\n(any server), but not remotely (from a normal user).\n=cut\n\nusage() if not @ARGV or $ARGV[0] eq '-h';\n\n_die \"HOSTNAME not set\" if not $rc{HOSTNAME};\n\nmy ( $cmd, $host, $repo ) = @ARGV;\n$host = 'copies' if $host eq 'slaves';\n$repo =~ s/\\.git$//;\nusage() if not $repo;\n\nif ( $cmd eq 'push' ) {\n    valid_copy( $host, $repo ) if exists $ENV{GL_USER};\n    # will die if host not in copies for repo\n\n    trace( 1, \"TID=$tid host=$host repo=$repo\", \"gitolite mirror push started\" );\n    _chdir( $rc{GL_REPO_BASE} );\n    _chdir(\"$repo.git\");\n\n    if ( -f \"gl-creator\" ) {\n        # try to propagate the wild repo, including creator name and gl-perms\n        my $creator = `cat gl-creator`; chomp($creator);\n        trace( 1, `cat gl-perms 2>/dev/null | ssh $host CREATOR=$creator perms -c \\\\'$repo\\\\' 2>/dev/null` );\n    }\n\n    my $errors = 0;\n    my $glss = '';\n    for (`git push --mirror $host:$repo 2>&1`) {\n        $errors = 1 if $?;\n        print STDERR \"$_\" if -t STDERR or exists $ENV{GL_USER};\n        $glss .= $_;\n        chomp;\n        if (/FATAL/) {\n            $errors = 1;\n            gl_log( 'mirror', $_ );\n        } else {\n            trace( 1, \"mirror: $_\" );\n        }\n    }\n    # save the mirror push status for this copy if the word 'fatal' is found,\n    # else remove the status file.  We don't store \"success\" output messages;\n    # you can always get those from the log files if you really need them.\n    if ( $glss =~ /fatal/i ) {\n        my $glss_prefix = Gitolite::Common::gen_ts() . \"\\t$ENV{GL_TID}\\t\";\n        $glss =~ s/^/$glss_prefix/gm;\n        _print(\"gl-copy-$host.status\", $glss);\n    } else {\n        unlink \"gl-copy-$host.status\";\n    }\n\n    exit $errors;\n} elsif ($cmd eq 'status') {\n    if (not exists $ENV{GL_USER} and $repo eq 'all') {\n        # this means 'gitolite mirror status all all'; in this case we only\n        # return a list of repos that *have* status files (indicating some\n        # problem).  It's upto you what you do with that list.  This is not\n        # allowed to be run remotely; far too wide ranging, sorry.\n        _chdir( $rc{GL_REPO_BASE} );\n        my $phy_repos = list_phy_repos(1);\n        for my $repo ( @{$phy_repos} ) {\n            my @x = glob(\"$rc{GL_REPO_BASE}/$repo.git/gl-copy-*.status\");\n            print \"$repo\\n\" if @x;\n        }\n        exit 0;\n    }\n\n    valid_copy( $host, $repo ) if exists $ENV{GL_USER};\n    # will die if host not in copies for repo\n\n    _chdir( $rc{GL_REPO_BASE} );\n    _chdir(\"$repo.git\");\n\n    $host = '*' if $host eq 'all';\n    map { print_status($repo, $_) } sort glob(\"gl-copy-$host.status\");\n} else {\n    # strictly speaking, we could allow some of the possible commands remotely\n    # also, at least for admins.  However, these commands are mainly intended\n    # for server-side scripting so I don't care.\n    usage() if $ENV{GL_USER};\n\n    server_side_commands(@ARGV);\n}\n\n# ----------------------------------------------------------------------\n\nsub valid_copy {\n    my ( $host, $repo ) = @_;\n    _die \"invalid repo '$repo'\" unless $repo =~ $REPONAME_PATT;\n\n    my %list = repo_copies($repo);\n    _die \"'$host' not a valid copy for '$repo'\" unless $list{$host};\n}\n\nsub repo_copies {\n    my $repo = shift;\n\n    my $ref = git_config( $repo, \"^gitolite-options\\\\.mirror\\\\.copies.*\" );\n    my %list = map { $_ => 1 } map { split } values %$ref;\n\n    return %list;\n}\n\nsub repo_master {\n    my $repo = shift;\n\n    my $ref = git_config( $repo, \"^gitolite-options\\\\.mirror\\\\.master\\$\" );\n    my @list = map { split } values %$ref;\n    _die \"'$repo' seems to have more than one master\" if @list > 1;\n\n    return $list[0] || '';\n}\n\nsub print_status {\n    my $repo = shift;\n    my $file = shift;\n    return unless -f $file;\n    my $copy = $1 if $file =~ /^gl-copy-(.+)\\.status$/;\n    print \"----------\\n\";\n    print \"WARNING: previous mirror push of repo '$repo' to host '$copy' failed, status is:\\n\";\n    print slurp($file);\n    print \"----------\\n\";\n}\n\n# ----------------------------------------------------------------------\n# server side commands.  Very little error checking.\n#   gitolite mirror list master <repo>\n#   gitolite mirror list copies <repo>\n\nsub server_side_commands {\n    if ( $cmd eq 'list' ) {\n        if ( $host eq 'master' ) {\n            say repo_master($repo);\n        } elsif ( $host eq 'copies' ) {\n            my %list = repo_copies($repo);\n            say join( \" \", sort keys %list );\n        } else {\n            _die \"gitolite mirror list master|copies <reponame>\";\n        }\n    } else {\n        _die \"invalid command\";\n    }\n}\n"
  },
  {
    "path": "src/commands/motd",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Easy;\n\n=for usage\nUsage:    ssh git@host motd <repo> rm\n          cat <filename> | ssh git@host motd <repo> set\n\nRemove or set the motd file for repo or the whole system.\n\nFor a repo: you need to have write access to the repo and the\n'writer-is-owner' option must be set for the repo, or it must be a\nuser-created ('wild') repo and you must be the owner.\n\nFor the whole system: you need to be an admin (have write access to the\ngitolite-admin repo).  Use @all in place of the repo name.\n\nPLEASE NOTE that if you're using http mode, the motd will only appear for\ngitolite commands, not for normal git operations.  This in turn means that\nonly the system wide motd can be seen; repo level motd's never show up.\n=cut\n\nusage() if not @ARGV or @ARGV < 1 or $ARGV[0] eq '-h';\n\nmy $repo = shift;\nmy $op = shift || '';\nusage() if $op ne 'rm' and $op ne 'set';\nmy $file = \"gl-motd\";\n\n#<<<\n_die \"you are not authorized\" unless\n    ( $repo eq '@all' and is_admin() )      or\n    ( $repo ne '@all' and owns($repo) )     or\n    ( $repo ne '@all' and can_write($repo)  and option( $repo, 'writer-is-owner' ) );\n#>>>\n\nmy @out =\n  $repo eq '@all'\n  ? ( dir => $rc{GL_ADMIN_BASE} )\n  : ( repo => $repo );\n\nif ( $op eq 'rm' ) {\n    $repo eq '@all'\n      ? unlink \"$rc{GL_ADMIN_BASE}/$file\"\n      : unlink \"$rc{GL_REPO_BASE}/$repo.git/$file\";\n} elsif ( $op eq 'set' ) {\n    textfile( file => $file, @out, prompt => '' );\n} else {\n    print textfile( file => $file, @out, );\n}\n"
  },
  {
    "path": "src/commands/newbranch",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Easy;\n\n=for usage\nUsage:    ssh git@host newbranch <repo name> <new branch name> <based-on ref name>\n\nCreate a new branch and set it to existing branch or tag.  You should have\nwrite access to that branch.\n\nNOTE: runs \"git branch arg-2 arg-3\" in repo given by arg-1, which means you\nshould NOT prefix arguments with \"refs/heads/\" or \"refs/tags/\".\n\n----\n\nThis is for people who have restrictions on what files they can \"touch\".  When\nyou fork a branch and change a file, even if you changed only the files you're\nallowed to, gitolite thinks you changed *all* the files in the repo because\nthe \"old SHA\" is basically empty.\n\nThis helps get around that by first creating the new branch, so that you can\nthen push to it.\n\nTo enable this command, add it to the rc file as a 'command'.\n\nTODO: handle deletes also (less commonly encountered and left as an \"exercise\nfor the reader\" for now!)\n=cut\n\nusage() if not @ARGV or @ARGV < 3 or $ARGV[0] eq '-h';\n\nmy $repo   = shift;\nmy $newbr  = shift;\nmy $oldref = shift;\n\n_die \"you are not authorized\" unless can_write($repo, \"W\", \"refs/heads/$newbr\");\n\nGitolite::Common::_system(\"git\", \"branch\", $newbr, $oldref);\n"
  },
  {
    "path": "src/commands/option",
    "content": "#!/usr/bin/perl\n\n# ----------------------------------------------------------------------\n# gitolite command to allow repo \"owners\" to set \"options\" on repos\n\n# This command can be run by a user to set \"options\" for any repo that she\n# owns.\n#\n# However, gitolite does *not* have the concept of an incremental \"compile\",\n# and options are only designed to be specified in the gitolite.conf file\n# (which a user should not be able to even see!).  Therefore, we allow one\n# specific file (conf/options.conf) to be manipulated by a remote user in a\n# *controlled* fashion, and this file is \"include\"d in the main gitolite.conf\n# file.\n\n# WARNINGS:\n#   1.  Runs \"gitolite compile\" at the end.  On really huge systems (where the\n#       sum total of the conf files is in the order of tens of thousands of\n#       lines) this may take a second or two :)\n#   2.  Since \"options.conf\" is not part of the admin repo, you may need to\n#       back it up separately, just like you currently back up gl-creator and\n#       gl-perms files from individual repos.\n#   3.  \"options.conf\" is formatted very strictly because it's not meant to be\n#       human edited.  If you edit it directly on the server, be careful.\n\n# Relevant gitolite doc links:\n#   \"wild\" repos and \"owners\"\n#       http://gitolite.com/gitolite/wild.html\n#       http://gitolite.com/gitolite/wild.html#specifying-owners\n#       http://gitolite.com/gitolite/wild.html#appendix-1-owner-and-creator\n#   gitolite \"options\"\n#       http://gitolite.com/gitolite/options.html\n#   the \"include\" statement\n#       http://gitolite.com/gitolite/conf.html#include-files\n\n# setup:\n#   1.  Enable the command by adding it to the ENABLE list in the rc file.\n#\n#   2.  Make sure your gitolite.conf has this line at the end:\n#\n#           include \"options.conf\"\n#\n#       then add/commit/push.\n#\n#       Do NOT add a file called \"options.conf\" to your gitolite-admin repo!\n#       This means every time you compile (push the admin repo) you will get a\n#       warning about the missing file.\n#\n#       You can either \"touch ~/.gitolite/conf/options.conf\" on the server, or\n#       take *any* wild repo and add *any* option to create it.\n#\n#   3.  Specify options allowed to be changed by the user.  For example:\n#\n#           repo foo/..*\n#               C   =   blah blah\n#               ...other rules...\n#               option user-options = hook\\..* foo bar[0-9].*\n#\n#       Users can then set any of these options, but no others.\n\n# ----------------------------------------------------------------------\n\nuse strict;\nuse warnings;\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Easy;\nuse Gitolite::Common;\n\n# ----------------------------------------------------------------------\n# usage and arg checks\n\n=for usage\nUsage:    ssh git@host option <repo> add <key> <val>\n          ssh git@host option <repo> del <key>\n          ssh git@host option <repo> list\n\nAdd, delete, or list options for wild repos.  Keys must match one of the\nallowed patterns; your system administrator will tell you what they are.\n\nDoesn't check things like adding a key that already exists (simply overwrites\nwithout warning), deleting a key that doesn't, etc.\n=cut\n\nusage() if not @ARGV or $ARGV[0] eq '-h';\n\nmy $OPTIONS = \"$ENV{HOME}/.gitolite/conf/options.conf\";\n\nmy $repo = shift;\ndie \"sorry, you are not authorised\\n\" unless owns($repo);\n\nmy $op = shift; usage() unless $op =~ /^(add|del|list)$/;\nmy $key = shift; usage() if not $key and $op ne 'list';\nmy $val = shift; usage() if not $val and $op eq 'add';\n\n_print( $OPTIONS, \"\" ) unless -f $OPTIONS;    # avoid error on first run\nmy $options = slurp($OPTIONS);\n\n# ----------------------------------------------------------------------\n# get 'list' out of the way first\nif ( $op eq 'list' ) {\n    print \"$1\\t$2\\n\" while $options =~ /^repo $repo\\n    option (\\S+) = (.*)/mg;\n    exit 0;\n}\n\n# ----------------------------------------------------------------------\n# that leaves 'add' or 'del'\n\n# NOTE: sanity check on characters in key and val not needed;\n# REMOTE_COMMAND_PATT is more restrictive than UNSAFE_PATT anyway!\n\n# check if the key is allowed\nmy $user_options = option( $repo, 'user-options' );\n# this is a space separated list of allowed option keys\nmy @validkeys = split( ' ', ( $user_options || '' ) );\nmy @matched = grep { $key =~ /^$_$/i } @validkeys;\n_die \"option '$key' not allowed\\n\" if ( @matched < 1 );\n\n# delete anyway\n$options =~ s/^repo $repo\\n    option $key = .*\\n//m;\n# then re-add if needed\n$options .= \"repo $repo\\n    option $key = $val\\n\" if $op eq 'add';\n\n# ----------------------------------------------------------------------\n# save and compile\n_print( $OPTIONS, $options );\nsystem(\"gitolite compile\");\n"
  },
  {
    "path": "src/commands/owns",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Easy;\n\n=for usage\nUsage:  gitolite owns <reponame>\n\nChecks if $GL_USER is an owner of the repo and returns an exit code (shell\ntruth, 0 for success), which makes it possible to do this in shell:\n\n    if gitolite owns someRepo\n    then\n        ...\n=cut\n\nusage() if not @ARGV or $ARGV[0] eq '-h';\nmy $repo = shift;\n\nexit not owns($repo);\n"
  },
  {
    "path": "src/commands/perms",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Rc;\nuse Gitolite::Common;\nuse Gitolite::Easy;\n\n=for usage\nperms -- list or set permissions for user-created (\"wild\") repo.\n\nUsage summary:\n    ssh git@host perms <repo> -l\n        # list current permissions on repo\n    ssh git@host perms <repo> -lr\n        # list available roles and their access rights\n\n    ssh git@host perms <repo> + <rolename> <username>\n        # change permissions: add a user to a role\n    ssh git@host perms <repo> - <rolename> <username>\n        # change permissions: remove a user from a role\n\nExamples:\n    ssh git@host perms my/repo + READERS alice\n    ssh git@host perms my/repo + WRITERS bob\n\n----\nThere is also a batch mode useful for scripting and bulk loading; see the\nsource code of the perms command for details.\n=cut\n\n# BATCH MODE: DO NOT combine this with the +/- mode above.  This mode also\n# creates the repo if it does not already exist (assuming $GL_USER has\n# permissions to create it).\n#\n# Example:\n#     cat copy-of-backed-up-gl-perms | ssh git@host perms -c <repo>\n\nusage() if not @ARGV or $ARGV[0] eq '-h' or @ARGV < 2;\n\n$ENV{GL_USER} or _die \"GL_USER not set\";\n\nmy $generic_error = \"repo does not exist, or you are not authorised\";\n\nif ( $ARGV[1] eq '-l' ) {\n    getperms($ARGV[0]);    # doesn't return\n}\n\n# auto-create the repo if -c passed and repo doesn't exist\nif ( $ARGV[0] eq '-c' ) {\n    shift;\n    my $repo = $ARGV[0] or usage();\n    _die \"invalid repo '$repo'\" unless $repo =~ $REPONAME_PATT;\n\n    if ( not -d \"$rc{GL_REPO_BASE}/$repo.git\" ) {\n        unless ($ENV{GL_BYPASS_CREATOR_CHECK}) {\n            my $ret = Gitolite::Conf::Load::access( $repo, $ENV{GL_USER}, '^C', 'any' );\n            _die $generic_error if $ret =~ /DENIED/;\n        }\n\n        require Gitolite::Conf::Store;\n        Gitolite::Conf::Store->import;\n        new_wild_repo( $repo, $ENV{GL_USER}, 'perms-c' );\n        gl_log( 'create', $repo, $ENV{GL_USER}, 'perms-c' );\n    }\n}\n\nmy $repo = shift;\n\nif ( @ARGV and $ARGV[0] eq '-lr' ) {\n    list_roles();\n    exit 0;\n} else {\n    setperms(@ARGV);\n}\n\n# cache control\nif ($rc{CACHE}) {\n    require Gitolite::Cache;\n    Gitolite::Cache::cache_control('flush', $repo);\n}\n\n_system( \"gitolite\", \"trigger\", \"POST_CREATE\", $repo, $ENV{GL_USER}, 'perms' );\n\n# ----------------------------------------------------------------------\n\nsub getperms {\n    my $repo = shift;\n    _die $generic_error if not owns($repo);\n    my $pf = \"$rc{GL_REPO_BASE}/$repo.git/gl-perms\";\n\n    print slurp($pf) if -f $pf;\n\n    exit 0;\n}\n\nsub setperms {\n    _die $generic_error if not owns($repo);\n    my $pf = \"$rc{GL_REPO_BASE}/$repo.git/gl-perms\";\n\n    if ( not @_ ) {\n        # legacy mode; pipe data in\n        print STDERR \"'batch' mode started, waiting for input (run with '-h' for details).\\n\";\n        print STDERR \"Please enter 'cancel' to abort if you did not intend to do this.\\n\";\n        @ARGV = ();\n        my @a;\n        while (<>) {\n            _die \"CANCELLED\" if /^\\s*cancel\\s*$/i;\n            invalid_role($1) if /(\\S+)/ and not $rc{ROLES}{$1};\n            push @a, $_;\n        }\n\n        _print( $pf, @a );\n        return;\n    }\n\n    _die \"Invalid syntax.  Please re-run with '-h' for detailed usage\" if @_ != 3;\n    my ( $op, $role, $user ) = @_;\n    _die \"Invalid syntax.  Please re-run with '-h' for detailed usage\" if $op ne '+' and $op ne '-';\n    _die \"Invalid user '$user'\"                                        if not $user =~ $USERNAME_PATT;\n\n    my $text = '';\n    my @text = slurp($pf) if -f $pf;\n\n    my $present = grep { $_ eq \"$role $user\\n\" } @text;\n\n    if ( $op eq '-' ) {\n        if ( not $present ) {\n            _warn \"'$role $user' was not present in file\";\n        } else {\n            @text = grep { $_ ne \"$role $user\\n\" } @text;\n            _print( $pf, @text );\n        }\n    } else {\n        invalid_role($role) unless grep { $_->[3] eq $role } load_roles();\n        if ($present) {\n            _warn \"'$role $user' already present in file\";\n        } else {\n            push @text, \"$role $user\\n\";\n            @text = sort @text;\n            _print( $pf, @text );\n        }\n    }\n}\n\nmy @rules;\n\nsub load_roles {\n    return @rules if @rules;\n\n    require Gitolite::Conf::Load;\n    Gitolite::Conf::Load::load($repo);\n\n    my %repos = %Gitolite::Conf::Load::repos;\n    my @repo_memberships = Gitolite::Conf::Load::memberships('repo', $repo);\n\n    for my $rp (@repo_memberships) {\n        my $hr = $repos{$rp};\n        for my $r ( keys %$hr ) {\n            next unless $r =~ s/^@//;\n            next unless $rc{ROLES}{$r};\n            map { $_->[3] = $r } @{ $hr->{\"\\@$r\"} };\n            push @rules, @{ $hr->{\"\\@$r\"} };\n        }\n    }\n    return @rules;\n}\n\nsub invalid_role {\n    my $role = shift;\n\n    print STDERR \"Invalid role '$role'; valid roles for this repo:\\n\";\n    open(STDOUT, '>&', \\*STDERR);   # make list_roles print to STDERR\n    list_roles();\n    exit 1;\n}\n\nsub list_roles {\n\n    my @rules = sort { $a->[0] <=> $b->[0] } load_roles();\n\n    for (@rules) {\n        $_->[2] =~ s(^refs/heads/)();\n        $_->[2] = '--any--' if $_->[2] eq 'refs/.*';\n    }\n\n    my $max = 0;\n    map { $max = $_ if $_ > $max } map { length($_->[2]) } @rules;\n    printf(\"\\t%s\\t%*s\\t \\t%s\\n\", \"perm\",  -$max, \"ref\",   \"role\");\n    printf(\"\\t%s\\t%*s\\t \\t%s\\n\", \"----\",  -$max, \"---\",   \"----\");\n    printf(\"\\t%s\\t%*s\\t=\\t%s\\n\", $_->[1], -$max, $_->[2], $_->[3]) for @rules;\n}\n"
  },
  {
    "path": "src/commands/print-default-rc",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Rc;\n\nprint glrc('default-text');\n"
  },
  {
    "path": "src/commands/push",
    "content": "#!/bin/sh\n\nexport GL_BYPASS_ACCESS_CHECKS=1\n\ngit push \"$@\"\n"
  },
  {
    "path": "src/commands/readme",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Easy;\n\n# README.html files work similar to \"description\" files. For further\n# information see\n#   https://www.kernel.org/pub/software/scm/git/docs/gitweb.html\n# under \"Per-repository gitweb configuration\".\n\n=for usage\nUsage:    ssh git@host readme <repo>\n          ssh git@host readme <repo> rm\n          cat <filename> | ssh git@host readme <repo> set\n\nShow, remove or set the README.html file for repo.\n\nYou need to have write access to the repo and the 'writer-is-owner' option\nmust be set for the repo, or it must be a user-created ('wild') repo and you\nmust be the owner.\n=cut\n\nusage() if not @ARGV or @ARGV < 1 or $ARGV[0] eq '-h';\n\nmy $repo = shift;\nmy $op = shift || '';\nusage() if $op and $op ne 'rm' and $op ne 'set';\nmy $file = 'README.html';\n\n#<<<\n_die \"you are not authorized\" unless\n    ( not $op and can_read($repo) )   or\n    (     $op and owns($repo) )       or\n    (     $op and can_write($repo)    and option( $repo, 'writer-is-owner' ) );\n#>>>\n\nif ( $op eq 'rm' ) {\n    unlink \"$rc{GL_REPO_BASE}/$repo.git/$file\";\n} elsif ( $op eq 'set' ) {\n    textfile( file => $file, repo => $repo, prompt => '' );\n} else {\n    print textfile( file => $file, repo => $repo );\n}\n\n__END__\n\nThe WRITER_CAN_UPDATE_README option is gone now; it applies to all the repos\nin the system.  Much better to add 'option writer-is-owner = 1' to repos or\nrepo groups that you want this to apply to.\n\nThis option is meant to cover desc, readme, and any other repo-specific text\nfile, so it's also a blunt instrument, though in a different dimension :-)\n"
  },
  {
    "path": "src/commands/rsync",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Easy;\n\n=for admins\n\nBUNDLE SUPPORT\n\n    (1) For each repo in gitolite.conf for which you want bundle support (or\n        '@all', if you wish), add the following line:\n\n            option bundle       =   1\n\n        Or you can say:\n\n            option bundle.ttl   =   <number>\n\n        A bundle file that is more than <number> seconds old (default value\n        86400, i.e., 1 day) is recreated on the next bundle request.  Increase\n        this if your repo is not terribly active.\n\n        Note: a bundle file is also deleted and recreated if it contains a ref\n        that was then either deleted or rewound in the repo.  This is checked\n        on every invocation.\n\n    (2) Add 'rsync' to the ENABLE list in the rc file\n\n=cut\n\n=for usage\nrsync helper for gitolite\n\nBUNDLE SUPPORT\n\n    Admins: see src/commands/rsync for setup instructions\n\n    Users:\n        rsync git@host:repo.bundle .\n            # downloads a file called \"<basename of repo>.bundle\"; repeat as\n            # needed till the whole thing is downloaded\n        git clone repo.bundle repo\n        cd repo\n        git remote set-url origin git@host:repo\n        git fetch origin    # and maybe git pull, etc. to freshen the clone\n\n    NOTE on options to the rsync command: you are only allowed to use the\n    \"-v\", \"-n\", \"-q\", and \"-P\" options.\n\n=cut\n\nusage() if not @ARGV or $ARGV[0] eq '-h';\n\n# rsync driver program.  Several things can be done later, but for now it\n# drives just the 'bundle' transfer.\n\nif ( $ENV{SSH_ORIGINAL_COMMAND} =~ /^rsync --server --sender (?:-[vn]*(?:e\\d*\\.\\w*)? )?\\. (\\S+)\\.bundle$/ ) {\n\n    my $repo = $1;\n    $repo =~ s/\\.git$//;\n\n    # all errors have the same message to avoid leaking info\n    can_read($repo) or _die \"you are not authorised\";\n    my %config = config( $repo, \"gitolite-options.bundle\" ) or _die \"you are not authorised\";\n\n    my $ttl = $config{'gitolite-options.bundle.ttl'} || 86400;    # in seconds (default 1 day)\n\n    my $bundle = bundle_create( $repo, $ttl );\n\n    $ENV{SSH_ORIGINAL_COMMAND} =~ s( \\S+\\.bundle)( $bundle);\n    trace( 1, \"rsync bundle\", $ENV{SSH_ORIGINAL_COMMAND} );\n    Gitolite::Common::_system( split ' ', $ENV{SSH_ORIGINAL_COMMAND} );\n    exit 0;\n}\n\n_warn \"Sorry, you are only allowed to use the '-v', '-n', '-q', and '-P' options.\";\nusage();\n\n# ----------------------------------------------------------------------\n# helpers\n# ----------------------------------------------------------------------\n\nsub bundle_create {\n    my ( $repo, $ttl ) = @_;\n    my $bundle = \"$repo.bundle\";\n    $bundle =~ s(.*/)();\n    my $recreate = 0;\n\n    my ( %b, %r );\n    if ( -f $bundle ) {\n        %b = map { chomp; reverse split; } `git ls-remote --heads --tags $bundle`;\n        %r = map { chomp; reverse split; } `git ls-remote --heads --tags .`;\n\n        for my $ref ( sort keys %b ) {\n\n            my $mtime = ( stat $bundle )[9];\n            if ( time() - $mtime > $ttl ) {\n                trace( 1, \"bundle too old\" );\n                $recreate++;\n                last;\n            }\n\n            if ( not $r{$ref} ) {\n                trace( 1, \"ref '$ref' deleted in repo\" );\n                $recreate++;\n                last;\n            }\n\n            if ( $r{$ref} eq $b{$ref} ) {\n                # same on both sides; ignore\n                delete $r{$ref};\n                delete $b{$ref};\n                next;\n            }\n\n            `git rev-list --count --left-right $b{$ref}...$r{$ref}` =~ /^(\\d+)\\s+(\\d+)$/ or _die \"git too old\";\n            if ($1) {\n                trace( 1, \"ref '$ref' rewound in repo\" );\n                $recreate++;\n                last;\n            }\n\n        }\n\n    } else {\n        trace( 1, \"no bundle found\" );\n        $recreate++;\n    }\n\n    return $bundle if not $recreate;\n\n    trace( 1, \"creating bundle for '$repo'\" );\n    -f $bundle and ( unlink $bundle or die \"a horrible death\" );\n    system(\"git bundle create $bundle --branches --tags >&2\");\n\n    return $bundle;\n}\n\nsub trace {\n    Gitolite::Common::trace(@_);\n}\n"
  },
  {
    "path": "src/commands/sshkeys-lint",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# complete rewrite of the sshkeys-lint program.  Usage has changed, see\n# usage() function or run without arguments.\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Common;\n\nuse Getopt::Long;\nmy $admin = 0;\nmy $quiet = 0;\nmy $help  = 0;\nGetOptions( 'admin|a=s' => \\$admin, 'quiet|q' => \\$quiet, 'help|h' => \\$help );\n\nuse Data::Dumper;\n$Data::Dumper::Deepcopy = 1;\n$|++;\n\nmy $in_gl_section = 0;\nmy $warnings      = 0;\nmy $KEYTYPE_REGEX = qr/\\b(?:ssh-(?:rsa|dss|ed25519)|ecdsa-sha2-nistp(?:256|384|521))\\b/;\n\nsub msg {\n    my $warning = shift;\n    return if $quiet and not $warning;\n    $warnings++ if $warning;\n    print \"sshkeys-lint: \" . ( $warning ? \"WARNING: \" : \"\" ) . $_ for @_;\n}\n\nusage() if $help;\n\nour @pubkeyfiles = @ARGV; @ARGV = ();\nmy $kd = \"$ENV{HOME}/.gitolite/keydir\";\nif ( not @pubkeyfiles ) {\n    chomp( @pubkeyfiles = `find $kd -type f -name \"*.pub\" | sort` );\n}\n\nif ( -t STDIN ) {\n    @ARGV = (\"$ENV{HOME}/.ssh/authorized_keys\");\n}\n\n# ------------------------------------------------------------------------\n\nmy @authkeys;\nmy %seen_fprints;\nmy %pkf_by_fp;\nmsg 0, \"==== checking authkeys file:\\n\";\nfill_authkeys();    # uses up STDIN\n\nif ($admin) {\n    my $fp = fprint(\"$admin.pub\");\n    my $fpu = ( $fp && $seen_fprints{$fp}{user} || 'no access' );\n    # dbg(\"fpu = $fpu, admin=$admin\");\n    #<<<\n    die \"\\t\\t*** FATAL ***\\n\" .\n        \"$admin.pub maps to $fpu, not $admin.\\n\" .\n        \"You will not be able to access gitolite with this key.\\n\" .\n        \"Look for the 'ssh troubleshooting' link in http://gitolite.com/gitolite/ssh.html.\\n\"\n    if $fpu ne \"user $admin\";\n    #>>>\n}\n\nmsg 0, \"==== checking pubkeys:\\n\" if @pubkeyfiles;\nfor my $pkf (@pubkeyfiles) {\n    # get the short name for the pubkey file\n    ( my $pkfsn = $pkf ) =~ s(^$kd/)();\n\n    my $fp = fprint($pkf);\n    next unless $fp;\n    msg 1, \"$pkfsn appears to be a COPY of $pkf_by_fp{$fp}\\n\" if $pkf_by_fp{$fp};\n    $pkf_by_fp{$fp} ||= $pkfsn;\n    my $fpu = ( $seen_fprints{$fp}{user} || 'no access' );\n    msg 0, \"$pkfsn maps to $fpu\\n\";\n}\n\nif ($warnings) {\n    print \"\\n$warnings warnings found\\n\";\n}\n\nexit $warnings;\n\n# ------------------------------------------------------------------------\nsub fill_authkeys {\n    while (<>) {\n        my $seq = $.;\n        next if ak_comment($_);    # also sets/clears $in_gl_section global\n        my $fp   = fprint($_);\n        my $user = user($_);\n\n        check( $seq, $fp, $user );\n\n        $authkeys[$seq]{fprint}  = $fp;\n        $authkeys[$seq]{ustatus} = $user;\n    }\n}\n\nsub check {\n    my ( $seq, $fp, $user ) = @_;\n\n    msg 1, \"line $seq, $user key found *outside* gitolite section!\\n\"\n      if $user =~ /^user / and not $in_gl_section;\n\n    msg 1, \"line $seq, $user key found *inside* gitolite section!\\n\"\n      if $user !~ /^user / and $in_gl_section;\n\n    if ( $seen_fprints{$fp} ) {\n        #<<<\n        msg 1, \"authkeys line $seq ($user) will be ignored by sshd; \" .\n              \"same key found on line \" .\n              $seen_fprints{$fp}{seq} . \" (\" .\n              $seen_fprints{$fp}{user} . \")\\n\";\n        return;\n        #>>>\n    }\n\n    $seen_fprints{$fp}{seq}  = $seq;\n    $seen_fprints{$fp}{user} = $user;\n}\n\nsub user {\n    my $user = '';\n    $user ||= \"user $1\"         if /^command=.*gitolite-shell (.*?)\"/;\n    $user ||= \"unknown command\" if /^command/;\n    $user ||= \"shell access\"    if /$KEYTYPE_REGEX/;\n\n    return $user;\n}\n\nsub ak_comment {\n    local $_ = shift;\n    $in_gl_section = 1 if /^# gitolite start/;\n    $in_gl_section = 0 if /^# gitolite end/;\n    die \"gitosis?  what's that?\\n\" if /^#.*gitosis/;\n    return /^\\s*(#|$)/;\n}\n\nsub fprint {\n    local $_ = shift;\n    my ($fp, $output);\n    if ( /$KEYTYPE_REGEX/ ) {\n        # an actual key was passed. ssh-keygen CAN correctly handle options on\n        # the front of the key, so don't bother to strip them at all.\n        ($fp, $output) = ssh_fingerprint_line($_);\n    } else {\n        # a filename was passed\n        ($fp, $output) = ssh_fingerprint_file($_);\n        # include the line of input as well, as it won't always be included by the ssh-keygen command\n        warn \"Bad line: $_\\n\" unless $fp;\n    }\n    # sshkeys-lint should only be run by a trusted admin, so we can give the output here.\n    warn \"$output\\n\" unless $fp;\n    return $fp;\n}\n\n# ------------------------------------------------------------------------\n=for usage\n\nUsage:  gitolite sshkeys-lint [-q] [optional list of pubkey filenames]\n        (optionally, STDIN can be a pipe or redirected from a file; see below)\n\nLook for potential problems in ssh keys.\n\nsshkeys-lint expects:\n  - the contents of an authorized_keys file via STDIN, otherwise it uses\n    \\$HOME/.ssh/authorized_keys\n  - one or more pubkey filenames as arguments, otherwise it uses all the keys\n    found (recursively) in \\$HOME/.gitolite/keydir\n\nThe '-q' option will print only warnings instead of all mappings.\n\nNote that this runs ssh-keygen -l for each line in the authkeys file and each\npubkey in the argument list, so be wary of running it on something huge.  This\nis meant for troubleshooting.\n\n=cut\n"
  },
  {
    "path": "src/commands/sskm",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Rc;\nuse Gitolite::Common;\n\n=for usage\nUsage for this command is not that simple.  Please read the full documentation\nin doc/sskm.mkd or online at http://gitolite.com/gitolite/contrib/sskm.html.\n=cut\n\nusage() if @ARGV and $ARGV[0] eq '-h';\n\nmy $rb = $rc{GL_REPO_BASE};\nmy $ab = $rc{GL_ADMIN_BASE};\n# get to the keydir\n_chdir(\"$ab/keydir\");\n\n# save arguments for later\nmy $operation = shift || 'list';\nmy $keyid     = shift || '';\n# keyid must fit a very specific pattern\n$keyid and $keyid !~ /^@[-0-9a-z_]+$/i and die \"invalid keyid $keyid\\n\";\n\n# get the actual userid and keytype\nmy $gl_user = $ENV{GL_USER};\nmy $keytype = '';\n$keytype = $1 if $gl_user =~ s/^zzz-marked-for-(...)-//;\nprint STDERR \"hello $gl_user, you are currently using \"\n  . (\n    $keytype\n    ? \"a key in the 'marked for $keytype' state\\n\"\n    : \"a normal (\\\"active\\\") key\\n\"\n  );\n\n# ----\n# first collect the keys\n\nmy ( @pubkeys, @marked_for_add, @marked_for_del );\n# get the list of pubkey files for this user, including pubkeys marked for\n# add/delete\n\nfor my $pubkey (`find . -type f -name \"*.pub\" | sort`) {\n    chomp($pubkey);\n    $pubkey =~ s(^./)();    # artifact of the find command\n\n    my $user = $pubkey;\n    $user =~ s(.*/)();                # foo/bar/baz.pub -> baz.pub\n    $user =~ s/(\\@[^.]+)?\\.pub$//;    # baz.pub, baz@home.pub -> baz\n\n    next unless $user eq $gl_user or $user =~ /^zzz-marked-for-...-$gl_user/;\n\n    if ( $user =~ m(^zzz-marked-for-add-) ) {\n        push @marked_for_add, $pubkey;\n    } elsif ( $user =~ m(^zzz-marked-for-del-) ) {\n        push @marked_for_del, $pubkey;\n    } else {\n        push @pubkeys, $pubkey;\n    }\n}\n\n# ----\n# list mode; just do it and exit\nsub print_keylist {\n    my ( $message, @list ) = @_;\n    return unless @list;\n    print \"== $message ==\\n\";\n    my $count = 1;\n    for (@list) {\n        my $fp = fingerprint($_);\n        s/zzz-marked(\\/|-for-...-)//g;\n        print $count++ . \": $fp : $_\\n\";\n    }\n}\nif ( $operation eq 'list' ) {\n    print \"you have the following keys:\\n\";\n    print_keylist( \"active keys\",                          @pubkeys );\n    print_keylist( \"keys marked for addition/replacement\", @marked_for_add );\n    print_keylist( \"keys marked for deletion\",             @marked_for_del );\n    print \"\\n\\n\";\n    exit;\n}\n\n# ----\n# please see docs for details on how a user interacts with this\n\nif ( $keytype eq '' ) {\n    # user logging in with a normal key\n    die \"valid operations: add, del, undo-add, confirm-del\\n\" unless $operation =~ /^(add|del|confirm-del|undo-add)$/;\n    if ( $operation eq 'add' ) {\n        print STDERR \"please supply the new key on STDIN.  (I recommend you\n        don't try to do this interactively, but use a pipe)\\n\";\n        kf_add( $gl_user, $keyid, safe_stdin() );\n    } elsif ( $operation eq 'del' ) {\n        kf_del( $gl_user, $keyid );\n    } elsif ( $operation eq 'confirm-del' ) {\n        die \"you dont have any keys marked for deletion\\n\" unless @marked_for_del;\n        kf_confirm_del( $gl_user, $keyid );\n    } elsif ( $operation eq 'undo-add' ) {\n        die \"you dont have any keys marked for addition\\n\" unless @marked_for_add;\n        kf_undo_add( $gl_user, $keyid );\n    }\n} elsif ( $keytype eq 'del' ) {\n    # user is using a key that was marked for deletion.  The only possible use\n    # for this is that she changed her mind for some reason (maybe she marked\n    # the wrong key for deletion) or is not able to get her client-side sshd\n    # to stop using this key\n    die \"valid operations: undo-del\\n\" unless $operation eq 'undo-del';\n\n    # reinstate the key\n    kf_undo_del( $gl_user, $keyid );\n} elsif ( $keytype eq 'add' ) {\n    die \"valid operations: confirm-add\\n\" unless $operation eq 'confirm-add';\n    # user is trying to validate a key that has been previously marked for\n    # addition.  This isn't interactive, but it *could* be... if someone asked\n    kf_confirm_add( $gl_user, $keyid );\n}\n\nexit;\n\n# ----\n\n# make a temp clone and switch to it\nour $TEMPDIR;\nBEGIN { $TEMPDIR = `mktemp -d -t tmp.XXXXXXXXXX`; }\nEND { `/bin/rm -rf $TEMPDIR`; }\n\nsub cd_temp_clone {\n    chomp($TEMPDIR);\n    hushed_git( \"clone\", \"$rb/gitolite-admin.git\", \"$TEMPDIR\" );\n    chdir($TEMPDIR);\n    my $hostname = `hostname`; chomp($hostname);\n    hushed_git( \"config\", \"--get\", \"user.email\" ) and hushed_git( \"config\", \"user.email\", $ENV{USER} . \"@\" . $hostname );\n    hushed_git( \"config\", \"--get\", \"user.name\" )  and hushed_git( \"config\", \"user.name\",  \"$ENV{USER} on $hostname\" );\n}\n\nsub fingerprint {\n    my ($fp, $output) = ssh_fingerprint_file(shift);\n    # Do not print the output of $output to an untrusted destination.\n    die \"does not seem to be a valid pubkey\\n\" unless $fp;\n    return $fp;\n}\n\nsub safe_stdin {\n    # read one line from STDIN\n    my $data;\n    my $ret = read STDIN, $data, 4096;\n    # current pubkeys are approx 400 bytes so we go a little overboard\n    die \"could not read pubkey data\" . ( defined($ret) ? \"\" : \": $!\" ) . \"\\n\" unless $ret;\n    die \"pubkey data seems to have more than one line\\n\" if $data =~ /\\n./;\n    return $data;\n}\n\nsub hushed_git {\n    local (*STDOUT) = \\*STDOUT;\n    local (*STDERR) = \\*STDERR;\n    open( STDOUT, \">\", \"/dev/null\" );\n    open( STDERR, \">\", \"/dev/null\" );\n    system( \"git\", @_ );\n}\n\nsub highlander {\n    # there can be only one\n    my ( $keyid, $die_if_empty, @a ) = @_;\n    # too many?\n    if ( @a > 1 ) {\n        print STDERR \"\nmore than one key satisfies this condition, and I can't deal with that!\nThe keys are:\n\n\";\n        print STDERR \"\\t\" . join( \"\\n\\t\", @a ), \"\\n\\n\";\n        exit 1;\n    }\n    # too few?\n    die \"no keys with \" . ( $keyid || \"empty\" ) . \" keyid found\\n\" if $die_if_empty and not @a;\n\n    return @a;\n}\n\nsub kf_add {\n    my ( $gl_user, $keyid, $keymaterial ) = @_;\n\n    # add a new \"marked for addition\" key for $gl_user.\n    cd_temp_clone();\n    chdir(\"keydir\");\n\n    mkdir(\"zzz-marked\");\n    _print( \"zzz-marked/zzz-marked-for-add-$gl_user$keyid.pub\", $keymaterial );\n    hushed_git( \"add\", \".\" ) and die \"git add failed\\n\";\n    my $fp = fingerprint(\"zzz-marked/zzz-marked-for-add-$gl_user$keyid.pub\");\n    hushed_git( \"commit\", \"-m\", \"sskm: add $gl_user$keyid ($fp)\" ) and die \"git commit failed\\n\";\n    system(\"gitolite push >/dev/null 2>/dev/null\") and die \"git push failed\\n\";\n}\n\nsub kf_confirm_add {\n    my ( $gl_user, $keyid ) = @_;\n    # find entries in both @pubkeys and @marked_for_add whose basename matches $gl_user$keyid\n    my @pk  = highlander( $keyid, 0, grep { m(^(.*/)?$gl_user$keyid.pub$) } @pubkeys );\n    my @mfa = highlander( $keyid, 1, grep { m(^zzz-marked/zzz-marked-for-add-$gl_user$keyid.pub$) } @marked_for_add );\n\n    cd_temp_clone();\n    chdir(\"keydir\");\n\n    my $fp = fingerprint( $mfa[0] );\n    if ( $pk[0] ) {\n        hushed_git( \"mv\", \"-f\", $mfa[0], $pk[0] );\n        hushed_git( \"commit\", \"-m\", \"sskm: confirm-add (replace) $pk[0] ($fp)\" ) and die \"git commit failed\\n\";\n    } else {\n        hushed_git( \"mv\", \"-f\", $mfa[0], \"$gl_user$keyid.pub\" );\n        hushed_git( \"commit\", \"-m\", \"sskm: confirm-add $gl_user$keyid ($fp)\" ) and die \"git commit failed\\n\";\n    }\n    system(\"gitolite push >/dev/null 2>/dev/null\") and die \"git push failed\\n\";\n}\n\nsub kf_undo_add {\n    # XXX some code at start is shared with kf_confirm_add\n    my ( $gl_user, $keyid ) = @_;\n    my @mfa = highlander( $keyid, 1, grep { m(^zzz-marked/zzz-marked-for-add-$gl_user$keyid.pub$) } @marked_for_add );\n\n    cd_temp_clone();\n    chdir(\"keydir\");\n\n    my $fp = fingerprint( $mfa[0] );\n    hushed_git( \"rm\", $mfa[0] );\n    hushed_git( \"commit\", \"-m\", \"sskm: undo-add $gl_user$keyid ($fp)\" ) and die \"git commit failed\\n\";\n    system(\"gitolite push >/dev/null 2>/dev/null\") and die \"git push failed\\n\";\n}\n\nsub kf_del {\n    my ( $gl_user, $keyid ) = @_;\n\n    cd_temp_clone();\n    chdir(\"keydir\");\n\n    mkdir(\"zzz-marked\");\n    my @pk = highlander( $keyid, 1, grep { m(^(.*/)?$gl_user$keyid.pub$) } @pubkeys );\n\n    my $fp = fingerprint( $pk[0] );\n    hushed_git( \"mv\", $pk[0], \"zzz-marked/zzz-marked-for-del-$gl_user$keyid.pub\" ) and die \"git mv failed\\n\";\n    hushed_git( \"commit\", \"-m\", \"sskm: del $pk[0] ($fp)\" ) and die \"git commit failed\\n\";\n    system(\"gitolite push >/dev/null 2>/dev/null\") and die \"git push failed\\n\";\n}\n\nsub kf_confirm_del {\n    my ( $gl_user, $keyid ) = @_;\n    my @mfd = highlander( $keyid, 1, grep { m(^zzz-marked/zzz-marked-for-del-$gl_user$keyid.pub$) } @marked_for_del );\n\n    cd_temp_clone();\n    chdir(\"keydir\");\n\n    my $fp = fingerprint( $mfd[0] );\n    hushed_git( \"rm\", $mfd[0] );\n    hushed_git( \"commit\", \"-m\", \"sskm: confirm-del $gl_user$keyid ($fp)\" ) and die \"git commit failed\\n\";\n    system(\"gitolite push >/dev/null 2>/dev/null\") and die \"git push failed\\n\";\n}\n\nsub kf_undo_del {\n    my ( $gl_user, $keyid ) = @_;\n\n    my @mfd = highlander( $keyid, 1, grep { m(^zzz-marked/zzz-marked-for-del-$gl_user$keyid.pub$) } @marked_for_del );\n\n    print STDERR \"\nYou're undeleting a key that is currently marked for deletion.\n    Hit ENTER to undelete this key\n    Hit Ctrl-C to cancel the undelete\nPlease see documentation for caveats on the undelete process as well as how to\nactually delete it.\n\";\n    <>;    # yeay... always wanted to do that -- throw away user input!\n\n    cd_temp_clone();\n    chdir(\"keydir\");\n\n    my $fp = fingerprint( $mfd[0] );\n    hushed_git( \"mv\", \"-f\", $mfd[0], \"$gl_user$keyid.pub\" );\n    hushed_git( \"commit\", \"-m\", \"sskm: undo-del $gl_user$keyid ($fp)\" ) and die \"git commit failed\\n\";\n    system(\"gitolite push >/dev/null 2>/dev/null\") and die \"git push failed\\n\";\n}\n"
  },
  {
    "path": "src/commands/sudo",
    "content": "#!/bin/sh\n\n# Usage:    ssh git@host sudo <user> <command> <arguments>\n#\n# Let super-user run commands as any other user.  \"Super-user\" is defined as\n# \"have write access to the gitolite-admin repo\".\n\ndie() { echo \"$@\" >&2; exit 1; }\nusage() { perl -lne 'print substr($_, 2) if /^# Usage/../^$/' < $0; exit 1; }\n[ -z \"$2\" ] && usage\n[ \"$1\" = \"-h\" ] && usage\n[ -z \"$GL_USER\" ] && die GL_USER not set\n\ngitolite access -q gitolite-admin $GL_USER W any || die \"You are not authorised\"\n\nuser=\"$1\"; shift\ncmd=\"$1\"; shift\n\n# switch user\nGL_USER=\"$user\"\n\n# figure out if the command is allowed from a remote user\ngitolite query-rc -q COMMANDS $cmd || die \"Command '$cmd' not allowed\"\ngitolite $cmd \"$@\"\n"
  },
  {
    "path": "src/commands/svnserve",
    "content": "#!/usr/bin/perl\n\nuse strict;\nuse warnings;\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Rc;\nmy $svnserve = $rc{SVNSERVE} || '';\n$svnserve ||= \"/usr/bin/svnserve -r /var/svn/ -t --tunnel-user=%u\";\n\nmy $cmd = $ENV{SSH_ORIGINAL_COMMAND};\n\ndie \"expecting 'svnserve -t', got '$cmd'\\n\" unless $cmd eq 'svnserve -t';\n\n$svnserve =~ s/%u/$ENV{GL_USER}/g;\nexec $svnserve;\ndie \"svnserve exec failed\\n\";\n"
  },
  {
    "path": "src/commands/symbolic-ref",
    "content": "#!/bin/sh\n\n# Usage:    ssh git@host symbolic-ref <repo> <arguments to git-symbolic-ref>\n#\n# allow 'git symbolic-ref' over a gitolite connection\n\n# Security: remember all arguments to commands must match a very conservative\n# pattern.  Once that is assured, the symbolic-ref command has no security\n# related side-effects, so we don't check arguments at all.\n\n# Note: because of the restriction on allowed characters in arguments, you\n# can't supply an arbitrary string to the '-m' option.  The simplest\n# work-around is-to-just-use-join-up-words-like-this if you feel the need to\n# supply a \"reason\" string.  In any case this is useless by default; you'd\n# have to have core.logAllRefUpdates set for it to have any meaning.\n\ndie() { echo \"$@\" >&2; exit 1; }\nusage() { perl -lne 'print substr($_, 2) if /^# Usage/../^$/' < $0; exit 1; }\n[ -z \"$1\" ] && usage\n[ \"$1\" = \"-h\" ] && usage\n[ -z \"$GL_USER\" ] && die GL_USER not set\n\n# ----------------------------------------------------------------------\nrepo=$1; shift\nrepo=${repo%.git}\ngitolite access -q \"$repo\" $GL_USER W any || die You are not authorised\n\n# change head\ncd $GL_REPO_BASE/$repo.git\n\ngit symbolic-ref \"$@\"\n"
  },
  {
    "path": "src/commands/who-pushed",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Easy;\n\nusage() if not @ARGV;\nusage($ARGV[1]) if $ARGV[1] and $ARGV[1] =~ /^[\\w-]+$/ and $ARGV[0] eq '-h';\n\n( my $logdir = $ENV{GL_LOGFILE} ) =~ s(/[^/]+$)();\n\n# deal with migrate\nmy %gl_log_lines_buffer;\nmy $countr = 0;\nmy $countl = 0;\nmigrate(@ARGV) if $ARGV[0] eq '--migrate';   # won't return; exits right there\n\n# tip search?\nmy $tip_search = 0;\nif ($ARGV[0] eq '--tip') {\n    shift;\n    $tip_search = 1;\n}\n\n# the normal who-pushed\nusage() if @ARGV < 2 or $ARGV[0] eq '-h';\nusage() if $ARGV[1] !~ /^[0-9a-f]+$/i;\n\nmy $repo = shift;\nmy $sha = shift; $sha =~ tr/A-F/a-f/;\n\n$ENV{GL_USER} and ( can_read($repo) or die \"no read permissions on '$repo'\" );\n\n# ----------------------------------------------------------------------\n\nmy $repodir = \"$ENV{GL_REPO_BASE}/$repo.git\";\nchdir $repodir or die \"repo '$repo' missing\";\n\nmy @logfiles = reverse glob(\"$logdir/*\");\n@logfiles = ( \"$repodir/gl-log\" ) if -f \"$repodir/gl-log\";\n\nfor my $logfile ( @logfiles ) {\n    @ARGV = ($logfile);\n    for my $line ( reverse grep { m(\\tupdate\\t($repo|$repodir)\\t) } <> ) {\n        chomp($line);\n        my @fields = split /\\t/, $line;\n        my ( $ts, $pid, $who, $ref, $d_old, $new ) = @fields[ 0, 1, 4, 6, 7, 8 ];\n\n        # d_old is what you display\n        my $old = $d_old;\n        $old = \"\"       if $d_old eq ( \"0\" x 40 );\n        $old = \"$old..\" if $old;\n\n        if ($tip_search) {\n            print \"$ts $pid $who $ref $d_old $new\\n\" if $new =~ /^$sha/;\n        } else {\n            system(\"git rev-list $old$new 2>/dev/null | grep ^$sha >/dev/null && echo '$ts $pid $who $ref $d_old $new'\");\n        }\n    }\n}\n\n# ----------------------------------------------------------------------\n# migration\n\nsub migrate {\n    chdir $ENV{GL_REPO_BASE};\n    my @repos = `gitolite list-phy-repos`; chomp @repos;\n\n    my $count = scalar( grep { -f \"$_.git/gl-log\" } @repos );\n    if ( $count and ( $_[1] || '' ) ne '--force' ) {\n        say2 \"$count repo(s) already have gl-log files.  To confirm overwriting, please re-run as:\";\n        say2 \"\\tgitolite who-pushed --migrate --force\";\n        say2 \"see help ('-h', '-h logfiles', or '-h migrate') for details.\";\n        exit 1;\n    }\n\n    foreach my $r (@repos) {\n        _print(\"$r.git/gl-log\", '');\n    }\n\n    my %repo_exists = map { $_ => 1 } @repos;\n    @ARGV = sort ( glob(\"$logdir/*\") );\n    while (<>) {\n        say2 \"processed '$ARGV'\" if eof(ARGV);\n        next unless /\\tupdate\\t/;\n        my @f = split /\\t/;\n        my $repo = $f[3];\n        if ($repo =~ m(^/)) {\n            $repo =~ s/^$ENV{GL_REPO_BASE}\\///;\n            $repo =~ s/\\.git$//;\n        }\n\n        gen_gl_log($repo, $_) if $repo_exists{$repo};\n    }\n    flush_gl_log();\n\n    exit 0;\n}\nsub gen_gl_log {\n    my ($repo, $l) = @_;\n\n    $countr++ unless $gl_log_lines_buffer{$repo};    # new repo, not yet seen\n    $countl++;\n    $gl_log_lines_buffer{$repo} .= $l;\n\n    # once we have buffered log lines for about 100 repos, or about 10,000 log\n    # lines, we flush them\n    flush_gl_log() if $countr >= 100 or $countl >= 10_000;\n}\nsub flush_gl_log {\n    while (my ($r, $l) = each %gl_log_lines_buffer) {\n        open my $fh, \">>\", \"$r.git/gl-log\" or _die \"open flush_gl_log failed: $!\";\n        print $fh $l;\n        close $fh;\n    }\n    %gl_log_lines_buffer = ();\n    say2 \"flushed $countl lines to $countr repos...\";\n    $countr = $countl = 0;\n}\n\n__END__\n\n=for usage\nusage:    ssh git@host who-pushed [--tip] <repo> <SHA>\n\nDetermine who pushed the given commit.  The first few hex digits of the SHA\nshould suffice.  If the '--tip' option is supplied, it'll only look for the\nSHA among \"tip\" commits (i.e., search the \"new SHA\"s, without running the\nexpensive 'git rev-parse' for each push).\n\nEach line of the output contains the following fields: timestamp, a\ntransaction ID, username, refname, and the old and new SHAs for the ref.\n\nNote on the \"transaction ID\" field: if looking at the log file doesn't help\nyou figure out what its purpose is, please just ignore it.\n\nTO SEE ADDITIONAL HELP, run with options \"-h logfiles\" or \"-h migrate\".\n=cut\n\n=for logfiles\nThere are 2 places that gitolite logs to, based on the value give to the\nLOG_DEST rc variable.  By default, log files go to ~/.gitolite/logs, but you\ncan choose to send them to syslog instead (in which case 'who-pushed' will not\nwork), or to both syslog and the normal log files.\n\nIn addition, gitolite can also be told to log just the \"update\" records to a\nspecial \"gl-log\" file in the bare repo directory.  This makes 'who-pushed'\n**much** faster (thanks to milki for the problem *and* the simple solution).\n\n'who-pushed' will look for that special file first and use only that if it is\nfound.  Otherwise it will look in the normal gitolite log files, which will of\ncourse be much slower.\n=cut\n\n=for migrate\nIf you installed gitolite before v3.6.4, and you wish to use the new, more\nefficient logging that helps who-pushed run faster, you should first update\nthe rc file (see http://gitolite.com/gitolite/rc.html for notes on that) to\nspecify a suitable value for LOG_DEST.\n\nAfter that you should probably do a one-time generation of the repo-specific\n'gl-log' files from the normal log files.  This can only be done from the\nserver command line, even if the 'who-pushed' command has been enabled for\nremote access.\n\nTo do this, just run 'gitolite who-pushed --migrate'.  If some of your repos\nalready had gl-log files, it will warn you, and tell you how to override.\nYou're only supposed to to use this *once* after upgrading to v3.6.4 and\nsetting LOG_DEST in the rc file anyway.\n=cut\n\n"
  },
  {
    "path": "src/commands/writable",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Easy;\n\n=for usage\nUsage: gitolite writable <reponame>|@all on|off|status\n\nDisable/re-enable pushes to all repos or named repo.  Useful to run\nnon-git-aware backups and so on.\n\n'on' enables, 'off' disables, writes (pushes) to the named repo or all repos.\n'status' returns the current status as shell truth (i.e., exit code 0 for\nwritable, 1 for not writable).\n\nWith 'off', any subsequent text is taken to be the message to be shown to\nusers when their pushes get rejected.  If it is not supplied, it will take it\nfrom STDIN; this allows longer messages.\n=cut\n\nusage() if not @ARGV or @ARGV < 2 or $ARGV[0] eq '-h';\nusage() if $ARGV[1] ne 'on' and $ARGV[1] ne 'off' and $ARGV[1] ne 'status';\n\nmy $repo = shift;\nmy $op   = shift;    # on|off|status\n\nif ( $repo eq '@all' ) {\n    _die \"you are not authorized\" if $ENV{GL_USER} and not is_admin();\n} else {\n    _die \"you are not authorized\" if $ENV{GL_USER} and not( owns($repo) or is_admin() or ( can_write($repo) and $op eq 'status' ) );\n}\n\nmy $msg = join( \" \", @ARGV );\n# try STDIN only if no msg found in args *and* it's an 'off' command\nif ( not $msg and $op eq 'off' ) {\n    say2 \"...please type the message to be shown to users:\";\n    $msg = join( \"\", <> );\n}\n\nmy $sf = \".gitolite.down\";\nmy $rb = $ENV{GL_REPO_BASE};\n\nif ( $repo eq '@all' ) {\n    target( $ENV{HOME} );\n} else {\n    target(\"$rb/$repo.git\");\n    target( $ENV{HOME} ) if $op eq 'status';\n}\n\nexit 0;\n\nsub target {\n    my $repodir = shift;\n    if ( $op eq 'status' ) {\n        exit 1 if -e \"$repodir/$sf\";\n    } elsif ( $op eq 'on' ) {\n        unlink \"$repodir/$sf\";\n    } elsif ( $op eq 'off' ) {\n        _print( \"$repodir/$sf\", $msg );\n    }\n}\n"
  },
  {
    "path": "src/gitolite",
    "content": "#!/usr/bin/perl\n\n# all gitolite CLI tools run as sub-commands of this command\n# ----------------------------------------------------------------------\n\n=for args\nUsage:  gitolite [sub-command] [options]\n\nThe following built-in subcommands are available; they should all respond to\n'-h' if you want further details on each:\n\n    setup                       1st run: initial setup; all runs: hook fixups\n    compile                     compile gitolite.conf\n\n    query-rc                    get values of rc variables\n\n    list-groups                 list all group names in conf\n    list-users                  list all users/user groups in conf\n    list-repos                  list all repos/repo groups in conf\n    list-phy-repos              list all repos actually on disk\n    list-memberships            list all groups a name is a member of\n    list-members                list all members of a group\n\nIn addition, running 'gitolite help' should give you a list of custom commands\navailable.  They may or may not respond to '-h', depending on how they were\nwritten, but it's worth a try, at least the first time you use a command.\n=cut\n\n# ----------------------------------------------------------------------\n\nuse FindBin;\n\nBEGIN { $ENV{GL_BINDIR} = $FindBin::RealBin; }\nBEGIN { $ENV{GL_LIBDIR} = \"$ENV{GL_BINDIR}/lib\"; }\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Rc;\nuse Gitolite::Common;\n\nuse strict;\nuse warnings;\n\n# ----------------------------------------------------------------------\n\nmy ( $command, @args ) = @ARGV;\ngl_log( 'cli', 'gitolite', @ARGV ) if -d $rc{GL_ADMIN_BASE} and $$ == ( $ENV{GL_TID} || 0 );\nargs();\n\n# the first two commands need options via @ARGV, as they have their own\n# GetOptions calls and older perls don't have 'GetOptionsFromArray'\n\nif ( $command eq 'setup' ) {\n    shift @ARGV;\n    require Gitolite::Setup;\n    Gitolite::Setup->import;\n    setup();\n\n} elsif ( $command eq 'query-rc' ) {\n    shift @ARGV;\n    query_rc();    # doesn't return\n\n# the rest don't need @ARGV per se\n\n} elsif ( $command eq 'compile' ) {\n    require Gitolite::Conf;\n    Gitolite::Conf->import;\n    compile(@args);\n\n} elsif ( $command eq 'trigger' ) {\n    my $s = $args[0];\n    _die \"trigger section '$s' not found in rc\"\n        unless  $s eq 'POST_COMPILE'\n             or $s eq 'POST_CREATE'\n             or ( exists $rc{$s} and ref( $rc{$s} ) eq 'ARRAY' );\n    trigger(@args);\n\n} elsif ( my $c = _which( \"commands/$command\", 'x' ) ) {\n    trace( 2, \"attempting gitolite command $c\" );\n    _system( $c, @args );\n\n} elsif ( $command eq 'list-phy-repos' ) {\n    _chdir( $rc{GL_REPO_BASE} );\n    print \"$_\\n\" for ( @{ list_phy_repos(@args) } );\n\n} elsif ( $command =~ /^list-/ ) {\n    trace( 2, \"attempting lister command $command\" );\n    require Gitolite::Conf::Load;\n    Gitolite::Conf::Load->import;\n    my $fn = lister_dispatch($command);\n    print \"$_\\n\" for ( @{ $fn->(@args) } );\n\n} else {\n    _die \"unknown gitolite sub-command\";\n}\n\ngl_log('END') if $$ == $ENV{GL_TID};\n\nexit 0;\n\nsub args {\n    usage() if not $command or $command eq '-h';\n}\n\n# ----------------------------------------------------------------------\n"
  },
  {
    "path": "src/gitolite-shell",
    "content": "#!/usr/bin/perl\n\n# gitolite shell, invoked from ~/.ssh/authorized_keys\n# ----------------------------------------------------------------------\n\nuse FindBin;\n\nBEGIN { $ENV{GL_BINDIR} = $FindBin::RealBin; }\nBEGIN { $ENV{GL_LIBDIR} = \"$ENV{GL_BINDIR}/lib\"; }\nuse lib $ENV{GL_LIBDIR};\n\n# set HOME\nBEGIN { $ENV{HOME} = $ENV{GITOLITE_HTTP_HOME} if $ENV{GITOLITE_HTTP_HOME}; }\n\nuse Gitolite::Rc;\nuse Gitolite::Common;\nuse Gitolite::Conf::Load;\n\nuse strict;\nuse warnings;\n\n# the main() sub expects ssh-ish things; set them up...\nmy $id = '';\nif ( exists $ENV{G3T_USER} ) {\n    $id = in_file();    # file:// masquerading as ssh:// for easy testing\n} elsif ( exists $ENV{SSH_CONNECTION} ) {\n    $id = in_ssh();\n} elsif ( exists $ENV{REQUEST_URI} ) {\n    $id = in_http();\n} else {\n    _die \"who the *heck* are you?\";\n}\n\n# sanity...\nmy $soc = $ENV{SSH_ORIGINAL_COMMAND};\n$soc =~ s/[\\n\\r]+/<<newline>>/g;\n_die \"I don't like newlines in the command: '$soc'\\n\" if $ENV{SSH_ORIGINAL_COMMAND} ne $soc;\n\n# allow gitolite-shell to be used as \"$SHELL\".  Experts only; no support, no docs\nif (@ARGV and $ARGV[0] eq '-c') {\n    shift;\n    $ARGV[0] =~ s/^$0 // or _die \"unknown git/gitolite command: '$ARGV[0]'\";\n}\n\n# the INPUT trigger massages @ARGV and $ENV{SSH_ORIGINAL_COMMAND} as needed\ntrigger('INPUT');\n\nmain($id);\n\ngl_log('END') if $$ == $ENV{GL_TID};\n\nexit 0;\n\n# ----------------------------------------------------------------------\n\nsub in_file {\n    gl_log( 'file', \"ARGV=\" . join( \",\", @ARGV ), \"SOC=$ENV{SSH_ORIGINAL_COMMAND}\" );\n\n    if ( $ENV{SSH_ORIGINAL_COMMAND} =~ /git-\\w+-pack/ ) {\n        print STDERR \"TRACE: gsh(\", join( \")(\", @ARGV ), \")\\n\";\n        print STDERR \"TRACE: gsh(SOC=$ENV{SSH_ORIGINAL_COMMAND})\\n\";\n    }\n    return 'file';\n}\n\nsub in_http {\n    http_setup_die_handler();\n\n    _die \"GITOLITE_HTTP_HOME not set\" unless $ENV{GITOLITE_HTTP_HOME};\n\n    _die \"fallback to DAV not supported\" if $ENV{REQUEST_METHOD} eq 'PROPFIND';\n\n    # fake out SSH_ORIGINAL_COMMAND and SSH_CONNECTION when called via http,\n    # so the rest of the code stays the same (except the exec at the end).\n    http_simulate_ssh_connection();\n    $ENV{SSH_ORIGINAL_COMMAND} ||= '';\n\n    $ENV{REMOTE_USER} ||= $rc{HTTP_ANON_USER};\n    @ARGV = ( $ENV{REMOTE_USER} );\n\n    my $ip;\n    ( $ip = $ENV{SSH_CONNECTION} || '(no-IP)' ) =~ s/ .*//;\n\n    gl_log( 'http', \"ARGV=\" . join( \",\", @ARGV ), \"SOC=\" . ( $ENV{SSH_ORIGINAL_COMMAND} || '' ), \"FROM=$ip\" );\n\n    return 'http';\n}\n\nsub in_ssh {\n    my $ip;\n    ( $ip = $ENV{SSH_CONNECTION} || '(no-IP)' ) =~ s/ .*//;\n\n    gl_log( 'ssh', \"ARGV=\" . join( \",\", @ARGV ), \"SOC=\" . ( $ENV{SSH_ORIGINAL_COMMAND} || '' ), \"FROM=$ip\" );\n\n    $ENV{SSH_ORIGINAL_COMMAND} ||= '';\n\n    return $ip;\n}\n\n# ----------------------------------------------------------------------\n\n# call this once you are sure arg-1 is the username and SSH_ORIGINAL_COMMAND\n# has been setup (even if it's not actually coming via ssh).\nsub main {\n    my $id = shift;\n\n    # set up the user\n    my $user = $ENV{GL_USER} = shift @ARGV;\n\n    # set up the repo and the attempted access\n    my ( $verb, $repo ) = parse_soc();    # returns only for git commands\n    Gitolite::Conf::Load::sanity($repo, $REPONAME_PATT);\n    $ENV{GL_REPO} = $repo;\n    my $aa = ( $verb =~ 'upload' ? 'R' : 'W' );\n\n    # set up env vars from options set for this repo\n    env_options($repo);\n\n    # auto-create?\n    if ( repo_missing($repo) and access( $repo, $user, '^C', 'any' ) !~ /DENIED/ ) {\n        require Gitolite::Conf::Store;\n        Gitolite::Conf::Store->import;\n        new_wild_repo( $repo, $user, $aa );\n        gl_log( 'create', $repo, $user, $aa );\n    }\n\n    # a ref of 'any' signifies that this is a pre-git check, where we don't\n    # yet know the ref that will be eventually pushed (and even that won't\n    # apply if it's a read operation).  See the matching code in access() for\n    # more information.\n    unless ( $ENV{GL_BYPASS_ACCESS_CHECKS} ) {\n        my $ret = access( $repo, $user, $aa, 'any' );\n        trigger( 'ACCESS_1', $repo, $user, $aa, 'any', $ret );\n        _die $ret . \"\\n(or you mis-spelled the reponame)\" if $ret =~ /DENIED/;\n\n        gl_log( \"pre_git\", $repo, $user, $aa, 'any', $ret );\n    }\n\n    trigger( 'PRE_GIT', $repo, $user, $aa, 'any', $verb );\n    if ( $ENV{REQUEST_URI} ) {\n        _system( \"git\", \"http-backend\" );\n    } else {\n        my $repodir = \"'$rc{GL_REPO_BASE}/$repo.git'\";\n        _system( \"git\", \"shell\", \"-c\", \"$verb $repodir\" );\n    }\n    trigger( 'POST_GIT', $repo, $user, $aa, 'any', $verb );\n}\n\n# ----------------------------------------------------------------------\n\nsub parse_soc {\n    my $soc = $ENV{SSH_ORIGINAL_COMMAND};\n    $soc ||= 'info';\n\n    my $git_commands = \"git-upload-pack|git-receive-pack|git-upload-archive\";\n    # simplify the regex; we'll handle all the reponame nuances later\n    if ( $soc =~ m(^($git_commands) '?/?(.*?)'?$) ) {\n        my ( $verb, $repo ) = ( $1, $2 );\n        trace( 2, \"git command\", $soc );\n\n        # clean up the repo name; first extract the trace level if supplied\n        # (and no, you can't have a trace level *and* a trailing slash).\n        $ENV{D} = $1 if $repo =~ s/\\.git(\\d)$//;\n        # and then the git-daemon-compatibility trailers\n        $repo =~ s(/$)();\n        $repo =~ s(\\.git$)();\n\n        _die \"invalid repo name: '$repo'\" if $repo !~ $REPONAME_PATT;\n        return ( $verb, $repo );\n    }\n\n    # after this we should not return; caller expects us to handle it all here\n    # and exit out\n\n    my @words = split ' ', $soc;\n    if ( $rc{COMMANDS}{ $words[0] } ) {\n        if ( $rc{COMMANDS}{ $words[0] } ne 'ua' ) {\n            _die \"suspicious characters loitering about '$soc'\" if $soc !~ $REMOTE_COMMAND_PATT;\n            _die \"no relative paths allowed anywhere!\" if $soc =~ m(\\.\\./);\n        }\n        trace( 2, \"gitolite command\", $soc );\n        _system( \"gitolite\", @words );\n        exit 0;\n    }\n\n    _die \"unknown git/gitolite command: '$soc'\";\n}\n\n# ----------------------------------------------------------------------\n# helper functions for \"in_http\"\n\nsub http_setup_die_handler {\n\n    $SIG{__DIE__} = sub {\n        my $service = ( $ENV{SSH_ORIGINAL_COMMAND} =~ /git-receive-pack/ ? 'git-receive-pack' : 'git-upload-pack' );\n        my $message = shift; chomp($message);\n        print STDERR \"$message\\n\";\n\n        http_print_headers($service);\n\n        # format the service response, then the message.  With initial\n        # help from Ilari and then a more detailed email from Shawn...\n        $service = \"# service=$service\\n\"; $message = \"ERR $message\\n\";\n        $service = sprintf( \"%04X\", length($service) + 4 ) . \"$service\";    # no CRLF on this one\n        $message = sprintf( \"%04X\", length($message) + 4 ) . \"$message\";\n\n        print $service;\n        print \"0000\";                                                       # flush-pkt, apparently\n        print $message;\n        print STDERR $service;\n        print STDERR $message;\n        exit 0;                                                             # if it's ok for die_webcgi in git.git/http-backend.c, it's ok for me ;-)\n      }\n}\n\nsub http_simulate_ssh_connection {\n    # these patterns indicate normal git usage; see \"services[]\" in\n    # http-backend.c for how I got that.  Also note that \"info\" is overloaded;\n    # git uses \"info/refs...\", while gitolite uses \"info\" or \"info?...\".  So\n    # there's a \"/\" after info in the list below\n    if ( $ENV{PATH_INFO} =~ m(^/(.*)/(HEAD$|info/refs$|objects/|git-(?:upload|receive)-pack$)) ) {\n        my $repo = $1;\n        my $verb = ( $ENV{REQUEST_URI} =~ /git-receive-pack/ ) ? 'git-receive-pack' : 'git-upload-pack';\n        $ENV{SSH_ORIGINAL_COMMAND} = \"$verb '$repo'\";\n    } else {\n        # this is one of our custom commands; could be anything really,\n        # because of the adc feature\n        my ($verb) = ( $ENV{PATH_INFO} =~ m(^/(\\S+)) );\n        my $args = $ENV{QUERY_STRING};\n        $args =~ s/\\+/ /g;\n        $args =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;\n        $ENV{SSH_ORIGINAL_COMMAND} = $verb;\n        $ENV{SSH_ORIGINAL_COMMAND} .= \" $args\" if $args;\n        http_print_headers();    # in preparation for the eventual output!\n\n        # we also need to pipe STDERR out via STDOUT, else the user doesn't see those messages!\n        open(STDERR, \">&STDOUT\") or _die \"Can't dup STDOUT: $!\";\n    }\n    $ENV{SSH_CONNECTION} = \"$ENV{REMOTE_ADDR} $ENV{REMOTE_PORT} $ENV{SERVER_ADDR} $ENV{SERVER_PORT}\";\n}\n\nmy $http_headers_printed = 0;\n\nsub http_print_headers {\n    my ( $service, $code, $text ) = @_;\n\n    return if $http_headers_printed++;\n    $code ||= 200;\n    $text ||= \"OK - gitolite\";\n\n    $|++;\n    print \"Status: $code $text\\r\\n\";\n    print \"Expires: Fri, 01 Jan 1980 00:00:00 GMT\\r\\n\";\n    print \"Pragma: no-cache\\r\\n\";\n    print \"Cache-Control: no-cache, max-age=0, must-revalidate\\r\\n\";\n    if ($service) {\n        print \"Content-Type: application/x-$service-advertisement\\r\\n\";\n    } else {\n        print \"Content-Type: text/plain\\r\\n\";\n    }\n    print \"\\r\\n\";\n}\n"
  },
  {
    "path": "src/lib/Gitolite/Cache.pm",
    "content": "package Gitolite::Cache;\n\n# cache stuff using an external database (redis)\n# ----------------------------------------------------------------------\n\n@EXPORT = qw(\n  cache_control\n  cache_wrap\n);\n\nuse Exporter 'import';\n\nuse Gitolite::Common;\nuse Gitolite::Rc;\nuse Storable qw(freeze thaw);\nuse Redis;\n\nmy $redis;\n\nmy $redis_sock = \"$ENV{HOME}/.redis-gitolite.sock\";\nif ( -S $redis_sock ) {\n    _connect_redis();\n} else {\n    _start_redis();\n    _connect_redis();\n\n    # this redis db is a transient, caching only, db, so let's not\n    # accidentally use any stale data when if we're just starting up\n    cache_control('stop');\n    cache_control('start');\n}\n\n# ----------------------------------------------------------------------\n\nmy %wrapped;\nmy $ttl = ( $rc{CACHE_TTL} || ( $rc{GROUPLIST_PGM} ? 900 : 90000 ) );\n\nsub cache_control {\n    my $op = shift;\n    if ( $op eq 'stop' ) {\n        $redis->flushall();\n    } elsif ( $op eq 'start' ) {\n        $redis->set( 'cache-up', 1 );\n    } elsif ( $op eq 'flush' ) {\n        flush_repo(@_);\n    }\n}\n\nsub cache_wrap {\n    my $sub   = shift;\n    my $tname = $sub;    # this is what will show up in the trace output\n    trace( 3, \"wrapping '$sub'\" );\n    $sub = ( caller 1 )[0] . \"::\" . $sub if $sub !~ /::/;\n    return if $wrapped{$sub}++;    # in case somehow it gets called twice for the same sub!\n\n    # collect names of wrapped subs into a redis 'set'\n    $redis->sadd( \"SUBWAY\", $sub );    # subway?  yeah well they wrap subs don't they?\n\n    my $cref = eval '\\&' . $sub;\n    my %opt  = @_;\n        # rest of the options come in as a hash.  'list' says this functions\n        # returns a list.  'ttl' is a number to override the default ttl for\n        # the cached value.\n\n    no strict 'refs';\n    no warnings 'redefine';\n    *{$sub} = sub {                    # the wrapper function\n        my $key = join( \", \", @_ );\n        trace( 2, \"$tname.args\", @_ );\n\n        if ( cache_up() and defined( my $val = $redis->get(\"$sub: $key\") ) ) {\n            # cache is up and we got a hit, return value from cache\n            if ( $opt{list} ) {\n                trace( 2, \"$tname.getl\", @{ thaw($val) } );\n                return @{ thaw($val) };\n            } else {\n                trace( 2, \"$tname.get\", $val );\n                return $val;\n            }\n        } else {\n            # cache is down or we got a miss, compute\n            my ( $r, @r );\n            if ( $opt{list} ) {\n                @r = $cref->(@_);    # provide list context\n                trace( 2, \"$tname.setl\", @r );\n            } else {\n                $r = $cref->(@_);    # provide scalar context\n                trace( 2, \"$tname.set\", $r );\n            }\n\n            # store computed value in cache if cache is up\n            if ( cache_up() ) {\n                $redis->set( \"$sub: $key\", ( $opt{list} ? freeze( \\@r ) : $r ) );\n                $redis->expire( \"$sub: $key\", $opt{ttl} || $ttl );\n                trace( 2, \"$tname.ttl\", ( $opt{ttl} || $ttl ) );\n            }\n\n            return @r if $opt{list};\n            return $r;\n        }\n    };\n    trace( 3, \"wrapped '$sub'\" );\n}\n\nsub cache_up {\n    return $redis->exists('cache-up');\n}\n\nsub flush_repo {\n    my $repo = shift;\n\n    my @wrapped = $redis->smembers(\"SUBWAY\");\n    for my $func (@wrapped) {\n        # if we wrap any more functions, make sure they're functions where the\n        # first argument is 'repo'\n        my @keys = $redis->keys(\"$func: $repo, *\");\n        $redis->del( @keys ) if @keys;\n    }\n}\n\n# ----------------------------------------------------------------------\n\nsub _start_redis {\n    my $conf = join( \"\", <DATA> );\n    $conf =~ s/%HOME/$ENV{HOME}/g;\n\n    open( REDIS, \"|-\", \"/usr/sbin/redis-server\", \"-\" ) or die \"start redis server failed: $!\";\n    print REDIS $conf;\n    close REDIS;\n\n    # give it a little time to come up\n    select( undef, undef, undef, 0.2 );\n}\n\nsub _connect_redis {\n    $redis = Redis->new( sock => $redis_sock, encoding => undef ) or die \"redis new failed: $!\";\n    $redis->ping or die \"redis ping failed: $!\";\n}\n\n1;\n\n__DATA__\n# resources\nmaxmemory 50MB\nport 0\nunixsocket %HOME/.redis-gitolite.sock\nunixsocketperm 700\ntimeout 0\ndatabases 1\n\n# daemon\ndaemonize yes\npidfile %HOME/.redis-gitolite.pid\ndbfilename %HOME/.redis-gitolite.rdb\ndir %HOME\n\n# feedback\nloglevel notice\nlogfile %HOME/.redis-gitolite.log\n\n# we don't save\n"
  },
  {
    "path": "src/lib/Gitolite/Common.pm",
    "content": "package Gitolite::Common;\n\n# common (non-gitolite-specific) functions\n# ----------------------------------------------------------------------\n\n#<<<\n@EXPORT = qw(\n  print2  dbg     _mkdir  _open   ln_sf     tsh_rc      sort_u\n  say     _warn   _chdir  _print            tsh_text    list_phy_repos\n  say2    _die    _system slurp             tsh_lines\n          trace           cleanup_conf_line tsh_try\n          usage                             tsh_run\n          gen_lfn\n          gl_log\n\n          dd\n          t_start\n          t_lap\n\n          ssh_fingerprint_file\n          ssh_fingerprint_line\n\n          update_hook_present\n);\n#>>>\nuse Exporter 'import';\nuse File::Path qw(mkpath);\nuse File::Temp qw(tempfile);\nuse Carp qw(carp cluck croak confess);\n\nuse strict;\nuse warnings;\n\n# ----------------------------------------------------------------------\n\nsub print2 {\n    local $/ = \"\\n\";\n    print STDERR @_;\n}\n\nsub say {\n    local $/ = \"\\n\";\n    print @_, \"\\n\";\n}\n\nsub say2 {\n    local $/ = \"\\n\";\n    print STDERR @_, \"\\n\";\n}\n\nsub trace {\n    gl_log( \"\\t\" . join( \",\", @_[ 1 .. $#_ ] ) ) if $_[0] <= 1 and defined $Gitolite::Rc::rc{LOG_EXTRA};\n\n    return unless defined( $ENV{D} );\n\n    my $level = shift; return if $ENV{D} < $level;\n    my $sub = ( caller 1 )[3] || ''; $sub =~ s/.*://;\n    if ( not $sub ) {\n        $sub = (caller)[1];\n        $sub =~ s(.*/(.*))(($1));\n    }\n    $sub .= ' ' x ( 31 - length($sub) );\n    say2 \"$level\\t$sub\\t\", join( \"\\t\", @_ );\n}\n\nsub dbg {\n    use Data::Dumper;\n    return unless defined( $ENV{D} );\n    for my $i (@_) {\n        print STDERR \"DBG: \" . Dumper($i);\n    }\n}\n\nsub dd {\n    local $ENV{D} = 1;\n    dbg(@_);\n}\n\n{\n    my %start_times;\n\n    eval \"require Time::HiRes\";\n    # we just ignore any errors from this; nothing needs to be done as long as\n    # no code *calls* either of the next two functions.\n\n    sub t_start {\n        my $name = shift || 'default';\n        $start_times{$name} = [ Time::HiRes::gettimeofday() ];\n    }\n\n    sub t_lap {\n        my $name = shift || 'default';\n        return Time::HiRes::tv_interval( $start_times{$name} );\n    }\n}\n\nsub _warn {\n    gl_log( 'warn', @_ );\n    if ( $ENV{D} and $ENV{D} >= 3 ) {\n        cluck \"WARNING: \", @_, \"\\n\";\n    } elsif ( defined( $ENV{D} ) ) {\n        carp \"WARNING: \", @_, \"\\n\";\n    } else {\n        warn \"WARNING: \", @_, \"\\n\";\n    }\n}\n$SIG{__WARN__} = \\&_warn;\n\nsub _die {\n    gl_log( 'die', @_ );\n    if ( $ENV{D} and $ENV{D} >= 3 ) {\n        confess \"FATAL: \" . join( \",\", @_ ) . \"\\n\" if defined( $ENV{D} );\n    } elsif ( defined( $ENV{D} ) ) {\n        croak \"FATAL: \" . join( \",\", @_ ) . \"\\n\";\n    } else {\n        die \"FATAL: \" . join( \",\", @_ ) . \"\\n\";\n    }\n}\n$SIG{__DIE__} = \\&_die;\n\nsub usage {\n    my $script = (caller)[1];\n    my $function = shift if @_ and $_[0] =~ /^[\\w-]+$/;\n    $function ||= ( ( ( caller(1) )[3] ) || ( ( caller(0) )[3] ) );\n    $function =~ s/.*:://;\n    my $code = slurp($script);\n    $code =~ /^=for $function\\b(.*?)^=cut/sm;\n    say( $1 ? $1 : \"...no usage message for '$function' in $script\" );\n    exit 1;\n}\n\nsub _mkdir {\n    # It's not an error if the directory exists, but it is an error if it\n    # doesn't exist and we can't create it. This includes not guaranteeing\n    # dead symlinks or if mkpath traversal is blocked by a file.\n    my $dir  = shift;\n    my $perm = shift;    # optional\n    return if -d $dir;\n    mkpath($dir);\n    chmod $perm, $dir if $perm;\n    return 1;\n}\n\nsub _chdir {\n    chdir( $_[0] || $ENV{HOME} ) or _die \"chdir $_[0] failed: $!\\n\";\n}\n\nsub _system {\n    # run system(), catch errors.  Be verbose only if $ENV{D} exists.  If not,\n    # exit with <rc of system()> if it applies, else just \"exit 1\".\n    trace( 1, 'system', @_ );\n    if ( system(@_) != 0 ) {\n        trace( 1, \"system() failed\", @_, \"-> $?\" );\n        if ( $? == -1 ) {\n            die \"failed to execute: $!\\n\" if $ENV{D};\n        } elsif ( $? & 127 ) {\n            die \"child died with signal \" . ( $? & 127 ) . \"\\n\" if $ENV{D};\n        } else {\n            die \"child exited with value \" . ( $? >> 8 ) . \"\\n\" if $ENV{D};\n            exit( $? >> 8 );\n        }\n        exit 1;\n    }\n}\n\nsub _open {\n    open( my $fh, $_[0], $_[1] ) or _die \"open $_[1] failed: $!\\n\";\n    return $fh;\n}\n\nsub _print {\n    my ( $file, @text ) = @_;\n    my $fh = _open( \">\", \"$file.$$\" );\n    print $fh @text;\n    close($fh) or _die \"close $file failed: $! at \", (caller)[1], \" line \", (caller)[2], \"\\n\";\n    my $oldmode = ( ( stat $file )[2] );\n    rename \"$file.$$\", $file;\n    chmod $oldmode, $file if $oldmode;\n}\n\nsub slurp {\n    return unless defined wantarray;\n    local $/ = undef unless wantarray;\n    my $fh = _open( \"<\", $_[0] );\n    return <$fh>;\n}\n\nsub dos2unix {\n    # WARNING: when calling this, make sure you supply a list context\n    s/\\r\\n/\\n/g for @_;\n    return @_;\n}\n\nsub ln_sf {\n    trace( 3, @_ );\n    my ( $srcdir, $glob, $dstdir ) = @_;\n    for my $hook ( glob(\"$srcdir/$glob\") ) {\n        $hook =~ s/$srcdir\\///;\n        unlink \"$dstdir/$hook\";\n        symlink \"$srcdir/$hook\", \"$dstdir/$hook\" or croak \"could not symlink $srcdir/$hook to $dstdir\\n\";\n    }\n}\n\nsub sort_u {\n    my %uniq;\n    my $listref = shift;\n    return [] unless @{$listref};\n    undef @uniq{ @{$listref} };    # expect a listref\n    my @sort_u = sort keys %uniq;\n    return \\@sort_u;\n}\n\nsub cleanup_conf_line {\n    my $line = shift;\n    return $line if $line =~ /^# \\S+ \\d+$/;\n\n    # kill comments, but take care of \"#\" inside *simple* strings\n    $line =~ s/^((\".*?\"|[^#\"])*)#.*/$1/;\n    # normalise whitespace; keeps later regexes very simple\n    $line =~ s/=/ = /;\n    $line =~ s/\\s+/ /g;\n    $line =~ s/^ //;\n    $line =~ s/ $//;\n    return $line;\n}\n\n{\n    my @phy_repos = ();\n\n    sub list_phy_repos {\n        # use cached value only if it exists *and* no arg was received (i.e.,\n        # receiving *any* arg invalidates cache)\n        return \\@phy_repos if ( @phy_repos and not @_ );\n\n        my $cmd = 'find . ' . ($Gitolite::Rc::rc{REPO_SYMLINKS} || '') . ' -name \"*.git\" -prune';\n        for my $repo (`$cmd`) {\n            chomp($repo);\n            $repo =~ s/\\.git$//;\n            $repo =~ s(^\\./)();\n            next if $repo =~ m(/$);\n                # tolerate non-bare repos within ~/repositories but silently ignore them\n            push @phy_repos, $repo;\n        }\n        trace( 3, scalar(@phy_repos) . \" physical repos found\" );\n        return sort_u( \\@phy_repos );\n    }\n}\n\n# 2025-06-12 -- this function is the only one in \"core\" gitolite [1] to have\n# support for Windows systems.  This is because one of gitolite's\n# \"contributed\" features, which is nevertheless very useful, is the \"testconf\"\n# feature [2] and [3].  The thing is, testconf is designed to run gitolite **on the\n# client machine**, which is at least for some people, Windows.\n# So yeah, a bit of tail wagging the dog, allowing a \"contrib\" feature to make\n# changes to \"core\" gitolite, and that too for an OS we don't support as a\n# server, but it is what it is.  At least we have managed to isolate the\n# change sufficiently.\n\n# [1]: https://gitolite.com/gitolite/internals.html#what-is-core\n# [2]: https://gitolite.com/gitolite/conf-2.html#appendix-3-embedding-test-code-in-your-conf\n# [3]: https://github.com/sitaramc/gitolite/blob/master/contrib/utils/testconf\nsub update_hook_present {\n    my $repo = shift;\n\n    return 1 unless -d \"$ENV{GL_REPO_BASE}/$repo.git\";  # non-existent repo is fine\n\n    my $repo_hook = \"$ENV{GL_REPO_BASE}/$repo.git/hooks/update\";\n    my $common_hook = \"$ENV{GL_ADMIN_BASE}/hooks/common/update\";\n\n    if ($^O eq 'msys') {\n        # No symlinks on Windows.  Please see important note placed just before this function.\n        my $repo_update_text = slurp($repo_hook) if -f $repo_hook;\n        my $common_update_text = slurp($common_hook) if -f $common_hook;\n\n        return 1 if $repo_update_text and $common_update_text and $repo_update_text eq $common_update_text;\n\n        return 0;\n    }\n\n    my $x = readlink($repo_hook);\n    return 1 if $x and $x eq $common_hook;\n\n    return 0;\n}\n\n# generate a timestamp\nsub gen_ts {\n    my ( $s, $min, $h, $d, $m, $y ) = (localtime)[ 0 .. 5 ];\n    $y += 1900; $m++;    # usual adjustments\n    for ( $s, $min, $h, $d, $m ) {\n        $_ = \"0$_\" if $_ < 10;\n    }\n    my $ts = \"$y-$m-$d.$h:$min:$s\";\n\n    return $ts;\n}\n\n# generate a log file name\nsub gen_lfn {\n    my ( $s, $min, $h, $d, $m, $y ) = (localtime)[ 0 .. 5 ];\n    $y += 1900; $m++;    # usual adjustments\n    for ( $s, $min, $h, $d, $m ) {\n        $_ = \"0$_\" if $_ < 10;\n    }\n\n    my ($template) = shift;\n    # substitute template parameters and set the logfile name\n    $template =~ s/%y/$y/g;\n    $template =~ s/%m/$m/g;\n    $template =~ s/%d/$d/g;\n\n    return $template;\n}\n\nmy $log_dest;\nmy $syslog_opened = 0;\nEND { closelog() if $syslog_opened; }\nsub gl_log {\n    # the log filename and the timestamp come from the environment.  If we get\n    # called even before they are set, we have no choice but to dump to STDERR\n    # (and probably call \"logger\").\n\n    # tab sep if there's more than one field\n    my $msg = join( \"\\t\", @_ );\n    $msg =~ s/[\\n\\r]+/<<newline>>/g;\n\n    my $ts = gen_ts();\n    my $tid = $ENV{GL_TID} ||= $$;\n\n    $log_dest = $Gitolite::Rc::rc{LOG_DEST} || '' if not defined $log_dest;\n\n    # log (update records only) to \"gl-log\" in the bare repo dir; this is to\n    # make 'who-pushed' more efficient.  Since this is only for the update\n    # records, it is not a replacement for the other two types of logging.\n    if ($log_dest =~ /repo-log/ and $_[0] eq 'update') {\n        # if the log line is 'update', we're already in the bare repo dir\n        open my $lfh, \">>\", \"gl-log\" or _die \"open gl-log failed: $!\";\n        print $lfh \"$ts\\t$tid\\t$msg\\n\";\n        close $lfh;\n    }\n\n    # syslog\n    if ($log_dest =~ /syslog/) {            # log_dest *includes* syslog\n        if ($syslog_opened == 0) {\n            require Sys::Syslog;\n            Sys::Syslog->import(qw(:standard));\n\n            openlog(\"gitolite\" . ( $ENV{GL_TID} ? \"[$ENV{GL_TID}]\" : \"\" ), \"pid\", $Gitolite::Rc::rc{LOG_FACILITY} || 'local0');\n            $syslog_opened = 1;\n        }\n\n        # gl_log is called either directly, or, if the rc variable LOG_EXTRA\n        # is set, from trace(1, ...).  The latter use is considered additional\n        # info for troubleshooting.  Trace prefixes a tab to the arguments\n        # before calling gl_log, to visually set off such lines in the log\n        # file.  Although syslog eats up that leading tab, we use it to decide\n        # the priority/level of the syslog message.\n        syslog( ( $msg =~ /^\\t/ ? 'debug' : 'info' ), \"%s\", $msg);\n\n        return if $log_dest !~ /normal/;\n    }\n\n    my $fh;\n    logger_plus_stderr( \"errors found before logging could be setup\", \"$msg\" ) if not $ENV{GL_LOGFILE};\n    open my $lfh, \">>\", $ENV{GL_LOGFILE}\n      or logger_plus_stderr( \"errors found but logfile could not be created\", \"$ENV{GL_LOGFILE}: $!\", \"$msg\" );\n    print $lfh \"$ts\\t$tid\\t$msg\\n\";\n    close $lfh;\n}\n\nsub logger_plus_stderr {\n    open my $fh, \"|-\", \"logger\" or confess \"it's really not my day is it...?\\n\";\n    for (@_) {\n        print STDERR \"FATAL: $_\\n\";\n        print $fh \"FATAL: $_\\n\";\n    }\n    exit 1;\n}\n\n# ----------------------------------------------------------------------\n# Get the SSH fingerprint of a file\n# If the fingerprint cannot be parsed, it will be undef\n# In a scalar context, returns the fingerprint\n# In a list context, returns (fingerprint, output) where output\n# is the raw output of the ssh-keygen command\nsub ssh_fingerprint_file {\n    my $in = shift;\n    -f $in or die \"file not found: $in\\n\";\n    my $fh;\n    open( $fh, \"ssh-keygen -l -f $in 2>&1 |\" ) or die \"could not fork: $!\\n\";\n    my $output = <$fh>;\n    chomp $output;\n    # dbg(\"fp = $fp\");\n    close $fh;\n    # Return a valid fingerprint or undef\n    my $fp = undef;\n    if($output =~ /((?:MD5:)?(?:[0-9a-f]{2}:){15}[0-9a-f]{2})/i or\n       $output =~ m{((?:RIPEMD|SHA)\\d+:[A-Za-z0-9+/=]+)}i) {\n        $fp = $1;\n    }\n    return wantarray ? ($fp, $output) : $fp;\n}\n\n# Get the SSH fingerprint of a line of text\n# If the fingerprint cannot be parsed, it will be undef\n# In a scalar context, returns the fingerprint\n# In a list context, returns (fingerprint, output) where output\n# is the raw output of the ssh-keygen command\nsub ssh_fingerprint_line {\n    my ( $fh, $fn ) = tempfile();\n    print $fh shift() . \"\\n\";\n    close $fh;\n    my ($fp,$output) = ssh_fingerprint_file($fn);\n    unlink $fn;\n    return wantarray ? ($fp,$output) : $fp;\n}\n\n# ----------------------------------------------------------------------\n\n# bare-minimum subset of 'Tsh' (see github.com/sitaramc/tsh)\n{\n    my ( $rc, $text );\n    sub tsh_rc   { return $rc   || 0; }\n    sub tsh_text { return $text || ''; }\n    sub tsh_lines { return split /\\n/, $text; }\n\n    sub tsh_try {\n        my $cmd = shift; die \"try: expects only one argument\" if @_;\n        $text = `( $cmd ) 2>&1; printf RC=\\$?`;\n        if ( $text =~ s/RC=(\\d+)$// ) {\n            $rc = $1;\n            trace( 3, $text );\n            return ( not $rc );\n        }\n        die \"couldnt find RC= in result; this should not happen:\\n$text\\n\\n...\\n\";\n    }\n\n    sub tsh_run {\n        open( my $fh, \"-|\", @_ ) or die \"popen failed: $!\";\n        local $/ = undef; $text = <$fh>;\n        close $fh; warn \"pclose failed: $!\" if $!;\n        $rc = ( $? >> 8 );\n        trace( 3, $text );\n        return $text;\n    }\n}\n\n1;\n"
  },
  {
    "path": "src/lib/Gitolite/Conf/Explode.pm",
    "content": "package Gitolite::Conf::Explode;\n\n# include/subconf processor\n# ----------------------------------------------------------------------\n\n@EXPORT = qw(\n  explode\n);\n\nuse Exporter 'import';\n\nuse Gitolite::Rc;\nuse Gitolite::Common;\n\nuse strict;\nuse warnings;\n\n# ----------------------------------------------------------------------\n\n# 'seen' for include/subconf files\nmy %included = ();\n# 'seen' for group names on LHS\nmy %prefixed_groupname = ();\n\nsub explode {\n    trace( 3, @_ );\n    my ( $file, $subconf, $out ) = @_;\n\n    # seed the 'seen' list if it's empty\n    $included{ device_inode(\"gitolite.conf\") }++ unless %included;\n\n    my $fh = _open( \"<\", $file );\n    while (<$fh>) {\n        my $line = cleanup_conf_line($_);\n        next unless $line =~ /\\S/;\n\n        # subst %HOSTNAME word if rc defines a hostname, else leave as is\n        $line =~ s/%HOSTNAME\\b/$rc{HOSTNAME}/g if $rc{HOSTNAME};\n\n        $line = prefix_groupnames( $line, $subconf ) if $subconf ne 'master';\n\n        if ( $line =~ /^(include|subconf) (?:(\\S+) )?(\\S.+)$/ ) {\n            incsub( $1, $2, $3, $subconf, $out );\n        } else {\n            # normal line, send it to the callback function\n            push @{$out}, \"# $file $.\";\n            push @{$out}, $line;\n        }\n    }\n}\n\nsub incsub {\n    my $is_subconf = ( +shift eq 'subconf' );\n    my ( $new_subconf, $include_glob, $current_subconf, $out ) = @_;\n\n    _die \"subconf '$current_subconf' attempting to run 'subconf'\\n\" if $is_subconf and $current_subconf ne 'master';\n\n    _die \"invalid include/subconf file/glob '$include_glob'\"\n      unless $include_glob =~ /^\"(.+)\"$/\n      or $include_glob =~ /^'(.+)'$/;\n    $include_glob = $1;\n\n    trace( 3, $is_subconf, $include_glob );\n\n    for my $file ( glob($include_glob) ) {\n        _warn(\"included file not found: '$file'\"), next unless -f $file;\n        _die \"invalid include/subconf filename '$file'\" unless $file =~ m(([^/]+).conf$);\n        my $basename = $1;\n\n        next if already_included($file);\n\n        if ($is_subconf) {\n            push @{$out}, \"subconf \" . ( $new_subconf || $basename );\n            explode( $file, ( $new_subconf || $basename ), $out );\n            push @{$out}, \"subconf $current_subconf\";\n        } else {\n            explode( $file, $current_subconf, $out );\n        }\n    }\n}\n\nsub prefix_groupnames {\n    my ( $line, $subconf ) = @_;\n\n    my $lhs = '';\n    # save 'foo' if it's an '@foo = list' line\n    $lhs = $1 if $line =~ /^@(\\S+) = /;\n    # prefix all @groups in the line\n    $line =~ s/(^| )(@\\S+)(?= |$)/ $1 . ($prefixed_groupname{$subconf}{$2} || $2) /ge;\n    # now prefix the LHS and store it if needed\n    if ($lhs) {\n        $line =~ s/^@\\S+ = /\"\\@$subconf.$lhs = \"/e;\n        $prefixed_groupname{$subconf}{\"\\@$lhs\"} = \"\\@$subconf.$lhs\";\n        trace( 3, \"prefixed_groupname.$subconf.\\@$lhs = \\@$subconf.$lhs\" );\n    }\n\n    return $line;\n}\n\nsub already_included {\n    my $file = shift;\n\n    my $file_id = device_inode($file);\n    return 0 unless $included{$file_id}++;\n\n    _warn(\"$file already included\");\n    trace( 3, \"$file already included\" );\n    return 1;\n}\n\nsub device_inode {\n    my $file = shift;\n    trace( 3, $file, ( stat $file )[ 0, 1 ] );\n    return join( \"/\", ( stat $file )[ 0, 1 ] );\n}\n\n1;\n\n"
  },
  {
    "path": "src/lib/Gitolite/Conf/Load.pm",
    "content": "package Gitolite::Conf::Load;\n\n# load conf data from stored files\n# ----------------------------------------------------------------------\n\n@EXPORT = qw(\n  load\n\n  access\n  git_config\n  env_options\n\n  option\n  repo_missing\n  creator\n\n  vrefs\n  lister_dispatch\n);\n\nuse Exporter 'import';\nuse Cwd;\n\nuse Gitolite::Rc;\nuse Gitolite::Common;\n\nuse strict;\nuse warnings;\n\n# ----------------------------------------------------------------------\n\n# our variables, because they get loaded by a 'do'\nour $data_version = '';\nour %repos;\nour %one_repo;\nour %groups;\nour %patterns;\nour %configs;\nour %one_config;\nour %split_conf;\n\nmy $subconf = 'master';\n\nmy %listers = (\n    'list-groups'      => \\&list_groups,\n    'list-users'       => \\&list_users,\n    'list-repos'       => \\&list_repos,\n    'list-memberships' => \\&list_memberships,\n    'list-members'     => \\&list_members,\n);\n\n# helps maintain the \"cache\" in both \"load_common\" and \"load_1\"\nmy $last_repo = '';\n\n# ----------------------------------------------------------------------\n\n{\n    my $loaded_repo = '';\n\n    sub load {\n        my $repo = shift or _die \"load() needs a reponame\";\n        trace( 3, \"$repo\" );\n        if ( $repo ne $loaded_repo ) {\n            load_common();\n            load_1($repo);\n            $loaded_repo = $repo;\n        }\n    }\n}\n\nsub access {\n    my ( $repo, $user, $aa, $ref ) = @_;\n    trace( 2, $repo, $user, $aa, $ref );\n    _die \"invalid user '$user'\" if not( $user and $user =~ $USERNAME_PATT );\n    sanity($repo);\n    return \"$aa any $repo $user DENIED by fallthru\" unless update_hook_present($repo);\n\n    my @rules;\n    my $deny_rules;\n\n    load($repo);\n    @rules = rules( $repo, $user );\n    $deny_rules = option( $repo, 'deny-rules' );\n\n    # sanity check the only piece the user can control\n    _die \"invalid characters in ref or filename: '$ref'\\n\" unless $ref =~ m(^VREF/NAME/) or $ref =~ $REF_OR_FILENAME_PATT;\n    # apparently we can't always force sanity; at least what we *return*\n    # should be sane/safe.  This pattern is based on REF_OR_FILENAME_PATT.\n    ( my $safe_ref = $ref ) =~ s([^-0-9a-zA-Z._\\@/+ :,])(.)g;\n    trace( 3, \"safe_ref\", $safe_ref ) if $ref ne $safe_ref;\n\n    # when a real repo doesn't exist, ^C is a pre-requisite for any other\n    # check to give valid results.\n    if ( $aa ne '^C' and $repo !~ /^\\@/ and $repo =~ $REPONAME_PATT and repo_missing($repo) ) {\n        my $iret = access( $repo, $user, '^C', $ref );\n        $iret =~ s/\\^C/$aa/;\n        return $iret if $iret =~ /DENIED/;\n    }\n    # similarly, ^C must be denied if the repo exists\n    if ( $aa eq '^C' and not repo_missing($repo) ) {\n        trace( 2, \"DENIED by existence\" );\n        return \"$aa $safe_ref $repo $user DENIED by existence\";\n    }\n\n    trace( 3, scalar(@rules) . \" rules found\" );\n\n    $rc{RULE_TRACE} = '';\n    for my $r (@rules) {\n        $rc{RULE_TRACE} .= \" \" . $r->[0] . \" \";\n\n        my $perm = $r->[1];\n        my $refex = $r->[2]; $refex =~ s(/USER/)(/$user/);\n        trace( 3, \"perm=$perm, refex=$refex\" );\n\n        $rc{RULE_TRACE} .= \"d\";\n        # skip 'deny' rules if the ref is not (yet) known\n        next if $perm eq '-' and $ref eq 'any' and not $deny_rules;\n\n        $rc{RULE_TRACE} .= \"r\";\n        # rule matches if ref matches or ref is any (see gitolite-shell)\n        next unless $ref =~ /^$refex/ or $ref eq 'any';\n\n        $rc{RULE_TRACE} .= \"D\";\n        trace( 2, \"DENIED by $refex\" ) if $perm eq '-';\n        return \"$aa $safe_ref $repo $user DENIED by $refex\" if $perm eq '-';\n\n        # For repo creation, perm will be C and aa will be \"^C\".  For branch\n        # access, $perm can be RW\\+?(C|D|CD|DC)?M?, and $aa can be W, +, C or\n        # D, or any of these followed by \"M\".\n\n        # We need to turn $aa into a regex that can match a suitable $perm.\n        # This is trivially true for \"^C\", \"W\" and \"D\", but the others (+, C,\n        # M) need some tweaking.\n\n        # first, quote the '+':\n        ( my $aaq = $aa ) =~ s/\\+/\\\\+/;\n        # if aa is just \"C\", the user is trying to create a *branch* (not a\n        # *repo*), so let's make the pattern clearer to reflect that.\n        $aaq = \"RW.*C\" if $aaq eq \"C\";\n        # if the aa is, say \"WM\", make this \"W.*M\" because the perm could be\n        # 'RW+M', 'RW+CDM' etc, and they are all valid:\n        $aaq =~ s/M/.*M/;\n\n        $rc{RULE_TRACE} .= \"A\";\n\n        # as far as *this* ref is concerned we're ok\n        return $refex if ( $perm =~ /$aaq/ );\n\n        $rc{RULE_TRACE} .= \"p\";\n    }\n    $rc{RULE_TRACE} .= \" F\";\n\n    trace( 2, \"DENIED by fallthru\" );\n    return \"$aa $safe_ref $repo $user DENIED by fallthru\";\n}\n\n# cache control\nif ($rc{CACHE}) {\n    require Gitolite::Cache;\n    Gitolite::Cache::cache_wrap('Gitolite::Conf::Load::access');\n}\n\nsub git_config {\n    my ( $repo, $key, $empty_values_OK ) = @_;\n    $key ||= '.';\n\n    if ( repo_missing($repo) ) {\n        load_common();\n    } else {\n        load($repo);\n    }\n\n    # read comments bottom up\n    my %ret =\n      # and take the second and third elements to make up your new hash\n      map { $_->[1] => $_->[2] }\n      # keep only the ones where the second element matches your key\n      grep { $_->[1] =~ qr($key) }\n      # sort this list of listrefs by the first element in each list ref'd to\n      sort { $a->[0] <=> $b->[0] }\n      # dereference it (into a list of listrefs)\n      map { @$_ }\n      # take the value of that entry\n      map { $configs{$_} }\n      # if it has an entry in %configs\n      grep { $configs{$_} }\n      # for each \"repo\" that represents us\n      memberships( 'repo', $repo );\n\n    # %configs looks like this (for each 'foo' that is in memberships())\n    # 'foo' => [ [ 6, 'foo.bar', 'repo' ], [ 7, 'foodbar', 'repoD' ], [ 8, 'foo.czar', 'jule' ] ],\n    # the first map gets you the value\n    #          [ [ 6, 'foo.bar', 'repo' ], [ 7, 'foodbar', 'repoD' ], [ 8, 'foo.czar', 'jule' ] ],\n    # the deref gets you\n    #            [ 6, 'foo.bar', 'repo' ], [ 7, 'foodbar', 'repoD' ], [ 8, 'foo.czar', 'jule' ]\n    # the sort rearranges it (in this case it's already sorted but anyway...)\n    # the grep gets you this, assuming the key is foo.bar (and \".\" is regex \".')\n    #            [ 6, 'foo.bar', 'repo' ], [ 7, 'foodbar', 'repoD' ]\n    # and the final map does this:\n    #                 'foo.bar'=>'repo'  ,      'foodbar'=>'repoD'\n\n    # now some of these will have an empty key; we need to delete them unless\n    # we're told empty values are OK\n    unless ($empty_values_OK) {\n        my ( $k, $v );\n        while ( ( $k, $v ) = each %ret ) {\n            delete $ret{$k} if not $v;\n        }\n    }\n\n    my ( $k, $v );\n    my $creator = creator($repo);\n    while ( ( $k, $v ) = each %ret ) {\n        $v =~ s/%GL_REPO/$repo/g;\n        $v =~ s/%GL_CREATOR/$creator/g if $creator;\n        $ret{$k} = $v;\n    }\n\n    map { trace( 3, \"$_\", \"$ret{$_}\" ) } ( sort keys %ret ) if $ENV{D};\n    return \\%ret;\n}\n\nsub env_options {\n    return unless -f \"$rc{GL_ADMIN_BASE}/conf/gitolite.conf-compiled.pm\";\n    # prevent catch-22 during initial install\n\n    my $cwd = getcwd();\n\n    my $repo = shift;\n    map { delete $ENV{$_} } grep { /^GL_OPTION_/ } keys %ENV;\n    my $h = git_config( $repo, '^gitolite-options.ENV\\.' );\n    while ( my ( $k, $v ) = each %$h ) {\n        next unless $k =~ /^gitolite-options.ENV\\.(\\w+)$/;\n        $ENV{ \"GL_OPTION_\" . $1 } = $v;\n    }\n\n    chdir($cwd);\n}\n\nsub option {\n    my ( $repo, $option ) = @_;\n    $option = \"gitolite-options.$option\";\n    my $ret = git_config( $repo, \"^\\Q$option\\E\\$\" );\n    return '' unless %$ret;\n    return $ret->{$option};\n}\n\nsub sanity {\n    my ($repo, $patt) = @_;\n    $patt ||= $REPOPATT_PATT;\n\n    _die \"invalid repo '$repo'\" if not( $repo and $repo =~ $patt );\n    _die \"'$repo' ends with a '/'\"  if $repo =~ m(/$);\n    _die \"'$repo' contains '..'\"    if $repo =~ $REPONAME_PATT and $repo =~ m(\\.\\.);\n    _die \"'$repo' contains '.git/'\" if $repo =~ $REPONAME_PATT and $repo =~ m(\\.git/);\n    _die \"'$repo' ends with '.git'\" if $repo =~ m(\\.git$);\n}\n\nsub repo_missing {\n    my $repo = shift;\n    sanity($repo);\n\n    return not -d \"$rc{GL_REPO_BASE}/$repo.git\";\n}\n\n# ----------------------------------------------------------------------\n\nsub load_common {\n\n    _chdir( $rc{GL_ADMIN_BASE} );\n\n    # we take an unusual approach to caching this function!\n    # (requires that first call to load_common is before first call to load_1)\n    if ( $last_repo and $split_conf{$last_repo} ) {\n        delete $repos{$last_repo};\n        delete $configs{$last_repo};\n        return;\n    }\n\n    my $cc = \"./conf/gitolite.conf-compiled.pm\";\n\n    _die \"parse '$cc' failed: \" . ( $! or $@ ) unless do $cc;\n\n    if ( data_version_mismatch() ) {\n        _system(\"gitolite setup\");\n        _die \"parse '$cc' failed: \" . ( $! or $@ ) unless do $cc;\n        _die \"data version update failed; this is serious\" if data_version_mismatch();\n    }\n}\n\nsub load_1 {\n    my $repo = shift;\n    return if $repo =~ /^\\@/;\n    trace( 3, $repo );\n\n    if ( repo_missing($repo) ) {\n        trace( 1, \"repo '$repo' missing\" ) if $repo =~ $REPONAME_PATT;\n        return;\n    }\n    _chdir(\"$rc{GL_REPO_BASE}/$repo.git\");\n\n    if ( $repo eq $last_repo ) {\n        $repos{$repo} = $one_repo{$repo};\n        $configs{$repo} = $one_config{$repo} if $one_config{$repo};\n        return;\n    }\n\n    if ( -f \"gl-conf\" ) {\n        return if not $split_conf{$repo} and not $rc{ALLOW_ORPHAN_GL_CONF};\n\n        my $cc = \"./gl-conf\";\n        _die \"parse '$cc' failed: \" . ( $@ or $! ) unless do $cc;\n\n        $last_repo = $repo;\n        $repos{$repo} = $one_repo{$repo};\n        $configs{$repo} = $one_config{$repo} if $one_config{$repo};\n    } else {\n        _die \"split conf set, gl-conf not present for '$repo'\" if $split_conf{$repo};\n    }\n}\n\n{\n    my $lastrepo = '';\n    my $lastuser = '';\n    my @cached   = ();\n\n    sub rules {\n        my ( $repo, $user ) = @_;\n        trace( 3, $repo, $user );\n\n        return @cached if ( $lastrepo eq $repo and $lastuser eq $user and @cached );\n\n        my @rules = ();\n\n        my @repos = memberships( 'repo', $repo );\n        my @users = memberships( 'user', $user, $repo );\n        trace( 3, \"memberships: \" . scalar(@repos) . \" repos and \" . scalar(@users) . \" users found\" );\n\n        for my $r (@repos) {\n            for my $u (@users) {\n                push @rules, @{ $repos{$r}{$u} } if exists $repos{$r} and exists $repos{$r}{$u};\n            }\n        }\n\n        @rules = sort { $a->[0] <=> $b->[0] } @rules;\n\n        $lastrepo = $repo;\n        $lastuser = $user;\n        @cached   = @rules;\n\n        # however if the repo was missing, invalidate the cache\n        $lastrepo = '' if repo_missing($repo);\n\n        return @rules;\n    }\n\n    sub vrefs {\n        my ( $repo, $user ) = @_;\n        # fill the cache if needed\n        rules( $repo, $user ) unless ( $lastrepo eq $repo and $lastuser eq $user and @cached );\n\n        my %seen;\n        my @vrefs = grep { /^VREF\\// and not $seen{$_}++ } map { $_->[2] } @cached;\n        return @vrefs;\n    }\n}\n\nsub memberships {\n    trace( 3, @_ );\n    my ( $type, $base, $repo ) = @_;\n    $repo ||= '';\n    my @ret;\n    my $base2 = '';\n\n    @ret = ( $base, '@all' );\n\n    if ( $type eq 'repo' ) {\n        # first, if a repo, say, pub/sitaram/project, has a gl-creator file\n        # that says \"sitaram\", find memberships for pub/CREATOR/project also\n        $base2 = generic_name($base);\n\n        # second, you need to check in %repos also\n        for my $i ( keys %repos, keys %configs ) {\n            if ( $base eq $i or $base =~ /^$i$/ or $base2 and ( $base2 eq $i or $base2 =~ /^$i$/ ) ) {\n                push @ret, $i;\n            }\n        }\n\n        # add in any group names explicitly given in (GIT_DIR)/gl-repo-groups\n        push @ret,\n            map { s/^\\@?/\\@/; $_ }\n            grep { ! /[^\\w@-]/ }\n            split (' ', slurp(\"$ENV{GL_REPO_BASE}/$base.git/gl-repo-groups\"))\n                if -f         \"$ENV{GL_REPO_BASE}/$base.git/gl-repo-groups\";\n    }\n\n    push @ret, @{ $groups{$base} } if exists $groups{$base};\n    push @ret, @{ $groups{$base2} } if $base2 and exists $groups{$base2};\n    if ($type eq 'repo') {\n        # regexes can only be used for repos, not for users\n        for my $i ( keys %{ $patterns{groups} } ) {\n            if ( $base =~ /^$i$/ or $base2 and ( $base2 =~ /^$i$/ ) ) {\n                push @ret, @{ $groups{$i} };\n            }\n        }\n    }\n\n    push @ret, @{ ext_grouplist($base) } if $type eq 'user' and $rc{GROUPLIST_PGM};\n\n    if ( $type eq 'user' and $repo and not repo_missing($repo) ) {\n        # find the roles this user has when accessing this repo and add those\n        # in as groupnames he is a member of.  You need the already existing\n        # memberships for this; see below this function for an example\n        push @ret, user_roles( $base, $repo, @ret );\n    }\n\n    @ret = @{ sort_u( \\@ret ) };\n    trace( 3, sort @ret );\n    return @ret;\n}\n\n=for example\n\nconf/gitolite.conf:\n    @g1 = u1\n    @g2 = u1\n    # now user is a member of both g1 and g2\n\ngl-perms for repo being accessed:\n    READERS @g1\n\nThis should result in @READERS being added to the memberships that u1 has\n(when accessing this repo).  So we send the current list (@g1, @g2) to\nuser_roles(), otherwise it has to redo that logic.\n\n=cut\n\nsub data_version_mismatch {\n    return $data_version ne glrc('current-data-version');\n}\n\nsub user_roles {\n    my ( $user, $repo, @eg ) = @_;\n\n    # eg == existing groups (that user is already known to be a member of)\n    my %eg = map { $_ => 1 } @eg;\n\n    my %ret   = ();\n    my $f     = \"$rc{GL_REPO_BASE}/$repo.git/gl-perms\";\n    my @roles = ();\n    if ( -f $f ) {\n        my $fh = _open( \"<\", $f );\n        chomp( @roles = <$fh> );\n    }\n    push @roles, \"CREATOR = \" . creator($repo);\n    for (@roles) {\n        # READERS u3 u4 @g1\n        s/^\\s+//; s/ +$//; s/=/ /; s/\\s+/ /g; s/^\\@//;\n        next if /^#/;\n        next unless /\\S/;\n        my ( $role, @members ) = split;\n        # role = READERS, members = u3, u4, @g1\n        if ( $role ne 'CREATOR' and not $rc{ROLES}{$role} ) {\n            _warn \"role '$role' not allowed, ignoring\";\n            next;\n        }\n        for my $m (@members) {\n            if ( $m !~ $USERNAME_PATT ) {\n                _warn \"ignoring '$m' in perms line\";\n                next;\n            }\n            # if user eq u3/u4, or is a member of @g1, he has role READERS\n            $ret{ '@' . $role } = 1 if $m eq $user or $eg{$m};\n        }\n    }\n\n    return keys %ret;\n}\n\nsub generic_name {\n    my $base  = shift;\n    my $base2 = '';\n    my $creator;\n\n    # get the creator name.  For not-yet-born repos this is $ENV{GL_USER},\n    # which should be set in all cases that we care about, viz., where we are\n    # checking ^C permissions before new_wild_repo(), and the info command.\n    # In particular, 'gitolite access' can't be used to check ^C perms on wild\n    # repos that contain \"CREATOR\" if GL_USER is not set.\n    $creator = creator($base);\n\n    $base2 = $base;\n    $base2 =~ s(\\b$creator\\b)(CREATOR) if $creator;\n    $base2 = '' if $base2 eq $base;    # if there was no change\n\n    return $base2;\n}\n\nsub creator {\n    my $repo = shift;\n    sanity($repo);\n\n    return ( $ENV{GL_USER} || '' ) if repo_missing($repo);\n    my $f       = \"$rc{GL_REPO_BASE}/$repo.git/gl-creator\";\n    my $creator = '';\n    chomp( $creator = slurp($f) ) if -f $f;\n    return $creator;\n}\n\n{\n    my %cache = ();\n\n    sub ext_grouplist {\n        my $user = shift;\n        my $pgm  = $rc{GROUPLIST_PGM};\n        return [] if not $pgm;\n\n        return $cache{$user} if $cache{$user};\n        my @extgroups = map { s/^@?/@/; $_; } split ' ', `$rc{GROUPLIST_PGM} $user`;\n        return ( $cache{$user} = \\@extgroups );\n    }\n}\n\n# ----------------------------------------------------------------------\n# api functions\n# ----------------------------------------------------------------------\n\nsub lister_dispatch {\n    my $command = shift;\n\n    my $fn = $listers{$command} or _die \"unknown gitolite sub-command\";\n    return $fn;\n}\n\n=for list_groups\nUsage:  gitolite list-groups\n\n  - lists all group names in conf\n  - no options, no flags\n=cut\n\nsub list_groups {\n    usage() if @_;\n\n    load_common();\n\n    my @g = ();\n    while ( my ( $k, $v ) = each(%groups) ) {\n        push @g, @{$v};\n    }\n    return ( sort_u( \\@g ) );\n}\n\n=for list_users\nUsage:  gitolite list-users [<repo name pattern>]\n\nList all users and groups explicitly named in a rule.\n\n-   you will have to run 'list-members' on each group name to expand it -- for\n    details and caveats on that please see its help message.\n-   User names not mentioned in an access rule will not show up at all (for\n    example, if you have users who only have access via an '@all' rule).\n\nWARNING: may be slow if you have thousands of repos.  The optional repo name\npattern is an unanchored regex; it can speed things up if you're interested\nonly in users of a matching set of repos.  This is only an optimisation, not\nan actual access list; you will still have to pipe it to 'gitolite access'\nwith appropriate arguments to get an actual access list.\n\nNOTE: If you're running in ssh mode, it may be simpler to parse the authorized\nkeys file in ~/.ssh, like so:\n    perl -lne '/ ([a-z0-9]+)\"/; print $1 if $1' < ~/.ssh/authorized_keys | sort -u\nIf you're running in http mode, only your web server knows all the potential\nuser names.\n=cut\n\nsub list_users {\n    my $patt = shift || '.';\n    usage() if $patt eq '-h' or @_;\n    my $count = 0;\n    my $total = 0;\n\n    load_common();\n\n    my @u = map { keys %{$_} } values %repos;\n    $total = scalar( grep { /$patt/ } keys %split_conf );\n    warn \"WARNING: you have $total repos to check; this could take some time!\\n\" if $total > 100;\n    for my $one ( grep { /$patt/ } keys %split_conf ) {\n        load_1($one);\n        $count++; print STDERR \"$count / $total\\r\" if not( $count % 100 ) and timer(5);\n        push @u, map { keys %{$_} } values %one_repo;\n    }\n    print STDERR \"\\n\" if $count >= 100;\n    return ( sort_u( \\@u ) );\n}\n\n=for list_repos\nUsage:  gitolite list-repos\n\n  - lists all repos/repo groups in conf\n  - no options, no flags\n=cut\n\nsub list_repos {\n    usage() if @_;\n\n    load_common();\n\n    my @r = keys %repos;\n    push @r, keys %split_conf;\n\n    return ( sort_u( \\@r ) );\n}\n\n=for list_memberships\nUsage:  gitolite list-memberships -u|-r <name>\n\nList all groups a name is a member of.  One of the flags '-u' or '-r' is\nmandatory, to specify if the name is a user or a repo.\n\nFor users, the output includes the result from GROUPLIST_PGM, if it is\ndefined.  For repos, the output includes any repo patterns that the repo name\nmatches, as well as any groups that contain those patterns.\n=cut\n\nsub list_memberships {\n    require Getopt::Long;\n\n    my ( $user, $repo, $help );\n\n    Getopt::Long::GetOptionsFromArray(\n        \\@_,\n        'user|u=s' => \\$user,\n        'repo|r=s' => \\$repo,\n        'help|h'   => \\$help,\n    );\n    usage() if $help or ( not $user and not $repo );\n\n    load_common();\n    my @m;\n\n    if ( $user and $repo ) {\n        # unsupported/undocumented except via \"in_role()\" in Easy.pm\n        @m = memberships( 'user', $user, $repo );\n    } elsif ($user) {\n        @m = memberships( 'user', $user );\n    } elsif ($repo) {\n        @m = memberships( 'repo', $repo );\n    }\n\n    @m = grep { $_ ne '@all' and $_ ne ( $user || $repo ) } @m;\n    return ( sort_u( \\@m ) );\n}\n\n=for list_members\nUsage:  gitolite list-members <group name>\n\n  - list all members of a group\n  - takes one group name\n\n'@all' is not expandable in this context.  Also, if you have GROUPLIST_PGM set\nin your rc file[1], gitolite cannot expand group names completely; only your\nexternal database can.\n\n[1]: http://gitolite.com/gitolite/conf.html#getting-user-group-info-from-ldap\n\n=cut\n\nsub list_members {\n    usage() if @_ and $_[0] eq '-h' or not @_;\n\n    my $name = shift;\n\n    load_common();\n\n    my @m = ();\n    while ( my ( $k, $v ) = each(%groups) ) {\n        for my $g ( @{$v} ) {\n            push @m, $k if $g eq $name;\n        }\n    }\n\n    return ( sort_u( \\@m ) );\n}\n\n# ----------------------------------------------------------------------\n\n{\n    my $start_time = 0;\n\n    sub timer {\n        unless ($start_time) {\n            $start_time = time();\n            return 0;\n        }\n        my $elapsed = shift;\n        return 0 if time() - $start_time < $elapsed;\n        $start_time = time();\n        return 1;\n    }\n}\n\n1;\n\n"
  },
  {
    "path": "src/lib/Gitolite/Conf/Store.pm",
    "content": "package Gitolite::Conf::Store;\n\n# receive parsed conf data and store it\n# ----------------------------------------------------------------------\n\n@EXPORT = qw(\n  add_to_group\n  set_repolist\n  parse_refs\n  parse_users\n  add_rule\n  add_config\n  set_subconf\n\n  expand_list\n  new_repos\n  new_repo\n  new_wild_repo\n  hook_repos\n  store\n  parse_done\n);\n\nuse Exporter 'import';\nuse Data::Dumper;\n$Data::Dumper::Indent   = 1;\n$Data::Dumper::Sortkeys = 1;\n\nuse Gitolite::Rc;\nuse Gitolite::Common;\nuse Gitolite::Hooks::Update;\nuse Gitolite::Hooks::PostUpdate;\n\nuse strict;\nuse warnings;\n\n# ----------------------------------------------------------------------\n\nmy %repos;\nmy %groups;\nmy %configs;\nmy %split_conf;\n\nmy @repolist;    # current repo list; reset on each 'repo ...' line\nmy $subconf = 'master';\nmy $nextseq = 0;\nmy %ignored;\n\n# ----------------------------------------------------------------------\n\nsub add_to_group {\n    my ( $lhs, @rhs ) = @_;\n    _die \"bad group '$lhs'\" unless $lhs =~ $REPONAME_PATT;\n    map { _die \"bad expansion '$_'\" unless $_ =~ $REPOPATT_PATT } @rhs;\n\n    # store the group association, but overload it to keep track of when\n    # the group was *first* created by using $subconf as the *value*\n    do { $groups{$lhs}{$_} ||= $subconf }\n      for ( expand_list(@rhs) );\n\n    # create the group hash even if empty\n    $groups{$lhs} = {} unless $groups{$lhs};\n}\n\nsub set_repolist {\n    my @in = @_;\n    @repolist = ();\n    # ...sanity checks\n    while (@in) {\n        $_ = shift @in;\n        if ( check_subconf_repo_disallowed( $subconf, $_ ) ) {\n            if ( exists $groups{$_} ) {\n                # groupname disallowed; try individual members now\n                ( my $g = $_ ) =~ s/^\\@$subconf\\./\\@/;\n                _warn \"expanding '$g'; this *may* slow down compilation\";\n                unshift @in, keys %{ $groups{$_} };\n                next;\n            }\n            $ignored{$subconf}{$_} = 1;\n            next;\n        }\n\n        _warn \"explicit '.git' extension ignored for $_.git\" if s/\\.git$//;\n        _die \"bad reponame '$_'\" if $_ !~ $REPOPATT_PATT;\n\n        push @repolist, $_;\n    }\n}\n\nsub parse_refs {\n    my $refs = shift;\n    my @refs; @refs = split( ' ', $refs ) if $refs;\n    @refs = expand_list(@refs);\n\n    # if no ref is given, this PERM applies to all refs\n    @refs = qw(refs/.*) unless @refs;\n\n    # fully qualify refs that dont start with \"refs/\" or \"VREF/\";\n    # prefix them with \"refs/heads/\"\n    @refs = map { m(^(refs|VREF)/) or s(^)(refs/heads/); $_ } @refs;\n\n    return @refs;\n}\n\nsub parse_users {\n    my $users = shift;\n    my @users = split ' ', $users;\n    do { _die \"bad username '$_'\" unless $_ =~ $USERNAME_PATT }\n      for @users;\n\n    return @users;\n}\n\nsub add_rule {\n    my ( $perm, $ref, $user, $fname, $lnum ) = @_;\n    _warn \"doesn't make sense to supply a ref ('$ref') for 'R' rule\"\n      if $perm eq 'R' and $ref ne 'refs/.*';\n    _warn \"possible undeclared group '$user'\"\n      if $user =~ /^@/\n      and not $groups{$user}\n      and not $rc{GROUPLIST_PGM}\n      and not special_group($user);\n    _die \"bad ref '$ref'\"   unless $ref =~ $REPOPATT_PATT;\n    _die \"bad user '$user'\" unless $user =~ $USERNAME_PATT;\n\n    $nextseq++;\n    store_rule_info( $nextseq, $fname, $lnum );\n    for my $repo (@repolist) {\n        push @{ $repos{$repo}{$user} }, [ $nextseq, $perm, $ref ];\n    }\n\n    sub special_group {\n        # ok perl doesn't really have lexical subs (at least not the older\n        # perls I want to support) but let's pretend...\n        my $g = shift;\n        $g =~ s/^\\@//;\n        return 1 if $g eq 'all' or $g eq 'CREATOR';\n        return 1 if $rc{ROLES}{$g};\n        return 0;\n    }\n\n}\n\nsub add_config {\n    my ( $n, $key, $value ) = @_;\n\n    $nextseq++;\n    for my $repo (@repolist) {\n        push @{ $configs{$repo} }, [ $nextseq, $key, $value ];\n    }\n}\n\nsub set_subconf {\n    $subconf = shift;\n    _die \"bad subconf '$subconf'\" unless $subconf =~ /^[-\\w.]+$/;\n}\n\n# ----------------------------------------------------------------------\n\nsub expand_list {\n    my @list     = @_;\n    my @new_list = ();\n\n    for my $item (@list) {\n        if ( $item =~ /^@/ and $item ne '@all' )    # nested group\n        {\n            _die \"undefined group '$item'\" unless $groups{$item};\n            # add those names to the list\n            push @new_list, sort keys %{ $groups{$item} };\n        } else {\n            push @new_list, $item;\n        }\n    }\n\n    return @new_list;\n}\n\nsub new_repos {\n    trace(3);\n    _chdir( $rc{GL_REPO_BASE} );\n\n    # normal repos\n    my @repos = grep { $_ =~ $REPONAME_PATT and not /^@/ } ( sort keys %repos, sort keys %configs );\n    # add in members of repo groups\n    map { push @repos, keys %{ $groups{$_} } } grep { /^@/ and $_ ne '@all' } keys %repos;\n\n    for my $repo ( @{ sort_u( \\@repos ) } ) {\n        next unless $repo =~ $REPONAME_PATT;    # skip repo patterns\n        next if $repo =~ m(^\\@|EXTCMD/);        # skip groups and fake repos\n\n        # use gl-conf as a sentinel; if it exists, all is well\n        next if -f \"$repo.git/gl-conf\";\n\n        if (-d \"$repo.git\") {\n            # directory exists but sentinel missing?  Maybe a freshly imported repo?\n            hook_1($repo);\n        } else {\n            push @{ $rc{NEW_REPOS_CREATED} }, $repo;\n            trigger( 'PRE_CREATE', $repo );\n            new_repo($repo);\n        }\n    }\n}\n\nsub new_repo {\n    my $repo = shift;\n    trace( 3, $repo );\n\n    _mkdir(\"$repo.git\");\n    _chdir(\"$repo.git\");\n    _system(\"git init --bare >&2\");\n    unlink \"description\";\n    _chdir( $rc{GL_REPO_BASE} );\n    hook_1($repo);\n}\n\nsub new_wild_repo {\n    my ( $repo, $user, $aa ) = @_;\n    _chdir( $rc{GL_REPO_BASE} );\n\n    trigger( 'PRE_CREATE', $repo, $user, $aa );\n    new_repo($repo);\n    _print( \"$repo.git/gl-creator\", $user );\n    trigger( 'POST_CREATE', $repo, $user, $aa );\n\n    _chdir( $rc{GL_ADMIN_BASE} );\n}\n\nsub hook_repos {\n    trace(3);\n\n    # all repos, all hooks\n    _chdir( $rc{GL_REPO_BASE} );\n    my $phy_repos = list_phy_repos(1);\n\n    for my $repo ( @{$phy_repos} ) {\n        hook_1($repo);\n    }\n}\n\nsub store {\n    trace(3);\n\n    # first write out the ones for the physical repos\n    _chdir( $rc{GL_REPO_BASE} );\n\n    # list of repos (union of keys of %repos plus %configs)\n    my %kr_kc;\n    @kr_kc{ keys %repos } = ();\n    @kr_kc{ keys %configs } = ();\n    for my $repo ( keys %kr_kc ) {\n        store_1($repo);\n    }\n\n    _chdir( $rc{GL_ADMIN_BASE} );\n    store_common();\n}\n\nsub parse_done {\n    for my $ig ( sort keys %ignored ) {\n        _warn \"subconf '$ig' attempting to set access for \" . join( \", \", sort keys %{ $ignored{$ig} } );\n    }\n\n    close_rule_info();\n}\n\n# ----------------------------------------------------------------------\n\nsub check_subconf_repo_disallowed {\n    # trying to set access for $repo (='foo')...\n    my ( $subconf, $repo ) = @_;\n    trace( 2, $subconf, $repo );\n\n    # processing the master config, not a subconf\n    return 0 if $subconf eq 'master';\n    # subconf is also called 'foo' (you're allowed to have a\n    # subconf that is only concerned with one repo)\n    return 0 if $subconf eq $repo;\n    # same thing in big-config-land; foo is just @foo now\n    return 0 if ( \"\\@$subconf\" eq $repo );\n    my @matched = grep { $repo =~ /^$_$/ }\n      grep { $groups{\"\\@$subconf\"}{$_} eq 'master' }\n      sort keys %{ $groups{\"\\@$subconf\"} };\n    return 0 if @matched > 0;\n\n    trace( 2, \"-> disallowed\" );\n    return 1;\n}\n\nsub store_1 {\n    # warning: writes and *deletes* it from %repos and %configs\n    my ($repo) = shift;\n    trace( 3, $repo );\n    return unless -d \"$repo.git\";\n\n    my ( %one_repo, %one_config );\n\n    my $dumped_data = '';\n    if ( $repos{$repo} ) {\n        $one_repo{$repo} = $repos{$repo};\n        delete $repos{$repo};\n        $dumped_data = Data::Dumper->Dump( [ \\%one_repo ], [qw(*one_repo)] );\n    }\n\n    if ( $configs{$repo} ) {\n        $one_config{$repo} = $configs{$repo};\n        delete $configs{$repo};\n        $dumped_data .= Data::Dumper->Dump( [ \\%one_config ], [qw(*one_config)] );\n    }\n\n    _print( \"$repo.git/gl-conf\", $dumped_data );\n\n    $split_conf{$repo} = 1;\n}\n\nsub store_common {\n    trace(3);\n    my $cc = \"conf/gitolite.conf-compiled.pm\";\n    my $compiled_fh = _open( \">\", \"$cc.new\" );\n\n    my %patterns = ();\n\n    my $data_version = glrc('current-data-version');\n    trace( 3, \"data_version = $data_version\" );\n    print $compiled_fh Data::Dumper->Dump( [$data_version], [qw(*data_version)] );\n\n    my $dumped_data = Data::Dumper->Dump( [ \\%repos ], [qw(*repos)] );\n    $dumped_data .= Data::Dumper->Dump( [ \\%configs ], [qw(*configs)] ) if %configs;\n\n    print $compiled_fh $dumped_data;\n\n    if (%groups) {\n        my %groups = %{ inside_out( \\%groups ) };\n        $dumped_data = Data::Dumper->Dump( [ \\%groups ], [qw(*groups)] );\n        print $compiled_fh $dumped_data;\n\n        # save patterns in %groups for faster handling of multiple repos, such\n        # as happens in the various POST_COMPILE scripts\n        for my $k ( keys %groups ) {\n            $patterns{groups}{$k} = 1 unless $k =~ $REPONAME_PATT;\n        }\n    }\n\n    print $compiled_fh Data::Dumper->Dump( [ \\%patterns ], [qw(*patterns)] ) if %patterns;\n\n    print $compiled_fh Data::Dumper->Dump( [ \\%split_conf ], [qw(*split_conf)] ) if %split_conf;\n\n    close $compiled_fh or _die \"close compiled-conf failed: $!\\n\";\n    rename \"$cc.new\", $cc;\n}\n\n{\n    my $hook_reset = 0;\n\n    sub hook_1 {\n        my $repo = shift;\n        trace( 3, $repo );\n\n        # reset the gitolite supplied hooks, in case someone fiddled with\n        # them, but only once per run\n        if ( not $hook_reset ) {\n            _mkdir(\"$rc{GL_ADMIN_BASE}/hooks/common\");\n            _mkdir(\"$rc{GL_ADMIN_BASE}/hooks/gitolite-admin\");\n            _print( \"$rc{GL_ADMIN_BASE}/hooks/common/update\",              update_hook() );\n            _print( \"$rc{GL_ADMIN_BASE}/hooks/gitolite-admin/post-update\", post_update_hook() );\n            chmod 0755, \"$rc{GL_ADMIN_BASE}/hooks/common/update\";\n            chmod 0755, \"$rc{GL_ADMIN_BASE}/hooks/gitolite-admin/post-update\";\n            $hook_reset++;\n        }\n\n        # propagate user-defined (custom) hooks to all repos\n        ln_sf( \"$rc{LOCAL_CODE}/hooks/common\", \"*\", \"$repo.git/hooks\" ) if $rc{LOCAL_CODE};\n\n        # override/propagate gitolite defined hooks for all repos\n        ln_sf( \"$rc{GL_ADMIN_BASE}/hooks/common\", \"*\", \"$repo.git/hooks\" );\n        # override/propagate gitolite defined hooks for the admin repo\n        ln_sf( \"$rc{GL_ADMIN_BASE}/hooks/gitolite-admin\", \"*\", \"$repo.git/hooks\" ) if $repo eq 'gitolite-admin';\n    }\n}\n\nsub inside_out {\n    my $href = shift;\n    # input conf: @aa = bb cc <newline> @bb = @aa dd\n\n    my %ret = ();\n    while ( my ( $k, $v ) = each( %{$href} ) ) {\n        # $k is '@aa', $v is a href\n        for my $k2 ( keys %{$v} ) {\n            # $k2 is bb, then cc\n            push @{ $ret{$k2} }, $k;\n        }\n    }\n    return \\%ret;\n    # %groups = ( 'bb' => [ '@bb', '@aa' ], 'cc' => [ '@bb', '@aa' ], 'dd' => [ '@bb' ]);\n}\n\n{\n    my $ri_fh = '';\n\n    sub store_rule_info {\n        $ri_fh = _open( \">\", $rc{GL_ADMIN_BASE} . \"/conf/rule_info\" ) unless $ri_fh;\n        # $nextseq, $fname, $lnum\n        print $ri_fh join( \"\\t\", @_ ) . \"\\n\";\n    }\n\n    sub close_rule_info {\n        close $ri_fh or die \"close rule_info file failed: $!\";\n    }\n}\n\n1;\n\n"
  },
  {
    "path": "src/lib/Gitolite/Conf/Sugar.pm",
    "content": "# and now for something completely different...\n\npackage SugarBox;\n\nsub run_sugar_script {\n    my ( $ss, $lref ) = @_;\n    do $ss if -r $ss;\n    $lref = sugar_script($lref);\n    return $lref;\n}\n\n# ----------------------------------------------------------------------\n\npackage Gitolite::Conf::Sugar;\n\n# syntactic sugar for the conf file, including site-local macros\n# ----------------------------------------------------------------------\n\n@EXPORT = qw(\n  sugar\n);\n\nuse Exporter 'import';\n\nuse Gitolite::Rc;\nuse Gitolite::Common;\nuse Gitolite::Conf::Explode;\n\nuse strict;\nuse warnings;\n\n# ----------------------------------------------------------------------\n\nsub sugar {\n    # gets a filename, returns a listref\n\n    my @lines = ();\n    explode( shift, 'master', \\@lines );\n\n    my $lines;\n    $lines = \\@lines;\n\n    # run through the sugar stack one by one\n\n    # first, user supplied sugar:\n    if ( exists $rc{SYNTACTIC_SUGAR} ) {\n        if ( ref( $rc{SYNTACTIC_SUGAR} ) ne 'ARRAY' ) {\n            _warn \"bad syntax for specifying sugar scripts; see docs\";\n        } else {\n            for my $s ( @{ $rc{SYNTACTIC_SUGAR} } ) {\n\n                # perl-ism; apart from keeping the full path separate from the\n                # simple name, this also protects %rc from change by implicit\n                # aliasing, which would happen if you touched $s itself\n                my $sfp = _which( \"syntactic-sugar/$s\", 'r' );\n\n                _warn(\"skipped sugar script '$s'\"), next if not -r $sfp;\n                $lines = SugarBox::run_sugar_script( $sfp, $lines );\n                $lines = [ grep /\\S/, map { cleanup_conf_line($_) } @$lines ];\n            }\n        }\n    }\n\n    # then our stuff:\n\n    $lines = rw_cdm($lines);\n    $lines = option($lines);       # must come after rw_cdm\n    $lines = owner_desc($lines);\n    $lines = name_vref($lines);\n    $lines = role_names($lines);\n    $lines = skip_block($lines);\n\n    return $lines;\n}\n\nsub rw_cdm {\n    my $lines = shift;\n    my @ret;\n\n    # repo foo <...> RWC = ...\n    #   ->  option CREATE_IS_C = 1\n    # (and similarly DELETE_IS_D and MERGE_CHECK)\n    # but only once per repo of course\n\n    my %seen = ();\n    for my $line (@$lines) {\n        push @ret, $line;\n        if ( $line =~ /^repo / ) {\n            %seen = ();\n        } elsif ( $line =~ /^(-|C|R|RW\\+?(?:C?D?|D?C?)M?) (.* )?= (.+)/ ) {\n            my $perms = $1;\n            push @ret, \"option DELETE_IS_D = 1\" if $perms =~ /D/     and not $seen{D}++;\n            push @ret, \"option CREATE_IS_C = 1\" if $perms =~ /RW.*C/ and not $seen{C}++;\n            push @ret, \"option MERGE_CHECK = 1\" if $perms =~ /M/     and not $seen{M}++;\n        }\n    }\n    return \\@ret;\n}\n\nsub option {\n    my $lines = shift;\n    my @ret;\n\n    # option foo = bar\n    #   ->  config gitolite-options.foo = bar\n\n    for my $line (@$lines) {\n        $line =~ s/option mirror\\.slaves/option mirror.copies/;\n        if ( $line =~ /^option (\\S+) = (\\S.*)/ ) {\n            push @ret, \"config gitolite-options.$1 = $2\";\n        } else {\n            push @ret, $line;\n        }\n    }\n    return \\@ret;\n}\n\nsub owner_desc {\n    my $lines = shift;\n    my @ret;\n\n    # owner = \"owner name\"\n    #   ->  config gitweb.owner = owner name\n    # desc = \"some long description\"\n    #   ->  config gitweb.description = some long description\n    # category = \"whatever...\"\n    #   ->  config gitweb.category = whatever...\n\n    for my $line (@$lines) {\n        if ( $line =~ /^desc = (\\S.*)/ ) {\n            push @ret, \"config gitweb.description = $1\";\n        } elsif ( $line =~ /^owner = (\\S.*)/ ) {\n            push @ret, \"config gitweb.owner = $1\";\n        } elsif ( $line =~ /^category = (\\S.*)/ ) {\n            push @ret, \"config gitweb.category = $1\";\n        } else {\n            push @ret, $line;\n        }\n    }\n    return \\@ret;\n}\n\nsub name_vref {\n    my $lines = shift;\n    my @ret;\n\n    # <perm> NAME/foo = <user>\n    #   ->  <perm> VREF/NAME/foo = <user>\n\n    for my $line (@$lines) {\n        if ( $line =~ /^(-|R\\S+) \\S.* = \\S.*/ ) {\n            $line =~ s( NAME/)( VREF/NAME/)g;\n        }\n        push @ret, $line;\n    }\n    return \\@ret;\n}\n\nsub role_names {\n    my $lines = shift;\n    my @ret;\n\n    # <perm> [<ref>] = <user list containing CREATOR|READERS|WRITERS>\n    #   ->  same but with \"@\" prepended to rolenames\n\n    for my $line (@$lines) {\n        if ( $line =~ /^(-|C|R|RW\\+?(?:C?D?|D?C?)M?) (.* )?= (.+)/ ) {\n            my ( $p, $r ) = ( $1, $2 );\n            my $u = '';\n            for ( split ' ', $3 ) {\n                $_ = \"\\@$_\" if $_ eq 'CREATOR' or $rc{ROLES}{$_};\n                $u .= \" $_\";\n            }\n            $r ||= '';\n            # mind the spaces (or play safe and run cleanup_conf_line again)\n            push @ret, cleanup_conf_line(\"$p $r = $u\");\n        } else {\n            push @ret, $line;\n        }\n    }\n    return \\@ret;\n}\n\nsub skip_block {\n    my $lines = shift;\n\n    my @out  = ();\n    for (@$lines) {\n        my $skip = 0;\n        $skip = 1 if /^= *begin testconf$/;\n        $skip = 1 if /^= *begin template-data$/;\n        # add code for other types of blocks here as needed\n\n        next if $skip .. /^= *end$/;\n        push @out, $_;\n    }\n\n    return \\@out;\n}\n\n1;\n\n"
  },
  {
    "path": "src/lib/Gitolite/Conf.pm",
    "content": "package Gitolite::Conf;\n\n# explode/parse a conf file\n# ----------------------------------------------------------------------\n\n@EXPORT = qw(\n  compile\n  explode\n  parse\n);\n\nuse Exporter 'import';\n\nuse Gitolite::Rc;\nuse Gitolite::Common;\nuse Gitolite::Conf::Sugar;\nuse Gitolite::Conf::Store;\n\nuse strict;\nuse warnings;\n\n# ----------------------------------------------------------------------\n\nsub compile {\n    _die \"'gitolite compile' does not take any arguments\" if @_;\n\n    _chdir( $rc{GL_ADMIN_BASE} );\n    _chdir(\"conf\");\n\n    parse( sugar('gitolite.conf') );\n\n    # the order matters; new repos should be created first, to give store a\n    # place to put the individual gl-conf files\n    new_repos();\n\n    # cache control\n    if ($rc{CACHE}) {\n        require Gitolite::Cache;\n        Gitolite::Cache->import(qw(cache_control));\n\n        cache_control('stop');\n    }\n\n    store();\n\n    if ($rc{CACHE}) {\n        cache_control('start');\n    }\n\n    # remove entries from POST_CREATE which also exist in POST_COMPILE.  This\n    # not only saves us having to implement an optimisation in *those*\n    # scripts, but more importantly, moves the optimisation one step up -- we\n    # don't even *call* those scripts now.\n    my %pco = map { $_ => 1 } @{ $rc{POST_COMPILE} };\n    @{ $rc{POST_CREATE} } = grep { ! exists $pco{$_} } @{ $rc{POST_CREATE} };\n\n    for my $repo ( @{ $rc{NEW_REPOS_CREATED} } ) {\n        trigger( 'POST_CREATE', $repo );\n    }\n\n    # process rule template data\n    _system(\"gitolite compile-template-data\");\n}\n\nsub parse {\n    my $lines = shift;\n    trace( 3, scalar(@$lines) . \" lines incoming\" );\n\n    my ( $fname, $lnum );\n    for my $line (@$lines) {\n        ( $fname, $lnum ) = ( $1, $2 ), next if $line =~ /^# (\\S+) (\\d+)$/;\n        # user or repo groups\n        if ( $line =~ /^(@\\S+) = (.*)/ ) {\n            add_to_group( $1, split( ' ', $2 ) );\n        } elsif ( $line =~ /^repo (.*)/ ) {\n            set_repolist( split( ' ', $1 ) );\n        } elsif ( $line =~ /^(-|C|R|RW\\+?(?:C?D?|D?C?)M?) (.* )?= (.+)/ ) {\n            my $perm  = $1;\n            my @refs  = parse_refs( $2 || '' );\n            my @users = parse_users($3);\n\n            for my $ref (@refs) {\n                for my $user (@users) {\n                    add_rule( $perm, $ref, $user, $fname, $lnum );\n                }\n            }\n        } elsif ( $line =~ /^config (.+) = ?(.*)/ ) {\n            my ( $key, $value ) = ( $1, $2 );\n            $value =~ s/^['\"](.*)[\"']$/$1/;\n            my @validkeys = split( ' ', ( $rc{GIT_CONFIG_KEYS} || '' ) );\n            push @validkeys, \"gitolite-options\\\\..*\";\n            my @matched = grep { $key =~ /^$_$/i } @validkeys;\n            _die \"git config '$key' not allowed\\ncheck GIT_CONFIG_KEYS in the rc file\" if ( @matched < 1 );\n            _die \"bad config value '$value'\" if $value =~ $UNSAFE_PATT;\n            while ( my ( $mk, $mv ) = each %{ $rc{SAFE_CONFIG} } ) {\n                $value =~ s/%$mk/$mv/g;\n            }\n            add_config( 1, $key, $value );\n        } elsif ( $line =~ /^subconf (\\S+)$/ ) {\n            trace( 3, $line );\n            set_subconf($1);\n        } else {\n            _warn \"syntax error, ignoring: '$line'\";\n        }\n    }\n    parse_done();\n}\n\n1;\n"
  },
  {
    "path": "src/lib/Gitolite/Easy.pm",
    "content": "package Gitolite::Easy;\n\n# easy access to gitolite from external perl programs\n# ----------------------------------------------------------------------\n# most/all functions in this module test $ENV{GL_USER}'s rights and\n# permissions so it needs to be set.\n\n# \"use\"-ing this module\n# ----------------------------------------------------------------------\n# Using this module from within a gitolite trigger or command is easy; you\n# just need 'use lib $ENV{GL_LIBDIR};' before the 'use Gitolite::Easy;'.\n#\n# Using it from something completely outside gitolite requires a bit more\n# work.  First, run 'gitolite query-rc -a' to find the correct values for\n# GL_BINDIR and GL_LIBDIR in your installation.  Then use this code in your\n# external program, using the paths you just found:\n#\n#   BEGIN {\n#       $ENV{HOME} = \"/home/git\";   # or whatever is the hosting user's $HOME\n#       $ENV{GL_BINDIR} = \"/full/path/to/gitolite/src\";\n#       $ENV{GL_LIBDIR} = \"/full/path/to/gitolite/src/lib\";\n#   }\n#   use lib $ENV{GL_LIBDIR};\n#   use Gitolite::Easy;\n\n# API documentation\n# ----------------------------------------------------------------------\n# documentation for each function is at the top of the function.\n# Documentation is NOT in pod format; just read the source with a nice syntax\n# coloring text editor and you'll be happy enough.  (I do not like POD; please\n# don't send me patches for this aspect of the module).\n\n#<<<\n@EXPORT = qw(\n  is_admin\n  is_super_admin\n  in_group\n  in_role\n\n  owns\n  can_read\n  can_write\n\n  config\n\n  textfile\n\n  %rc\n  say\n  say2\n  _die\n  _warn\n  _print\n  usage\n\n  option\n);\n#>>>\nuse Exporter 'import';\n\nuse Gitolite::Rc;\nuse Gitolite::Common;\nuse Gitolite::Conf::Load;\n\nuse strict;\nuse warnings;\n\nmy $user;\n\n# ----------------------------------------------------------------------\n\n# is_admin()\n\n# return true if $ENV{GL_USER} is set and has W perms to the admin repo\n\n# shell equivalent\n#   if gitolite access -q gitolite-admin $GL_USER W; then ...\n\nsub is_admin {\n    valid_user();\n    return not( access( 'gitolite-admin', $user, 'W', 'any' ) =~ /DENIED/ );\n}\n\n# is_super_admin()\n\n# (useful only if you are using delegation)\n\n# return true if $ENV{GL_USER} is set and has W perms to any file in the admin\n# repo\n\n# shell equivalent\n#   if gitolite access -q gitolite-admin $GL_USER W VREF/NAME/; then ...\nsub is_super_admin {\n    valid_user();\n    return not( access( 'gitolite-admin', $user, 'W', 'VREF/NAME/' ) =~ /DENIED/ );\n}\n\n# in_group()\n\n# return true if $ENV{GL_USER} is set and is in the given group\n\n# shell equivalent\n#   if gitolite list-memberships $GL_USER | grep -x $GROUPNAME >/dev/null; then ...\nsub in_group {\n    valid_user();\n    my $g = shift;\n    $g =~ s/^\\@?/@/;\n\n    return grep { $_ eq $g } @{ Gitolite::Conf::Load::list_memberships( '-u', $user ) };\n}\n\n# in_role()\n\n# return true if $ENV{GL_USER} is set and has the given role for the given repo\n\n# shell equivalent\n#   if gitolite list-memberships -u $GL_USER -r $GL_REPO | grep -x $ROLENAME >/dev/null; then ...\nsub in_role {\n    valid_user();\n    my $r = shift;\n    $r =~ s/^\\@?/@/;\n    my $repo = shift;\n\n    return grep { $_ eq $r } @{ Gitolite::Conf::Load::list_memberships( \"-u\", $user, \"-r\", $repo ) };\n}\n\n# owns()\n\n# return true if $ENV{GL_USER} is set and is an OWNER of the given repo.\n\n# shell equivalent (assuming GL_USER is set)\n#   if gitolite owns $REPONAME; then ...\nsub owns {\n    valid_user();\n    my $r = shift;\n\n    # prevent unnecessary disclosure of repo existence info\n    return 0 if repo_missing($r);\n\n    return ( creator($r) eq $user or $rc{OWNER_ROLENAME} and in_role( $rc{OWNER_ROLENAME}, $r ) );\n}\n\n# can_read()\n# return true if $ENV{GL_USER} is set and can read the given repo\n\n# shell equivalent\n#   if gitolite access -q $REPONAME $GL_USER R; then ...\nsub can_read {\n    valid_user();\n    my $r = shift;\n    return not( access( $r, $user, 'R', 'any' ) =~ /DENIED/ );\n}\n\n# can_write()\n# return true if $ENV{GL_USER} is set and can write to the given repo.\n# Optional second argument can be '+' to check that instead of 'W'.  Optional\n# third argument can be a full ref name instead of 'any'.\n\n# shell equivalent\n#   if gitolite access -q $REPONAME $GL_USER W; then ...\nsub can_write {\n    valid_user();\n    my ( $r, $aa, $ref ) = @_;\n    $aa  ||= 'W';\n    $ref ||= 'any';\n    return not( access( $r, $user, $aa, $ref ) =~ /DENIED/ );\n}\n\n# config()\n# given a repo and a key, return a hash containing all the git config\n# variables for that repo where the section+key match the regex.  If none are\n# found, return an empty hash.  If you don't want it as a regex, use \\Q\n# appropriately\n\n# shell equivalent\n#   foo=$(gitolite git-config -r $REPONAME foo\\\\.bar)\nsub config {\n    my $repo = shift;\n    my $key  = shift;\n\n    return () if repo_missing($repo);\n\n    my $ret = git_config( $repo, $key );\n    return %$ret;\n}\n\n# ----------------------------------------------------------------------\n\n# maintain a textfile; see comments in code for details, and calls in various\n# other programs (like 'motd', 'desc', and 'readme') for how to call\nsub textfile {\n    my %h = @_;\n    my $repodir;\n\n    # target file\n    _die \"need file\" unless $h{file};\n    _die \"'$h{file}' contains a '/'\" if $h{file} =~ m(/);\n    Gitolite::Conf::Load::sanity($h{file}, $REPONAME_PATT);\n\n    # target file's location.  This can come from one of two places: dir\n    # (which comes from our code, so does not need to be sanitised), or repo,\n    # which may come from the user\n    _die \"need exactly one of repo or dir\" unless $h{repo} xor $h{dir};\n    _die \"'$h{dir}' does not exist\" if $h{dir} and not -d $h{dir};\n    if ($h{repo}) {\n        Gitolite::Conf::Load::sanity($h{repo}, $REPONAME_PATT);\n        $h{dir} = \"$rc{GL_REPO_BASE}/$h{repo}.git\";\n        _die \"repo '$h{repo}' does not exist\" if not -d $h{dir};\n\n        my $umask = option( $h{repo}, 'umask' );\n        # note: using option() moves us to ADMIN_BASE, but we don't care here\n        umask oct($umask) if $umask;\n    }\n\n    # final full file name\n    my $f = \"$h{dir}/$h{file}\";\n\n    # operation\n    _die \"can't have both prompt and text\" if defined $h{prompt} and defined $h{text};\n    if (defined $h{prompt}) {\n        print STDERR $h{prompt};\n        my $t = join( \"\", <> );\n        _print($f, $t);\n    } elsif (defined $h{text}) {\n        _print($f, $h{text});\n    } else {\n        return slurp($f) if -f $f;\n    }\n\n    return '';\n}\n\n# ----------------------------------------------------------------------\n\nsub valid_user {\n    _die \"GL_USER not set\" unless exists $ENV{GL_USER};\n    $user = $ENV{GL_USER};\n}\n\n1;\n"
  },
  {
    "path": "src/lib/Gitolite/Hooks/PostUpdate.pm",
    "content": "package Gitolite::Hooks::PostUpdate;\n\n# everything to do with the post-update hook\n# ----------------------------------------------------------------------\n\n@EXPORT = qw(\n  post_update\n  post_update_hook\n);\n\nuse Exporter 'import';\n\nuse Gitolite::Rc;\nuse Gitolite::Common;\n\nuse strict;\nuse warnings;\n\n# ----------------------------------------------------------------------\n\nsub post_update {\n    trace( 3, 'post-up', @ARGV );\n\n    my $master=`git symbolic-ref HEAD`; chomp $master;\n\n    exit 0 unless grep( $_ eq $master, @ARGV );\n    # this is the *real* post_update hook for gitolite\n    $master =~ s(.*/)();\n\n    tsh_try(\"git ls-tree --name-only $master\");\n    _die \"no files/dirs called 'hooks' or 'logs' are allowed\" if tsh_text() =~ /^(hooks|logs)$/m;\n\n    my $hooks_changed = 0;\n    {\n        local $ENV{GIT_WORK_TREE} = $rc{GL_ADMIN_BASE};\n\n        tsh_try(\"git diff --name-only $master\");\n        $hooks_changed++ if tsh_text() =~ m(/hooks/common/);\n        # the leading slash ensure that this hooks/common directory is below\n        # some top level directory, not *at* the top.  That's LOCAL_CODE, and\n        # it's actual name could be anything but it doesn't matter to us.\n\n        tsh_try(\"git checkout -f --quiet $master\");\n    }\n    _system(\"gitolite compile\");\n    _system(\"gitolite setup --hooks-only\") if $hooks_changed;\n    _system(\"gitolite trigger POST_COMPILE\");\n\n    exit 0;\n}\n\n{\n    my $text = '';\n\n    sub post_update_hook {\n        if ( not $text ) {\n            local $/ = undef;\n            $text = <DATA>;\n        }\n        return $text;\n    }\n}\n\n1;\n\n__DATA__\n#!/usr/bin/perl\n\nuse strict;\nuse warnings;\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Hooks::PostUpdate;\n\n# gitolite post-update hook (only for the admin repo)\n# ----------------------------------------------------------------------\n\npost_update();          # is not expected to return\nexit 1;                 # so if it does, something is wrong\n"
  },
  {
    "path": "src/lib/Gitolite/Hooks/Update.pm",
    "content": "package Gitolite::Hooks::Update;\n\n# everything to do with the update hook\n# ----------------------------------------------------------------------\n\n@EXPORT = qw(\n  update\n  update_hook\n);\n\nuse Exporter 'import';\n\nuse Gitolite::Rc;\nuse Gitolite::Common;\nuse Gitolite::Conf::Load;\n\nuse strict;\nuse warnings;\n\n$|++;\n\n# ----------------------------------------------------------------------\n\nsub update {\n    # this is the *real* update hook for gitolite\n\n    bypass() if $ENV{GL_BYPASS_ACCESS_CHECKS};\n\n    my ( $ref, $oldsha, $newsha, $oldtree, $newtree, $aa ) = args(@ARGV);\n\n    trace( 2, $ENV{GL_REPO}, $ENV{GL_USER}, $aa, @ARGV );\n\n    my $ret = access( $ENV{GL_REPO}, $ENV{GL_USER}, $aa, $ref );\n    trigger( 'ACCESS_2', $ENV{GL_REPO}, $ENV{GL_USER}, $aa, $ref, $ret, $oldsha, $newsha );\n    _die $ret if $ret =~ /DENIED/;\n\n    check_vrefs( $ref, $oldsha, $newsha, $oldtree, $newtree, $aa );\n\n    gl_log( 'update', $ENV{GL_REPO}, $ENV{GL_USER}, $aa, @ARGV, $ret );\n    exit 0;\n}\n\nsub bypass {\n    require Cwd;\n    Cwd->import;\n    gl_log( 'update', getcwd(), '(' . ( $ENV{USER} || '?' ) . ')', 'bypass', @ARGV );\n    exit 0;\n}\n\nsub check_vrefs {\n    my ( $ref, $oldsha, $newsha, $oldtree, $newtree, $aa ) = @_;\n    my $name_seen = 0;\n    my $n_vrefs   = 0;\n    for my $vref ( vrefs( $ENV{GL_REPO}, $ENV{GL_USER} ) ) {\n        $n_vrefs++;\n        if ( $vref =~ m(^VREF/NAME/) ) {\n            # this one is special; we process it right here, and only once\n            next if $name_seen++;\n\n            for my $ref ( map { chomp; s(^)(VREF/NAME/); $_; } `git diff --name-only $oldtree $newtree` ) {\n                check_vref( $aa, $ref );\n            }\n        } else {\n            my ( $dummy, $pgm, @args ) = split '/', $vref;\n            $pgm = _which( \"VREF/$pgm\", 'x' );\n            $pgm or _die \"'$vref': helper program missing or unexecutable\";\n\n            open( my $fh, \"-|\", $pgm, @_, $vref, @args ) or _die \"'$vref': can't spawn helper program: $!\";\n            while (<$fh>) {\n                # print non-vref lines and skip processing (for example,\n                # normal STDOUT by a normal update hook)\n                unless (m(^VREF/)) {\n                    print;\n                    next;\n                }\n                my ( $ref, $deny_message ) = split( ' ', $_, 2 );\n                check_vref( $aa, $ref, $deny_message );\n            }\n            close($fh) or _die $!\n              ? \"Error closing sort pipe: $!\"\n              : \"$vref: helper program exit status $?\";\n        }\n    }\n    return $n_vrefs;\n}\n\nsub check_vref {\n    my ( $aa, $ref, $deny_message ) = @_;\n\n    my $ret = access( $ENV{GL_REPO}, $ENV{GL_USER}, $aa, $ref );\n    trace( 2, \"access($ENV{GL_REPO}, $ENV{GL_USER}, $aa, $ref)\", \"-> $ret\" );\n    if ( $ret =~ /by fallthru/ ) {\n        trace( 3, \"remember, fallthru is success here!\" );\n        return;\n    }\n    trigger( 'ACCESS_2', $ENV{GL_REPO}, $ENV{GL_USER}, $aa, $ref, $ret );\n    _die \"$ret\" . ( $deny_message ? \"\\n$deny_message\" : '' ) if $ret =~ /DENIED/;\n}\n\n{\n    my $text = '';\n\n    sub update_hook {\n        if ( not $text ) {\n            local $/ = undef;\n            $text = <DATA>;\n        }\n        return $text;\n    }\n}\n\n# ----------------------------------------------------------------------\n\nsub args {\n    my ( $ref, $oldsha, $newsha ) = @_;\n    my ( $oldtree, $newtree, $aa );\n\n    my $sha256 = 0;\n    my $zeroes = '0' x 40;\n    # this is special to git -- the hash of an empty tree\n    my $empty = '4b825dc642cb6eb9a060e54bf8d69288fbee4904';\n    if (length($oldsha) == 64) {\n        $sha256 = 1;\n        $zeroes = '0' x 64;\n        $empty = '6ef19b41225c5369f1c104d45d8d85efa9b057b53b14b4b9b939dd74decc5321';\n    }\n\n    $oldtree = $oldsha eq $zeroes ? $empty : $oldsha;\n    $newtree = $newsha eq $zeroes ? $empty : $newsha;\n\n    my $merge_base = $zeroes;\n    # for branch create or delete, merge_base stays at '0'x40\n    chomp( $merge_base = `git merge-base $oldsha $newsha` )\n      unless $oldsha eq $zeroes\n      or $newsha eq $zeroes;\n\n    $aa = 'W';\n    # tag rewrite\n    $aa = '+' if $ref =~ m(refs/tags/) and $oldsha ne ( $zeroes );\n    # non-ff push to ref (including ref delete)\n    $aa = '+' if $oldsha ne $merge_base;\n\n    $aa = 'D' if ( option( $ENV{GL_REPO}, 'DELETE_IS_D' ) ) and $newsha eq $zeroes;\n    $aa = 'C' if ( option( $ENV{GL_REPO}, 'CREATE_IS_C' ) ) and $oldsha eq $zeroes;\n\n    # and now \"M\" commits.  All the other accesses (W, +, C, D) were mutually\n    # exclusive in some sense.  Sure a W could be a C or a + could be a D but\n    # that's by design.  A merge commit, however, could still be any of the\n    # others (except a \"D\").\n\n    # so we have to *append* 'M' to $aa (if the repo has MERGE_CHECK in\n    # effect and this push contains a merge inside)\n\n    if ( option( $ENV{GL_REPO}, 'MERGE_CHECK' ) ) {\n        if ( $oldsha eq $zeroes or $newsha eq $zeroes ) {\n            _warn \"ref create/delete ignored for purposes of merge-check\\n\";\n        } else {\n            $aa .= 'M' if `git rev-list -n 1 --merges $oldsha..$newsha` =~ /./;\n        }\n    }\n\n    return ( $ref, $oldsha, $newsha, $oldtree, $newtree, $aa );\n}\n\n1;\n\n__DATA__\n#!/usr/bin/perl\n\nuse strict;\nuse warnings;\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Hooks::Update;\n\n# gitolite update hook\n# ----------------------------------------------------------------------\n\nupdate();               # is not expected to return\nexit 1;                 # so if it does, something is wrong\n"
  },
  {
    "path": "src/lib/Gitolite/Rc.pm",
    "content": "package Gitolite::Rc;\n\n# everything to do with 'rc'.  Also defines some 'constants'\n# ----------------------------------------------------------------------\n\n@EXPORT = qw(\n  %rc\n  glrc\n  query_rc\n  version\n  greeting\n  trigger\n  _which\n\n  $REMOTE_COMMAND_PATT\n  $REF_OR_FILENAME_PATT\n  $REPONAME_PATT\n  $REPOPATT_PATT\n  $USERNAME_PATT\n  $UNSAFE_PATT\n);\n\nuse Exporter 'import';\n\nuse Gitolite::Common;\n\n# ----------------------------------------------------------------------\n\nour %rc;\nour $non_core;\n\n# ----------------------------------------------------------------------\n\n# pre-populate some important rc keys\n# ----------------------------------------------------------------------\n\n$rc{GL_BINDIR} = $ENV{GL_BINDIR};\n$rc{GL_LIBDIR} = $ENV{GL_LIBDIR};\n\n# these keys could be overridden by the rc file later\n$rc{GL_REPO_BASE}  = \"$ENV{HOME}/repositories\";\n$rc{GL_ADMIN_BASE} = \"$ENV{HOME}/.gitolite\";\n$rc{LOG_TEMPLATE}  = \"$ENV{HOME}/.gitolite/logs/gitolite-%y-%m.log\";\n\n# variables that should probably never be changed but someone will want to, I'll bet...\n# ----------------------------------------------------------------------\n\n#<<<\n$REMOTE_COMMAND_PATT  =                qr(^[-0-9a-zA-Z._\\@/+ :,\\%=]*$);\n$REF_OR_FILENAME_PATT =     qr(^[0-9a-zA-Z][-0-9a-zA-Z._\\@/+ :,]*$);\n$REPONAME_PATT        =  qr(^\\@?[0-9a-zA-Z][-0-9a-zA-Z._\\@/+]*$);\n$REPOPATT_PATT        = qr(^\\@?[[0-9a-zA-Z][-0-9a-zA-Z._\\@/+\\\\^$|()[\\]*?{},]*$);\n$USERNAME_PATT        =  qr(^\\@?[0-9a-zA-Z][-0-9a-zA-Z._\\@+]*$);\n\n$UNSAFE_PATT          = qr([`~#\\$\\&()|;<>]);\n#>>>\n\n# ----------------------------------------------------------------------\n\n# find the rc file and 'do' it\n# ----------------------------------------------------------------------\nmy $current_data_version = \"3.2\";\n\nmy $rc = glrc('filename');\nif ( -r $rc and -s $rc ) {\n    do $rc or die $@;\n}\nif ( defined($GL_ADMINDIR) ) {\n    say2 \"\";\n    say2 \"FATAL: '$rc' seems to be for older gitolite; please see\\nhttp://gitolite.com/gitolite/migr.html\";\n\n    exit 1;\n}\n\n# let values specified in rc file override our internal ones\n# ----------------------------------------------------------------------\n@rc{ keys %RC } = values %RC;\n\n# expand the non_core list into INPUT, PRE_GIT, etc using 'ENABLE' settings\nnon_core_expand() if $rc{ENABLE};\n\n# add internal triggers\n# ----------------------------------------------------------------------\n\n# is the server/repo in a writable state (i.e., not down for maintenance etc)\nunshift @{ $rc{ACCESS_1} }, 'Writable::access_1';\n\n# (testing only) override the rc file silently\n# ----------------------------------------------------------------------\n# use an env var that is highly unlikely to appear in real life :)\ndo $ENV{G3T_RC} if exists $ENV{G3T_RC} and -r $ENV{G3T_RC};\n\n# setup some perl/rc/env vars, plus umask\n# ----------------------------------------------------------------------\n\numask ( $rc{UMASK} || 0077 );\n\nunshift @INC, \"$rc{LOCAL_CODE}/lib\" if $rc{LOCAL_CODE};\n\n$ENV{PATH} = \"$ENV{GL_BINDIR}:$ENV{PATH}\" unless $ENV{PATH} =~ /^$ENV{GL_BINDIR}:/;\n\n{\n    $rc{GL_TID} = $ENV{GL_TID} ||= $$;\n    # TID: loosely, transaction ID.  The first PID at the entry point passes\n    # it down to all its children so you can track each access, across all the\n    # various commands it spawns and actions it generates.\n\n    $rc{GL_LOGFILE} = $ENV{GL_LOGFILE} ||= gen_lfn( $rc{LOG_TEMPLATE} );\n}\n\n# these two are meant to help externally written commands (see\n# src/commands/writable for an example)\n$ENV{GL_REPO_BASE}  = $rc{GL_REPO_BASE};\n$ENV{GL_ADMIN_BASE} = $rc{GL_ADMIN_BASE};\n\n# ----------------------------------------------------------------------\n\nuse strict;\nuse warnings;\n\n# ----------------------------------------------------------------------\n\nmy $glrc_default_text = '';\n{\n    local $/ = undef;\n    $glrc_default_text = <DATA>;\n}\n\n# ----------------------------------------------------------------------\n\nsub non_core_expand {\n    my %enable;\n\n    for my $e ( @{ $rc{ENABLE} } ) {\n        my ( $name, $arg ) = split ' ', $e, 2;\n        # store args as the hash value for the name\n        $enable{$name} = $arg || '';\n\n        # for now, we pretend everything is a command, because commands\n        # are the only thing that the non_core list does not contain\n        $rc{COMMANDS}{$name} = $arg || 1;\n    }\n\n    # bring in additional non-core specs from the rc file, if given\n    if ( my $nc2 = $rc{NON_CORE} ) {\n        for ( $non_core, $nc2 ) {\n            # beat 'em into shape :)\n            s/#.*//g;\n            s/[ \\t]+/ /g; s/^ //mg; s/ $//mg;\n            s/\\n+/\\n/g;\n        }\n\n        for ( split \"\\n\", $nc2 ) {\n            next unless /\\S/;\n            my ( $name, $where, $module, $before, $name2 ) = split ' ', $_;\n            if ( not $before ) {\n                $non_core .= \"$name $where $module\\n\";\n                next;\n            }\n            die if $before ne 'before';\n            $non_core =~ s(^(?=$name2 $where( |$)))($name $where $module\\n)m;\n        }\n    }\n\n    my @data = split \"\\n\", $non_core || '';\n    for (@data) {\n        next if /^\\s*(#|$)/;\n        my ( $name, $where, $module ) = split ' ', $_;\n\n        # if it appears here, it's not a command, so delete it.  At the end of\n        # this loop, what's left in $rc{COMMANDS} will be those names in the\n        # enable list that do not appear in the non_core list.\n        delete $rc{COMMANDS}{$name};\n\n        next unless exists $enable{$name};\n\n        # module to call is name if specified as \".\"\n        $module = $name if $module eq \".\";\n\n        # module to call is \"name::pre_git\" or such if specified as \"::\"\n        ( $module = $name ) .= \"::\" . lc($where) if $module eq '::';\n\n        # append arguments, if supplied\n        $module .= \" $enable{$name}\" if $enable{$name};\n\n        push @{ $rc{$where} }, $module;\n    }\n\n    # finally, add in commands that were declared in the non-core list\n    map { /^(\\S+)/; $rc{COMMANDS}{$1} = 1 } @{ $rc{COMMAND} };\n}\n\n# exported functions\n# ----------------------------------------------------------------------\n\nsub glrc {\n    my $cmd = shift;\n    if ( $cmd eq 'default-filename' ) {\n        return \"$ENV{HOME}/.gitolite.rc\";\n    } elsif ( $cmd eq 'default-text' ) {\n        return $glrc_default_text if $glrc_default_text;\n        _die \"rc file default text not set; this should not happen!\";\n    } elsif ( $cmd eq 'filename' ) {\n        # where is the rc file?\n\n        # search $HOME first\n        return \"$ENV{HOME}/.gitolite.rc\" if -f \"$ENV{HOME}/.gitolite.rc\";\n\n        return '';\n    } elsif ( $cmd eq 'current-data-version' ) {\n        return $current_data_version;\n    } else {\n        _die \"unknown argument to glrc: '$cmd'\";\n    }\n}\n\nmy $all   = 0;\nmy $dump  = 0;\nmy $nonl  = 0;\nmy $quiet = 0;\n\nsub query_rc {\n\n    my @vars = args();\n\n    no strict 'refs';\n\n    if ($all) {\n        for my $e ( sort keys %rc ) {\n            print \"$e=\" . ( defined( $rc{$e} ) ? $rc{$e} : 'undef' ) . \"\\n\";\n        }\n        exit 0;\n    }\n\n    if ($dump) {\n        require Data::Dumper;\n        $Data::Dumper::Sortkeys = 1;\n        print Data::Dumper::Dumper \\%rc;\n        exit 0;\n    }\n\n    my $cv = \\%rc;    # current \"value\"\n    while (@vars) {\n        my $v = shift @vars;\n\n        # dig into the rc hash, using each var as a component\n        if ( not ref($cv) ) {\n            _warn \"unused arguments...\";\n            last;\n        } elsif ( ref($cv) eq 'HASH' ) {\n            $cv = $cv->{$v} || '';\n        } elsif ( ref($cv) eq 'ARRAY' ) {\n            $cv = $cv->[$v] || '';\n        } else {\n            _die \"dont know what to do with \" . ref($cv) . \" item in the rc file\";\n        }\n    }\n\n    # we've run out of arguments so $cv is what we have.  If we're supposed to\n    # be quiet, we don't have to print anything so let's get that done first:\n    exit( $cv ? 0 : 1 ) if $quiet;    # shell truth\n\n    # print values (notice we ignore the '-n' option if it's a ref)\n    if ( ref($cv) eq 'HASH' ) {\n        print join( \"\\n\", sort keys %$cv ), \"\\n\" if %$cv;\n    } elsif ( ref($cv) eq 'ARRAY' ) {\n        print join( \"\\n\", @$cv ), \"\\n\" if @$cv;\n    } else {\n        print $cv . ( $nonl ? '' : \"\\n\" ) if $cv;\n    }\n    exit( $cv ? 0 : 1 );              # shell truth\n}\n\nsub version {\n    my $version = '';\n    $version = '(unknown)';\n    for (\"$ENV{GL_BINDIR}/VERSION\") {\n        $version = slurp($_) if -r $_;\n    }\n    chomp($version);\n    return $version;\n}\n\nsub greeting {\n    my $json = shift;\n\n    chomp( my $hn = `hostname -s 2>/dev/null || hostname` );\n    my $gv = substr( `git --version`, 12 );\n    my $gl_user = $ENV{GL_USER} || '';\n    $gl_user = \" $gl_user\" if $gl_user;\n\n    if ($json) {\n        $json->{GL_USER}          = $ENV{GL_USER};\n        $json->{USER}             = ( $ENV{USER} || \"httpd\" ) . \"\\@$hn\";\n        $json->{gitolite_version} = version();\n        chomp( $json->{git_version} = $gv );    # this thing has a newline at the end\n        return;\n    }\n\n    # normal output\n    return \"hello$gl_user, this is \" . ( $ENV{USER} || \"httpd\" ) . \"\\@$hn running gitolite3 \" . version() . \" on git $gv\\n\";\n}\n\nsub trigger {\n    my $rc_section = shift;\n\n    # if arg-2 (now arg-1, due to the 'shift' above) exists, it is a repo\n    # name, so setup env from options\n    require Gitolite::Conf::Load;\n    Gitolite::Conf::Load->import('env_options');\n    env_options( $_[0] ) if $_[0];\n\n    if ( exists $rc{$rc_section} ) {\n        if ( ref( $rc{$rc_section} ) ne 'ARRAY' ) {\n            _die \"'$rc_section' section in rc file is not a perl list\";\n        } else {\n            for my $s ( @{ $rc{$rc_section} } ) {\n                my ( $pgm, @args ) = split ' ', $s;\n\n                if ( my ( $module, $sub ) = ( $pgm =~ /^(.*)::(\\w+)$/ ) ) {\n\n                    require Gitolite::Triggers;\n                    trace( 2, 'trigger module', $module, $sub, @args, $rc_section, @_ );\n                    Gitolite::Triggers::run( $module, $sub, @args, $rc_section, @_ );\n\n                } else {\n                    $pgm = _which( \"triggers/$pgm\", 'x' );\n\n                    _warn(\"skipped trigger '$s' (not found or not executable)\"), next if not $pgm;\n                    trace( 2, 'trigger command', $s );\n                    _system( $pgm, @args, $rc_section, @_ );    # they better all return with 0 exit codes!\n                }\n            }\n        }\n        return;\n    }\n    trace( 3, \"'$rc_section' not found in rc\" );\n}\n\nsub _which {\n    # looks for a file in LOCAL_CODE or GL_BINDIR.  Returns whichever exists\n    # (LOCAL_CODE preferred if defined) or 0 if not found.\n    my $file = shift;\n    my $mode = shift;    # could be 'x' or 'r'\n\n    my @files = (\"$rc{GL_BINDIR}/$file\");\n    unshift @files, (\"$rc{LOCAL_CODE}/$file\") if $rc{LOCAL_CODE};\n\n    for my $f (@files) {\n        return $f if -x $f;\n        return $f if -r $f and $mode eq 'r';\n    }\n\n    return 0;\n}\n\n# ----------------------------------------------------------------------\n\n=for args\nUsage:  gitolite query-rc -a\n        gitolite query-rc -d\n        gitolite query-rc [-n] [-q] rc-variable\n\n    -a          print all variables and values (first level only)\n    -d          dump the entire rc structure\n    -n          do not append a newline if variable is scalar\n    -q          exit code only (shell truth; 0 is success)\n\nQuery the rc hash.  Second and subsequent arguments dig deeper into the hash.\nThe examples are for the default configuration; yours may be different.\n\nSingle values:\n    gitolite query-rc GL_ADMIN_BASE     # prints \"/home/git/.gitolite\" or similar\n    gitolite query-rc UMASK             # prints \"63\" (that's 0077 in decimal!)\n\nHashes:\n    gitolite query-rc COMMANDS\n        # prints \"desc\", \"help\", \"info\", \"perms\", \"writable\", one per line\n    gitolite query-rc COMMANDS help     # prints 1\n    gitolite query-rc -q COMMANDS help  # prints nothing; exit code is 0\n    gitolite query-rc COMMANDS fork     # prints nothing; exit code is 1\n\nArrays (somewhat less useful):\n    gitolite query-rc POST_GIT          # prints nothing; exit code is 0\n    gitolite query-rc POST_COMPILE      # prints 4 lines\n    gitolite query-rc POST_COMPILE 0    # prints the first of those 4 lines\n\nExplore:\n    gitolite query-rc -a\n    # prints all first level variables and values, one per line.  Any that are\n    # listed as HASH or ARRAY can be explored further in subsequent commands.\n    gitolite query-rc -d                # dump the entire rc structure\n=cut\n\nsub args {\n    my $help = 0;\n\n    require Getopt::Long;\n    Getopt::Long::GetOptions(\n        'all|a'   => \\$all,\n        'dump|d'  => \\$dump,\n        'nonl|n'  => \\$nonl,\n        'quiet|q' => \\$quiet,\n        'help|h'  => \\$help,\n    ) or usage();\n\n    _die(\"'-a' cannot be combined with other arguments or options; run with '-h' for usage\") if $all and ( @ARGV or $dump or $nonl or $quiet );\n    usage() if not $all and not $dump and not @ARGV or $help;\n    return @ARGV;\n}\n\n# ----------------------------------------------------------------------\n\nBEGIN {\n    $non_core = \"\n    # No user-servicable parts inside.  Warranty void if seal broken.  Refer\n    # servicing to authorised service center only.\n\n    continuation-lines      SYNTACTIC_SUGAR .\n    keysubdirs-as-groups    SYNTACTIC_SUGAR .\n    macros                  SYNTACTIC_SUGAR .\n    refex-expr              SYNTACTIC_SUGAR .\n\n    renice                  PRE_GIT         .\n\n    Kindergarten            INPUT           ::\n\n    CpuTime                 INPUT           ::\n    CpuTime                 POST_GIT        ::\n\n    Shell                   INPUT           ::\n\n    Alias                   INPUT           ::\n\n    Motd                    INPUT           ::\n    Motd                    PRE_GIT         ::\n    Motd                    COMMAND         motd\n\n    Mirroring               INPUT           ::\n    Mirroring               PRE_GIT         ::\n    Mirroring               POST_GIT        ::\n\n    refex-expr              ACCESS_2        RefexExpr::access_2\n\n    expand-deny-messages    ACCESS_1        .\n    expand-deny-messages    ACCESS_2        .\n\n    RepoUmask               PRE_GIT         ::\n    RepoUmask               POST_CREATE     ::\n\n    partial-copy            PRE_GIT         .\n\n    upstream                PRE_GIT         .\n\n    no-create-on-read       PRE_CREATE      AutoCreate::deny_R\n    no-auto-create          PRE_CREATE      AutoCreate::deny_RW\n\n    ssh-authkeys-split      POST_COMPILE    post-compile/ssh-authkeys-split\n    ssh-authkeys            POST_COMPILE    post-compile/ssh-authkeys\n    Shell                   POST_COMPILE    post-compile/ssh-authkeys-shell-users\n\n    set-default-roles       POST_CREATE     .\n\n    git-config              POST_COMPILE    post-compile/update-git-configs\n    git-config              POST_CREATE     post-compile/update-git-configs\n\n    create-with-reference   POST_CREATE     post-compile/create-with-reference\n\n    gitweb                  POST_CREATE     post-compile/update-gitweb-access-list\n    gitweb                  POST_COMPILE    post-compile/update-gitweb-access-list\n\n    cgit                    POST_COMPILE    post-compile/update-description-file\n\n    daemon                  POST_CREATE     post-compile/update-git-daemon-access-list\n    daemon                  POST_COMPILE    post-compile/update-git-daemon-access-list\n\n    repo-specific-hooks     POST_COMPILE    .\n    repo-specific-hooks     POST_CREATE     .\n\";\n}\n\n1;\n\n# ----------------------------------------------------------------------\n\n__DATA__\n# configuration variables for gitolite\n\n# This file is in perl syntax.  But you do NOT need to know perl to edit it --\n# just mind the commas, use single quotes unless you know what you're doing,\n# and make sure the brackets and braces stay matched up!\n\n# (Tip: perl allows a comma after the last item in a list also!)\n\n# HELP for commands can be had by running the command with \"-h\".\n\n# HELP for all the other FEATURES can be found in the documentation (look for\n# \"list of non-core programs shipped with gitolite\" in the master index) or\n# directly in the corresponding source file.\n\n%RC = (\n\n    # ------------------------------------------------------------------\n\n    # default umask gives you perms of '0700'; see the rc file docs for\n    # how/why you might change this\n    UMASK                           =>  0077,\n\n    # look for \"git-config\" in the documentation\n    GIT_CONFIG_KEYS                 =>  '',\n\n    # comment out if you don't need all the extra detail in the logfile\n    LOG_EXTRA                       =>  1,\n    # logging options\n    # 1. leave this section as is for 'normal' gitolite logging (default)\n    # 2. uncomment this line to log ONLY to syslog:\n    # LOG_DEST                      => 'syslog',\n    # 3. uncomment this line to log to syslog and the normal gitolite log:\n    # LOG_DEST                      => 'syslog,normal',\n    # 4. prefixing \"repo-log,\" to any of the above will **also** log just the\n    #    update records to \"gl-log\" in the bare repo directory:\n    # LOG_DEST                      => 'repo-log,normal',\n    # LOG_DEST                      => 'repo-log,syslog',\n    # LOG_DEST                      => 'repo-log,syslog,normal',\n    # syslog 'facility': defaults to 'local0', uncomment if needed.  For example:\n    # LOG_FACILITY                  => 'local4',\n\n    # roles.  add more roles (like MANAGER, TESTER, ...) here.\n    #   WARNING: if you make changes to this hash, you MUST run 'gitolite\n    #   compile' afterward, and possibly also 'gitolite trigger POST_COMPILE'\n    ROLES => {\n        READERS                     =>  1,\n        WRITERS                     =>  1,\n    },\n\n    # enable caching (currently only Redis).  PLEASE RTFM BEFORE USING!!!\n    # CACHE                         =>  'Redis',\n\n    # ------------------------------------------------------------------\n\n    # rc variables used by various features\n\n    # the 'info' command prints this as additional info, if it is set\n        # SITE_INFO                 =>  'Please see http://blahblah/gitolite for more help',\n\n    # the CpuTime feature uses these\n        # display user, system, and elapsed times to user after each git operation\n        # DISPLAY_CPU_TIME          =>  1,\n        # display a warning if total CPU times (u, s, cu, cs) crosses this limit\n        # CPU_TIME_WARN_LIMIT       =>  0.1,\n\n    # the Mirroring feature needs this\n        # HOSTNAME                  =>  \"foo\",\n\n    # TTL for redis cache; PLEASE SEE DOCUMENTATION BEFORE UNCOMMENTING!\n        # CACHE_TTL                 =>  600,\n\n    # ------------------------------------------------------------------\n\n    # suggested locations for site-local gitolite code (see cust.html)\n\n        # this one is managed directly on the server\n        # LOCAL_CODE                =>  \"$ENV{HOME}/local\",\n\n        # or you can use this, which lets you put everything in a subdirectory\n        # called \"local\" in your gitolite-admin repo.  For a SECURITY WARNING\n        # on this, see http://gitolite.com/gitolite/non-core.html#using-the-gitolite-admin-repo-to-manage-non-core-code\n        # LOCAL_CODE                =>  \"$rc{GL_ADMIN_BASE}/local\",\n\n    # ------------------------------------------------------------------\n\n    # List of commands and features to enable\n\n    ENABLE => [\n\n        # COMMANDS\n\n            # These are the commands enabled by default\n            'help',\n            'desc',\n            'info',\n            'perms',\n            'writable',\n\n            # Uncomment or add new commands here.\n            # 'create',\n            # 'fork',\n            # 'mirror',\n            # 'readme',\n            # 'sskm',\n            # 'D',\n\n        # These FEATURES are enabled by default.\n\n            # essential (unless you're using smart-http mode)\n            'ssh-authkeys',\n\n            # creates git-config entries from gitolite.conf file entries like 'config foo.bar = baz'\n            'git-config',\n\n            # creates git-daemon-export-ok files; if you don't use git-daemon, comment this out\n            'daemon',\n\n            # creates projects.list file; if you don't use gitweb, comment this out\n            'gitweb',\n\n        # These FEATURES are disabled by default; uncomment to enable.  If you\n        # need to add new ones, ask on the mailing list :-)\n\n        # user-visible behaviour\n\n            # prevent wild repos auto-create on fetch/clone\n            # 'no-create-on-read',\n            # no auto-create at all (don't forget to enable the 'create' command!)\n            # 'no-auto-create',\n\n            # access a repo by another (possibly legacy) name\n            # 'Alias',\n\n            # give some users direct shell access.  See documentation in\n            # sts.html for details on the following two choices.\n            # \"Shell $ENV{HOME}/.gitolite.shell-users\",\n            # 'Shell alice bob',\n\n            # set default roles from lines like 'option default.roles-1 = ...', etc.\n            # 'set-default-roles',\n\n            # show more detailed messages on deny\n            # 'expand-deny-messages',\n\n            # show a message of the day\n            # 'Motd',\n\n        # system admin stuff\n\n            # enable mirroring (don't forget to set the HOSTNAME too!)\n            # 'Mirroring',\n\n            # allow people to submit pub files with more than one key in them\n            # 'ssh-authkeys-split',\n\n            # selective read control hack\n            # 'partial-copy',\n\n            # manage local, gitolite-controlled, copies of read-only upstream repos\n            # 'upstream',\n\n            # updates 'description' file instead of 'gitweb.description' config item\n            # 'cgit',\n\n            # allow repo-specific hooks to be added\n            # 'repo-specific-hooks',\n\n        # performance, logging, monitoring...\n\n            # be nice\n            # 'renice 10',\n\n            # log CPU times (user, system, cumulative user, cumulative system)\n            # 'CpuTime',\n\n        # syntactic_sugar for gitolite.conf and included files\n\n            # allow backslash-escaped continuation lines in gitolite.conf\n            # 'continuation-lines',\n\n            # create implicit user groups from directory names in keydir/\n            # 'keysubdirs-as-groups',\n\n            # allow simple line-oriented macros\n            # 'macros',\n\n        # Kindergarten mode\n\n            # disallow various things that sensible people shouldn't be doing anyway\n            # 'Kindergarten',\n    ],\n\n);\n\n# ------------------------------------------------------------------------------\n# per perl rules, this should be the last line in such a file:\n1;\n\n# Local variables:\n# mode: perl\n# End:\n# vim: set syn=perl:\n"
  },
  {
    "path": "src/lib/Gitolite/Setup.pm",
    "content": "package Gitolite::Setup;\n\n# implements 'gitolite setup'\n# ----------------------------------------------------------------------\n\n=for args\nUsage:  gitolite setup [<option>]\n\nSetup gitolite, compile conf, run the POST_COMPILE trigger (see rc file) and\npropagate hooks.\n\n    -a, --admin <name>          admin name\n    -pk, --pubkey <file>        pubkey file name\n    -ho, --hooks-only           skip other steps and just propagate hooks\n    -m, --message               set setup commit message\n\nFirst run: either the pubkey or the admin name is *required*, depending on\nwhether you're using ssh mode or http mode.\n\nSubsequent runs:\n\n  - Without options, 'gitolite setup' is a general \"fix up everything\" command\n    (for example, if you brought in repos from outside, or someone messed\n    around with the hooks, or you made an rc file change that affects access\n    rules, etc.)\n\n  - '-pk' can be used to replace the admin key; useful if you lost the admin's\n    private key but do have shell access to the server.\n\n  - '-ho' is mainly for scripting use.  Do not combine with other options.\n\n  - '-a' is ignored\n\n  - '-m' can be used to replace default commit message \"gitolite setup $argv\"\n    with a custom message (e.g. \"Setting up your repository mgmt\").\n\n=cut\n\n# ----------------------------------------------------------------------\n\n@EXPORT = qw(\n  setup\n);\n\nuse Exporter 'import';\n\nuse Gitolite::Rc;\nuse Gitolite::Common;\nuse Gitolite::Conf::Store;\n\nuse strict;\nuse warnings;\n\n# ----------------------------------------------------------------------\n\nsub setup {\n    my ( $admin, $pubkey, $h_only, $message ) = args();\n\n    unless ($h_only) {\n        setup_glrc();\n        setup_gladmin( $admin, $pubkey, $message );\n\n        _system(\"gitolite compile\");\n        _system(\"gitolite trigger POST_COMPILE\");\n    }\n\n    hook_repos();    # all of them, just to be sure\n}\n\n# ----------------------------------------------------------------------\n\nsub args {\n    my $admin   = '';\n    my $pubkey  = '';\n    my $message = '';\n    my $h_only  = 0;\n    my $help    = 0;\n    my $argv    = join( \" \", @ARGV );\n\n    require Getopt::Long;\n    Getopt::Long::GetOptions(\n        'admin|a=s'     => \\$admin,\n        'pubkey|pk=s'   => \\$pubkey,\n        'message|m=s'   => \\$message,\n        'hooks-only|ho' => \\$h_only,\n        'help|h'        => \\$help,\n    ) or usage();\n\n    usage() if $help or ( $pubkey and $admin );\n    usage() if $h_only and ( $admin or $pubkey );\n\n    if ($pubkey) {\n        $pubkey =~ /\\.pub$/                 or _die \"'$pubkey' name does not end in .pub\";\n        tsh_try(\"cat $pubkey\")              or _die \"'$pubkey' not a readable file\";\n        tsh_lines() == 1                    or _die \"'$pubkey' must have exactly one line\";\n        tsh_try(\"ssh-keygen -l -f $pubkey\") or _die \"'$pubkey' does not seem to be a valid ssh pubkey file\";\n\n        $admin = $pubkey;\n        # next 2 lines duplicated from args() in ssh-authkeys\n        $admin =~ s(.*/)();                # foo/bar/baz.pub -> baz.pub\n        $admin =~ s/(\\@[^.]+)?\\.pub$//;    # baz.pub, baz@home.pub -> baz\n        $pubkey =~ /\\@/ and print STDERR \"NOTE: the admin username is '$admin'\\n\";\n\n    }\n\n    return ( $admin || '', $pubkey || '', $h_only || 0, $message || \"gitolite setup $argv\");\n}\n\nsub setup_glrc {\n    _print( glrc('default-filename'), glrc('default-text') ) if not glrc('filename');\n}\n\nsub setup_gladmin {\n    my ( $admin, $pubkey, $message ) = @_;\n    _die \"'-pk' or '-a' required; see 'gitolite setup -h' for more\"\n      if not $admin and not -f \"$rc{GL_ADMIN_BASE}/conf/gitolite.conf\";\n\n    # reminder: 'admin files' are in ~/.gitolite, 'admin repo' is\n    # $rc{GL_REPO_BASE}/gitolite-admin.git\n\n    # grab the pubkey content before we chdir() away\n    my $pubkey_content = '';\n    $pubkey_content = slurp($pubkey) if $pubkey;\n\n    # set up the admin files in admin-base\n\n    _mkdir( $rc{GL_ADMIN_BASE} );\n    _chdir( $rc{GL_ADMIN_BASE} );\n\n    _mkdir(\"conf\");\n    _mkdir(\"logs\");\n    my $conf;\n    {\n        local $/ = undef;\n        $conf = <DATA>;\n    }\n    $conf =~ s/%ADMIN/$admin/g;\n\n    _print( \"conf/gitolite.conf\", $conf ) if not -f \"conf/gitolite.conf\";\n\n    if ($pubkey) {\n        _mkdir(\"keydir\");\n        _print( \"keydir/$admin.pub\", $pubkey_content );\n    }\n\n    # set up the admin repo in repo-base\n\n    _chdir();\n    _mkdir( $rc{GL_REPO_BASE} );\n    _chdir( $rc{GL_REPO_BASE} );\n\n    new_repo(\"gitolite-admin\") if not -d \"gitolite-admin.git\";\n\n    # commit the admin files to the admin repo\n\n    $ENV{GIT_WORK_TREE} = $rc{GL_ADMIN_BASE};\n    _chdir(\"$rc{GL_REPO_BASE}/gitolite-admin.git\");\n    _system(\"git add conf/gitolite.conf\");\n    _system(\"git add keydir\") if $pubkey;\n    tsh_try(\"git config --get user.email\") or tsh_run( \"git config user.email $ENV{USER}\\@\" . `hostname` );\n    tsh_try(\"git config --get user.name\")  or tsh_run( \"git config user.name '$ENV{USER} on '\" . `hostname` );\n    tsh_try(\"git diff --cached --quiet\")\n      or tsh_try(\"git commit -am '$message'\")\n      or _die \"setup failed to commit to the admin repo\";\n    delete $ENV{GIT_WORK_TREE};\n}\n\n1;\n\n__DATA__\nrepo gitolite-admin\n    RW+     =   %ADMIN\n\nrepo testing\n    RW+     =   @all\n"
  },
  {
    "path": "src/lib/Gitolite/Test/Tsh.pm",
    "content": "#!/usr/bin/perl\nuse 5.10.0;\n\n# Tsh -- non interactive Testing SHell in perl\n\n# TODO items:\n# - allow an RC file to be used to add basic and extended commands\n# - convert internal defaults to additions to the RC file\n# - implement shell commands as you go\n# - solve the \"pass/fail\" inconsistency between shell and perl\n# - solve the pipes problem (use 'overload'?)\n\n# ----------------------------------------------------------------------\n# modules\n\npackage Tsh;\n\nuse Exporter 'import';\n@EXPORT = qw(\n  try run cmp AUTOLOAD\n  rc error_count text lines error_list put\n  cd tsh_tempdir\n\n  $HOME $PWD $USER\n);\n@EXPORT_OK = qw();\n\nuse Env qw(@PATH HOME PWD USER TSH_VERBOSE);\n# other candidates:\n# GL_ADMINDIR GL_BINDIR GL_RC GL_REPO_BASE_ABS GL_REPO GL_USER\n\nuse strict;\nuse warnings;\n\nuse Text::Tabs;    # only used for formatting the usage() message\nuse Text::ParseWords;\n\nuse File::Temp qw(tempdir);\nEND { chdir( $ENV{HOME} ); }\n# we need this END handler *after* the 'use File::Temp' above.  Without\n# this, if $PWD at exit was $tempdir, you get errors like \"cannot remove\n# path when cwd is [...] at /usr/share/perl5/File/Temp.pm line 902\".\n\nuse Data::Dumper;\n\n# ----------------------------------------------------------------------\n# globals\n\nmy $rc;      # return code from backticked (external) programs\nmy $text;    # STDOUT+STDERR of backticked (external) programs\nmy $lec;     # the last external command (the rc and text are from this)\nmy $cmd;     # the current command\n\nmy $testnum;     # current test number, for info in TAP output\nmy $testname;    # current test name, for error info to user\nmy $line;        # current line number and text\n\nmy $err_count;   # count of test failures\nmy @errors_in;   # list of testnames that errored\n\nmy $tick;        # timestamp for git commits\n\nmy %autoloaded;\nmy $tempdir = '';\n\n# ----------------------------------------------------------------------\n# setup\n\n# unbuffer STDOUT and STDERR\nselect(STDERR); $|++;\nselect(STDOUT); $|++;\n\n# set the timestamp (needed only under harness)\ntest_tick() if $ENV{HARNESS_ACTIVE};\n\n# ----------------------------------------------------------------------\n# this is for one-liner access from outside, using @ARGV, as in:\n#   perl -MTsh -e 'tsh()' 'tsh command list'\n# or via STDIN\n#   perl -MTsh -e 'tsh()' < file-containing-tsh-commands\n# NOTE: it **exits**!\n\nsub tsh {\n    my @lines;\n\n    if (@ARGV) {\n        # simple, single argument which is a readable filename\n        if ( @ARGV == 1 and $ARGV[0] !~ /\\s/ and -r $ARGV[0] ) {\n            # take the contents of the file\n            @lines = <>;\n        } else {\n            # more than one argument *or* not readable filename\n            # just take the arguments themselves as the command list\n            @lines = @ARGV;\n            @ARGV  = ();\n        }\n    } else {\n        # no arguments given, take STDIN\n        usage() if -t;\n        @lines = <>;\n    }\n\n    # and process them\n    try(@lines);\n\n    # print error summary by default\n    if ( not defined $TSH_VERBOSE ) {\n        say STDERR \"$err_count error(s)\" if $err_count;\n    }\n\n    exit $err_count;\n}\n\n# these two get called with series of tsh commands, while the autoload,\n# (later) handles single commands\n\nsub try {\n    $line = $rc = $err_count = 0;\n    @errors_in = ();\n\n    # break up multiline arguments into separate lines\n    my @lines = map { split /\\n/ } @_;\n\n    # and process them\n    rc_lines(@lines);\n\n    # bump err_count if the last command had a non-0 rc (that was apparently not checked).\n    $err_count++ if $rc;\n\n    # finish up...\n    dbg( 1, \"$err_count error(s)\" ) if $err_count;\n    return ( not $err_count );\n}\n\n# run() differs from try() in that\n#   -   uses open(), not backticks\n#   -   takes only one command, not tsh-things like ok, /patt/ etc\n#   -   -   if you pass it an array it uses the list form!\n\nsub run {\n    open( my $fh, \"-|\", @_ ) or die \"tell sitaram $!\";\n    local $/ = undef; $text = <$fh>;\n    close $fh; warn \"tell sitaram $!\" if $!;\n    $rc = ( $? >> 8 );\n    return $text;\n}\n\nsub put {\n    my ( $file, $data ) = @_;\n    die \"probable quoting error in arguments to put: $file\\n\" if $file =~ /^\\s*['\"]/;\n    my $mode = \">\";\n    $mode = \"|-\" if $file =~ s/^\\s*\\|\\s*//;\n\n    $rc = 0;\n    my $fh;\n    open( $fh, $mode, $file )\n      and print $fh $data\n      and close $fh\n      and return 1;\n\n    $rc = 1;\n    dbg( 1, \"put $file: $!\" );\n    return '';\n}\n\n# ----------------------------------------------------------------------\n# TODO: AUTOLOAD and exportable convenience subs for common shell commands\n\nsub cd {\n    my $dir = shift || '';\n    _cd($dir);\n    dbg( 1, \"cd $dir: $!\" ) if $rc;\n    return ( not $rc );\n}\n\n# this is classic AUTOLOAD, almost from the perlsub manpage.  Although, if\n# instead of `ls('bin');` you want to be able to say `ls 'bin';` you will need\n# to predeclare ls, with `sub ls;`.\nsub AUTOLOAD {\n    my $program = $Tsh::AUTOLOAD;\n    dbg( 4, \"program = $program, arg=$_[0]\" );\n    $program =~ s/.*:://;\n    $autoloaded{$program}++;\n\n    die \"tsh's autoload support expects only one arg\\n\" if @_ > 1;\n    _sh(\"$program $_[0]\");\n    return ( not $rc );    # perl truth\n}\n\n# ----------------------------------------------------------------------\n# exportable service subs\n\nsub rc {\n    return $rc || 0;\n}\n\nsub text {\n    return $text || '';\n}\n\nsub lines {\n    return split /\\n/, $text;\n}\n\nsub error_count {\n    return $err_count;\n}\n\nsub error_list {\n    return (\n        wantarray\n        ? @errors_in\n        : join( \"\\n\", @errors_in )\n    );\n}\n\nsub tsh_tempdir {\n    # create tempdir if not already done\n    $tempdir = tempdir( \"tsh_tempdir.XXXXXXXXXX\", TMPDIR => 1, CLEANUP => 1 ) unless $tempdir;\n    # XXX TODO that 'UNLINK' doesn't work for Ctrl_C\n\n    return $tempdir;\n}\n\n# ----------------------------------------------------------------------\n# internal (non-exportable) service subs\n\nsub print_plan {\n    return unless $ENV{HARNESS_ACTIVE};\n    local $_ = shift;\n    say \"1..$_\";\n}\n\nsub rc_lines {\n    my @lines = @_;\n\n    while (@lines) {\n        local $_ = shift @lines;\n        chomp; $_ = trim_ws($_);\n\n        no warnings;\n        $line++;\n        use warnings;\n\n        # this also sets $testname\n        next if is_comment_or_empty($_);\n\n        dbg( 2, \"L: $_\" );\n        $line .= \": $_\";    # save line for printing with 'FAIL:'\n\n        # a DEF has to be on a line by itself\n        if (/^DEF\\s+([-.\\w]+)\\s*=\\s*(\\S.*)$/) {\n            def( $1, $2 );\n            next;\n        }\n\n        my @cmds = cmds($_);\n\n        # process each command\n        # (note: some of the commands may put stuff back into @lines)\n        while (@cmds) {\n            # this needs to be the 'global' one, since fail() prints it\n            $cmd = shift @cmds;\n\n            # is the current command a \"testing\" command?\n            my $testing_cmd = (\n                   $cmd =~ m(^ok(?:\\s+or\\s+(.*))?$)\n                or $cmd =~ m(^!ok(?:\\s+or\\s+(.*))?$)\n                or $cmd =~ m(^/(.*?)/(?:\\s+or\\s+(.*))?$)\n                or $cmd =~ m(^!/(.*?)/(?:\\s+or\\s+(.*))?$)\n            );\n\n            # warn if the previous command failed but rc is not being checked\n            if ( $rc and not $testing_cmd ) {\n                dbg( 1, \"rc: $rc from cmd prior to '$cmd'\\n\" );\n                # count this as a failure, for exit status purposes\n                $err_count++;\n                # and reset the rc, otherwise for example 'ls foo; tt; tt; tt'\n                # will tell you there are 3 errors!\n                $rc = 0;\n                push @errors_in, $testname if $testname;\n            }\n\n            # prepare to run the command\n            dbg( 3, \"C: $cmd\" );\n            if ( def($cmd) ) {\n                # expand macro and replace head of @cmds (unshift)\n                dbg( 2, \"DEF: $cmd\" );\n                unshift @cmds, cmds( def($cmd) );\n            } else {\n                parse($cmd);\n            }\n            # reset rc if checking is done\n            $rc = 0 if $testing_cmd;\n            # assumes you will (a) never have *both* 'ok' and '!ok' after\n            # an action command, and (b) one of them will come immediately\n            # after the action command, with /patt/ only after it.\n        }\n    }\n}\n\nsub def {\n    my ( $cmd, $list ) = @_;\n    state %def;\n    %def = read_rc_file() unless %def;\n\n    if ($list) {\n        # set mode\n        die \"attempt to redefine macro $cmd\\n\" if $def{$cmd};\n        $def{$cmd} = $list;\n        return;\n    }\n\n    # get mode: split the $cmd at spaces, see if there is a definition\n    # available, substitute any %1, %2, etc., in it and send it back\n    my ( $c, @d ) = shellwords($cmd);\n    my $e;    # the expanded value\n    if ( $e = $def{$c} ) {    # starting value\n        for my $i ( 1 .. 9 ) {\n            last unless $e =~ /%$i/;                              # no more %N's (we assume sanity)\n            die \"$def{$c} requires more arguments\\n\" unless @d;\n            my $f = shift @d;                                     # get the next datum\n            $e =~ s/%$i/$f/g;                                     # and substitute %N all over\n        }\n        return join( \" \", $e, @d );                               # join up any remaining data\n    }\n    return '';\n}\n\nsub _cd {\n    my $dir = shift || $HOME;\n    # a directory name of 'tsh_tempdir' is special\n    $dir = tsh_tempdir() if $dir eq 'tsh_tempdir';\n    $rc = 0;\n    chdir($dir) or $rc = 1;\n}\n\nsub _sh {\n    my $cmd = shift;\n    # TODO: switch to IPC::Open3 or something...?\n\n    dbg( 4, \"  running: ( $cmd ) 2>&1\" );\n    $text = `( $cmd ) 2>&1; /bin/echo -n RC=\\$?`;\n    $lec  = $cmd;\n    dbg( 4, \"  results:\\n$text\" );\n\n    if ( $text =~ /RC=(\\d+)$/ ) {\n        $rc = $1;\n        $text =~ s/RC=\\d+$//;\n    } else {\n        die \"couldnt find RC= in result; this should not happen:\\n$text\\n\\n...\\n\";\n    }\n}\n\nsub _perl {\n    my $perl = shift;\n    local $_;\n    $_ = $text;\n\n    dbg( 4, \"  eval: $perl\" );\n    my $evrc = eval $perl;\n\n    if ($@) {\n        $rc = 1;    # shell truth\n        dbg( 1, $@ );\n        # leave $text unchanged\n    } else {\n        $rc = not $evrc;\n        # $rc is always shell truth, so we need to cover the case where\n        # there was no error but it still returned a perl false\n        $text = $_;\n    }\n    dbg( 4, \"  eval-rc=$evrc, results:\\n$text\" );\n}\n\nsub parse {\n    my $cmd = shift;\n\n    if ( $cmd =~ /^sh (.*)/ ) {\n\n        _sh($1);\n\n    } elsif ( $cmd =~ /^perl (.*)/ ) {\n\n        _perl($1);\n\n    } elsif ( $cmd eq 'tt' or $cmd eq 'test-tick' ) {\n\n        test_tick();\n\n    } elsif ( $cmd =~ /^plan ?(\\d+)$/ ) {\n\n        print_plan($1);\n\n    } elsif ( $cmd =~ /^cd ?(\\S*)$/ ) {\n\n        _cd($1);\n\n    } elsif ( $cmd =~ /^ENV (\\w+)=['\"]?(.+?)['\"]?$/ ) {\n\n        $ENV{$1} = $2;\n\n    } elsif ( $cmd =~ /^(?:tc|test-commit)\\s+(\\S.*)$/ ) {\n\n        # this is the only \"git special\" really; the default expansions are\n        # just that -- defaults.  But this one is hardwired!\n        dummy_commits($1);\n\n    } elsif ( $cmd =~ '^put(?:\\s+(\\S.*))?$' ) {\n\n        if ($1) {\n            put( $1, $text );\n        } else {\n            print $text if defined $text;\n        }\n\n    } elsif ( $cmd =~ m(^ok(?:\\s+or\\s+(.*))?$) ) {\n\n        $rc ? fail( \"ok, rc=$rc from $lec\", $1 || '' ) : ok();\n\n    } elsif ( $cmd =~ m(^!ok(?:\\s+or\\s+(.*))?$) ) {\n\n        $rc ? ok() : fail( \"!ok, rc=0 from $lec\", $1 || '' );\n\n    } elsif ( $cmd =~ m(^/(.*?)/(?:\\s+or\\s+(.*))?$) ) {\n\n        expect( $1, $2 );\n\n    } elsif ( $cmd =~ m(^!/(.*?)/(?:\\s+or\\s+(.*))?$) ) {\n\n        not_expect( $1, $2 );\n\n    } else {\n\n        _sh($cmd);\n\n    }\n}\n\n# currently unused\nsub executable {\n    my $cmd = shift;\n    # path supplied\n    $cmd =~ m(/) and -x $cmd and return 1;\n    # barename; look up in $PATH\n    for my $p (@PATH) {\n        -x \"$p/$cmd\" and return 1;\n    }\n    return 0;\n}\n\nsub ok {\n    $testnum++;\n    say \"ok ($testnum)\" if $ENV{HARNESS_ACTIVE};\n}\n\nsub fail {\n    $testnum++;\n    say \"not ok ($testnum)\" if $ENV{HARNESS_ACTIVE};\n\n    my $die = 0;\n    my ( $msg1, $msg2 ) = @_;\n    if ($msg2) {\n        # if arg2 is non-empty, print it regardless of debug level\n        $die = 1 if $msg2 =~ s/^die //;\n        say STDERR \"# $msg2\";\n    }\n\n    local $TSH_VERBOSE = 1 if $ENV{TSH_ERREXIT};\n    dbg( 1, \"FAIL: $msg1\", $testname || '', \"test number $testnum\", \"L: $line\", \"results:\\n$text\" );\n\n    # count the error and add the testname to the list if it is set\n    $err_count++;\n    push @errors_in, $testname if $testname;\n\n    return unless $die or $ENV{TSH_ERREXIT};\n    dbg( 1, \"exiting at cmd $cmd\\n\" );\n\n    exit( $rc || 74 );\n}\n\nsub cmp {\n    # compare input string with second input string or text()\n    my $in = shift;\n    my $text = ( @_ ? +shift : text() );\n\n    if ( $text eq $in ) {\n        ok();\n    } else {\n        fail( 'cmp failed', '' );\n        dbg( 4, \"\\n\\ntext = <<<$text>>>, in = <<<$in>>>\\n\\n\" );\n    }\n}\n\nsub expect {\n    my ( $patt, $msg ) = @_;\n    $msg =~ s/^\\s+// if $msg;\n    my $sm;\n    if ( $sm = sm($patt) ) {\n        dbg( 4, \"  M: $sm\" );\n        ok();\n    } else {\n        fail( \"/$patt/\", $msg || '' );\n    }\n}\n\nsub not_expect {\n    my ( $patt, $msg ) = @_;\n    $msg =~ s/^\\s+// if $msg;\n    my $sm;\n    if ( $sm = sm($patt) ) {\n        dbg( 4, \"  M: $sm\" );\n        fail( \"!/$patt/\", $msg || '' );\n    } else {\n        ok();\n    }\n}\n\nsub sm {\n    # smart match?  for now we just do regex match\n    my $patt = shift;\n\n    return ( $text =~ qr($patt) ? $& : \"\" );\n}\n\nsub trim_ws {\n    local $_ = shift;\n    s/^\\s+//; s/\\s+$//;\n    return $_;\n}\n\nsub is_comment_or_empty {\n    local $_ = shift;\n    chomp; $_ = trim_ws($_);\n    if (/^##\\s(.*)/) {\n        $testname = $1;\n        say \"# $1\";\n    }\n    return ( /^#/ or /^$/ );\n}\n\nsub cmds {\n    local $_ = shift;\n    chomp; $_ = trim_ws($_);\n\n    # split on unescaped ';'s, then unescape the ';' in the results\n    my @cmds = map { s/\\\\;/;/g; $_ } split /(?<!\\\\);/;\n    @cmds = grep { $_ = trim_ws($_); /\\S/; } @cmds;\n    return @cmds;\n}\n\nsub dbg {\n    return unless $TSH_VERBOSE;\n    my $level = shift;\n    return unless $TSH_VERBOSE >= $level;\n    my $all = join( \"\\n\", grep( /./, @_ ) );\n    chomp($all);\n    $all =~ s/\\n/\\n\\t/g;\n    say STDERR \"# $all\";\n}\n\nsub ddump {\n    for my $i (@_) {\n        print STDERR \"DBG: \" . Dumper($i);\n    }\n}\n\nsub usage {\n    # TODO\n    print \"Please see documentation at:\n\n        https://github.com/sitaramc/tsh/blob/master/README.mkd\n\nMeanwhile, here are your local 'macro' definitions:\n\n\";\n    my %m = read_rc_file();\n    my @m = map { \"$_\\t$m{$_}\\n\" } sort keys %m;\n    $tabstop = 16;\n    print join( \"\", expand(@m) );\n    exit 1;\n}\n\n# ----------------------------------------------------------------------\n# git-specific internal service subs\n\nsub dummy_commits {\n    for my $f ( split ' ', shift ) {\n        if ( $f eq 'tt' or $f eq 'test-tick' ) {\n            test_tick();\n            next;\n        }\n        my $ts = ( $tick ? gmtime( $tick + 19800 ) : gmtime() );\n        _sh(\"echo $f at $ts >> $f && git add $f && git commit -m '$f at $ts'\");\n    }\n}\n\nsub test_tick {\n    unless ( $ENV{HARNESS_ACTIVE} ) {\n        sleep 1;\n        return;\n    }\n    $tick += 60 if $tick;\n    $tick ||= 1310000000;\n    $ENV{GIT_COMMITTER_DATE} = \"$tick +0530\";\n    $ENV{GIT_AUTHOR_DATE}    = \"$tick +0530\";\n}\n\n# ----------------------------------------------------------------------\n# the internal macros, for easy reference and reading\n\nsub read_rc_file {\n    my $rcfile = \"$HOME/.tshrc\";\n    my $rctext;\n    if ( -r $rcfile ) {\n        local $/ = undef;\n        open( my $rcfh, \"<\", $rcfile ) or die \"this should not happen: $!\\n\";\n        $rctext = <$rcfh>;\n    } else {\n        # this is the default \"rc\" content\n        $rctext = \"\n            add         =   git add\n            branch      =   git branch\n            clone       =   git clone\n            checkout    =   git checkout\n            commit      =   git commit\n            fetch       =   git fetch\n            init        =   git init\n            push        =   git push\n            reset       =   git reset\n            tag         =   git tag\n\n            empty       =   git commit --allow-empty -m empty\n            push-om     =   git push origin master\n            reset-h     =   git reset --hard\n            reset-hu    =   git reset --hard \\@{u}\n        \"\n    }\n\n    # ignore everything except lines of the form \"aa = bb cc dd\"\n    my %commands = ( $rctext =~ /^\\s*([-.\\w]+)\\s*=\\s*(\\S.*)$/gm );\n    return %commands;\n}\n\n1;\n"
  },
  {
    "path": "src/lib/Gitolite/Test.pm",
    "content": "package Gitolite::Test;\n\n# functions for the test code to use\n# ----------------------------------------------------------------------\n\n#<<<\n@EXPORT = qw(\n  try\n  put\n  text\n  lines\n  dump\n  confreset\n  confadd\n  cmp\n  md5sum\n);\n#>>>\nuse Exporter 'import';\nuse File::Path qw(mkpath);\nuse Carp qw(carp cluck croak confess);\nuse Digest::MD5 qw(md5_hex);\n\nuse Gitolite::Common;\n\nBEGIN {\n    require Gitolite::Test::Tsh;\n    *{'try'}   = \\&Tsh::try;\n    *{'put'}   = \\&Tsh::put;\n    *{'text'}  = \\&Tsh::text;\n    *{'lines'} = \\&Tsh::lines;\n    *{'cmp'}   = \\&Tsh::cmp;\n}\n\nuse strict;\nuse warnings;\n\n# ----------------------------------------------------------------------\n\n# make sure the user is ready for it\nif ( not $ENV{GITOLITE_TEST} or $ENV{GITOLITE_TEST} ne 'y' ) {\n    print \"Bail out! See t/README for information on how to run the tests.\\n\";\n    exit 255;\n}\n\n# required preamble for all tests\ntry \"\n    DEF gsh = /TRACE: gsh.SOC=/\n    DEF reject = /hook declined to update/; /remote rejected.*hook declined/; /error: failed to push some refs to/\n\n    DEF AP_1 = cd ../gitolite-admin; ok or die cant find admin repo clone;\n    DEF AP_2 = AP_1; git add conf ; ok; git commit -m %1; ok; /master.* %1/\n    DEF ADMIN_PUSH = AP_2 %1; glt push admin origin; ok; gsh; /master -> master/\n\n    DEF CS_1 = pwd; //tmp/tsh_tempdir.*gitolite-admin/; git remote -v; ok; /file:///gitolite-admin/\n    DEF CHECK_SETUP = CS_1; git log; ok; /fa7564c1b903ea3dce49314753f25b34b9e0cea0/\n\n    DEF CLONE = glt clone %1 file:///%2\n    DEF PUSH  = glt push %1 origin\n\n    # clean install\n    mkdir -p $ENV{HOME}/bin\n    ln -sf $ENV{PWD}/t/glt ~/bin\n    ./install -ln\n    cd; rm -vrf .gito* repositories\n    git config --file $ENV{HOME}/.gitconfig.local user.name \\\"gitolite tester\\\"\n    git config --file $ENV{HOME}/.gitconfig.local user.email \\\"tester\\@example.com\\\"\n    git config --global                           include.path \\\"~/.gitconfig.local\\\"\n\n    # setup\n    gitolite setup -a admin\n\n    # clone admin repo\n    cd tsh_tempdir\n    glt clone admin --progress file:///gitolite-admin\n    cd gitolite-admin\n\" or die \"could not setup the test environment; errors:\\n\\n\" . text() . \"\\n\\n\";\n\nsub dump {\n    use Data::Dumper;\n    for my $i (@_) {\n        print STDERR \"DBG: \" . Dumper($i);\n    }\n}\n\nsub _confargs {\n    return @_ if ( $_[1] );\n    return 'gitolite.conf', $_[0];\n}\n\nsub confreset {\n    chdir(\"../gitolite-admin\") or die \"in `pwd`, could not cd ../g-a\";\n    system( \"rm\", \"-rf\", \"conf\" );\n    mkdir(\"conf\");\n    system(\"mv ~/repositories/gitolite-admin.git ~/repositories/.ga\");\n    system(\"mv ~/repositories/testing.git        ~/repositories/.te\");\n    system(\"find ~/repositories -name '*.git' |xargs rm -rf\");\n    system(\"mv ~/repositories/.ga ~/repositories/gitolite-admin.git\");\n    system(\"mv ~/repositories/.te ~/repositories/testing.git       \");\n    put \"|cut -c9- > conf/gitolite.conf\", '\n        repo    gitolite-admin\n            RW+     =   admin\n        repo    testing\n            RW+     =   @all\n';\n}\n\nsub confadd {\n    chdir(\"../gitolite-admin\") or die \"in `pwd`, could not cd ../g-a\";\n    my ( $file, $string ) = _confargs(@_);\n    put \"|cat >> conf/$file\", $string;\n}\n\nsub md5sum {\n    my $out = '';\n    for my $file (@_) {\n        $out .= md5_hex( slurp($file) ) . \"  $file\\n\";\n    }\n    return $out;\n}\n\n1;\n"
  },
  {
    "path": "src/lib/Gitolite/Triggers/Alias.pm",
    "content": "package Gitolite::Triggers::Alias;\n\nuse Gitolite::Rc;\nuse Gitolite::Common;\nuse Gitolite::Conf::Load;\n\nuse strict;\nuse warnings;\n\n# aliasing a repo to another\n# ----------------------------------------------------------------------\n\n=for usage\n\nWhy:\n\n    We had an existing repo \"foo\" that lots of people use.  We wanted to\n    rename it to \"foo/code\", so that related repos \"foo/upstream\" and\n    \"foo/docs\" (both containing stuff we did not want to put in \"foo\") could\n    also be made and then the whole thing would be structured nicely.\n\n    At the same time we did not want to *force* all the users to change the\n    name.  At least git operations should still work with the old name,\n    although it is OK for \"info\" and other \"commands\" to display/require the\n    proper name (i.e., the new name).\n\nHow:\n\n  * uncomment the line \"Alias\" in the \"user-visible behaviour\" section in the\n    rc file\n\n  * add a new variable REPO_ALIASES to the rc file, with entries like:\n\n        REPO_ALIASES                =>\n            {\n                # if you need a more aggressive warning message than the default\n                WARNING             => \"Please change your URLs to use '%new'; '%old' will not work after XXXX-XX-XX\",\n\n                # prefix mapping section\n                PREFIX_MAPS         =>  {\n                    # note: NO leading slash in keys or values below\n                    'var/lib/git/'  =>  '',\n                    'var/opt/git/'  =>  'opt/',\n                },\n\n                # individual repo mapping section\n                'foo'               =>  'foo/code',\n\n                # force users to change their URLs\n                'bar'               =>  '301/bar/code',\n                    # a target repo starting with \"301/\" won't actually work;\n                    # it will just produce an error message pointing the user\n                    # to the new name.  This allows admins to force users to\n                    # fix their URLs.\n            },\n\n    If a prefix map is supplied, each key is checked (in *undefined* order),\n    and the *first* key which matches the prefix of the repo will be applied.\n    If more than one key matches (for example if you specify '/abc/def' as one\n    key, and '/abc' as another), it is undefined which will get picked up.\n\n    The result of this, (or the original repo name if no map was found), will\n    then be subject to the individual repo mappings.  Since these are full\n    repo names, there is no possibility of multiple matches.\n\nNotes:\n\n  * only git operations (clone/fetch/push) are alias aware.  Nothing else in\n    gitolite, such as all the gitolite commands etc., are alias-aware and will\n    always use/require the proper repo name.\n\n  * http mode has not been tested and will not be.  If someone has the time to\n    test it and make it work please let me know.\n\n  * funnily enough, this even works with mirroring!  That is, a master can\n    push a repo \"foo\" to a copy per its configuration, while the copy thinks\n    it is getting repo \"bar\" from the master per its configuration.\n\n    Just make sure to put the Alias::input line *before* the Mirroring::input\n    line in the rc file on the copy.\n\n    However, it will probably not work with redirected pushes unless you setup\n    the opposite alias (\"bar\" -> \"foo\") on master.\n=cut\n\nsub input {\n    my $git_commands = \"git-upload-pack|git-receive-pack|git-upload-archive\";\n    my $user = $ARGV[0] || '@all';    # user name is undocumented for now\n\n    if ( $ENV{SSH_ORIGINAL_COMMAND} =~ /(?:$git_commands) '\\/?(\\S+)'$/ ) {\n        my $repo = $1;\n        ( my $norm = $repo ) =~ s/\\.git$//;    # normalised repo name\n\n        my $target = $norm;\n\n        # prefix maps first\n        my $pm = $rc{REPO_ALIASES}{PREFIX_MAPS} || {};\n        while (my($k, $v) = each %$pm) {\n            last if $target =~ s/^$k/$v/;\n            # no /i, /g, etc. by design\n        }\n\n        # individual repo map next\n        $target = $rc{REPO_ALIASES}{$target} || $target;\n\n        # undocumented; don't use without discussing on mailing list\n        $target = $target->{$user} if ref($target) eq 'HASH';\n\n        # if the repo name finally maps to empty, we bail, with no changes\n        return unless $target;\n\n        # we're done.  Did we actually change anything?\n        return if $norm eq $target;\n\n        # if the new name starts with \"301/\", inform and abort\n        _die \"please use '$target' instead of '$norm'\" if $target =~ s(^301/)();\n        # otherwise print a warning and continue with the new name\n        my $wm = $rc{REPO_ALIASES}{WARNING} || \"'%old' is an alias for '%new'\";\n        $wm =~ s/%new/$target/g;\n        $wm =~ s/%old/$norm/g;\n        _warn $wm;\n\n        $ENV{SSH_ORIGINAL_COMMAND} =~ s/'\\/?$repo'/'$target'/;\n    }\n\n}\n\n1;\n"
  },
  {
    "path": "src/lib/Gitolite/Triggers/AutoCreate.pm",
    "content": "package Gitolite::Triggers::AutoCreate;\n\nuse strict;\nuse warnings;\n\n# perl trigger set for stuff to do with auto-creating repos\n# ----------------------------------------------------------------------\n\n# to deny auto-create on read access, uncomment 'no-create-on-read' in the\n# ENABLE list in the rc file\nsub deny_R {\n    die \"autocreate denied\\n\" if $_[3] and $_[3] eq 'R';\n    return;\n}\n\n# to deny auto-create on read *and* write, uncomment 'no-auto-create' in the\n# ENABLE list in the rc file.  This means you can only create wild repos using\n# the 'create' command, (which needs to be enabled in the ENABLE list).\nsub deny_RW {\n    die \"autocreate denied\\n\" if $_[3] and ( $_[3] eq 'R' or $_[3] eq 'W' );\n    return;\n}\n\n1;\n"
  },
  {
    "path": "src/lib/Gitolite/Triggers/CpuTime.pm",
    "content": "package Gitolite::Triggers::CpuTime;\n\nuse Time::HiRes;\n\nuse Gitolite::Rc;\nuse Gitolite::Common;\n\nuse strict;\nuse warnings;\n\n# cpu and elapsed times for gitolite+git operations\n# ----------------------------------------------------------------------\n# uncomment the appropriate lines in the rc file to enable this\n\n# Ideally, you will (a) write your own code with a different filename so later\n# gitolite upgrades won't overwrite your copy, (b) add appropriate variables\n# to the rc file, and (c) change your rc file to call your program instead.\n\n# ----------------------------------------------------------------------\nmy $start_time;\n\nsub input {\n    _warn \"something wrong with the invocation of CpuTime::input\" if $ENV{GL_TID} ne $$;\n    $start_time = [ Time::HiRes::gettimeofday() ];\n}\n\nsub post_git {\n    _warn \"something wrong with the invocation of CpuTime::post_git\" if $ENV{GL_TID} ne $$;\n\n    my ( $trigger, $repo, $user, $aa, $ref, $verb ) = @_;\n    my ( $utime, $stime, $cutime, $cstime ) = times();\n    my $elapsed = Time::HiRes::tv_interval($start_time);\n\n    gl_log( 'times', $utime, $stime, $cutime, $cstime, $elapsed );\n\n    # now do whatever you want with the data; the following is just an example.\n\n    if ( my $limit = $rc{CPU_TIME_WARN_LIMIT} ) {\n        my $total = $utime + $cutime + $stime + $cstime;\n        # some code to send an email or whatever...\n        say2 \"limit = $limit, actual = $total\" if $total > $limit;\n    }\n\n    if ( $rc{DISPLAY_CPU_TIME} ) {\n        say2 \"perf stats for $verb on repo '$repo':\";\n        say2 \"  user CPU time: \" . ( $utime + $cutime );\n        say2 \"  sys  CPU time: \" . ( $stime + $cstime );\n        say2 \"   elapsed time: \" . $elapsed;\n    }\n}\n\n1;\n"
  },
  {
    "path": "src/lib/Gitolite/Triggers/Kindergarten.pm",
    "content": "package Gitolite::Triggers::Kindergarten;\n\n# http://www.great-quotes.com/quote/424177\n#   \"Doctor, it hurts when I do this.\"\n#   \"Then don't do that!\"\n\n# Prevent various things that sensible people shouldn't be doing anyway. List\n# of things it prevents is at the end of the program.\n\n# If you were forced to enable this module because someone is *constantly*\n# doing things that need to be caught, consider getting rid of that person.\n# Because, really, who knows what *else* he/she is doing that can't be caught\n# with some clever bit of code?\n\nuse Gitolite::Rc;\nuse Gitolite::Common;\n\nuse strict;\nuse warnings;\n\nmy %active;\nsub active {\n    # in rc, you either see just 'Kindergarten' to activate all features, or\n    # 'Kindergarten U0 CREATOR' (i.e., a space sep list of features after the\n    # word Kindergarten) to activate only those named features.\n\n    # no features specifically activated; implies all of them are active\n    return 1 if not %active;\n    # else check if this specific feature is active\n    return 1 if $active{ +shift };\n\n    return 0;\n}\n\nmy ( $verb, $repo, $cmd, $args );\nsub input {\n    # get the features to be activated, if supplied\n    while ( $_[0] ne 'INPUT' ) {\n        $active{ +shift } = 1;\n    }\n\n    # generally fill up variables you might use later\n    my $git_commands = \"git-upload-pack|git-receive-pack|git-upload-archive\";\n    if ( $ENV{SSH_ORIGINAL_COMMAND} =~ /($git_commands) '\\/?(\\S+)'$/ ) {\n        $verb = $1;\n        $repo = $2;\n    } elsif ( $ENV{SSH_ORIGINAL_COMMAND} =~ /^(\\S+) (.*)$/ ) {\n        $cmd  = $1;\n        $args = $2;\n    }\n\n    prevent_CREATOR($repo) if active('CREATOR') and $verb;\n    prevent_0(@ARGV)       if active('U0')      and @ARGV;\n}\n\nsub prevent_CREATOR {\n    my $repo = shift;\n    _die \"'CREATOR' not allowed as part of reponame\" if $repo =~ /\\bCREATOR\\b/;\n}\n\nsub prevent_0 {\n    my $user = shift;\n    _die \"'0' is not a valid username\" if $user eq '0';\n}\n\n1;\n\n__END__\n\nCREATOR\n\n    prevent literal 'CREATOR' from being part of a repo name\n\n    a quirk deep inside gitolite would let this config\n\n        repo foo/CREATOR/..*\n            C   =   ...\n\n    allow the creation of repos like \"foo/CREATOR/bar\", i.e., the word CREATOR is\n    literally used.\n\n    I consider this a totally pathological situation to check for.  The worst that\n    can happen is someone ends up cluttering the server with useless repos.\n\n    One solution could be to prevent this only for wild repos, but I can't be\n    bothered to fine tune this, so this module prevents even normal repos from\n    having the literal CREATOR in them.\n\n    See https://groups.google.com/forum/#!topic/gitolite/cS34Vxix0Us for more.\n\nU0\n\n    prevent a user from being called literal '0'\n\n    Ideally we should prevent keydir/0.pub (or variants) from being created,\n    but for \"Then don't do that\" purposes it's enough to prevent the user from\n    logging in.\n\n    See https://groups.google.com/forum/#!topic/gitolite/F1IBenuSTZo for more.\n"
  },
  {
    "path": "src/lib/Gitolite/Triggers/Mirroring.pm",
    "content": "package Gitolite::Triggers::Mirroring;\n\nuse Gitolite::Rc;\nuse Gitolite::Common;\nuse Gitolite::Conf::Load;\n\nuse strict;\nuse warnings;\n\nmy $hn           = $rc{HOSTNAME};\n\nmy ( $mode, $master, %copies, %trusted_copies );\n\n# ----------------------------------------------------------------------\n\nsub input {\n    unless ( $ARGV[0] =~ /^server-(\\S+)$/ ) {\n        _die \"'$ARGV[0]' is not a valid server name\" if $ENV{SSH_ORIGINAL_COMMAND} =~ /^USER=(\\S+) SOC=(git-receive-pack '(\\S+)')$/;\n        return;\n    }\n\n    # note: we treat %rc as our own internal \"poor man's %ENV\"\n    $rc{FROM_SERVER} = $1;\n    trace( 3, \"from_server: $1\" );\n    my $sender = $rc{FROM_SERVER} || '';\n\n    # custom peer-to-peer commands.  At present the only one is 'perms -c',\n    # sent from a mirror command\n    if ( $ENV{SSH_ORIGINAL_COMMAND} =~ /^CREATOR=(\\S+) perms -c '(\\S+)'$/ ) {\n        $ENV{GL_USER} = $1;\n\n        my $repo = $2;\n        details($repo);\n        _die \"$hn: '$repo' is local\"                        if $mode eq 'local';\n        _die \"$hn: '$repo' is native\"                       if $mode eq 'master';\n        _die \"$hn: '$sender' is not the master for '$repo'\" if $master ne $sender;\n\n        $ENV{GL_BYPASS_CREATOR_CHECK} = option($repo, \"bypass-creator-check\");\n        # this expects valid perms content on STDIN\n        _system(\"gitolite perms -c $repo\");\n        delete $ENV{GL_BYPASS_CREATOR_CHECK};\n\n        # we're done.  Yes, really...\n        exit 0;\n    }\n\n    if ( $ENV{SSH_ORIGINAL_COMMAND} =~ /^USER=(\\S+) SOC=(git-receive-pack '(\\S+)')$/ ) {\n        # my ($user, $newsoc, $repo) = ($1, $2, $3);\n        $ENV{SSH_ORIGINAL_COMMAND} = $2;\n        @ARGV                      = ($1);\n        $rc{REDIRECTED_PUSH}       = 1;\n        trace( 3, \"redirected_push for user $1\" );\n    } else {\n        # master -> copy push, no access checks needed\n        $ENV{GL_BYPASS_ACCESS_CHECKS} = 1;\n    }\n}\n\n# ----------------------------------------------------------------------\n\nsub pre_git {\n    return unless $hn;\n    # nothing, and I mean NOTHING, happens if HOSTNAME is not set\n    trace( 3, \"pre_git() on $hn\" );\n\n    my ( $repo, $user, $aa ) = @_[ 1, 2, 3 ];\n\n    my $sender = $rc{FROM_SERVER} || '';\n    $user = '' if $sender and not exists $rc{REDIRECTED_PUSH};\n\n    # ------------------------------------------------------------------\n    # now you know the repo, get its mirroring details\n    details($repo);\n\n    # print mirror status if at least one copy status file is present\n    print_status( $repo ) if not $rc{HUSH_MIRROR_STATUS} and $mode ne 'local' and glob(\"$rc{GL_REPO_BASE}/$repo.git/gl-copy-*.status\");\n\n    # we don't deal with any reads.  Note that for pre-git this check must\n    # happen *after* getting details, to give mode() a chance to die on \"known\n    # unknown\" repos (repos that are in the config, but mirror settings\n    # exclude this host from both the master and copy lists)\n    return if $aa eq 'R';\n\n    trace( 1, \"mirror\", \"pre_git\", $repo, \"user=$user\", \"sender=$sender\", \"mode=$mode\", ( $rc{REDIRECTED_PUSH} ? (\"redirected\") : () ) );\n\n    # ------------------------------------------------------------------\n    # case 1: we're master or copy, normal user pushing to us\n    if ( $user and not $rc{REDIRECTED_PUSH} ) {\n        trace( 3, \"case 1, user push\" );\n        return if $mode eq 'local' or $mode eq 'master';\n        if ( $trusted_copies{$hn} ) {\n            trace( 1, \"redirect to $master\" );\n            exec( \"ssh\", $master, \"USER=$user\", \"SOC=$ENV{SSH_ORIGINAL_COMMAND}\" );\n        } else {\n            _die \"$hn: pushing '$repo' to copy '$hn' not allowed\";\n        }\n    }\n\n    # ------------------------------------------------------------------\n    # case 2: we're copy, master pushing to us\n    if ( $sender and not $rc{REDIRECTED_PUSH} ) {\n        trace( 3, \"case 2, master push\" );\n        _die \"$hn: '$repo' is local\"                        if $mode eq 'local';\n        _die \"$hn: '$repo' is native\"                       if $mode eq 'master';\n        _die \"$hn: '$sender' is not the master for '$repo'\" if $master ne $sender;\n        return;\n    }\n\n    # ------------------------------------------------------------------\n    # case 3: we're master, copy sending a redirected push to us\n    if ( $sender and $rc{REDIRECTED_PUSH} ) {\n        trace( 3, \"case 2, copy redirect\" );\n        _die \"$hn: '$repo' is local\"                           if $mode eq 'local';\n        _die \"$hn: '$repo' is not native\"                      if $mode eq 'copy';\n        _die \"$hn: '$sender' is not a valid copy for '$repo'\"  if not $copies{$sender};\n        _die \"$hn: redirection not allowed from '$sender'\"     if not $trusted_copies{$sender};\n        return;\n    }\n\n    _die \"$hn: should not reach this line\";\n\n}\n\n# ----------------------------------------------------------------------\n\nsub post_git {\n    return unless $hn;\n    # nothing, and I mean NOTHING, happens if HOSTNAME is not set\n    trace( 1, \"post_git() on $hn\" );\n\n    my ( $repo, $user, $aa ) = @_[ 1, 2, 3 ];\n    # we don't deal with any reads\n    return if $aa eq 'R';\n\n    my $sender = $rc{FROM_SERVER} || '';\n    $user = '' if $sender;\n\n    # ------------------------------------------------------------------\n    # now you know the repo, get its mirroring details\n    details($repo);\n\n    trace( 1, \"mirror\", \"post_git\", $repo, \"user=$user\", \"sender=$sender\", \"mode=$mode\", ( $rc{REDIRECTED_PUSH} ? (\"redirected\") : () ) );\n\n    # ------------------------------------------------------------------\n    # case 1: we're master or copy, normal user pushing to us\n    if ( $user and not $rc{REDIRECTED_PUSH} ) {\n        trace( 3, \"case 1, user push\" );\n        return if $mode eq 'local';\n        # copy was eliminated earlier anyway, so that leaves 'master'\n\n        # find all copies and push to each of them\n        push_to_copies($repo);\n\n        return;\n    }\n\n    # ------------------------------------------------------------------\n    # case 2: we're copy, master pushing to us\n    if ( $sender and not $rc{REDIRECTED_PUSH} ) {\n        trace( 3, \"case 2, master push\" );\n        # nothing to do\n        return;\n    }\n\n    # ------------------------------------------------------------------\n    # case 3: we're master, copy sending a redirected push to us\n    if ( $sender and $rc{REDIRECTED_PUSH} ) {\n        trace( 3, \"case 2, copy redirect\" );\n\n        # find all copies and push to each of them\n        push_to_copies($repo);\n\n        return;\n    }\n}\n\n{\n    my $lastrepo = '';\n\n    sub details {\n        my $repo = shift;\n        return if $lastrepo eq $repo;\n\n        $master         = master($repo);\n        %copies         = copies($repo);\n        $mode           = mode($repo);\n        %trusted_copies = trusted_copies($repo);\n        trace( 3, $master, $mode, join( \",\", sort keys %copies ), join( \",\", sort keys %trusted_copies ) );\n    }\n\n    sub master {\n        return option( +shift, 'mirror.master' );\n    }\n\n    sub copies {\n        my $repo = shift;\n        my %out;\n\n        my $ref = git_config( $repo, \"^gitolite-options\\\\.mirror\\\\.copies.*\" );\n        map { $out{$_} = 'async' } map { split } values %$ref;\n\n        my @sync_types = qw(sync async nosync nosync-quiet);\n        foreach my $sync_type ( @sync_types ) {\n            $ref = git_config( $repo, \"^gitolite-options\\\\.mirror\\\\.copies\\\\.${sync_type}.*\" );\n            map { $out{$_} = $sync_type } map { split } values %$ref;\n        }\n\n        return %out;\n    }\n\n    sub trusted_copies {\n        my $ref = git_config( +shift, \"^gitolite-options\\\\.mirror\\\\.redirectOK.*\" );\n        # the list of trusted copies (where we accept redirected pushes from)\n        # is either explicitly given...\n        my @out = map { split } values %$ref;\n        my %out = map { $_ => 1 } @out;\n        # ...or it's all the copies mentioned if the list is just a \"all\"\n        %out = %copies if ( @out == 1 and $out[0] eq 'all' );\n        return %out;\n    }\n\n    sub mode {\n        my $repo = shift;\n        return 'local'  if not $hn;\n        return 'master' if $master eq $hn;\n        return 'copy'   if $copies{$hn};\n        return 'local'  if not $master and not %copies;\n        _die \"$hn: '$repo' is mirrored but not here\";\n    }\n}\n\nsub push_to_copies {\n    my $repo = shift;\n\n    my $u = $ENV{GL_USER};\n    delete $ENV{GL_USER};    # why?  see src/commands/mirror\n\n    my $lb = \"$ENV{GL_REPO_BASE}/$repo.git/.gl-mirror-lock\";\n    for my $s ( sort keys %copies ) {\n        trace( 1, \"push_to_copies skipping self\" ), next if $s eq $hn;\n        my $mirror_command = \"gitolite 1plus1 $lb.$s gitolite mirror push $s $repo </dev/null >/dev/null 2>&1\";\n        if ($copies{$s} eq 'async') {\n            system($mirror_command . \" &\");\n        } elsif ($copies{$s} eq 'sync') {\n            system($mirror_command);\n        } elsif ($copies{$s} eq 'nosync') {\n            _warn \"manual mirror push pending for '$s'\";\n        } elsif ($copies{$s} eq 'nosync-quiet') {\n            1;\n        } else {\n            _warn \"unknown mirror copy type $copies{$s} for '$s'\";\n        }\n    }\n\n    $ENV{GL_USER} = $u;\n}\n\nsub print_status {\n    my $repo = shift;\n    my $u = $ENV{GL_USER};\n    delete $ENV{GL_USER};\n    system(\"gitolite mirror status all $repo >&2\");\n    $ENV{GL_USER} = $u;\n}\n\n1;\n"
  },
  {
    "path": "src/lib/Gitolite/Triggers/Motd.pm",
    "content": "package Gitolite::Triggers::Motd;\n\nuse Gitolite::Rc;\nuse Gitolite::Common;\n\nuse strict;\nuse warnings;\n\n# print a message of the day to STDERR\n# ----------------------------------------------------------------------\n\nmy $file = \"gl-motd\";\n\nsub input {\n    # at present, we print it for every single interaction with gitolite.  We\n    # may want to change that later; if we do, get code from Kindergarten.pm\n    # to get the gitcmd+repo or cmd+args so you can filter on them\n\n    my $f = \"$rc{GL_ADMIN_BASE}/$file\";\n    print STDERR slurp($f) if -f $f;\n}\n\nsub pre_git {\n    my $repo = $_[1];\n    my $f    = \"$rc{GL_REPO_BASE}/$repo.git/$file\";\n    print STDERR slurp($f) if -f $f;\n}\n\n1;\n"
  },
  {
    "path": "src/lib/Gitolite/Triggers/RefexExpr.pm",
    "content": "package Gitolite::Triggers::RefexExpr;\nuse strict;\nuse warnings;\n\n# track refexes passed and evaluate expressions on them\n# ----------------------------------------------------------------------\n# see src/VREF/refex-expr for instructions and WARNINGS!\n\nuse Gitolite::Easy;\n\nmy %passed;\nmy %rules;\nmy $init_done = 0;\n\nsub access_2 {\n    # get out quick for repos that don't have any rules\n    return if $init_done and not %rules;\n\n    # but we don't really know that the first time, heh!\n    if ( not $init_done ) {\n        my $repo = $_[1];\n        init($repo);\n        return unless %rules;\n    }\n\n    my $refex = $_[5];\n    return if $refex =~ /DENIED/;\n\n    $passed{$refex}++;\n\n    # evaluate the rules each time; it's not very expensive\n    for my $k ( sort keys %rules ) {\n        $ENV{ \"GL_REFEX_EXPR_\" . $k } = eval_rule( $rules{$k} );\n    }\n}\n\nsub eval_rule {\n    my $rule = shift;\n\n    my $e;\n    $e = join \" \", map { convert($_) } split ' ', $rule;\n\n    my $ret = eval $e;\n    _die \"eval '$e' -> '$@'\" if $@;\n    Gitolite::Common::trace( 1, \"RefexExpr\", \"'$rule' -> '$e' -> '$ret'\" );\n\n    return \"'$rule' -> '$e'\" if $ret;\n}\n\nmy %constant;\n%constant = map { $_ => $_ } qw(1 not and or xor + - ==);\n$constant{'-lt'} = '<';\n$constant{'-gt'} = '>';\n$constant{'-eq'} = '==';\n$constant{'-le'} = '<=';\n$constant{'-ge'} = '>=';\n$constant{'-ne'} = '!=';\n\nsub convert {\n    my $i = shift;\n    return $i if $i =~ /^-?\\d+$/;\n    return $constant{$i} || $passed{$i} || $passed{\"refs/heads/$i\"} || 0;\n}\n\n# called only once\nsub init {\n    $init_done = 1;\n    my $repo = shift;\n\n    # find all the rule expressions\n    my %t = config( $repo, \"^gitolite-options\\\\.refex-expr\\\\.\" );\n    my ( $k, $v );\n    # get rid of the cruft and store just the rule name as the key\n    while ( ( $k, $v ) = each %t ) {\n        $k =~ s/^gitolite-options\\.refex-expr\\.//;\n        $rules{$k} = $v;\n    }\n}\n\n1;\n"
  },
  {
    "path": "src/lib/Gitolite/Triggers/RepoUmask.pm",
    "content": "package Gitolite::Triggers::RepoUmask;\n\nuse Gitolite::Rc;\nuse Gitolite::Common;\nuse Gitolite::Conf::Load;\n\nuse strict;\nuse warnings;\n\n# setting a repo specific umask\n# ----------------------------------------------------------------------\n# this is for people who are too paranoid to trust e.g., gitweb's repo\n# exclusion logic, but not paranoid enough to put it on a different server\n\n=for usage\n\n  * In the rc file, add the line\n        'RepoUmask',\n    somewhere in the ENABLE list\n\n  * For each repo that is to get a different umask than the default, add a\n    line like this:\n\n        option umask = 0027\n\n  * Anytime you add or change the value, if there are existing repos that\n    would be affected, you will need to do a manual \"chmod\" adjustment,\n    because umask only affects newly created files.\n\n=cut\n\n# sadly option/config values are not available at pre_create time for normal\n# repos.  So we have to do a one-time fixup in a post_create trigger.\nsub post_create {\n    my $repo = $_[1];\n\n    my $umask = option( $repo, 'umask' );\n    _chdir( $rc{GL_REPO_BASE} );    # because using option() moves us to ADMIN_BASE!\n\n    return unless $umask;\n\n    # unlike the one in the rc file, this is a string\n    $umask = oct($umask);\n    my $mode = \"0\" . sprintf( \"%o\", $umask ^ 0777 );\n\n    system(\"chmod -R $mode $repo.git >&2\");\n    system(\"find $repo.git -type f -exec chmod a-x '{}' \\\\;\");\n}\n\nsub pre_git {\n    my $repo = $_[1];\n\n    my $umask = option( $repo, 'umask' );\n    _chdir( $rc{GL_REPO_BASE} );    # because using option() moves us to ADMIN_BASE!\n\n    return unless $umask;\n\n    # unlike the one in the rc file, this is a string\n    umask oct($umask);\n}\n\n1;\n"
  },
  {
    "path": "src/lib/Gitolite/Triggers/Shell.pm",
    "content": "package Gitolite::Triggers::Shell;\n\n# usage notes: uncomment 'Shell' in the ENABLE list in the rc file.\n\n# documentation is in the ssh troubleshooting and tips document, under the\n# section \"giving shell access to gitolite users\"\n\nuse Gitolite::Rc;\nuse Gitolite::Common;\n\n# fedora likes to do things that are a little off the beaten track, compared\n# to typical gitolite usage:\n# - every user has their own login\n# - the forced command may not get the username as an argument.  If it does\n#   not, the gitolite user name is $USER (the unix user name)\n# - and finally, if the first argument to the forced command is '-s', and\n#   $SSH_ORIGINAL_COMMAND is empty or runs a non-git/gitolite command, then\n#   the user gets a shell\n\nsub input {\n    my $shell_allowed = 0;\n    if ( @ARGV and $ARGV[0] eq '-s' ) {\n        shift @ARGV;\n        $shell_allowed++;\n    }\n\n    @ARGV = ( $ENV{USER} ) unless @ARGV;\n\n    return unless $shell_allowed;\n\n    # now determine if this was intended as a shell command or git/gitolite\n    # command\n\n    my $soc = $ENV{SSH_ORIGINAL_COMMAND};\n\n    # no command, just 'ssh alice@host'; doesn't return ('exec's out)\n    shell_out() if $shell_allowed and not $soc;\n\n    return if git_gitolite_command($soc);\n\n    gl_log( 'shell', $ENV{SHELL}, \"-c\", $soc );\n    exec $ENV{SHELL}, \"-c\", $soc;\n}\n\nsub shell_out {\n    my $shell = $ENV{SHELL};\n    $shell =~ s/.*\\//-/;    # change \"/bin/bash\" to \"-bash\"\n    gl_log( 'shell', $shell );\n    exec { $ENV{SHELL} } $shell;\n}\n\n# some duplication with gitolite-shell, factor it out later, if it works fine\n# for fedora and they like it.\nsub git_gitolite_command {\n    my $soc = shift;\n\n    my $git_commands = \"git-upload-pack|git-receive-pack|git-upload-archive\";\n    return 1 if $soc =~ /^($git_commands) /;\n\n    my @words = split ' ', $soc;\n    return 1 if $rc{COMMANDS}{ $words[0] };\n\n    return 0;\n}\n\n1;\n"
  },
  {
    "path": "src/lib/Gitolite/Triggers/TProxy.pm",
    "content": "package Gitolite::Triggers::TProxy;\n\n# ----------------------------------------------------------------------\n# transparent proxy for git repos, hosted on a gitolite server\n\n# ----------------------------------------------------------------------\n# WHAT\n\n#   1.  user runs a git command (clone, fetch, push) against a gitolite\n#       server.\n#   2.  if that server has the repo, it will serve it up.  Else it will\n#       *transparently* forward the git operation to a designated upstream\n#       server.  The user does not have to do anything, and in fact may not\n#       even know this has happened.\n\n# can be combined with, but does not *require*, gitolite mirroring.\n\n# ----------------------------------------------------------------------\n# SECURITY\n#\n#   1.  Most of the issues that apply to \"redirected push\" in mirroring.html\n#       also apply here.  In particular, you had best make sure the two\n#       servers use the same authentication data (i.e., \"alice\" here should be\n#       \"alice\" there!)\n#\n#   2.  Also, do not add keys for servers you don't trust!\n\n# ----------------------------------------------------------------------\n# HOW\n\n# on transparent proxy server (the one that is doing the redirect):\n#   1.  add\n#           INPUT => ['TProxy::input'],\n#       just before the ENABLE list in the rc file\n#   2.  add an RC variable to tell gitolite where to go; this is also just\n#       before the ENABLE list:\n#           TPROXY_FORWARDS_TO => 'git@upstream',\n\n# on upstream server (the one redirected TO):\n#   1.  add\n#           INPUT => ['TProxy::input'],\n#       just before the ENABLE list in the rc file\n#   2.  add the pubkey of the proxy server (the one that will be redirecting\n#       to us) to this server's gitolite-admin \"keydir\" as\n#       \"server-<something>.pub\", and push the change.\n\n# to use in combination with gitolite mirroring\n#   1.  just follow the same instructions as above.  Server names and\n#       corresponding pub keys would already be set ok so step 2 in the\n#       upstream server setup (above) will not be needed.\n#   2.  needless to say, **don't** declare the repos you want to be\n#       transparently proxied in the gitolite.conf for the copy.\n\nuse Gitolite::Rc;\nuse Gitolite::Common;\nuse Gitolite::Conf::Load;\n\nuse strict;\nuse warnings;\n\nmy $soc = $ENV{SSH_ORIGINAL_COMMAND};\n\n# ----------------------------------------------------------------------\n\nsub input {\n    # are we the upstream, getting something from a tproxy server?\n    my $git_commands = \"git-upload-pack|git-receive-pack|git-upload-archive\";\n    if ( $ARGV[0] =~ /^server-/ and $soc =~ /^TPROXY_FOR=(\\S+) SOC=(($git_commands) '\\S+')$/ ) {\n        @ARGV = ($1);\n        # you better make sure you read the security warnings up there!\n\n        $ENV{SSH_ORIGINAL_COMMAND} = $2;\n        delete $ENV{GL_BYPASS_ACCESS_CHECKS};\n        # just in case we somehow end up running before Mirroring::input!\n\n        return;\n    }\n\n    # well we're not upstream; are we a tproxy?\n    return unless $rc{TPROXY_FORWARDS_TO};\n\n    # is it a normal git command?\n    return unless $ENV{SSH_ORIGINAL_COMMAND} =~ m(^($git_commands) '/?(.*?)(?:\\.git(\\d)?)?'$);\n\n    # ...get the repo name from $ENV{SSH_ORIGINAL_COMMAND}\n    my ( $verb, $repo, $trace_level ) = ( $1, $2, $3 );\n    $ENV{D} = $trace_level if $trace_level;\n    _die \"invalid repo name: '$repo'\" if $repo !~ $REPONAME_PATT;\n\n    # nothing to do if the repo exists locally\n    return if -d \"$ENV{GL_REPO_BASE}/$repo.git\";\n\n    my $user = shift @ARGV;\n    # redirect to upstream\n    exec( \"ssh\", $rc{TPROXY_FORWARDS_TO}, \"TPROXY_FOR=$user\", \"SOC=$ENV{SSH_ORIGINAL_COMMAND}\" );\n}\n\n1;\n"
  },
  {
    "path": "src/lib/Gitolite/Triggers/Writable.pm",
    "content": "package Gitolite::Triggers::Writable;\n\nuse Gitolite::Rc;\nuse Gitolite::Common;\n\nsub access_1 {\n    my ( $repo, $aa, $result ) = @_[ 1, 3, 5 ];\n    return if $aa eq 'R' or $result =~ /DENIED/;\n\n    for my $f ( \"$ENV{HOME}/.gitolite.down\", \"$rc{GL_REPO_BASE}/$repo.git/.gitolite.down\" ) {\n        next unless -f $f;\n        _die slurp($f) if -s $f;\n        _die \"sorry, writes are currently disabled (no more info available)\\n\";\n    }\n}\n\n1;\n"
  },
  {
    "path": "src/lib/Gitolite/Triggers.pm",
    "content": "package Gitolite::Triggers;\n\n# load and run triggered modules\n# ----------------------------------------------------------------------\n\n#<<<\n@EXPORT = qw(\n);\n#>>>\nuse Exporter 'import';\n\nuse Gitolite::Rc;\nuse Gitolite::Common;\n\nuse strict;\nuse warnings;\n\n# ----------------------------------------------------------------------\n\nsub run {\n    my ( $module, $sub, @args ) = @_;\n    $module = \"Gitolite::Triggers::$module\" if $module !~ /^Gitolite::/;\n\n    eval \"require $module\";\n    _die \"$@\" if $@;\n    my $subref;\n    eval \"\\$subref = \\\\\\&$module\" . \"::\" . \"$sub\";\n    _die \"module '$module' does not exist or does not have sub '$sub'\" unless ref($subref) eq 'CODE';\n\n    $subref->(@args);\n}\n\n1;\n"
  },
  {
    "path": "src/syntactic-sugar/continuation-lines",
    "content": "# vim: syn=perl:\n\n# \"sugar script\" (syntactic sugar helper) for gitolite3\n\n# Enabling this script in the rc file allows you to use back-slash escaped\n# continuation lines, like in C or shell etc.\n\n# This script also serves as an example \"sugar script\" if you want to write\n# your own (and maybe send them to me).  A \"sugar script\" in gitolite will be\n# executed via a perl 'do' and is expected to contain one function called\n# 'sugar_script'.  This function should take a listref and return a listref.\n# Each item in the list is one line.  There are NO newlines; g3 kills them off\n# fairly early in the process.\n\n# If you're not familiar with perl please do not try this.  Ask me to write\n# you a sugar script instead.\n\nsub sugar_script {\n    my $lines = shift;\n\n    my @out  = ();\n    my $keep = '';\n    for my $l (@$lines) {\n        # skip RULE_INFO lines if in continuation mode\n        next if $keep and $l =~ /^ *#/;\n        if ( $l =~ s/\\\\$// ) {\n            $keep .= $l;\n        } else {\n            $l = $keep . $l if $keep;\n            $keep = '';\n            push @out, $l;\n        }\n    }\n\n    return \\@out;\n}\n"
  },
  {
    "path": "src/syntactic-sugar/keysubdirs-as-groups",
    "content": "# vim: syn=perl:\n\n# \"sugar script\" (syntactic sugar helper) for gitolite3\n\n# Enabling this script in the rc file allows you to use subdirectories in\n# keydir as group names.  The last component other than keydir itself will be\n# taken as the group name.\n\nsub sugar_script {\n    Gitolite::Common::trace( 2, \"running 'keysubdirs-as-groups' sugar script...\" );\n    my $lines = shift;\n\n    my @out = @{$lines};\n    unshift @out, groupnames();\n\n    return \\@out;\n}\n\nsub groupnames {\n    my @out     = ();\n    my %members = ();\n    for my $pk (`find ../keydir/ -name \"*.pub\"`) {\n        next unless $pk =~ m(.*/([^/]+)/([^/]+?)(?:@[^./]+)?\\.pub$);\n        next if $1 eq 'keydir';\n        $members{$1} .= \" $2\";\n    }\n    for my $m ( sort keys %members ) {\n        push @out, \"\\@$m =\" . $members{$m};\n    }\n\n    return @out;\n}\n"
  },
  {
    "path": "src/syntactic-sugar/macros",
    "content": "# vim: syn=perl:\n\n# \"sugar script\" (syntactic sugar helper) for gitolite3\n\n# simple line-wise macro processor\n# ----------------------------------------------------------------------\n# see documentation at the end of this script\n\nmy %macro;\n\nsub sugar_script {\n    my $lines = shift;\n    my @out   = ();\n\n    my $l = join( \"\\n\", @$lines );\n    while ( $l =~ s/^macro (\\w+)\\b(.*?)\\nend//ms ) {\n        $macro{$1} = $2;\n    }\n\n    $l =~ s/^((\\w+)\\b.*)/$macro{$2} ? expand($1) : $1/gem;\n\n    $lines = [ split \"\\n\", $l ];\n    return $lines;\n}\n\nsub expand {\n    my $l = shift;\n    my ( $word, @arg );\n\n    eval \"require Text::ParseWords\";\n    if ($@) {\n        ( $word, @arg ) = split ' ', $l;\n    } else {\n        ( $word, @arg ) = Text::ParseWords::shellwords($l);\n    }\n    my $v = $macro{$word};\n    $v =~ s/%(\\d+)/$arg[$1-1] or die \"macro '$word' needs $1 arguments at '$l'\\n\"/gem;\n    return $v;\n}\n\n__END__\n\nDocumentation is mostly by example.\n\nSetup:\n\n  * uncomment the line\n        'macros',\n    in the ENABLE list in ~/.gitolite.rc\n\nNotes on macro definition:\n\n  * the keywords 'macro' and 'end' should start on a new line\n  * the first word after 'macro' is the name of the macro, and the rest, until\n    the 'end', is the body\n\nNotes on macro use:\n\n  * the macro name should be the first word on a line\n  * the rest of the line is used as arguments to the macro\n\nExample:\n\n    if your conf contains:\n\n        macro foo repo aa-%1\n            RW  =   u1 %2\n            R   =   u2\n        end\n\n        foo 1 alice\n        foo 2 bob\n\n    this will effectively turn into\n\n        repo aa-1\n            RW  =   u1 alice\n            R   =   u2\n\n        repo aa-2\n            RW  =   u1 bob\n            R   =   u2\n"
  },
  {
    "path": "src/syntactic-sugar/refex-expr",
    "content": "# vim: syn=perl:\n\n# \"sugar script\" (syntactic sugar helper) for gitolite3\n# ----------------------------------------------------------------------\n# see src/VREF/refex-expr for instructions and WARNINGS!\n\nmy $perm = qr(-|R|RW\\+?C?D?M?);\n\nmy $seq = 1;\n\nsub sugar_script {\n    my $lines = shift;\n\n    # my @out  = ();\n    for my $l (@$lines) {\n        push @out, $l;\n\n        # quick check\n        next unless $l =~ /^($perm) /;\n        # more detailed check\n        next unless $l =~ /^($perm) (\\S.*) = (\\S.*)$/;\n        my ( $perm, $refexes, $users ) = ( $1, $2, $3 );\n        next unless $refexes =~ / (and|not|or|xor|\\+|-|==|-lt|-gt|-eq|-le|-ge|-ne) /;\n\n        print STDERR \">>>> $l\\n\";\n        pop @out;    # we need to replace that last line\n\n        push @out, \"option refex-expr.sugar$seq = $refexes\";\n        push @out, \"$perm VREF/refex-expr/sugar$seq = $users\";\n\n        $seq++;\n    }\n\n    return \\@out;\n}\n"
  },
  {
    "path": "src/triggers/bg",
    "content": "#!/bin/bash\n\n# quick and dirty program to background any of the triggers programs that are\n# taking too long.  To use, just replace a line like\n#       'post-compile/update-gitweb-access-list',\n# with\n#       'bg post-compile/update-gitweb-access-list',\n\n# We dump output to a file in the log directory but please keep in mind this\n# is not a \"log\" so much as a redirection of the entire output.\n\necho `date` $GL_TID \"$0: $@\" >> $GL_LOGFILE.bg\n\npath=${0%/*}\nscript=$path/$1; shift\n\n( ( $script \"$@\" < /dev/null >> $GL_LOGFILE.bg 2>&1 & ) )\n"
  },
  {
    "path": "src/triggers/expand-deny-messages",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n$|++;\n\n# program name: expand-deny-messages\n\n# DOCUMENTATION IS AT THE BOTTOM OF THIS FILE; PLEASE READ\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Rc;\nuse Gitolite::Common;\n\nmy %attempted_access = (\n    # see triggers.html\n    'ACCESS_1' => {\n        'R' => 'Repo read',\n        'W' => 'Repo write',\n    },\n    'ACCESS_2' => {\n        'W' => \"Fast forward push\",\n        '+' => \"Rewind push branch or overwrite tag\",\n        'C' => \"Create ref\",\n        'D' => \"Delete ref\",\n    }\n);\n\n# env var to disable is set?\nexit 0 if $ENV{GL_OPTION_EDM_DISABLE};\n\n# argument 1\nmy $a12 = shift;    # ACCESS_1 or ACCESS_2\nexit 0 if $a12 !~ /^ACCESS_[12]$/;    # shouldn't happen; error in rc file?\n\n# the rest of the arguments\nmy ( $repo, $user, $aa, $ref, $msg, $oldsha, $newsha ) = @ARGV;\n\n# we're only interested in deny messages\nexit 0 if $msg !~ /DENIED/;\n\nprint STDERR \"\\nFATAL -- ACCESS DENIED\\n\";\n\n_info( \"Repo\",      $repo );\n_info( \"User\",      $user );\n_info( \"Stage\",     ( $a12 eq 'ACCESS_1' ? \"Before git was called\" : \"From git's update hook\" ) );\n_info( \"Ref\",       _ref($ref) ) if $a12 eq 'ACCESS_2';\n_info( \"Operation\", _op( $a12, $aa, $oldsha, $newsha ) );\n\nif ( $ref =~ m((^VREF/[^/]+)) ) {\n    my $vref      = $1;\n    if ($ref =~ s(^VREF/NAME/)()) {\n        print STDERR \"You're apparently not allowed to push '$ref'\";\n    } else {\n        my $vref_text = slurp( _which( $vref, 'x' ) );\n        my $etag      = '(?:help|explain|explanation)';\n        $vref_text =~ m(^\\s*# $etag.start\\n(.*)^\\s*# $etag.end\\n)sm\n          and print STDERR \"Explanation for $vref:\\n$1\";\n  }\n}\n\nprint STDERR \"\\n\";\nprint STDERR \"$ENV{GL_OPTION_EDM_EXTRA_INFO}\\n\\n\" if $ENV{GL_OPTION_EDM_EXTRA_INFO};\n\n# ------------------------------------------------------------------------\n\nsub _ref {\n    my $r = shift;\n    return \"VREF '$r'\"   if $r =~ s(^VREF/)();\n    return \"Branch '$r'\" if $r =~ s(^refs/heads/)();\n    return \"Tag '$r'\"    if $r =~ s(^refs/tags/)();\n    return \"Non-standard ref '$r'\";\n}\n\nsub _info {\n    printf STDERR \"%-14s  %-60s\\n\", @_;\n}\n\nsub _op {\n    my ( $a12, $aa, $oldsha, $newsha ) = @_;\n\n    # first remove the M part and save the text for later addition if needed\n    my $merge = ( $aa =~ s/M// ? \" with merge commit\" : \"\" );\n\n    # next, the attempted access is modified to reflect the actual operation being\n    # attempted.  NOTE: this no longer necessarily reflects what the gitolite log\n    # file stores; it's more granular and truly distinguishes a branch create from\n    # an ff push, etc.  Could help when user typos a branch name I suppose\n    $aa = 'C' if $oldsha and $oldsha eq '0' x 40;\n    $aa = 'D' if $newsha and $newsha eq '0' x 40;\n\n    # then we map it, add merge text if any\n    my $op = $attempted_access{$a12}{$aa} || \"Unknown operation '$aa'\";\n    $op .= $merge;\n\n    return $op;\n}\n\n__END__\n\nENABLING THE FEATURE\n--------------------\n\nTo enable this feature, uncomment the line in the rc file if your gitolite was\ninstalled recently enough.  Otherwise you will need to add these lines to the\nend of your rc file, just before the \"%RC\" block ends:\n\n    ACCESS_1 => [\n        'expand-deny-messages',\n    ],\n\n    ACCESS_2 => [\n        'expand-deny-messages',\n    ],\n\nPlease don't miss the trailing commas!\n\nDISABLING IT FOR SPECIFIC REPOS\n-------------------------------\n\nOnce it is enabled at the rc file level, if you wish to disable it for\nspecific repositories just add a line like this to those repos:\n\n        option ENV.EDM_DISABLE = 1\n\nOr you can also disable it for all repos, then enable it for some:\n\n    repo @all\n        option ENV.EDM_DISABLE = 1\n\n    # ... then later ...\n\n    repo foo bar @baz\n        option ENV.EDM_DISABLE = 0\n\n(options.html[1] and pages linked from it will explain how that works).\n\n[1]: http://gitolite.com/gitolite/options.html\n\nSUPPLYING EXTRA INFORMATION\n---------------------------\n\nYou can also supply some extra information to be printed, by adding a line\nlike this to each repository in the gitolite.conf file:\n\n        option ENV.EDM_EXTRA_INFO = \"please contact alice@example.com\"\n\nYou could of course add it under a \"repo @all\" section if you like.\n\nSUPPLYING EXTRA INFORMATION FOR VREFs\n-------------------------------------\n\nIf you have VREFs that do funky things and you want to **lecture** your users\nwhen they screw up, add something like the following to your VREF code.\n\n    # help start\n\n    Some help text.\n\n    Some more help text.  This can be\n    multi-line.\n\n    (etc etc etc)\n\n    # help end\n\nThen everything between the \"# help start\" line and the \"# help end\" line will\nget printed if a users falls afoul of this VREF.  If any of the lines shown\nare not valid syntax for your language, figure out some way to put the whole\nthing in a comment block.  Here a C example:\n\n    /*\n    # help start\n    line 1\n    line 2\n    ...\n    last line\n    # help end\n    */\n\nEven if your language does not support multi-line comments like C does, there\nmay be other ways to specify those lines.  Here's an example in shell:\n\n    cat << EOF > /dev/null\n    # help start\n    line 1\n    line 2\n    ...\n    last line\n    # help end\n    EOF\n"
  },
  {
    "path": "src/triggers/partial-copy",
    "content": "#!/bin/sh\n\n# this is a wee bit expensive in terms of forks etc., compared to doing it in\n# perl, but I wanted to show how *easy* it actually is now.  And really,\n# you'll only notice if you access this repo like a hundred times a minute or\n# something so don't sweat it.\n\n# given a repo and a user, check if option('partialCopyOf') is set, and if so,\n# fetch all allowed branches from there.\n\ndie() { echo \"$@\" >&2; exit 1; }\n\n# make sure we're being called from the pre_git trigger\n[ \"$1\" = \"PRE_GIT\" ] || die I must be called from PRE_GIT, not \"$1\"\nshift\n\nrepo=$1\nuser=$2\nmain=`git config --file $GL_REPO_BASE/$repo.git/config --get gitolite.partialCopyOf`;\n[ -z \"$main\" ] && exit 0\n\n# \"we\", \"our repo\"  =>  the partial copy\n# \"main\", \"pco\"     =>  the one which we are a \"partial copy of\"\n\ncd $GL_REPO_BASE/$main.git\n\nfor ref in `git for-each-ref refs/heads '--format=%(refname)'`\ndo\n    cd $GL_REPO_BASE/$repo.git\n\n    gitolite access -q $repo $user R $ref &&\n    git fetch -f $GL_REPO_BASE/$main.git $ref:$ref\ndone\n\nexport GL_BYPASS_ACCESS_CHECKS=1\n\n# remove all refs not in main or accessible\ncd $GL_REPO_BASE/$repo.git\n\nfor ref in `git for-each-ref refs/heads refs/tags '--format=%(refname)'`\ndo\n    cd $GL_REPO_BASE/$main.git\n\n    if git show-ref --verify --quiet $ref &&\n       gitolite access -q $repo $user R $ref ; then\n        # ref is present in main and accessible in repo\n        continue\n    fi\n\n    git push -f $GL_REPO_BASE/$repo.git :$ref || die \"FATAL: failed to delete $ref\"\ndone\n\n# remove all tags no longer reachable\ncd $GL_REPO_BASE/$repo.git\n\nfor ref in `git for-each-ref refs/tags '--format=%(refname)'`\ndo\n    SHA=`git rev-list -1 $ref`\n    for branch in `git for-each-ref refs/heads '--format=%(refname)'`\n    do\n       if [ \"`git merge-base $SHA $branch`\" = \"$SHA\" ]; then\n           # tag is reachable in current branch, continue higher loop\n           continue 2\n       fi\n    done\n    git push -f $GL_REPO_BASE/$repo.git :$ref || die \"FATAL: failed to delete $ref\"\ndone\n\nexit 0\n"
  },
  {
    "path": "src/triggers/post-compile/create-with-reference",
    "content": "#!/usr/bin/perl\n\n# Set alternates if option reference.repo is set\n# ----------------------------------------------------------------------\n\nuse FindBin;\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Rc;\nuse Gitolite::Common;\nuse Gitolite::Conf::Load;\n\nuse strict;\nuse warnings;\n\nmy $RB = $rc{GL_REPO_BASE};\n\nif ( @ARGV and $ARGV[0] eq 'POST_CREATE' ) {\n    my $repo = $ARGV[1];\n    create_alternates($repo);\n\n    exit 0;\n}\n\n# not interested in any other triggers\nexit 0;\n\nsub create_alternates {\n    my $pr      = shift;\n\n    my $refrepos = git_config( $pr, \"^gitolite-options\\\\.reference\\\\.repo.*\" );\n    my %list = map { $_ => 1 } map { split } values %$refrepos;\n    my @alts = keys %list;\n    if ( @alts ) {\n        my $altlist = join \"\\n\", map { \"$RB/$_.git/objects\" } @alts;\n        _print( \"$RB/$pr.git/objects/info/alternates\", \"$altlist\\n\" );\n\n    }\n}\n"
  },
  {
    "path": "src/triggers/post-compile/ssh-authkeys",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nuse Getopt::Long;\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Rc;\nuse Gitolite::Common;\n\n$|++;\n\n# best called via 'gitolite trigger POST_COMPILE'; other modes at your own\n# risk, especially if the rc file specifies arguments for it.  (That is also\n# why it doesn't respond to \"-h\" like most gitolite commands do).\n\n# option procesing\n# ----------------------------------------------------------------------\n\n# currently has one option:\n#   -kfn, --key-file-name        adds the keyfilename as a second argument\n\nmy $kfn = '';\nGetOptions( 'key-file-name|kfn' => \\$kfn, );\n\ntsh_try(\"sestatus\");\nmy $selinux = ( tsh_text() =~ /enforcing/ );\n\nmy $ab = $rc{GL_ADMIN_BASE};\ntrace( 1, \"'keydir' not found in '$ab'; exiting\" ), exit if not -d \"$ab/keydir\";\nmy $akdir        = \"$ENV{HOME}/.ssh\";\nmy $akfile       = \"$ENV{HOME}/.ssh/authorized_keys\";\nmy $glshell      = $rc{GL_BINDIR} . \"/gitolite-shell\";\nmy $auth_options = auth_options();\n\nsanity();\n\n# ----------------------------------------------------------------------\n\n_chdir($ab);\n\n# old data\nmy $old_ak = slurp($akfile);\nmy @non_gl = grep { not /^# gito.*start/ .. /^# gito.*end/ } slurp($akfile);\nchomp(@non_gl);\nmy %seen = map { $_ => 'a non-gitolite key' } ( fp(@non_gl) );\n\n# pubkey files\nchomp( my @pubkeys = `find keydir/ -type f -name \"*.pub\" | sort` );\nmy @gl_keys = ();\nfor my $f (@pubkeys) {\n    my $fp = fp($f);\n    if ( $seen{$fp} ) {\n        _warn \"$f duplicates $seen{$fp}, sshd will ignore it\";\n    } else {\n        $seen{$fp} = $f;\n    }\n    push @gl_keys, grep { /./ } optionise($f);\n}\n\n# dump it out\nmy $out = join( \"\\n\", @non_gl, \"# gitolite start\", @gl_keys, \"# gitolite end\" ) . \"\\n\";\n\nmy $ak = slurp($akfile);\n_die \"'$akfile' changed between start and end of this program!\" if $ak ne $old_ak;\n_print( $akfile, $out );\n\n_warn \"you have no keys left; I hope you intended to do that!\" unless @gl_keys;\n\n# ----------------------------------------------------------------------\n\nsub sanity {\n    _die \"'$glshell' not found; this should NOT happen...\"                if not -f $glshell;\n    _die \"'$glshell' found but not readable; this should NOT happen...\"   if not -r $glshell;\n    _die \"'$glshell' found but not executable; this should NOT happen...\" if not -x $glshell;\n\n    my $n = \"    (this is normal on a brand new install)\";\n    _warn \"$akdir missing; creating a new one\\n$n\"  if not -d $akdir;\n    _warn \"$akfile missing; creating a new one\\n$n\" if not -f $akfile;\n\n    _mkdir( $akdir, 0700 ) if not -d $akdir;\n    if ( not -f $akfile ) {\n        _print( $akfile, \"\" );\n        chmod 0600, $akfile;\n    }\n}\n\nsub auth_options {\n    my $auth_options = $rc{AUTH_OPTIONS};\n    $auth_options ||= \"no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty\";\n\n    return $auth_options;\n}\n\nsub fp {\n    # input: see below\n    # output: a (list of) FPs\n    my $in = shift || '';\n    if ( $in =~ /\\.pub$/ ) {\n        # single pubkey file\n        _die \"bad pubkey file '$in'\" unless $in =~ $REPONAME_PATT;\n        return fp_file($in);\n    } elsif ( -f $in ) {\n        # an authkeys file\n        return map { fp_line($_) } grep { !/^#/ and /\\S/ } slurp($in);\n    } else {\n        # one or more actual keys\n        return map { fp_line($_) } grep { !/^#/ and /\\S/ } ( $in, @_ );\n    }\n}\n\nsub fp_file {\n    return $selinux++ if $selinux;    # return a unique \"fingerprint\" to prevent noise\n    my $f  = shift;\n    my ($fp, $output) = ssh_fingerprint_file($f);\n    _die \"fingerprinting failed for '$f': $output\" unless $fp;\n    return $fp;\n}\n\nsub fp_line {\n    my $line = shift;\n    my ($fp, $output) = ssh_fingerprint_line($line);\n    _die \"fingerprinting failed for '$line': $output\" unless $fp;\n    return $fp;\n}\n\nsub optionise {\n    my $f = shift;\n\n    my $user = $f;\n    $user =~ s(.*/)();                # foo/bar/baz.pub -> baz.pub\n    $user =~ s/(\\@[^.]+)?\\.pub$//;    # baz.pub, baz@home.pub -> baz\n\n    my @line = slurp($f);\n    if ( @line != 1 ) {\n        _warn \"$f does not contain exactly 1 line; ignoring\";\n        return '';\n    }\n    chomp(@line);\n    return \"command=\\\"$glshell $user\" . ( $kfn ? \" $f\" : \"\" ) . \"\\\",$auth_options $line[0]\";\n}\n\n"
  },
  {
    "path": "src/triggers/post-compile/ssh-authkeys-shell-users",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Rc;\nuse Gitolite::Common;\n\n$|++;\n\nmy $akfile = \"$ENV{HOME}/.ssh/authorized_keys\";\n\n# ----------------------------------------------------------------------\n\nmy $aktext = slurp($akfile);\n\nfor my $su ( shell_users() ) {\n    $aktext =~ s(/gitolite-shell $su([\" ].*?),no-pty )(/gitolite-shell -s $su$1 )g;\n}\n\n_print( $akfile, $aktext );\n\n# two methods to specify list of shell-capable users.  (1) list of usernames\n# as arguments to 'Shell' in rc file, (2) list of usernames in a plain text\n# file whose name is the first argument to 'Shell' in the rc file.  Or both!\nsub shell_users {\n    my ($sufile, @ret);\n\n    # backward compat for 3.6 and below.  This code will be removed in 3.7.\n    # Also, the variable is ignored if you end up using the new variant (i.e.,\n    # put a file name on the 'Shell' line itself).\n    $sufile = $rc{SHELL_USERS_LIST} if $rc{SHELL_USERS_LIST} and -r $rc{SHELL_USERS_LIST};\n\n    $sufile = shift @ARGV if @ARGV and -r $ARGV[0];\n\n    if ($sufile) {\n        @ret = grep { not /^#/ } slurp($sufile);\n        chomp(@ret);\n    }\n\n    for my $u (@ARGV) {\n        # arguments placed in the rc file appear before the trigger name\n        last if $u eq 'POST_COMPILE';\n\n        push @ret, $u;\n        # no sanity checking, since the rc file can only be created by someone\n        # who already has shell access\n    }\n    _die \"'Shell': enabled but no usernames supplied\" unless @ret;\n    return @ret;\n}\n"
  },
  {
    "path": "src/triggers/post-compile/ssh-authkeys-split",
    "content": "#!/bin/bash\n\n#   split multi-key files into separate keys like ssh-authkeys likes\n\n# WHY\n# ---\n#\n# Yeah I wonder that too, when it's so much more maintainable to keep the damn\n# keys as sitaram@home.pub and sitaram@work.pub or such.  But there's no\n# accounting for tastes, and some old fogies apparently want to put all of a\n# user's keys into a single \".pub\" file.\n\n# WARNINGS AND CAVEATS\n# --------------------\n#\n# - assumes no \"@\" sign in basenames of any multi-key files (single line file\n#   may still have them)\n\n# - assumes you don't have a subdir in keydir called \"__split_keys__\"\n\n# SUPPORT\n# -------\n#\n# NONE.\n\n# USAGE\n# -----\n#\n# to enable, uncomment the 'ssh-authkeys-split' line in the ENABLE list in the\n# rc file.\n\ncd $GL_ADMIN_BASE/keydir\n\nrm -rf __split_keys__\nmkdir __split_keys__\nexport SKD=$PWD/__split_keys__\n\n# if we're coming from a gitolite-admin push, delete all *.multi, and rename\n# all multi-line *.pub to *.multi\nif [ \"$GL_REPO\" = \"gitolite-admin\" ] || [ \"$GL_BYPASS_ACCESS_CHECKS\" = \"1\" ]\nthen\n    find . -type f -name \"*.multi\" | while read k\n    do\n        rm -f \"$k\"\n    done\n    find . -type f -name \"*.pub\" | while read k\n    do\n        # is this a multi-key?\n        lines=`wc -l < $k`\n        case $lines in\n            (0|1) continue\n        esac\n\n        base=`basename $k .pub`\n        mv $k $base.multi\n    done\nfi\n\n# now process *.multi\nfind . -type f -name \"*.multi\" | while read k\ndo\n    # do we need to split?\n    lines=`wc -l < $k`\n    case $lines in\n        (0|1) continue\n    esac\n\n    base=`basename $k .multi`\n    # sanity check\n    echo $base | grep '@' >/dev/null && continue\n\n    # ok do it\n    seq=0\n    while read line\n    do\n        (( seq++ ))\n        [ -z \"$line\" ] && continue\n        f=$SKD/$base@$seq.pub\n        echo \"$line\" > $f\n        # similar sanity check as main ssh-authkeys script\n        if ! ssh-keygen -l -f $f >/dev/null\n        then\n            echo 1>&2 \"ssh-authkeys-split: bad line $seq in keydir/$k\"\n            rm -f $f\n        fi\n    done < $k\ndone\n"
  },
  {
    "path": "src/triggers/post-compile/update-description-file",
    "content": "#!/bin/sh\n\n# For normal (not \"wild\") repos, gitolite v3 sets 'gitweb.description' instead\n# of putting the text in the \"description\" file.  This is easier because it\n# just goes with the flow of setting config variables; nothing special needs\n# to be done for the description.\n\n# But this only works for gitweb, not for cgit.  Cgit users must uncomment the\n# 'cgit' line in the ENABLE list in the rc file (which has the effect of\n# adding this program to the POST_COMPILE trigger list).\n\ncd $GL_REPO_BASE\ngitolite list-phy-repos | gitolite git-config % gitweb.description | perl -I\"$GL_LIBDIR\" -MGitolite::Easy -lne '\n            my @F = split /\\t/,$_,3;\n            textfile( file => \"description\", repo => $F[0], text => $F[2] );\n    '\n"
  },
  {
    "path": "src/triggers/post-compile/update-git-configs",
    "content": "#!/usr/bin/perl\n\n# update git-config entries in each repo\n# ----------------------------------------------------------------------\n\nuse FindBin;\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Rc;\nuse Gitolite::Common;\nuse Gitolite::Conf::Load;\n\nuse strict;\nuse warnings;\n\nmy $RB = $rc{GL_REPO_BASE};\n_chdir($RB);\n\n# ----------------------------------------------------------------------\n# if called from POST_CREATE, we have only a single repo to worry about\nif ( @ARGV and $ARGV[0] eq 'POST_CREATE' ) {\n    my $repo = $ARGV[1];\n    fixup_config($repo);\n\n    exit 0;\n}\n\n# ----------------------------------------------------------------------\n# else it's all repos (i.e., called from POST_COMPILE)\n\nmy $lpr = list_phy_repos();\n\nfor my $pr (@$lpr) {\n    fixup_config($pr);\n}\n\nsub fixup_config {\n    my $pr      = shift;\n    my $creator = creator($pr);\n\n    my $gc = git_config( $pr, '.', 1 );\n    my $ac = `git config --file $RB/$pr.git/config -l`;\n    while ( my ( $key, $value ) = each( %{$gc} ) ) {\n        next if $key =~ /^gitolite-options\\./;\n        $value =~ s/(@\\w+)/expand_group($1)/ge if $rc{EXPAND_GROUPS_IN_CONFIG};\n        my $lkey = lc $key;\n        next if $ac =~ /^\\Q$lkey\\E=\\Q$value\\E$/m;\n        if ( $value ne \"\" ) {\n            system( \"git\", \"config\", \"--file\", \"$RB/$pr.git/config\", $key, $value );\n        } elsif ( $ac =~ /^\\Q$lkey\\E=/m ) {\n            system( \"git\", \"config\", \"--file\", \"$RB/$pr.git/config\", \"--unset-all\", $key );\n        }\n    }\n}\n\nsub expand_group {\n    my $g = shift;\n    my @m = @{ Gitolite::Conf::Load::list_members($1) };\n    return join(\" \", @m) if @m;\n    return $g;\n}\n"
  },
  {
    "path": "src/triggers/post-compile/update-git-daemon-access-list",
    "content": "#!/usr/bin/perl\n\n# update git-daemon-export-ok files in each repo\n# ----------------------------------------------------------------------\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Rc;\nuse Gitolite::Easy;\nuse Gitolite::Common;\n\nuse strict;\nuse warnings;\n\nmy $EO = \"git-daemon-export-ok\";\nmy $RB = $rc{GL_REPO_BASE};\n\nmy $cmd = \"gitolite list-phy-repos\";\nif ( @ARGV and $ARGV[0] eq 'POST_CREATE' ) {\n    # only one repo to do\n    $cmd = \"echo $ARGV[1]\";\n}\n\nfor my $d (`$cmd | gitolite access % daemon R any`) {\n    my @F = split \"\\t\", $d;\n    if ($F[2] =~ /DENIED/) {\n        unlink \"$RB/$F[0].git/$EO\";\n    } elsif (! -f \"$RB/$F[0].git/$EO\") {\n        textfile( file => $EO, repo => $F[0], text => \"\" );\n    }\n}\n\n# As a quick recap, the gitolite output looks somewhat like this:\n\n#   bar^Idaemon^IR any bar daemon DENIED by fallthru$\n#   foo^Idaemon^Irefs/.*$\n#   fubar^Idaemon^Irefs/.*$\n#   gitolite-admin^Idaemon^IR any gitolite-admin daemon DENIED by fallthru$\n#   testing^Idaemon^Irefs/.*$\n\n# where I've typed \"^I\" to denote a tab.\n"
  },
  {
    "path": "src/triggers/post-compile/update-gitweb-access-list",
    "content": "#!/bin/sh\n\n# this is literally the simplest gitweb update possible.  You are free to add\n# whatever you want and contribute it back, as long as it is upward\n# compatible.\n\n# ----------------------------------------------------------------------\n# delete the 'description' file that 'git init' created if this is run from\n# the post-create trigger.  However, note that POST_CREATE is also called from\n# perms (since POST_CREATE doubles as eqvt of POST_COMPILE to propagate ad hoc\n# permissions changes for wild repos) and then you should not delete it.\n[ \"$1\" = \"POST_CREATE\" ] && [ \"$4\" != \"perms\" ] && rm -f $GL_REPO_BASE/$2.git/description 2>/dev/null\n\nplf=`gitolite query-rc GITWEB_PROJECTS_LIST`\n[ -z \"$plf\" ] && plf=$HOME/projects.list\n# since mktemp does not honor umask, we just use it to generate a temp\n# filename (note: 'mktemp -u' on some systems, this gets close enough)\ntmpfile=`mktemp $plf.tmp_XXXXXXXX`\nrm -f $tmpfile;\n\nif [ \"$1\" = \"POST_CREATE\" ] && [ -n \"$2\" ]\nthen\n    # just one to be done\n    repo=\"$2\"\n    grep -v \"^$repo.git$\" $plf > $tmpfile\n    if gitolite access -q $repo gitweb R any || gitolite git-config -q -r $repo gitweb\\\\.\n    then\n        echo \"$repo.git\" >> $tmpfile\n    fi\nelse\n    # all of them\n    (\n        gitolite list-phy-repos | gitolite access % gitweb R any | grep -v DENIED\n        gitolite list-phy-repos | gitolite git-config -r % gitweb\\\\.\n    ) |\n        cut -f1 | sort -u | sed -e 's/$/.git/' > $tmpfile\nfi\n\n[ -f $plf ] && perl -e \"chmod ( ( (stat('$plf'))[2] & 07777 ), '$tmpfile')\"\nmv $tmpfile $plf\n"
  },
  {
    "path": "src/triggers/post-compile/update-gitweb-daemon-from-options",
    "content": "#!/bin/sh\n\n# TODO: look at the commit in which *this* line was added, and see the changes\n# to the other scripts.  We need to make those changes here also, but I'm too\n# lazy right now.  Plus I'm not even sure if anyone is using this!\n\n# Update git-daemon and gitweb access using 'option' lines instead of special\n# usernames.\n\n# To use:\n\n# * enable this combined updater in the rc file by removing the other two\n#   update-*-access-list entries and inserting this one instead.  (This would\n#   be in the POST_CREATE and POST_COMPILE lists).\n\n# * the add option lines in the conf file, like this:\n#\n#       repo foo @bar\n#           option daemon = 1\n#           option gitweb = 1\n\n# Note: don't forget that gitweb can also be enabled by actual config\n# variables (gitweb.owner, gitweb.description, gitweb.category)\n\n# This is useful for people who don't like '@all' to be literally *all* users,\n# including gitweb and daemon, and can't/won't use deny-rules properly.\n\n# first do the gitweb stuff\n\nplf=`gitolite query-rc GITWEB_PROJECTS_LIST`\n[ -z \"$plf\" ] && plf=$HOME/projects.list\n\n(\n    gitolite list-phy-repos | gitolite git-config % gitolite-options.gitweb\n    gitolite list-phy-repos | gitolite git-config -r % gitweb\\\\.\n) |\n    cut -f1 | sort -u | sed -e 's/$/.git/' > $plf\n\n# now deal with git-daemon\n\nEO=git-daemon-export-ok\nRB=`gitolite query-rc GL_REPO_BASE`\nexport EO RB\n\nexport tmp=$(mktemp -d)\ntrap \"rm -rf $tmp\" 0\n\ngitolite list-phy-repos | sort | tee $tmp/all | gitolite git-config % gitolite-options.daemon | cut -f1 > $tmp/daemon\n\ncomm -23 $tmp/all $tmp/daemon | perl -lne 'unlink \"$ENV{RB}/$_.git/$ENV{EO}\"'\ncat               $tmp/daemon | perl -I\"$GL_LIBDIR\" -MGitolite::Easy -lne 'textfile( file => $ENV{EO}, repo => $_, text => \"\");'\n"
  },
  {
    "path": "src/triggers/renice",
    "content": "#!/bin/sh\n\nn=$1\n[ \"$n\" = \"PRE_GIT\" ] && n=10\nrenice -n $n $GL_TID >/dev/null\n"
  },
  {
    "path": "src/triggers/repo-specific-hooks",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# setup repo-specific hooks\n\nuse lib $ENV{GL_LIBDIR};\nuse Gitolite::Rc;\nuse Gitolite::Common;\n\n_die \"repo-specific-hooks: LOCAL_CODE not defined in rc\" unless $rc{LOCAL_CODE};\n_die \"repo-specific-hooks: '$rc{LOCAL_CODE}/hooks/repo-specific' does not exist or is not a directory\" unless -d \"$rc{LOCAL_CODE}/hooks/repo-specific\";\n\n_chdir( $ENV{GL_REPO_BASE} );\n\nif ($ARGV[0] eq 'POST_CREATE') {\n    # just the repo given in arg-2\n    @ARGV = (\"gitolite git-config -ev -r $ARGV[1] gitolite-options\\\\.hook\\\\. |\");\n} else {\n    # POST_COMPILE, all repos\n    @ARGV = (\"gitolite list-phy-repos | gitolite git-config -ev -r % gitolite-options\\\\.hook\\\\. |\");\n}\n\nmy $driver = $rc{MULTI_HOOK_DRIVER} || \"$rc{LOCAL_CODE}/hooks/multi-hook-driver\";\n# Hook Driver\n{\n    local $/ = undef;\n    my $hook_text = <DATA>;\n    _print( $driver, $hook_text );\n    chmod 0755, $driver;\n}\n\nmy %repo_hooks;\nwhile (<>) {\n    chomp;\n    my ( $repo, $hook, $codes ) = split /\\t/, $_;\n    $codes ||= '';\n\n    # get the hook name\n    $hook =~ s/^gitolite-options\\.hook\\.//;\n    $hook =~ s/\\..*//;\n\n    my @codes = split /\\s+/, $codes;\n\n    # bail on disallowed hook types (but warn only if @codes is non-empty)\n    if ( $repo eq 'gitolite-admin' and $hook eq 'post-update' ) {\n        _warn \"repo-specific-hooks: ignoring attempts to set post-update hook for the admin repo\" if @codes;\n        next;\n    }\n    unless ( $hook =~ /^(pre-receive|post-receive|post-update|pre-auto-gc)$/ ) {\n        if (@codes) {\n            _warn \"repo-specific-hooks: '$hook' is not allowed, ignoring\";\n            _warn \"    (only pre-receive, post-receive, post-update, and pre-auto-gc are allowed)\";\n        }\n        next;\n    }\n\n    push @{ $repo_hooks{$repo}{$hook} }, @codes;\n}\n\nfor my $repo (keys %repo_hooks) {\n    for my $hook (keys %{ $repo_hooks{$repo} }) {\n        my @codes = @{ $repo_hooks{$repo}{$hook} };\n\n        my $dst = \"$repo.git/hooks/$hook\";\n        unlink( glob(\"$dst.*\") );\n\n        my $counter = \"h00\";\n        foreach my $code (@codes) {\n            if ( $code =~ m(^/|\\.\\.) ) {\n                _warn \"repo-specific-hooks: double dot or leading slash not allowed in '$code'\";\n                next;\n            }\n\n            my $src = $rc{LOCAL_CODE} . \"/hooks/repo-specific/$code\";\n\n            # if $code has slashes in it, flatten it for use in $dst, to avoid\n            # having to re-create those intermediate sub-directories\n            $code =~ s(/)(_)g;\n            my $dst = \"$repo.git/hooks/$hook.$counter-$code\";\n\n            unless ( -x $src ) {\n                _warn \"repo-specific-hooks: '$src' doesn't exist or is not executable\";\n                next;\n            }\n            unlink $dst;\n            symlink $src, $dst or _warn \"could not symlink '$src' to '$dst'\";\n            $counter++;\n\n            # no sanity checks for multiple overwrites of the same hook\n        }\n\n        unlink $dst;\n        symlink $driver, $dst or die \"could not symlink '$driver' to '$dst'\";\n    }\n}\n\n__DATA__\n#!/bin/sh\n\n# Determine what input the hook needs\n# post-update takes args, pre/post-receive take stdin\ntype=args\nstdin=''\n[ $0 != hooks/post-update ] && {\n    type=stdin\n    stdin=`cat`\n}\n\nfor h in $0.*; do\n    [ -x $h ] || continue\n    if [ $type = args ]\n    then\n        $h $@ || { [ $0 = hooks/pre-receive ] && exit 1; }\n    else\n        echo \"$stdin\" | $h || { [ $0 = hooks/pre-receive ] && exit 1; }\n    fi\ndone\n"
  },
  {
    "path": "src/triggers/set-default-roles",
    "content": "#!/bin/sh\n\n# POST_CREATE trigger to set up default set of perms for a new wild repo\n\n# ----------------------------------------------------------------------\n# skip if arg-1 is POST_CREATE and no arg-3 (user name) exists (i.e., it's not\n# a wild repo)\n[ \"$1\" = \"POST_CREATE\" ] && [ -z \"$3\" ] && exit 0;\n[ \"$4\" = \"R\" ] || [ \"$4\" = \"W\" ] || [ \"$4\" = \"perms-c\" ] || [ \"$4\" = \"create\" ] || [ \"$4\" = \"fork\" ] || exit 0\n\ndie() { echo \"$@\" >&2; exit 1; }\n\ncd $GL_REPO_BASE/$2.git || die \"could not cd to $GL_REPO_BASE/$2.git\"\ngitolite git-config -r $2 gitolite-options.default.roles | sort | cut -f3 |\n    perl -pe 's/(\\s)CREATOR(\\s|$)/$1$ENV{GL_USER}$2/' > gl-perms\n\n# cache control, if rc says caching is on\ngitolite query-rc -q CACHE && perl -I$GL_LIBDIR -MGitolite::Cache -e \"cache_control('flush', '$2')\";\n\nexit 0\n"
  },
  {
    "path": "src/triggers/upstream",
    "content": "#!/bin/sh\n\n# manage local, gitolite-controlled, copies of read-only upstream repos.\n\nrepo=$2\n\nurl=$(gitolite git-config $repo gitolite-options.upstream.url)\n[ -z \"$url\" ] && exit 0     # exit if no url was specified\n\ncd $GL_REPO_BASE/$repo.git || exit 1\n\n[ \"$1\" != \"fetch\" ] && {\n    nice=$(gitolite git-config $repo gitolite-options.upstream.nice)\n    [ -n \"$nice\" ] && find FETCH_HEAD -mmin -$nice 2>/dev/null | grep . >/dev/null && exit 0\n}\n\ngit fetch -q \"$url\" '+refs/*:refs/*'\n\n# ----------------------------------------------------------------------\n\n# FEATURES:\n# * invokes upstream fetch on each local fetch\n#   (unless the optional 'nice' setting is enabled)\n# * can force a fetch (ignoring 'nice' value) from server CLI\n\n# INSTRUCTIONS:\n#\n# * uncomment 'upstream' in the ENABLE list in the rc file.\n# * add option lines to conf file.  For example:\n#\n#       repo git\n#           R                       =   @all\n#           RW+ my-company/         =   @developers\n#\n#           option  upstream.url    =   https://git.kernel.org/pub/scm/git/git.git\n#           option  upstream.nice   =   120\n#\n# * to force a fetch on the server shell (or via cron), run this command:\n#       gitolite ../triggers/upstream fetch reponame\n\n# ADDITIONAL NOTES:\n# * restrict local pushes to a namespace that the upstream won't use\n#   (otherwise the next fetch will wipe them out)\n# * if the upstream URL changes, just change the conf and push admin repo\n# * the 'nice' setting is in minutes and is optional; it is the minimum\n#   elapsed time between 2 upstream fetches.\n\n# USAGE EXAMPLE:\n#\n# Let's say you want to keep a read-only local mirror of all your github repos\n# on your local gitolite installation.  Assuming your github usernames are the\n# same as your local usernames, and you have updated GIT_CONFIG_KEYS in the rc\n# file to allow 'config' lines, you can do this:\n#\n#   repo github/CREATOR/..*\n#       C   = @all\n#       R   = @all\n#       option upstream.url                         =   https://github.com/%GL_REPO.git\n#       option upstream.nice                        =   120\n#       config url.https://github.com/.insteadOf    =   https://github.com/github/\n#\n# Now you can make local, read-only, clones of all your github repos with\n#\n#   git ls-remote gitolite:github/sitaramc/gitolite\n#   git ls-remote gitolite:github/sitaramc/hap\n#   (etc)\n#\n# and if milki were also a user on this gitolite instance, then\n#\n#   git ls-remote gitolite:github/milki/xclip\n#   git ls-remote gitolite:github/milki/ircblogger\n#   (etc)\n"
  },
  {
    "path": "t/0-me-first.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\nmy $rb = `gitolite query-rc -n GL_REPO_BASE`;\n\n# initial smoke tests\n# ----------------------------------------------------------------------\n\ntry \"plan 71\";\n\n# basic push admin repo\nconfreset;confadd '\n    repo aa\n        RW+     =   u1\n        RW      =   u2 u3\n\n    repo cc/..*\n        C       =   u4\n        RW+     =   CREATOR u5\n        R       =   READERS\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"\n                                            /Initialized empty Git repository in .*/aa.git//\n\n    # basic clone\n    cd ..\n    glt clone u1 file:///aa u1aa;    ok;     /Cloning into 'u1aa'.../\n                                            /warning: You appear to have cloned an empty repository/\n    [ -d u1aa ];                    ok\n\n    # basic clone deny\n    glt clone u4 file:///aa u4aa;    !ok;    /R any aa u4 DENIED by fallthru/\n    [ -d u4aa ];                    !ok\n\n    # basic push\n    cd u1aa;                        ok\n    tc z-507;                       ok;     /master .root-commit. 7cf7624. z-507/\n    glt push u1 origin HEAD;        ok;     /To file:///aa/\n                                            /\\\\[new branch\\\\] *HEAD -> master/\n\n    # basic rewind\n    tc o-866 o-867 o-868;           ok;     /master 2d066fb. o-868/\n    glt push u1 origin HEAD;        ok;     /7cf7624..2d066fb  HEAD -> master/\n    git reset --hard HEAD^;         ok;     /HEAD is now at 8b1456b o-867/\n    tc x-967;                       ok;     /master 284951d. x-967/\n    glt push u1 -f origin HEAD;     ok;     /\\\\+ 2d066fb...284951d HEAD -> master \\\\(forced update\\\\)/\n\n    # log file\n    cat \\$(gitolite query-rc GL_LOGFILE);\n                                    ok;     /\\tupdate\\t/\n                                            /aa\\tu1\\t\\\\+\\trefs/heads/master/\n                                            /2d066fb4860c29cf321170c17695c6883f3d50e8/\n                                            /284951dfa11d58f99ab76b9f4e4c1ad2f2461236/\n\n    # basic rewind deny\n    cd ..\n    glt clone u2 file:///aa u2aa;    ok;     /Cloning into 'u2aa'.../\n    cd u2aa;                        ok\n    tc g-776 g-777 g-778;           ok;     /master 9cbc181. g-778/\n    glt push u2 origin HEAD;        ok;     /284951d..9cbc181  HEAD -> master/\n    git reset --hard HEAD^;         ok;     /HEAD is now at 2edf7fc g-777/\n    tc d-485;                       ok;     /master 1c01d32. d-485/\n    glt push u2 -f origin HEAD;     !ok;    reject\n                                            /\\\\+ refs/heads/master aa u2 DENIED by fallthru/\n\n    # non-existent repos etc\n    glt ls-remote u4 file:///bb;    !ok;    /DENIED by fallthru/\n    glt ls-remote u4 file:///cc/1;  ok;     /Initialized empty/\n    glt ls-remote u5 file:///cc/1;  ok;     perl s/TRACE.*//g; !/\\\\S/\n    glt ls-remote u5 file:///cc/2;  !ok;    /DENIED by fallthru/\n    glt ls-remote u6 file:///cc/2;  !ok;    /DENIED by fallthru/\n\n    # command\n    glt perms u4 -c cc/bar/baz/frob + READERS u2;\n                                    ok;     /Initialized empty .*cc/bar/baz/frob.git/\n\n    # path traversal\n    glt ls-remote u4 file:///cc/dd/../ee\n                                    !ok;    /FATAL: 'cc/dd/\\\\.\\\\./ee' contains '\\\\.\\\\.'/\n    glt ls-remote u5 file:///cc/../../../../../..$rb/gitolite-admin\n                                    !ok;    /FATAL: 'cc/../../../../../..$rb/gitolite-admin' contains '\\\\.\\\\.'/\n\n    glt perms u4 -c cc/bar/baz/../frob + READERS u2\n                                    !ok;    /FATAL: no relative paths allowed anywhere!/\n\n\";\n"
  },
  {
    "path": "t/C-vs-C.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# the commit message in which this test is introduced should have details, but\n# briefly, this test makes sure that access() does not get confused by\n# repo-create permissions being allowed, when looking for branch-create\n# permissions.\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\n# branch permissions test\n# ----------------------------------------------------------------------\n\ntry \"plan 25\";\n\nconfreset;confadd '\n    repo foo/..*\n        C       =   @all\n        RW+CD   =   CREATOR\n        RW      =   u2\n\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"\n    cd ..;                          ok\n    glt clone u1 file:///foo/aa;    ok\n    cd aa;                          ok\n    tc l-1;                         ok;     /master/\n    glt push u1 origin master:m1;   ok;     /To file:///foo/aa/\n                                            /\\\\* \\\\[new branch\\\\]      master -> m1/\n\n    tc l-2;                         ok;     /master/\n    glt push u2 origin master:m2;   !ok;    /FATAL: C/\n                                            /DENIED by fallthru/\n    glt push u2 origin master:m1;   ok;     /To file:///foo/aa/\n                                            /8cd302a..29b8683/\n                                            /master -> m1/\n\";\n"
  },
  {
    "path": "t/README",
    "content": "# instructions for running the tests\n\n# Pre-requisites\n\nInstall the following packages:\n\n*   Manjaro (and probably Arch):\n\n        pacman -S perl-json perl-json-xs apache\n\n*   Fedora (and probably CentOS):\n\n        dnf install -y perl-Test-Harness perl-JSON perl-JSON-XS httpd httpd-tools\n\n*   others:\n\n    (TBD)\n\n# RUNNING THE MAIN TEST SUITE\n\n    ======================================\n    WARNING: THE TEST SUITE DELETES STUFF!\n    ======================================\n\nPlease run the tests ONLY on a userid where it's ok to LOSE DATA.\n\nOn such a userid, clone gitolite then run this command in the clone:\n\n    GITOLITE_TEST=y prove\n\nhttp://gitolite.com/gitolite/testing.html has more details.  Alternatively,\nhttps://gitolite.com/gitolite/install.html#trying-out-gitolite-safely will help you try out gitolite if\nyou want to play with gitolite safely.\n\n# RUNNING THE HTTP AND MIRROR TESTS\n\n    ======================================\n    WARNING: THE TEST SUITE DELETES STUFF!\n    ======================================\n\nThe http and mirror tests require a lot more preparation, including commands\nand/or scripts to be run as root, so they're not invoked when you simply run\n\"prove\" as above.\n\n## Manjaro\n\n1.  Create 3 users: sam, frodo, and gollum (`useradd -m`).\n\n2.  Assuming you're running the tests using a local user called `g3`, run\n    `visudo` and add the following line:\n\n        g3 ALL = (sam,frodo,gollum) NOPASSWD: ALL\n\n    Test this by running this command from within `g3` and making sure you get\n    the correct results:\n\n        sudo -u sam -i pwd\n        # should print /home/sam\n        # similarly make sure frodo and gollum also give correct results\n\n    The mirror test will not run if this does not work.  That does not mean\n    *mirroring* will not work; only the test suite depends on this feature.\n\n3.  Manjaro does not, by default, add $HOME/bin to $PATH, so you will need the\n    following on at least sam, frodo, and gollum:\n\n        # copy-paste this into a root terminal\n        for u in frodo sam gollum; do\n            grep '$HOME/bin' /home/$u/.bash_profile || echo 'export PATH=\"$HOME/bin:$PATH\"' >> /home/$u/.bash_profile\n        done\n\n    Again, test this by running:\n\n        sudo -u sam -i echo '$PATH'\n\n    and making sure the output starts with `/home/sam/bin:` (and similarly for\n    frodo and gollum).\n\n4.  Take a look inside `t/manjaro-root-smart-http-test-setup` to make sure\n    everything looks sane (because you have to run it as root!!), then run it\n    as root.\n\n5.  Now you are ready to run the last two tests:\n\n        GITOLITE_TEST=y prove t/smart-http\n        GITOLITE_TEST=y prove t/mirror-test\n\n## Fedora\n\n1.  Create 3 users: sam, frodo, and gollum (`useradd`).\n\n2.  Assuming you're running the tests using a local user called `g3`, run\n    `visudo` and add the following line:\n\n        g3 ALL = (sam,frodo,gollum) NOPASSWD: ALL\n\n    Test this by running this command from within `g3` and making sure you get\n    the correct results:\n\n        sudo -u sam -i pwd\n        # should print /home/sam\n        # similarly make sure frodo and gollum also give correct results\n\n    The mirror test will not run if this does not work.  That does not mean\n    *mirroring* will not work; only the test suite depends on this feature.\n\n3.  Take a look inside `t/fedora-root-smart-http-test-setup` to make sure\n    everything looks sane (because you have to run it as root!!), then run it\n    as root.\n\n4.  Now you are ready to run the last two tests:\n\n        prove t/smart-http\n        prove t/mirror-test\n\nvim: ft=markdown\n"
  },
  {
    "path": "t/access.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\n# test 'gitolite access'\n# ----------------------------------------------------------------------\n\ntry \"plan 254\";\n\nconfreset;confadd '\n    @admins     =   admin dev1\n    repo gitolite-admin\n        RW+     =   admin\n\n    repo testing\n        RW+     =   @all\n\n    @g1 = t1\n    repo @g1\n        R       =   u2\n        RW      =   u3\n        RW+     =   u4\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"\n\n    gitolite access -q t1 u1;   !ok;    !/./\n    gitolite access -q t1 u1 R; !ok;    !/./\n    gitolite access -q t1 u1 W; !ok;    !/./\n    gitolite access -q t1 u1 +; !ok;    !/./\n    gitolite access -q t1 u2;   !ok;    !/./\n    gitolite access -q t1 u2 R; ok;     !/./\n    gitolite access -q t1 u2 W; !ok;    !/./\n    gitolite access -q t1 u2 +; !ok;    !/./\n    gitolite access -q t1 u3;   !ok;    !/./\n    gitolite access -q t1 u3 R; ok;     !/./\n    gitolite access -q t1 u3 W; ok;     !/./\n    gitolite access -q t1 u3 +; !ok;    !/./\n    gitolite access -q t1 u4;   ok;     !/./\n    gitolite access -q t1 u4 R; ok;     !/./\n    gitolite access -q t1 u4 W; ok;     !/./\n    gitolite access -q t1 u4 +; ok;     !/./\n\n    gitolite access t1 u1;      !ok;    /\\\\+ any t1 u1 DENIED by fallthru/\n    gitolite access t1 u1 R;    !ok;    /R any t1 u1 DENIED by fallthru/\n    gitolite access t1 u1 W;    !ok;    /W any t1 u1 DENIED by fallthru/\n    gitolite access t1 u1 +;    !ok;    /\\\\+ any t1 u1 DENIED by fallthru/\n    gitolite access t1 u2;      !ok;    /\\\\+ any t1 u2 DENIED by fallthru/\n    gitolite access t1 u2 R;    ok;     /refs/\\.\\*/\n    gitolite access t1 u2 W;    !ok;    /W any t1 u2 DENIED by fallthru/\n    gitolite access t1 u2 +;    !ok;    /\\\\+ any t1 u2 DENIED by fallthru/\n    gitolite access t1 u3;      !ok;    /\\\\+ any t1 u3 DENIED by fallthru/\n    gitolite access t1 u3 R;    ok;     /refs/\\.\\*/\n    gitolite access t1 u3 W;    ok;     /refs/\\.\\*/\n    gitolite access t1 u3 +;    !ok;    /\\\\+ any t1 u3 DENIED by fallthru/\n    gitolite access t1 u4;      ok;     /refs/\\.\\*/\n    gitolite access t1 u4 R;    ok;     /refs/\\.\\*/\n    gitolite access t1 u4 W;    ok;     /refs/\\.\\*/\n    gitolite access t1 u4 +;    ok;     /refs/\\.\\*/\n\n\";\n\nconfreset;confadd '\n    @admins     =   admin dev1\n    repo gitolite-admin\n        RW+     =   admin\n\n    @g1 = u1\n    @g2 = u2\n    @g3 = u3\n    @gaa = aa\n    repo @gaa\n        RW+                 =   @g1\n        RW                  =   @g2\n        RW+     master      =   @g3\n        RW      master      =   u4\n        -       master      =   u5\n        RW+     dev         =   u5\n        RW                  =   u5\n';\n\ntry \"ADMIN_PUSH set2; !/FATAL/\" or die text();\n\ntry \"\n    gitolite access \\@gaa \\@g1 + any ;                  ok;     /refs/.*/; !/DENIED/\n    gitolite access aa \\@g1 + refs/heads/master ;       ok;     /refs/.*/; !/DENIED/\n    gitolite access \\@gaa \\@g1 + refs/heads/next ;      ok;     /refs/.*/; !/DENIED/\n    gitolite access \\@gaa \\@g1 W refs/heads/next ;      ok;     /refs/.*/; !/DENIED/\n    gitolite access \\@gaa u1 + refs/heads/dev ;         ok;     /refs/.*/; !/DENIED/\n    gitolite access \\@gaa u1 + refs/heads/next ;        ok;     /refs/.*/; !/DENIED/\n    gitolite access aa u1 W refs/heads/next ;           ok;     /refs/.*/; !/DENIED/\n    gitolite access \\@gaa \\@g2 + refs/heads/master ;    !ok;    /\\\\+ refs/heads/master \\@gaa \\@g2 DENIED by fallthru/\n    gitolite access \\@gaa \\@g2 + refs/heads/next ;      !ok;    /\\\\+ refs/heads/next \\@gaa \\@g2 DENIED by fallthru/\n    gitolite access aa \\@g2 W refs/heads/master ;       ok;     /refs/.*/; !/DENIED/\n    gitolite access aa u2 + any ;                       !ok;    /\\\\+ any aa u2 DENIED by fallthru/\n    gitolite access \\@gaa u2 + refs/heads/master ;      !ok;    /\\\\+ refs/heads/master \\@gaa u2 DENIED by fallthru/\n    gitolite access \\@gaa u2 W refs/heads/master ;      ok;     /refs/.*/; !/DENIED/\n    gitolite access \\@gaa \\@g3 + refs/heads/master ;    ok;     /refs/heads/master/; !/DENIED/\n    gitolite access \\@gaa \\@g3 W refs/heads/next ;      !ok;    /W refs/heads/next \\@gaa \\@g3 DENIED by fallthru/\n    gitolite access \\@gaa \\@g3 W refs/heads/dev ;       !ok;    /W refs/heads/dev \\@gaa \\@g3 DENIED by fallthru/\n    gitolite access aa u3 + refs/heads/dev ;            !ok;    /\\\\+ refs/heads/dev aa u3 DENIED by fallthru/\n    gitolite access aa u3 + refs/heads/next ;           !ok;    /\\\\+ refs/heads/next aa u3 DENIED by fallthru/\n    gitolite access \\@gaa u4 + refs/heads/master ;      !ok;    /\\\\+ refs/heads/master \\@gaa u4 DENIED by fallthru/\n    gitolite access \\@gaa u4 W refs/heads/master ;      ok;     /refs/heads/master/; !/DENIED/\n    gitolite access aa u4 + refs/heads/next ;           !ok;    /\\\\+ refs/heads/next aa u4 DENIED by fallthru/\n    gitolite access \\@gaa u4 W refs/heads/next ;        !ok;    /W refs/heads/next \\@gaa u4 DENIED by fallthru/\n    gitolite access \\@gaa u5 R any ;                    ok;     /refs/heads/dev/; !/DENIED/\n    gitolite access aa u5 R any ;                       ok;     /refs/heads/dev/; !/DENIED/\n    gitolite access \\@gaa u5 + refs/heads/dev ;         ok;     /refs/heads/dev/; !/DENIED/\n    gitolite access \\@gaa u5 + refs/heads/master ;      !ok;    /\\\\+ refs/heads/master \\@gaa u5 DENIED by refs/heads/master/\n    gitolite access aa u5 + refs/heads/next ;           !ok;    /\\\\+ refs/heads/next aa u5 DENIED by fallthru/\n    gitolite access \\@gaa u5 R refs/heads/dev ;         ok;     /refs/heads/dev/; !/DENIED/\n    gitolite access \\@gaa u5 R refs/heads/master ;      !ok;    /R refs/heads/master \\@gaa u5 DENIED by refs/heads/master/\n    gitolite access \\@gaa u5 R refs/heads/next ;        ok;     /refs/.*/; !/DENIED/\n    gitolite access aa u5 W refs/heads/dev ;            ok;     /refs/heads/dev/; !/DENIED/\n    gitolite access aa u5 W refs/heads/master ;         !ok;    /W refs/heads/master aa u5 DENIED by refs/heads/master/\n    gitolite access \\@gaa u5 W refs/heads/next ;        ok;     /refs/.*/; !/DENIED/\n\";\n\nconfreset;confadd '\n    @admins     =   admin dev1\n    repo gitolite-admin\n        RW+     =   admin\n\n    @gr1 = r1\n    repo @gr1\n        RW  refs/heads/v[0-9]   = u1\n        RW  refs/heads          = tester\n\n    @gr2 = r2\n    repo @gr2\n        RW  refs/heads/v[0-9]   = u1\n        -   refs/heads/v[0-9]   = tester\n        RW  refs/heads          = tester\n';\n\ntry \"ADMIN_PUSH set3; !/FATAL/\" or die text();\n\ntry \"\n    gitolite access \\@gr2 tester W refs/heads/v1;       !ok;    /W refs/heads/v1 \\@gr2 tester DENIED by refs/heads/v\\\\[0-9\\\\]/\n    gitolite access \\@gr1 tester W refs/heads/v1;       ok;     /refs/heads/; !/DENIED/\n    gitolite access r1 tester W refs/heads/v1;          ok;     /refs/heads/; !/DENIED/\n    gitolite access r2 tester W refs/heads/v1;          !ok;    /W refs/heads/v1 r2 tester DENIED by refs/heads/v\\\\[0-9\\\\]/\n    gitolite access r2 tester W refs/heads/va;          ok;     /refs/heads/; !/DENIED/\n\";\n\nconfreset;confadd '\n    repo foo\n        RW+ =   u1\n\n    @gr1 = foo bar\n\n    repo @gr1\n        RW  =   u2\n        R   =   u3\n\n    repo @all\n        R   =   gitweb\n\n    repo c0\n        RW+ =   @all\n    repo c1\n        RWC =   u1\n        RW+ =   @all\n';\n\ntry \"ADMIN_PUSH set4; !/FATAL/\" or die text();\n\ntry \"\n    gitolite access foo u1 +;           ok\n    gitolite access foo u2 +;           !ok\n    gitolite access foo u3 +;           !ok\n    gitolite access foo u4 +;           !ok\n    gitolite access foo gitweb +;       !ok\n\n    gitolite access foo u1 W;           ok\n    gitolite access foo u2 W;           ok\n    gitolite access foo u3 W;           !ok\n    gitolite access foo u4 W;           !ok\n    gitolite access foo gitweb W;       !ok\n\n    gitolite access foo u1 R;           ok\n    gitolite access foo u2 R;           ok\n    gitolite access foo u3 R;           ok\n    gitolite access foo u4 R;           !ok\n    gitolite access foo gitweb R;       ok\n\n    gitolite access c0  u1 +;           ok\n    gitolite access c0  u1 C;           ok\n    gitolite access c0  u2 +;           ok\n    gitolite access c0  u2 C;           ok\n    gitolite access c1  u1 +;           ok\n    gitolite access c1  u1 C;           ok\n    gitolite access c1  u2 +;           ok\n    gitolite access c1  u2 C;           !ok\n\";\n\nconfreset;confadd '\n    repo foo\n        R   =   u1\n        RW  =   u2\n        RW+ =   u3\n\n    repo bar\n        R   =   u1\n        RW  =   u2\n        RW+ =   u3\n        RW+CDM  =   u6\n\n';\n\ntry \"ADMIN_PUSH set4; !/FATAL/\" or die text();\n\ntry \"\n    gitolite access foo u1 +;           !ok\n    gitolite access foo u2 +;           !ok\n    gitolite access foo u3 +;           ok\n    gitolite access foo u1 C;           !ok\n    gitolite access foo u2 C;           ok\n    gitolite access foo u3 C;           ok\n    gitolite access foo u1 D;           !ok\n    gitolite access foo u2 D;           !ok\n    gitolite access foo u3 D;           ok\n    gitolite access foo u1 M;           !ok\n    gitolite access foo u2 M;           ok\n    gitolite access foo u3 M;           ok\n\n    gitolite access bar u1 +;           !ok\n    gitolite access bar u2 +;           !ok\n    gitolite access bar u3 +;           ok\n    gitolite access bar u1 C;           !ok\n    gitolite access bar u2 C;           !ok\n    gitolite access bar u3 C;           !ok\n    gitolite access bar u1 D;           !ok\n    gitolite access bar u2 D;           !ok\n    gitolite access bar u3 D;           !ok\n    gitolite access bar u1 M;           !ok\n    gitolite access bar u2 M;           !ok\n    gitolite access bar u3 M;           !ok\n\n    gitolite access bar u6 R;           ok\n    gitolite access bar u6 W;           ok\n    gitolite access bar u6 +;           ok\n    gitolite access bar u6 C;           ok\n    gitolite access bar u6 D;           ok\n    gitolite access bar u6 M;           ok\n\";\n"
  },
  {
    "path": "t/all-yall.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\n# could anything be clearer than \"all y'all\"?\n# ----------------------------------------------------------------------\n\ntry \"plan 26\";\n\nconfreset;confadd '\n    repo @all\n        R   =   @all\n    repo foo\n        RW+ =   u1\n    repo bar\n        RW+ =   u2\n    repo dev/..*\n        C   =   u3 u4\n        RW+ =   CREATOR\n';\n\ntry \"\n    rm $ENV{HOME}/projects.list\n\";\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"\n    glt ls-remote u1 file:///dev/wild1\n                /FATAL: R any dev/wild1 u1 DENIED by fallthru/\n\n    glt clone u3 file:///dev/wild1\n                /Cloning into 'wild1'.../\n                /Initialized empty Git repository in .*/dev/wild1.git//\n                /warning: You appear to have cloned an empty repository./\n\n    cd wild1\n    tc n-855 n-856\n    glt push u3 origin master:wild1\n                /To file:///dev/wild1/\n                /\\\\* \\\\[new branch\\\\]      master -> wild1/\n    glt push u1 file:///foo master:br-foo\n                /To file:///foo/\n                /\\\\* \\\\[new branch\\\\]      master -> br-foo/\n    glt push u2 file:///bar master:br-bar\n                /To file:///bar/\n                /\\\\* \\\\[new branch\\\\]      master -> br-bar/\n\n    glt ls-remote u6 file:///foo\n                /refs/heads/br-foo/\n\n    glt ls-remote u6 file:///bar\n                /refs/heads/br-bar/\n\n    glt ls-remote u6 file:///dev/wild1\n                /refs/heads/wild1/\n\";\n\ntry \"\n    gitolite ../triggers/post-compile/update-git-daemon-access-list;    ok\n    gitolite ../triggers/post-compile/update-gitweb-access-list;        ok\n    cat $ENV{HOME}/projects.list;                           ok\n\";\ncmp 'bar.git\ndev/wild1.git\nfoo.git\ngitolite-admin.git\ntesting.git\n';\n\nmy $rb = `gitolite query-rc -n GL_REPO_BASE`;\n\ntry \"\n    cd ..\n    cd ..\n    echo $rb\n    find $rb -name git-daemon-export-ok | sort\n    perl s,$rb/,,g\n\";\n\ncmp 'bar.git/git-daemon-export-ok\ndev/wild1.git/git-daemon-export-ok\nfoo.git/git-daemon-export-ok\ngitolite-admin.git/git-daemon-export-ok\ntesting.git/git-daemon-export-ok\n';\n"
  },
  {
    "path": "t/basic.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\n# some more basic tests\n# ----------------------------------------------------------------------\n\ntry \"\n    plan 217\n    CHECK_SETUP\n\n    # subtest 1\n    cd ..\n    CLONE dev2 gitolite-admin ga2\n                                !ok;    gsh\n                                        /DENIED by fallthru/\n                                        /fatal: Could not read from remote repository/\n    glt clone admin --progress file:///gitolite-admin ga2\n                                ok;     gsh\n                                        /Counting/; /Compressing/; /Total/\n    cd gitolite-admin;          ok\n    \";\n\nput \"conf/gitolite.conf\", \"\n    \\@admins     =   admin dev1\n    repo gitolite-admin\n        -   mm  =   \\@admins\n        RW      =   \\@admins\n        RW+     =   admin\n\n    repo testing\n        RW+     =   \\@all\n\";\n\ntry \"\n    # push\n    git add conf;               ok\n    git status -s;              ok;     /M  conf/gitolite.conf/\n    git commit -m t01a;         ok;     /master.*t01a/\n    PUSH dev2;                  !ok;    gsh\n                                        /DENIED by fallthru/\n                                        /fatal: Could not read from remote repository/\n    PUSH admin;                 ok;     /master -> master/\n    empty;                      ok;\n    PUSH admin master:mm\n                                !ok;    gsh\n                                        /DENIED by refs/heads/mm/\n                                        reject\n    \";\n\nput \"conf/gitolite.conf\", \"\n    \\@admins     =   admin dev1\n    repo gitolite-admin\n        RW+     =   admin\n\n    repo testing\n        RW+     =   \\@all\n\n    repo t1\n        R       =   u2\n        RW      =   u3\n        RW+     =   u4\n\";\n\ntry \"\n    # subtest 2\n    ADMIN_PUSH t01b\n\n    # clone\n    cd ..;                      ok;\n    CLONE u1 t1;                !ok;    gsh\n                                        /DENIED by fallthru/\n                                        /fatal: Could not read from remote repository/\n    CLONE u2 t1;                ok;     gsh\n                                        /warning: You appear to have cloned an empty repository./\n    [ -d t1/.git ];             ok\n    cd t1;                      ok;\n\n    # push\n    test-commit tc1 tc2 tc2;    ok;     /a530e66/\n    PUSH u2;                    !ok;    gsh\n                                        /DENIED by fallthru/\n                                        /fatal: Could not read from remote repository/\n    PUSH u3 master;             ok;     gsh\n                                        /master -> master/\n\n    # rewind\n    reset-h HEAD^;              ok;     /HEAD is now at aa2b5c5 tc2/\n    test-tick; test-commit tc3; ok;     /3ffced1/\n    PUSH u3;                    !ok;    gsh\n                                        /rejected.*master -> master.*non-fast-forward./\n    PUSH u3 -f;                 !ok;    gsh\n                                        reject\n                                        /DENIED by fallthru/\n    PUSH u4 +master;            ok;     gsh\n                                        / \\\\+ a530e66...3ffced1 master -> master.*forced update./\n\";\n\nput \"../gitolite-admin/conf/gitolite.conf\", \"\n    \\@admins     =   admin dev1\n    repo gitolite-admin\n        RW+     =   admin\n\n    include 'i1.conf'\n\";\n\nput \"../gitolite-admin/conf/i1.conf\", \"\n    \\@g1 = u1\n    \\@g2 = u2\n    \\@g3 = u3\n    \\@gaa = aa\n    repo \\@gaa\n        RW+                 =   \\@g1\n        RW                  =   \\@g2\n        RW+     master      =   \\@g3\n        RW      master      =   u4\n        -       master      =   u5\n        RW+     dev         =   u5\n        RW                  =   u5\n\";\n\ntry \"\n    # subtest 3\n    ADMIN_PUSH t01c\n\n    cd ..;                      ok\n\";\n\ntry \"\n    CLONE u1 aa;                ok;     gsh\n    cd aa;                      ok\n    test-commit set3 t1 t2 t3 t4 t5 t6 t7 t8 t9\n                                ok\n    PUSH u1 HEAD;               ok;     gsh\n                                        /To file:///aa/\n                                        /\\\\* \\\\[new branch\\\\]      HEAD -> master/\n    branch dev;                 ok\n    branch foo;                 ok\n\n    # u1 rewind master ok\n    reset-h HEAD^;              ok\n    test-commit r1;             ok\n    PUSH u1 +master;            ok;     gsh\n                                        /To file:///aa/\n                                        /\\\\+ 27ed463...05adfb0 master -> master .forced update./\n\n    # u2 rewind master !ok\n    reset-h HEAD^;              ok\n    test-commit r2;             ok\n    PUSH u2 +master;            !ok;    gsh\n                                        reject\n                                        /DENIED by fallthru/\n\n    # u3 rewind master ok\n    reset-h HEAD^;              ok\n    test-commit r3;             ok\n    PUSH u3 +master;            ok;     gsh\n                                        /To file:///aa/\n                                        /\\\\+ 05adfb0...6a532fe master -> master .forced update./\n\n    # u4 push master ok\n    test-commit u4;             ok\n    PUSH u4 master;             ok;     gsh\n                                        /To file:///aa/\n                                        /6a532fe..f929773 +master -> master/\n\n    # u4 rewind master !ok\n    reset-h HEAD^;              ok\n    PUSH u4 +master;            !ok;    gsh\n                                        reject\n                                        /DENIED by fallthru/\n\n    # u3,u4 push other branches !ok\n    PUSH u3 dev;                !ok;    gsh\n                                        reject\n                                        /DENIED by fallthru/\n    PUSH u4 dev;                !ok;    gsh\n                                        reject\n                                        /DENIED by fallthru/\n    PUSH u3 foo;                !ok;    gsh\n                                        reject\n                                        /DENIED by fallthru/\n    PUSH u4 foo;                !ok;    gsh\n                                        reject\n                                        /DENIED by fallthru/\n\n    # clean up for next set\n    glt push u1 -f origin master dev foo\n                                ok;     gsh\n                                        /f929773...6a532fe master -> master .forced update./\n                                        /new branch.*dev -> dev/\n                                        /new branch.*foo -> foo/\n\n    # u5 push master !ok\n    test-commit u5\n    PUSH u5 master;             !ok;    gsh\n                                        reject\n                                        /DENIED by refs/heads/master/\n\n    # u5 rewind dev ok\n    PUSH u5 +dev^:dev\n                                ok;     gsh\n                                        /\\\\+ 27ed463...1ad477a dev\\\\^ -> dev .forced update./\n\n\n    # u5 rewind foo !ok\n    PUSH u5 +foo^:foo\n                                !ok;    gsh\n                                        reject\n                                        /FATAL: \\\\+ refs/heads/foo aa u5 DENIED by fallthru/\n\n    # u5 push foo ok\n    git checkout foo\n    /Switched to branch 'foo'/\n\n    test-commit u5\n    PUSH u5 foo;                ok;     gsh\n                                        /27ed463..83da62c *foo -> foo/\n\n    # u1 delete dev ok\n    PUSH u1 :dev;               ok;     gsh\n                                        / - \\\\[deleted\\\\] *dev/\n\n    # push it back\n    PUSH u1 dev;                ok;     gsh\n                                        /\\\\* \\\\[new branch\\\\] *dev -> dev/\n\n\";\n\nput \"| cat >> ../gitolite-admin/conf/gitolite.conf\", \"\n    \\@gr1 = r1\n    repo \\@gr1\n        RW  refs/heads/v[0-9]   = u1\n        RW  refs/heads          = tester\n\";\n\ntry \"\n    # subtest 4\n    ADMIN_PUSH t01d\n\n    cd ..;                      ok\n\n    CLONE tester r1;            ok;     gsh\n                                        /Cloning into 'r1'.../\n    cd r1;                      ok\n    test-commit r1a r1b r1c r1d r1e r1f\n                                ok\n    PUSH tester HEAD;           ok;     gsh\n                                        /\\\\* \\\\[new branch\\\\] *HEAD -> master/\n    git branch v1\n    PUSH tester v1;             ok;     gsh\n                                        /\\\\* \\\\[new branch\\\\] *v1 -> v1/\n\n\";\n\nput \"| cat >> ../gitolite-admin/conf/gitolite.conf\", \"\n    \\@gr2 = r2\n    repo \\@gr2\n        RW  refs/heads/v[0-9]   = u1\n        -   refs/heads/v[0-9]   = tester\n        RW  refs/heads          = tester\n\";\n\ntry \"\n    # subtest 5\n    ADMIN_PUSH t01e\n\n    cd ..;                      ok\n\n    CLONE tester r2;            ok;     gsh\n                                        /Cloning into 'r2'.../\n    cd r2;                      ok\n    test-commit r2a r2b r2c r2d r2e r2f\n                                ok\n    PUSH tester HEAD;           ok;     gsh\n                                        /\\\\* \\\\[new branch\\\\] *HEAD -> master/\n    git branch v1\n    PUSH tester v1;             !ok;    gsh\n                                        /W refs/heads/v1 r2 tester DENIED by refs/heads/v\\\\[0-9\\\\]/\n\"\n"
  },
  {
    "path": "t/branch-perms.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\n# branch permissions test\n# ----------------------------------------------------------------------\n\ntry \"plan 82\";\n\nconfreset;confadd '\n    @g1 = u1\n    @g2 = u2\n    @g3 = u3\n    @gaa = aa\n    repo @gaa\n        RW+                 =   @g1\n        RW                  =   @g2\n        RW+     master      =   @g3\n        RW      master      =   u4\n        -       master      =   u5\n        RW+     dev         =   u5\n        RW                  =   u5\n\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"\n    cd ..;                          ok\n    glt clone u1 file:///aa;         ok\n    cd aa;                          ok\n    tc l-995 l-996 l-997 l-998 l-999 l-1000 l-1001 l-1002 l-1003;\n                                    ok;     /master a788db9. l-1003/\n    glt push u1 origin HEAD;        ok;     /To file:///aa/\n                                            /\\\\* \\\\[new branch\\\\]      HEAD -> master/\n\n    git branch dev;                 ok\n    git branch foo;                 ok\n\n    # u1 rewind master succeed\n    git reset --hard HEAD^;         ok;     /HEAD is now at 65d5f4a l-1002/\n    tc v-865;                       ok;     /master 3053bb4. v-865/\n    glt push u1 origin +master;     ok;     /\\\\+ a788db9...3053bb4 master -> master \\\\(forced update\\\\)/\n\n    # u2 rewind master fail\n    git reset --hard HEAD^;         ok;     /HEAD is now at 65d5f4a l-1002/\n    tc s-361;                       ok;     /master b331651. s-361/\n    glt push u2 file:///aa +master;  !ok;    reject\n                                            /\\\\+ refs/heads/master aa u2 DENIED by fallthru/\n\n    # u3 rewind master succeed\n    git reset --hard HEAD^;         ok\n    tc m-508;                       ok\n    glt push u3 file:///aa +master;  ok;     /\\\\+ .* master -> master \\\\(forced update\\\\)/\n\n    # u4 push master succeed\n    tc f-526;                       ok;\n    glt push u4 file:///aa master;   ok;     /master -> master/\n\n    # u4 rewind master fail\n    git reset --hard HEAD^;         ok;\n    glt push u4 file:///aa +master;  !ok;    /\\\\+ refs/heads/master aa u4 DENIED by fallthru/\n\n    # u3 and u4 / dev foo -- all 4 fail\n    glt push u3 file:///aa dev;      !ok;    /W refs/heads/dev aa u3 DENIED by fallthru/\n    glt push u4 file:///aa dev;      !ok;    /W refs/heads/dev aa u4 DENIED by fallthru/\n    glt push u3 file:///aa foo;      !ok;    /W refs/heads/foo aa u3 DENIED by fallthru/\n    glt push u4 file:///aa foo;      !ok;    /W refs/heads/foo aa u4 DENIED by fallthru/\n\n    # clean up for next set\n    glt push u1 -f origin master dev foo\n                                    ok\n\n    # u5 push master fail\n    tc l-417;                       ok\n    glt push u5 file:///aa master;   !ok;    /W refs/heads/master aa u5 DENIED by refs/heads/master/\n\n    # u5 rewind dev succeed\n    glt push u5 file:///aa +dev^:dev\n                                    ok;     /\\\\+ .* dev\\\\^ -> dev \\\\(forced update\\\\)/\n\n    # u5 rewind foo fail\n    glt push u5 file:///aa +foo^:foo\n                                    !ok;    /\\\\+ refs/heads/foo aa u5 DENIED by fallthru/\n\n    # u5 tries to push foo; succeeds\n    git checkout foo;               ok;     /Switched to branch 'foo'/\n\n    # u5 push foo succeed\n    tc e-530;                       ok;\n    glt push u5 file:///aa foo;      ok;     /foo -> foo/\n\n    # u1 delete branch dev succeed\n    glt push u1 origin :dev;        ok;     / - \\\\[deleted\\\\] *dev/\n\n    # quietly push it back again\n    glt push u1 origin dev;         ok;     / * \\\\[new branch\\\\]      dev -> dev/\n\n    \";\n\n    confadd '\n        repo @gaa\n            RWD     dev         =   u4\n    ';\n\ntry \"ADMIN_PUSH set2; !/FATAL/\" or die text();\n\ntry \"\n    # u1 tries to delete dev on a new setup\n    cd ../aa;                       ok;     /master -> master/\n\n    # u1 delete branch dev fail\n    glt push u1 origin :dev;        !ok;    /D refs/heads/dev aa u1 DENIED by fallthru/\n\n    # u4 delete branch dev succeed\n    glt push u4 file:///aa :dev;     ok;     / - \\\\[deleted\\\\] *dev/\n\n\";\n"
  },
  {
    "path": "t/daemon-gitweb-via-perms.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\n# basic tests\n# ----------------------------------------------------------------------\n\ntry \"plan 24\";\ntry \"DEF POK = !/DENIED/; !/failed to push/\";\n\nconfreset;confadd '\n\n@leads = u1 u2\n@devs = u1 u2 u3 u4\n\n@gbar = bar/CREATOR/..*\nrepo    @gbar\n    C               =   @leads\n    RW+             =   @leads\n    RW              =   WRITERS @devs\n    R               =   READERS\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\nmy $rb = `gitolite query-rc -n GL_REPO_BASE`;\nchdir($rb);\nmy $h = $ENV{HOME};\n\ntry \"\n    glt ls-remote u1 file:///bar/u1/try1\n    /Initialized empty Git repository in .*/bar/u1/try1.git/\n\n    find . -name git-daemon-export-ok\n    /testing.git/git-daemon-export-ok/\n\n    cat $h/projects.list\n    /testing.git/\n\n    glt ls-remote u1 file:///bar/u1/try2\n    /Initialized empty Git repository in .*/bar/u1/try2.git/\n\n    find $h/repositories -name git-daemon-export-ok\n    /testing.git/git-daemon-export-ok/\n\n    cat $h/projects.list\n    /testing.git/\n\n    glt perms u1 bar/u1/try1 + READERS daemon\n    !/./\n\n    glt perms u1 bar/u1/try1 -l\n    /READERS daemon/\n\n    find $h/repositories -name git-daemon-export-ok\n    /repositories/testing.git/git-daemon-export-ok/\n    /repositories/bar/u1/try1.git/git-daemon-export-ok/\n\n    cat $h/projects.list\n    /testing.git/\n\n    glt perms u1 bar/u1/try2 + READERS gitweb\n\n    glt perms u1 bar/u1/try2 -l\n    /READERS gitweb/\n\n    find $h/repositories -name git-daemon-export-ok\n    /testing.git/git-daemon-export-ok/\n    /bar/u1/try1.git/git-daemon-export-ok/\n\n    cat $h/projects.list\n    /bar/u1/try2.git/\n    /testing.git/\n\";\n"
  },
  {
    "path": "t/deleg-1.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\n# delegation tests -- part 1\n# ----------------------------------------------------------------------\n\ntry \"plan 54\";\n\ntry \"\n    DEF SP_1 = git add conf ; ok; git commit -m %1; ok; /master.* %1/\n    DEF SUBCONF_PUSH = SP_1 %2; glt push %1 origin; gsh; /master -> master/\n\";\n\nconfreset;confadd '\n    @u1r    =   r1a r1b\n    @u2r    =   r2a r2b\n    @u3r    =   r3a r3b\n\n    # the admin repo access was probably like this to start with:\n    repo gitolite-admin\n        RW                              = u1 u2 u3\n        RW+ NAME/                       = admin\n        RW  NAME/conf/fragments/u1r     = u1\n        RW  NAME/conf/fragments/u2r     = u2\n        RW  NAME/conf/fragments/u3r     = u3\n        -   NAME/                       = @all\n\n        subconf \"fragments/*.conf\"\n';\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\nmkdir \"conf/fragments\";\nput   \"conf/fragments/u1r.conf\", '\n    repo @u1r\n        RW+     =   tester\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\ntry \"\n        /Initialized empty Git repository in .*/r1a.git//\n        /Initialized empty Git repository in .*/r1b.git//\n\";\n\n# u1 push u1r pass\nput   \"conf/fragments/u1r.conf\", '\n    repo @u1r\n        RW+     =   u5\n';\ntry \"SUBCONF_PUSH u1 u1; !/FATAL/\" or die text();\n\n# u2 main push fail\nconfadd '\n    repo @u1r\n        RW+     =   u6\n';\ntry \"SUBCONF_PUSH u2 u2; /FATAL/;\n        /W VREF/NAME/conf/gitolite.conf gitolite-admin u2 DENIED by VREF/NAME//\n\";\n\ntry \"git reset --hard origin/master; ok\";\n\n# u2 push u1r fail\nput   \"conf/fragments/u1r.conf\", '\n    repo @u1r\n        RW+     =   u6\n';\ntry \"SUBCONF_PUSH u2 u2; /FATAL/\n        /W VREF/NAME/conf/fragments/u1r.conf gitolite-admin u2 DENIED by VREF/NAME//\n\";\n\ntry \"git reset --hard origin/master; ok\";\n\n# u3 set perms for r2a fail\nput   \"conf/fragments/u3r.conf\", '\n    repo r2a\n        RW+     =   u6\n';\ntry \"SUBCONF_PUSH u3 u3;\n        /WARNING: subconf 'u3r' attempting to set access for r2a/\n\";\n\ntry \"git reset --hard origin/master; ok\";\n\n# u3 add r2b to u3r fail\n\nput   \"conf/fragments/u3r.conf\", '\n    @u3r    =   r2b\n    repo @u3r\n        RW+     =   u6\n';\n\ntry \"SUBCONF_PUSH u3 u3\n        /WARNING: expanding '\\@u3r'/\n        /WARNING: subconf 'u3r' attempting to set access for r2b/\n\";\n"
  },
  {
    "path": "t/deleg-2.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\n# delegation tests -- part 2\n# ----------------------------------------------------------------------\n\ntry \"plan 55\";\n\ntry \"\n    DEF SP_1 = git add conf ; ok; git commit -m %1; ok; /master.* %1/\n    DEF SUBCONF_PUSH = SP_1 %2; glt push %1 origin; gsh; /master -> master/\n\";\n\nconfreset;confadd '\n    # group your projects/repos however you want\n    @u1r    =   r1[ab]\n    @u2r    =   r2[ab]\n    @u3r    =   r3[ab]\n\n    # the admin repo access was probably like this to start with:\n    repo gitolite-admin\n        RW                              = u1 u2 u3\n        RW+ NAME/                       = admin\n        RW  NAME/conf/fragments/u1r     = u1\n        RW  NAME/conf/fragments/u2r     = u2\n        RW  NAME/conf/fragments/u3r     = u3\n        -   NAME/                       = @all\n\n    subconf \"fragments/*.conf\"\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"mkdir -p conf/fragments; ok\";\n\nput \"conf/fragments/u1r.conf\", '\n    repo r1a r1b\n        C       =   @all\n        RW+     =   CREATOR\n    repo @u1r\n        RW+     =   tester\n';\n\nput \"conf/fragments/u2r.conf\", '\n    repo @u2r\n        C       =   @all\n        RW+     =   CREATOR\n    repo @u2r\n        RW+     =   tester\n';\n\nput \"conf/fragments/u3r.conf\", '\n    repo @u3r\n        C       =   @all\n        RW+     =   CREATOR\n    repo @u3r\n        RW+     =   tester\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\ntry \"\n        /Initialized empty Git repository in .*/r1a.git//\n        /Initialized empty Git repository in .*/r1b.git//\n\";\n\n# u1 push u1r pass\nput   \"conf/fragments/u1r.conf\", '\n    repo @u1r\n        RW+     =   u5\n';\ntry \"SUBCONF_PUSH u1 u1; !/FATAL/\" or die text();\n\n# u2 main push fail\nconfadd '\n    repo @u1r\n        RW+     =   u6\n';\ntry \"SUBCONF_PUSH u2 u2; /FATAL/;\n        /W VREF/NAME/conf/gitolite.conf gitolite-admin u2 DENIED by VREF/NAME//\n\";\n\ntry \"git reset --hard origin/master; ok\";\n\n# u2 push u1r fail\nput   \"conf/fragments/u1r.conf\", '\n    repo @u1r\n        RW+     =   u6\n';\ntry \"SUBCONF_PUSH u2 u2; /FATAL/\n        /W VREF/NAME/conf/fragments/u1r.conf gitolite-admin u2 DENIED by VREF/NAME//\n\";\n\ntry \"git reset --hard origin/master; ok\";\n\n# u3 set perms for r2a fail\nput   \"conf/fragments/u3r.conf\", '\n    repo r2a\n        RW+     =   u6\n';\ntry \"SUBCONF_PUSH u3 u3;\n        /WARNING: subconf 'u3r' attempting to set access for r2a/\n\";\n\ntry \"git reset --hard origin/master; ok\";\n\n# u3 add r2b to u3r fail\n\nput   \"conf/fragments/u3r.conf\", '\n    @u3r    =   r2b\n    repo @u3r\n        RW+     =   u6\n';\n\ntry \"SUBCONF_PUSH u3 u3\n        /WARNING: expanding '\\@u3r'/\n        /WARNING: subconf 'u3r' attempting to set access for r2b/\n\";\n"
  },
  {
    "path": "t/deny-create.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\n# deny-create, the RW.*C flag\n# ----------------------------------------------------------------------\n\ntry \"plan 72\";\n\ntry \"DEF POK = !/DENIED/; !/failed to push/\";\n\n# test \"C\" permissions\n\nconfreset; confadd '\n    @leads = u1 u2\n    @devs = u1 u2 u3 u4\n\n    @gfoo = foo\n    repo    @gfoo\n        RW+C                =   @leads\n        RW+C personal/USER/ =   @devs\n        RW                  =   @devs\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"\n    cd ..\n    glt clone u1 file:///foo\n\n    cd foo\n    tc t-413 t-414 t-415 t-416 t-417\n\n    # u1 can push/rewind master on foo\n    glt push u1 origin master\n        POK; /master -> master/\n    glt push u1 -f origin master^^:master\n        POK; /master\\\\^\\\\^ -> master/\n\n    # u2 can create newbr1 on foo\n    glt push u2 file:///foo master:newbr1\n        POK; /master -> newbr1/\n\n    # u2 can create newtag on foo\n    git tag newtag\n    glt push u2 file:///foo newtag\n        POK; /newtag -> newtag/\n\n    # u3 can push newbr1 on foo\n    tc u-962 u-963 u-964 u-965 u-966\n    glt push u3 file:///foo master:newbr1\n        POK; /master -> newbr1/\n\n    # u4 canNOT create newbr2 on foo\n    tc e-615 e-616 e-617 e-618 e-619\n    glt push u3 file:///foo master:newbr2\n        /C refs/heads/newbr2 foo u3 DENIED by fallthru/\n        reject\n\n    # u4 canNOT create newtag2 on foo\n    git tag newtag2\n    glt push u3 file:///foo newtag2\n        /C refs/tags/newtag2 foo u3 DENIED by fallthru/\n        reject\n\n    # u4 can create/rewind personal/u4/newbr3 on foo\n    tc f-664 f-665 f-666 f-667 f-668\n    glt push u4 file:///foo master:personal/u4/newbr3\n        POK; /master -> personal/u4/newbr3/\n    glt push u4 -f origin master^^:personal/u4/newbr3\n        POK; /master\\\\^\\\\^ -> personal/u4/newbr3/\n\";\n\n# bar, without \"C\" permissions, should behave like old\n\nconfadd '\n    @leads = u1 u2\n    @devs = u1 u2 u3 u4\n\n    @gbar = bar\n    repo    @gbar\n        RW+                 =   @leads\n        RW+  personal/USER/ =   @devs\n        RW                  =   @devs\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"\n    cd ..\n    glt clone u1 file:///bar\n\n    cd bar\n    tc u-907 u-908 u-909 u-910 u-911\n\n    # u1 can push/rewind master on bar\n    glt push u1 origin master\n        POK; /master -> master/\n    glt push u1 -f origin master^^:master\n        POK; /master\\\\^\\\\^ -> master/\n\n    # u2 can create newbr1 on bar\n    glt push u2 file:///bar master:newbr1\n        POK; /master -> newbr1/\n\n    # u2 can create newtag on bar\n    git tag newtag\n    glt push u2 file:///bar newtag\n        POK; /newtag -> newtag/\n\n    # u3 can push newbr1 on bar\n    tc y-862 y-863 y-864 y-865 y-866\n    glt push u3 file:///bar master:newbr1\n        POK; /master -> newbr1/\n\n    # u4 can create newbr2 on bar\n    tc q-417 q-418 q-419 q-420 q-421\n    glt push u3 file:///bar master:newbr2\n        POK; /master -> newbr2/\n\n    # u4 can create newtag2 on bar\n    git tag newtag2\n    glt push u3 file:///bar newtag2\n        POK; /newtag2 -> newtag2/\n\n    # u4 can create/rewind personal/u4/newbr3 on bar\n    tc v-605 v-606 v-607 v-608 v-609\n    glt push u4 file:///bar master:personal/u4/newbr3\n        POK; /master -> personal/u4/newbr3/\n    glt push u4 -f origin master^^:personal/u4/newbr3\n        POK; /master\\\\^\\\\^ -> personal/u4/newbr3/\n\n\";\n"
  },
  {
    "path": "t/deny-rules-2.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\n# more on deny-rules\n# ----------------------------------------------------------------------\n\ntry \"plan 126\";\n\ntry \"\n    DEF GOOD    = /refs/\\\\.\\\\*/\n    DEF BAD     = /DENIED/\n\n    DEF Ryes    = gitolite access %1 %2 R any;  ok; GOOD\n    DEF Rno     = gitolite access %1 %2 R any;  !ok; BAD\n\n    DEF Wyes    = gitolite access %1 %2 W any;  ok; GOOD\n    DEF Wno     = gitolite access %1 %2 W any;  !ok; BAD\n\n    DEF GWyes   = Ryes %1 gitweb\n    DEF GWno    = Rno  %1 gitweb\n\n    DEF GDyes   = Ryes %1 daemon\n    DEF GDno    = Rno  %1 daemon\n\";\n\nconfreset;confadd '\n    repo one\n        RW+ =   u1\n        R   =   u2\n        -   =   u2 u3\n        R   =   @all\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"\n    Wyes one u1\n\n    Ryes one u2\n    Wno  one u2\n\n    Ryes one u3\n    Wno  one u3\n\n    Ryes one u6\n    Wno  one u6\n\n    GDyes one\n    GWyes one\n\";\n\nconfadd '\n    option deny-rules = 1\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"\n    Wyes one u1\n\n    Ryes one u2\n    Wno  one u2\n\n    Rno  one u3\n\n    Ryes one u6\n    Wno  one u6\n\n    GDyes one\n    GWyes one\n\";\n\nconfadd '\n    repo two\n        RW+ =   u1\n        R   =   u2\n        -   =   u2 u3 gitweb daemon\n        R   =   @all\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"\n    GWyes two\n    GDyes two\n\";\n\nconfadd '\n    option deny-rules = 1\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"\n    GWno  two\n    GDno  two\n\";\n\n# set 3 -- allow gitweb to all but admin repo\n\nconfadd '\n    repo gitolite-admin\n        -   =   gitweb daemon\n    option deny-rules = 1\n\n    repo three\n        RW+ =   u3\n        R   =   gitweb daemon\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"\n    GDyes   three\n    GWyes   three\n    GDno    gitolite-admin\n    GWno    gitolite-admin\n\";\n\n# set 4 -- allow gitweb to all but admin repo\n\nconfadd '\n    repo four\n        RW+ =   u4\n        -   =   gitweb daemon\n\n    repo @all\n        R   =   @all\n';\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"\n    GDyes   four\n    GWyes   four\n    GDno    gitolite-admin\n    GWno    gitolite-admin\n\";\n\n# set 5 -- go wild\n\nconfreset; confadd '\n    repo foo/..*\n        C   =   u1\n        RW+ =   CREATOR\n        -   =   gitweb daemon\n        R   =   @all\n\n    repo bar/..*\n        C   =   u2\n        RW+ =   CREATOR\n        -   =   gitweb daemon\n        R   =   @all\n    option deny-rules = 1\n';\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"\n    glt ls-remote u1 file:///foo/one\n    glt ls-remote u2 file:///bar/two\n    Wyes foo/one u1\n    Wyes bar/two u2\n\n    GDyes foo/one\n    GDyes foo/one\n    GWno  bar/two\n    GWno  bar/two\n\";\n"
  },
  {
    "path": "t/deny-rules.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\n# deny rules\n# ----------------------------------------------------------------------\n\ntry \"plan 11\";\n\nconfreset;confadd '\n    # start with...\n\n    repo gitolite-admin\n        -   =   gitweb daemon\n    option deny-rules = 1\n\n    # main ruleset goes here\n\n    @ga = a\n    @gb = b\n    @gc = c\n\n    # and end with\n\n    repo @ga\n        RW  =   u1\n        -   =   @all\n    option deny-rules = 1\n\n    repo @gb\n        RW  =   u2\n        -   =   daemon\n    option deny-rules = 1\n\n    repo @gc\n        RW  =   u3\n\n    repo @all\n        R   =   @all\n\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\nmy $rb = `gitolite query-rc -n GL_REPO_BASE`;\ntry \"\n    cat $ENV{HOME}/projects.list;                           ok\n\";\ncmp 'b.git\nc.git\ntesting.git\n';\n\ntry \"\n    cd ..\n    cd ..\n    echo $rb\n    find $rb -name git-daemon-export-ok | sort\n    perl s,$rb/,,g\n\";\ncmp 'c.git/git-daemon-export-ok\ntesting.git/git-daemon-export-ok\n'\n"
  },
  {
    "path": "t/easy.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Easy;\nuse Gitolite::Test;\n# put this after ::Easy because it chdirs away from where you were and the\n# 'use lib \"src\"', not being absolute, fails\n\n# smoke tests for Easy.pm\n# ----------------------------------------------------------------------\n# for a change these are actual perl tests, so not much call for tsh here,\n# although I still need the basic infrastructure for setting up the repos and\n# I still can't intermix this with perl's Test.pm or Test::More etc\nsub ok { (+shift) ? print \"ok\\n\" : print \"not ok\\n\"; }\nsub nok { (+shift) ? print \"not ok\\n\" : print \"ok\\n\"; }\nsub msg { return unless $ENV{D}; print STDERR \"#\" . +shift . \"\\n\"; }\n\ntry \"plan 98\";\n\ntry \"\n    cat $ENV{HOME}/.gitolite.rc\n    perl s/GIT_CONFIG_KEYS.*/GIT_CONFIG_KEYS => '.*',/\n    put $ENV{HOME}/.gitolite.rc\n\";\n\n# basic push admin repo\nconfreset;confadd '\n    repo gitolite-admin\n        RW+     VREF/NAME/      =   admin\n        RW+     VREF/NAME/u5/   =   u5\n\n    repo aa\n        RW+     =   u1\n        RW      =   u2\n        R       =   u4\n\n        config for.aa   =   1\n\n    repo cc/..*\n        C       =   u4\n        RW+     =   CREATOR u5\n        R       =   u6\n\n        config for.cc   =   1\n\n    @oddguys = u1 u3 u5\n    @evensout = u2 u4 u6\n\n    repo cc/sub/..*\n        config sub.cc   =   1\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\n# valid_user() -- an internal function but still worth testing by itself first\neval { Gitolite::Easy::valid_user(); };\nok($@ =~ /FATAL.*GL_USER not set/);\n$ENV{GL_USER} = \"u2\";\neval { Gitolite::Easy::valid_user(); };\nnok($@ =~ /FATAL.*GL_USER not set/);\n\n# is_admin\nmsg('is_admin');\n$ENV{GL_USER} = \"admin\"; ok(is_admin());\n$ENV{GL_USER} = \"u5\"; ok(is_admin());\n$ENV{GL_USER} = \"u2\"; nok(is_admin());\n\n# is_super_admin -- not sure how useful it is right now\nmsg('is_super_admin');\n$ENV{GL_USER} = \"admin\"; ok( is_super_admin() );\n$ENV{GL_USER} = \"u5\";    nok( is_super_admin() );\n$ENV{GL_USER} = \"u2\";    nok( is_super_admin() );\n\n# in_group\nmsg('in_group');\n$ENV{GL_USER} = \"u1\"; ok( in_group('oddguys') );  nok( in_group('evensout') );\n$ENV{GL_USER} = \"u3\"; ok( in_group('oddguys') );  nok( in_group('evensout') );\n$ENV{GL_USER} = \"u4\"; nok( in_group('oddguys') ); ok( in_group('evensout') );\n$ENV{GL_USER} = \"u2\"; nok( in_group('oddguys') ); ok( in_group('evensout') );\n\n# owns\nmsg('owns');\ntry(\"glt ls-remote u4 cc/u4; /Initialized empty.*cc/u4/\");\n$ENV{GL_USER} = \"u3\"; nok( owns(\"cc/u3\") ); nok( owns(\"cc/u4\") );\n$ENV{GL_USER} = \"u4\"; nok( owns(\"cc/u3\") ); ok( owns(\"cc/u4\") );\n$ENV{GL_USER} = \"u5\"; nok( owns(\"cc/u3\") ); nok( owns(\"cc/u4\") );\n\n# can_read\nmsg('can_read');\n$ENV{GL_USER} = \"u1\"; ok(can_read(\"aa\"));\n$ENV{GL_USER} = \"u2\"; ok(can_read(\"aa\"));\n$ENV{GL_USER} = \"u3\"; nok(can_read(\"aa\"));\n$ENV{GL_USER} = \"u4\"; ok(can_read(\"aa\"));\n\n$ENV{GL_USER} = \"u1\"; nok(can_read(\"bb\"));\n$ENV{GL_USER} = \"u2\"; nok(can_read(\"bb\"));\n$ENV{GL_USER} = \"u3\"; nok(can_read(\"bb\"));\n$ENV{GL_USER} = \"u4\"; nok(can_read(\"bb\"));\n\n$ENV{GL_USER} = \"u3\"; nok(can_read(\"cc/u3\"));\n$ENV{GL_USER} = \"u4\"; nok(can_read(\"cc/u3\"));\n$ENV{GL_USER} = \"u5\"; nok(can_read(\"cc/u3\"));\n$ENV{GL_USER} = \"u6\"; nok(can_read(\"cc/u3\"));\n\n$ENV{GL_USER} = \"u3\"; nok(can_read(\"cc/u4\"));\n$ENV{GL_USER} = \"u4\"; ok(can_read(\"cc/u4\"));\n$ENV{GL_USER} = \"u5\"; ok(can_read(\"cc/u4\"));\n$ENV{GL_USER} = \"u6\"; ok(can_read(\"cc/u4\"));\n\n# can_write\nmsg('can_write');\n$ENV{GL_USER} = \"u1\"; ok(can_write(\"aa\"));\n$ENV{GL_USER} = \"u2\"; ok(can_write(\"aa\"));\n$ENV{GL_USER} = \"u3\"; nok(can_write(\"aa\"));\n$ENV{GL_USER} = \"u4\"; nok(can_write(\"aa\"));\n\n$ENV{GL_USER} = \"u1\"; ok(can_write(\"aa\", \"+\"));\n$ENV{GL_USER} = \"u2\"; nok(can_write(\"aa\", \"+\"));\n$ENV{GL_USER} = \"u3\"; nok(can_write(\"aa\", \"+\"));\n$ENV{GL_USER} = \"u4\"; nok(can_write(\"aa\", \"+\"));\n\n$ENV{GL_USER} = \"u1\"; nok(can_write(\"bb\"));\n$ENV{GL_USER} = \"u2\"; nok(can_write(\"bb\"));\n$ENV{GL_USER} = \"u3\"; nok(can_write(\"bb\"));\n$ENV{GL_USER} = \"u4\"; nok(can_write(\"bb\"));\n\n$ENV{GL_USER} = \"u3\"; nok(can_write(\"cc/u3\"));\n$ENV{GL_USER} = \"u4\"; nok(can_write(\"cc/u3\"));\n$ENV{GL_USER} = \"u5\"; nok(can_write(\"cc/u3\"));\n$ENV{GL_USER} = \"u6\"; nok(can_write(\"cc/u3\"));\n\n$ENV{GL_USER} = \"u3\"; nok(can_write(\"cc/u4\"));\n$ENV{GL_USER} = \"u4\"; ok(can_write(\"cc/u4\"));\n$ENV{GL_USER} = \"u5\"; ok(can_write(\"cc/u4\"));\n$ENV{GL_USER} = \"u6\"; nok(can_write(\"cc/u4\"));\n\n$ENV{GL_USER} = \"u3\"; nok(can_write(\"cc/u4\", \"+\"));\n$ENV{GL_USER} = \"u4\"; ok(can_write(\"cc/u4\", \"+\"));\n$ENV{GL_USER} = \"u5\"; ok(can_write(\"cc/u4\", \"+\"));\n$ENV{GL_USER} = \"u6\"; nok(can_write(\"cc/u4\", \"+\"));\n\n# config\ntry(\"glt ls-remote u4 cc/sub/one; /Initialized empty.*cc/sub/one/\");\ntry(\"glt ls-remote u4 cc/two; /Initialized empty.*cc/two/\");\nok(1);\nmy @a;\n@a = config(\"aa\", \"fo..aa\");   ok($a[0] eq 'for.aa' and $a[1] eq '1');\n@a = config(\"aa\", \"for.aa\");   ok($a[0] eq 'for.aa' and $a[1] eq '1');\n@a = config(\"aa\", \"fo\\\\..aa\"); ok(scalar(@a) == 0);\n\n@a = config(\"aa\", \"fo..cc\");   ok(scalar(@a) == 0);\n@a = config(\"aa\", \"for.cc\");   ok(scalar(@a) == 0);\n@a = config(\"aa\", \"fo\\\\..cc\"); ok(scalar(@a) == 0);\n\n@a = config(\"bb\", \"fo..aa\");   ok(scalar(@a) == 0);\n@a = config(\"bb\", \"for.aa\");   ok(scalar(@a) == 0);\n@a = config(\"bb\", \"fo\\\\..aa\"); ok(scalar(@a) == 0);\n\n@a = config(\"cc/u4\", \"fo..aa\");   ok(scalar(@a) == 0);\n@a = config(\"cc/u4\", \"for.aa\");   ok(scalar(@a) == 0);\n@a = config(\"cc/u4\", \"fo\\\\..aa\"); ok(scalar(@a) == 0);\n\n@a = config(\"cc/u4\", \"fo..cc\");   ok($a[0] eq 'for.cc' and $a[1] eq '1');\n@a = config(\"cc/u4\", \"for.cc\");   ok($a[0] eq 'for.cc' and $a[1] eq '1');\n@a = config(\"cc/u4\", \"fo\\\\..cc\"); ok(scalar(@a) == 0);\n\n@a = config(\"cc/two\", \"fo..cc\");   ok($a[0] eq 'for.cc' and $a[1] eq '1');\n@a = config(\"cc/two\", \"for.cc\");   ok($a[0] eq 'for.cc' and $a[1] eq '1');\n@a = config(\"cc/two\", \"fo\\\\..cc\"); ok(scalar(@a) == 0);\n\n@a = config(\"cc/sub/one\", \"fo..cc\");   ok($a[0] eq 'for.cc' and $a[1] eq '1');\n@a = config(\"cc/sub/one\", \"for.cc\");   ok($a[0] eq 'for.cc' and $a[1] eq '1');\n@a = config(\"cc/sub/one\", \"fo\\\\..cc\"); ok(scalar(@a) == 0);\n\n@a = config(\"cc/sub/one\", \"su..cc\");   ok($a[0] eq 'sub.cc' and $a[1] eq '1');\n@a = config(\"cc/sub/one\", \"sub.cc\");   ok($a[0] eq 'sub.cc' and $a[1] eq '1');\n@a = config(\"cc/sub/one\", \"su\\\\..cc\"); ok(scalar(@a) == 0);\n\n"
  },
  {
    "path": "t/fedora-root-smart-http-test-setup",
    "content": "#!/bin/bash\n\n# gitolite http mode TESTING setup for Fedora\n# - Probably works for CentOS also; if someone tests it let me know\n# - Use the comments to create a version for your distro if needed\n\n# CAUTION: This script needs to be run as root, so you best eyeball it at\n# least once to make sure you know what changes it is making.\n\n# WARNING: clobbers /usr/share/httpd/gitolite-home, and also creates 7 http\n# users with trivial passwords FOR TESTING.\n\n# HOWEVER: if you remove some of that, especially the part that creates test\n# users, this *should* work as a quick \"setup gitolite http mode\" script.\n\n# CAUTION: This script assumes the httpd.conf file is pretty much the default\n# \"as shipped\" version.  If you fiddled with it, this script *may* break.\n# It's on you to determine if that is the case and manually simulate the\n# actions of this script.  It's not that hard, and anyway it's just once (for\n# a given server) so it's not too bad.\n\n# ----------------------------------------------------------------------\n\ncd ~apache\n# should be /usr/share/httpd; you may want to check just to be safe\nexport GITOLITE_HTTP_HOME=$PWD/gitolite-home\n# WARNING: do not add a trailing slash to the value of GITOLITE_HTTP_HOME\n\n[[ -d gitolite-home ]] && {\n    [[ $GITOLITE_TEST != y ]] && {\n        echo \"If you're OK with clobbering $GITOLITE_HTTP_HOME, please rerun with\nenvironment variable GITOLITE_TEST set to 'y'.\"\n        exit 1;\n    }\n}\n\nrm -rf gitolite-home\nmkdir gitolite-home\n\n# setup apache conf for gitolite\ncd /etc/httpd/conf.d\n[[ -f gitolite.conf ]] || {\n    cat > gitolite.conf <<-EOF\n\t\tSetEnv GIT_PROJECT_ROOT $GITOLITE_HTTP_HOME/repositories\n\t\tScriptAlias /git/ $GITOLITE_HTTP_HOME/gitolite-source/src/gitolite-shell/\n\t\tScriptAlias /gitmob/ $GITOLITE_HTTP_HOME/gitolite-source/src/gitolite-shell/\n\t\tSetEnv GITOLITE_HTTP_HOME $GITOLITE_HTTP_HOME\n\t\tSetEnv GIT_HTTP_EXPORT_ALL\n\n\t\t<Location /git>\n\t\t    AuthType Basic\n\t\t    AuthName \"Private Git Access\"\n\t\t    Require valid-user\n\t\t    AuthUserFile $GITOLITE_HTTP_HOME/gitolite-http-authuserfile\n\t\t</Location>\n\tEOF\n}\n\n# get the gitolite sources\ncd $GITOLITE_HTTP_HOME\n\nif [[ -d /tmp/gitolite.git ]]; then\n    git clone /tmp/gitolite.git                      gitolite-source\n    # I do this because I have to test stuff *before* it gets to github, so I\n    # can't simply clone what's on github.  Instead, I use a local\n    # world-readable bare repo cloned from my dev environment.\nelse\n    git clone 'https://github.com/sitaramc/gitolite' gitolite-source\nfi\n\n# make the bin directory, and add it to PATH\ncd gitolite-source\nmkdir             $GITOLITE_HTTP_HOME/bin\n./install -ln     $GITOLITE_HTTP_HOME/bin\nexport PATH=$PATH:$GITOLITE_HTTP_HOME/bin\n\n# come back to base, then run setup.  Notice that you have to point HOME to\n# the right place, even if it is just for this command\ncd $GITOLITE_HTTP_HOME\nHOME=$GITOLITE_HTTP_HOME gitolite setup -a admin\n\n# insert some essential lines at the beginning of the rc file\necho '$ENV{PATH} .= \":$ENV{GITOLITE_HTTP_HOME}/bin\";'  > 1\necho >> 1\ncat .gitolite.rc >> 1\n\\mv 1 .gitolite.rc\n\n# create users \"admin\" and \"u1\" thru \"u6\" for testing\nhtpasswd -bc $GITOLITE_HTTP_HOME/gitolite-http-authuserfile admin admin\nseq 6 | xargs -I % htpasswd -b $GITOLITE_HTTP_HOME/gitolite-http-authuserfile u% u%\n\n# fix up ownership\nchown -R apache:apache $GITOLITE_HTTP_HOME\n\n# restart httpd to make it pick up all the new stuff\nsystemctl restart httpd\n"
  },
  {
    "path": "t/fork.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\nmy $h = $ENV{HOME};\n\n# fork command\n# ----------------------------------------------------------------------\n\ntry \"plan 38\";\n\nmy $rb = `gitolite query-rc -n GL_REPO_BASE`;\n\nconfreset;confadd '\n\n    repo foo/CREATOR/..*\n        C   =   u1 u2\n        RW+ =   CREATOR\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"\n    cd ..\n\n    # make the initial repo\n    glt ls-remote u1 file:///foo/u1/u1a;ok;     gsh\n                                                /Initialized empty Git repository in .*/foo/u1/u1a.git/\n    # vrc doesn't have the fork command\n    glt fork u1 foo/u1/u1a foo/u1/u1a2; !ok;    /FATAL: unknown git/gitolite command: \\\\'fork/\n\";\n\n# allow fork as a valid command\n$ENV{G3T_RC} = \"$ENV{HOME}/g3trc\";\nput \"$ENV{G3T_RC}\", \"\\$rc{COMMANDS}{fork} = 1;\\n\";\n\n# enable set-default-roles feature, add options, push\ntry \"\n    cat $h/.gitolite.rc\n    perl s/# 'set-default-roles'/'set-default-roles'/\n    put $h/.gitolite.rc\n\";\ntry \"cd gitolite-admin\";\nconfadd '\n    repo foo/CREATOR/..*\n        C   =   u1 u2\n        RW+ =   CREATOR\n    option default.roles-1 = READERS @all\n';\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\ntry \"cd ..\";\n\ntry \"\n    # now the fork succeeds\n    glt fork u1 foo/u1/u1a foo/u1/u1a2; ok;     /Cloning into bare repository '.*/foo/u1/u1a2.git'/\n                                                /foo/u1/u1a forked to foo/u1/u1a2/\n\n    # now the actual testing starts\n    # read error\n    glt fork u1 foo/u1/u1c foo/u1/u1d;  !ok;    /'foo/u1/u1c' does not exist or you are not allowed to read it/\n    glt fork u2 foo/u1/u1a foo/u1/u1d;  !ok;    /'foo/u1/u1a' does not exist or you are not allowed to read it/\n\n    # write error\n    glt fork u1 foo/u1/u1a foo/u2/u1d;  !ok;    /'foo/u2/u1d' already exists or you are not allowed to create it/\n\n    # no error\n    glt fork u1 foo/u1/u1a foo/u1/u1e;  ok;     /Cloning into bare repository '.*/foo/u1/u1e.git'/\n                                                /warning: You appear to have cloned an empty repository/\n                                                /foo/u1/u1a forked to foo/u1/u1e/\n    # both exist\n    glt fork u1 foo/u1/u1a foo/u1/u1e;  !ok;    /'foo/u1/u1e' already exists or you are not allowed to create it/\n\";\n\n# now check the various files that should have been produced\n\nmy $t;\ntry \"cd $rb; find . -name gl-perms\"; $t = md5sum(sort (lines())); cmp $t,\n'59b3a74b4d33c7631f08e75e7b60c7ce  ./foo/u1/u1a2.git/gl-perms\n59b3a74b4d33c7631f08e75e7b60c7ce  ./foo/u1/u1e.git/gl-perms\n';\n\ntry \"cd $rb; find . -name gl-creator\"; $t = md5sum(sort (lines())); cmp $t,\n'e4774cdda0793f86414e8b9140bb6db4  ./foo/u1/u1a.git/gl-creator\n346955ff2eadbf76e19373f07dd370a9  ./foo/u1/u1a2.git/gl-creator\n346955ff2eadbf76e19373f07dd370a9  ./foo/u1/u1e.git/gl-creator\n';\n"
  },
  {
    "path": "t/git-config.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\n# git config settings\n# ----------------------------------------------------------------------\n\ntry \"plan 57\";\n\ntry \"pwd\";\nmy $od = text();\nchomp($od);\n\nmy $t;  # temp\n\n# try an invalid config key\nconfreset;confadd '\n\n    repo @all\n        config foo.bar  =   dft\n';\n\ntry \"ADMIN_PUSH set1; /FATAL/\" or die text();\ntry \"\n    /git config \\\\'foo.bar\\\\' not allowed/\n    /check GIT_CONFIG_KEYS in the rc file/\n\";\n\n# make foo.bar a valid gc key\n$ENV{G3T_RC} = \"$ENV{HOME}/g3trc\";\nput \"$ENV{G3T_RC}\", \"\\$rc{GIT_CONFIG_KEYS} = 'foo\\.bar';\\n\";\n\nconfreset;confadd '\n\n    repo @all\n        config foo.bar  =   dft\n\n    repo gitolite-admin\n        RW+     =   admin\n        config foo.bar  =\n\n    repo testing\n        RW+     =   @all\n\n    repo foo\n        RW      =   u1\n        config foo.bar  =   f1\n\n    repo frob\n        RW      =   u3\n\n    repo bar\n        RW      =   u2\n        config foo.bar  =   one\n\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\nmy $rb = `gitolite query-rc -n GL_REPO_BASE`;\ntry \"\n    cd $rb;                             ok\n    grep -E foo\\\\|bar *.git/config\n\";\n$t = join(\"\\n\", sort (lines()));\n\ncmp $t, 'bar.git/config:\tbar = one\nbar.git/config:\tbare = true\nbar.git/config:[foo]\nfoo.git/config:\tbar = f1\nfoo.git/config:\tbare = true\nfoo.git/config:[foo]\nfrob.git/config:\tbar = dft\nfrob.git/config:\tbare = true\nfrob.git/config:[foo]\ngitolite-admin.git/config:\tbare = true\ntesting.git/config:\tbar = dft\ntesting.git/config:\tbare = true\ntesting.git/config:[foo]';\n\ntry \"cd $od; ok\";\n\nconfadd '\n\n    repo frob\n        RW      =   u3\n        config foo.bar  =   none\n\n    repo bar\n        RW      =   u2\n        config foo.bar  =   one\n\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"\n    cd $rb;                             ok\n    grep -E foo\\\\|bar *.git/config\n\";\n$t = join(\"\\n\", sort (lines()));\n\ncmp $t, 'bar.git/config:\tbar = one\nbar.git/config:\tbare = true\nbar.git/config:[foo]\nfoo.git/config:\tbar = f1\nfoo.git/config:\tbare = true\nfoo.git/config:[foo]\nfrob.git/config:\tbar = none\nfrob.git/config:\tbare = true\nfrob.git/config:[foo]\ngitolite-admin.git/config:\tbare = true\ntesting.git/config:\tbar = dft\ntesting.git/config:\tbare = true\ntesting.git/config:[foo]';\n\ntry \"cd $od; ok\";\n\nconfadd '\n\n    repo bar\n        RW      =   u2\n        config foo.bar  =   \n\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"\n    cd $rb;                             ok\n    grep -E foo\\\\|bar *.git/config\n\";\n$t = join(\"\\n\", sort (lines()));\n\ncmp $t, 'bar.git/config:\tbare = true\nfoo.git/config:\tbar = f1\nfoo.git/config:\tbare = true\nfoo.git/config:[foo]\nfrob.git/config:\tbar = none\nfrob.git/config:\tbare = true\nfrob.git/config:[foo]\ngitolite-admin.git/config:\tbare = true\ntesting.git/config:\tbar = dft\ntesting.git/config:\tbare = true\ntesting.git/config:[foo]';\n\ntry \"cd $od; ok\";\n\nconfreset;confadd '\n\n    repo @gr1\n        RW      =   u1\n        config foo.bar  =   f1\n\n    repo bar/CREATOR/[one].*\n        C       =   u2\n        RW      =   u2\n        config foo.bar  =   one\n\n    @gr1 = foo frob\n\n';\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\ntry \"\n    glt ls-remote u2 file:///bar/u2/one;        ok;     /Initialized empty/\n    glt ls-remote u2 file:///bar/u2/two;        !ok;    /DENIED by fallthru/\n\";\n\ntry \"\n    cd $rb;                             ok\n    find . -name config | xargs grep -E foo\\\\|bar\n\";\n$t = join(\"\\n\", sort (lines()));\n\ncmp $t, './bar/u2/one.git/config:\tbar = one\n./bar/u2/one.git/config:\tbare = true\n./bar/u2/one.git/config:[foo]\n./foo.git/config:\tbar = f1\n./foo.git/config:\tbare = true\n./foo.git/config:[foo]\n./frob.git/config:\tbar = f1\n./frob.git/config:\tbare = true\n./frob.git/config:[foo]\n./gitolite-admin.git/config:\tbare = true\n./testing.git/config:\tbar = dft\n./testing.git/config:\tbare = true\n./testing.git/config:[foo]';\n"
  },
  {
    "path": "t/gitolite-receive-pack",
    "content": "#!/usr/bin/perl\n\nuse strict;\nuse warnings;\nprint STDERR \"TRACE: grp(\", join( \")(\", @ARGV ), \")\\n\";\n\nmy $repo = shift;\n$repo =~ s/\\.git$//;\nmy $user = $ENV{G3T_USER} || 'no-such-user';\n\n$ENV{SSH_ORIGINAL_COMMAND} = \"git-receive-pack '$repo'\";\nexec( \"$ENV{GL_BINDIR}/../src/gitolite-shell\", $user );\n"
  },
  {
    "path": "t/gitolite-upload-pack",
    "content": "#!/usr/bin/perl\n\nuse strict;\nuse warnings;\nprint STDERR \"TRACE: gup(\", join( \")(\", @ARGV ), \")\\n\";\n\nmy $repo = shift;\n$repo =~ s/\\.git$//;\nmy $user = $ENV{G3T_USER} || 'no-such-user';\n\n$ENV{SSH_ORIGINAL_COMMAND} = \"git-upload-pack '$repo'\";\nexec( \"$ENV{GL_BINDIR}/../src/gitolite-shell\", $user );\n"
  },
  {
    "path": "t/glt",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nuse FindBin;\nBEGIN { $ENV{GL_BINDIR} = $FindBin::RealBin; }\n\nmy $cmd  = shift or die \"need command\";\nmy $user = shift or die \"need user\";\nmy $rc;\n\nmy %extcmds = (\n    help        => 1,\n    info        => 1,\n    desc        => 1,\n    fork        => 1,\n    perms       => 1,\n    writable    => 1,\n);\n\n$ENV{G3T_USER} = $user;\nif ($extcmds{$cmd}) {\n    $ENV{SSH_ORIGINAL_COMMAND} = join(\" \", $cmd, @ARGV);\n    exec( \"$ENV{GL_BINDIR}/../src/gitolite-shell\", $user );\n} elsif ( $cmd eq 'push' ) {\n    print STDERR \"TRACE: glt(\", join( \")(\", @ARGV ), \")\\n\";\n    $rc = system( \"git\", $cmd, \"--receive-pack=$ENV{GL_BINDIR}/gitolite-receive-pack\", @ARGV );\n} else {\n    print STDERR \"TRACE: glt(\", join( \")(\", @ARGV ), \")\\n\";\n    $rc = system( \"git\", $cmd, \"--upload-pack=$ENV{GL_BINDIR}/gitolite-upload-pack\", @ARGV );\n}\n\nif ( $? == -1 ) {\n    die \"F: failed to execute: $!\\n\";\n} elsif ( $? & 127 ) {\n    printf STDERR \"E: child died with signal %d\\n\", ( $? & 127 );\n    exit 1;\n} else {\n    printf STDERR \"W: child exited with value %d\\n\", $? >> 8 if $? >> 8;\n    exit( $? >> 8 );\n}\n\nexit 0;\n"
  },
  {
    "path": "t/hostname.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\n# %HOSTNAME tests\n# ----------------------------------------------------------------------\n\ntry \"plan 60\";\n\ntry \"pwd\";\nmy $od = text();\nchomp($od);\n\n# without setting HOSTNAME in rc\nconfreset;confadd '\n\n    repo foo\n        RW  dev/%HOSTNAME   =   u1\n';\n\ntry \"ADMIN_PUSH set1; /FATAL/\";\ntry \"/bad ref 'refs/heads/dev/%HOSTNAME'/\";\n\n# make a hostname entry\n$ENV{G3T_RC} = \"$ENV{HOME}/g3trc\";\nput \"$ENV{G3T_RC}\", \"\\$rc{HOSTNAME} = 'frodo';\\n\";\n\nconfreset;confadd '\n\n    repo bar\n        RW  %HOSTNAME_baz   =   u1\n';\n\ntry \"ADMIN_PUSH set1; /FATAL/\";\ntry \"/bad ref 'refs/heads/%HOSTNAME_baz'/\";\n\nconfreset;confadd '\n\n    repo bar\n        RW  %HOSTNAME/      =   u1\n        RW  %HOSTNAME-baz   =   u1\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\";\ntry \"\n    gitolite access bar u2 R any;                   /R any bar u2 DENIED by fallthru/\n    gitolite access bar u2 W any;                   /W any bar u2 DENIED by fallthru/\n    gitolite access bar u1 W any;                   !/DENIED/; /refs/heads/frodo/; !/baz/\n    gitolite access bar u1 R any;                   !/DENIED/; /refs/heads/frodo/; !/baz/\n    gitolite access bar u1 R refs/heads/frodo;      /R refs/heads/frodo bar u1 DENIED by fallthru/\n    gitolite access bar u1 W refs/heads/frodo;      /W refs/heads/frodo bar u1 DENIED by fallthru/\n    gitolite access bar u1 R refs/heads/frodo/1;    !/DENIED/; /refs/heads/frodo/; !/baz/\n    gitolite access bar u1 W refs/heads/frodo/1;    !/DENIED/; /refs/heads/frodo/; !/baz/\n    gitolite access bar u1 R refs/heads/sam;        /R refs/heads/sam bar u1 DENIED by fallthru/\n    gitolite access bar u1 W refs/heads/sam;        /W refs/heads/sam bar u1 DENIED by fallthru/\n    gitolite access bar u1 R refs/heads/master;     /R refs/heads/master bar u1 DENIED by fallthru/\n    gitolite access bar u1 W refs/heads/master;     /W refs/heads/master bar u1 DENIED by fallthru/\n\n    gitolite access bar u1 R refs/heads/frodo-baz;  !/DENIED/; /refs/heads/frodo-baz/\n    gitolite access bar u1 W refs/heads/frodo-baz;  !/DENIED/; /refs/heads/frodo-baz/\n\";\n\nconfreset;confadd '\n\n    repo foo-%HOSTNAME\n        RW  =   u1\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\";\ntry \"\n    gitolite list-repos;            /foo-frodo/\n    gitolite list-phy-repos;        /foo-frodo/\n\";\n"
  },
  {
    "path": "t/include-subconf.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\n# include and subconf\n# ----------------------------------------------------------------------\n\ntry 'plan 58';\n\nconfreset; confadd '\n    include \"i1.conf\"\n    @i2 = b1\n    subconf \"i2.conf\"\n    include \"i1.conf\"\n';\nconfadd 'i1.conf', '\n    @g1 = a1 a2\n    repo foo\n        RW = u1\n\n    include \"j1.conf\"\n';\nconfadd 'i2.conf', '\n    @g2 = b1 b2\n    repo bar b1 b2 i1 i2 @i1 @i2 @g2\n        RW = u2\n';\nconfadd 'j1.conf', '\n    @h2 = c1 c2\n    repo baz\n        RW = u3\n';\n\ntry \"ADMIN_PUSH set2; !/FATAL/\" or die text();\n\ntry \"\n                                        /i1.conf already included/\n\t                                    /subconf 'i2' attempting to set access for \\@i1, b2, bar, i1/\n                                        /WARNING: expanding '\\@g2'/\n\n                                        !/attempting to set access.*i2/\n                                        /Initialized.*empty.*baz.git/\n                                        /Initialized.*empty.*foo.git/\n                                        /Initialized.*empty.*b1.git/\n                                        /Initialized.*empty.*i2.git/\n                                        !/Initialized.*empty.*b2.git/\n                                        !/Initialized.*empty.*i1.git/\n                                        !/Initialized.*empty.*bar.git/\n\";\n\nconfreset;confadd '\n    @g2 = i1 i2 i3\n    subconf \"g2.conf\"\n';\nconfadd 'g2.conf', '\n    @g2 = g2 h2 i2\n    repo @g2\n        RW = u1\n';\n\ntry \"ADMIN_PUSH set3; !/FATAL/\" or die text();\ntry \"\n                                        /WARNING: expanding '\\@g2'/\n                                        /WARNING: subconf 'g2' attempting to set access for h2/\n                                        /Initialized.*empty.*g2.git/\n                                        /Initialized.*empty.*i2.git/\n\";\n\nconfreset;confadd '\n    @g2 = i1 i2 i3\n    subconf \"g2.conf\"\n';\nconfadd 'g2.conf', '\n    subconf master\n    @g2 = g2 h2 i2\n    repo @g2\n        RW = u1\n';\n\ntry \"\n    ADMIN_PUSH set3;           ok;     /FATAL: subconf \\\\'g2\\\\' attempting to run 'subconf'/\n\";\n\n# ----------------------------------------------------------------------\n\nconfreset; confadd '\n    include \"i1.conf\"\n    @i2 = b1\n    subconf i2 \"eye2.conf\"\n';\nconfadd 'eye2.conf', '\n    repo @eye2\n        RW = u2\n';\n\ntry \"ADMIN_PUSH set2; !/FATAL/\" or die text();\n\ntry \"\n    /subconf 'i2' attempting to set access for \\@eye2/\n\";\n\nconfreset; confadd '\n    include \"i1.conf\"\n    @i2 = b1\n    subconf i2 \"eye2.conf\"\n';\nconfadd 'eye2.conf', '\n    repo @i2\n        RW = u2\n';\n\ntry \"ADMIN_PUSH set2; !/FATAL/\" or die text();\n\ntry \"\n    !/subconf 'i2' attempting to set access for \\@eye2/\n\";\n"
  },
  {
    "path": "t/info-json.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\nuse JSON;\n\n# the info command\n# ----------------------------------------------------------------------\n\ntry 'plan 162';\n\ntry \"## info\";\n\nconfreset;confadd '\n    @t1 = t1\n    repo    @t1\n        RW              =   u1\n        R               =   u2\n    repo    t2\n        RW  =               u2\n        R   =               u1\n    repo    t3\n        RW  =   u3\n        R   =   u4\n\n    repo foo/..*\n        C   =   u1\n        RW  =   CREATOR u3\n';\n\ntry \"ADMIN_PUSH info; !/FATAL/\" or die text();\ntry \"\n                                        /Initialized.*empty.*t1.git/\n                                        /Initialized.*empty.*t2.git/\n                                        /Initialized.*empty.*t3.git/\n\";\n\nmy $href;   # semi-global (or at least file scoped lexical!)\n\n# testing for info -json is a bit unusual.  The actual tests are done within\n# this test script itself, and we send Tsh just enough for it to decide if\n# it's 'ok' or 'not ok' and print that.\n\ntry \"glt info u1 -json; ok\";\n$href = from_json(text());\ntry \"## u1 test_gs\";\ntest_gs('u1');\ntry \"## u1\";\nperm('foo/..*', 'r w C');\nperm('testing', 'R W c');\nperm('t1', 'R W c');\nperm('t2', 'R w c');\nperm('t3', 'r w c');\n\ntry \"## u2\";\ntry \"glt info u2 -json; ok\";\n$href = from_json(text());\nperm('foo/..*', 'r w c');\nperm('testing', 'R W c');\nperm('t1', 'R w c');\nperm('t2', 'R W c');\nperm('t3', 'r w c');\n\ntry \"## u3\";\ntry \"glt info u3 -json; ok\";\n$href = from_json(text());\nperm('foo/..*', 'R W c');\nperm('testing', 'R W c');\nperm('t1', 'r w c');\nperm('t2', 'r w c');\nperm('t3', 'R W c');\n\ntry \"## u4\";\ntry \"glt info u4 -json; ok\";\n$href = from_json(text());\nperm('foo/..*', 'r w c');\nperm('testing', 'R W c');\nperm('t1', 'r w c');\nperm('t2', 'r w c');\nperm('t3', 'R w c');\n\ntry \"## u5\";\ntry \"glt info u5 -json; ok\";\n$href = from_json(text());\nperm('foo/..*', 'r w c');\nperm('testing', 'R W c');\nperm('t1', 'r w c');\nperm('t2', 'r w c');\nperm('t3', 'r w c');\n\ntry \"## u6\";\ntry \"glt info u6 -json; ok\";\n$href = from_json(text());\nperm('foo/..*', 'r w c');\nperm('testing', 'R W c');\nperm('t1', 'r w c');\nperm('t2', 'r w c');\nperm('t3', 'r w c');\n\ntry \"## ls-remote foo/one\";\ntry \"glt ls-remote u1 file:///foo/one;   ok\";\n\ntry \"## u1\";\ntry \"glt info u1 -json; ok; !/creator..:/\";\n$href = from_json(text());\nperm('foo/..*', 'r w C');\nperm('foo/one', 'R W c');\ntest_creator('foo/one', 'u1', 'undef');\n\ntry \"## u2\";\ntry \"glt info u2 -json; ok; !/creator..:/\";\n$href = from_json(text());\nperm('foo/..*', 'r w c');\nperm('foo/one', 'r w c');\ntest_creator('foo/one', 'u1', 'undef');\n\ntry \"## u3\";\ntry \"glt info u3 -json; ok; !/creator..:/\";\n$href = from_json(text());\nperm('foo/..*', 'R W c');\nperm('foo/one', 'R W c');\ntest_creator('foo/one', 'u1', 'undef');\n\ntry(\"## with -lc now\");\n\ntry \"## u1\";\ntry \"glt info u1 -lc -json; ok\";\n$href = from_json(text());\nperm('foo/..*', 'r w C');\nperm('foo/one', 'R W c');\ntest_creator('foo/one', 'u1', 1);\n\ntry \"## u2\";\ntry \"glt info u2 -lc -json; ok\";\n$href = from_json(text());\nperm('foo/..*', 'r w c');\nperm('foo/one', 'r w c');\ntest_creator('foo/one', 'u1', 'undef');\n\ntry \"## u3\";\ntry \"glt info u3 -lc -json; ok\";\n$href = from_json(text());\nperm('foo/..*', 'R W c');\nperm('foo/one', 'R W c');\ntest_creator('foo/one', 'u1', 1);\n\n# ----------------------------------------------------------------------\n\n# test perms given repo and expected perms.  (lowercase r/w/c means NOT\n# expected, uppercase means expected)\nsub perm {\n    my ($repo, $aa) = @_;\n    for my $aa1 (split ' ', $aa) {\n        my $exp = 1;\n        if ($aa1 =~ /[a-z]/) {\n            $exp = 'undef';     # we can't use 0, though I'd like to\n            $aa1 = uc($aa1);\n        }\n        my $perm = $href->{repos}{$repo}{perms}{$aa1} || 'undef';\n        try 'perl $_ = \"' . $perm  . '\"; /' . $exp . '/';\n    }\n}\n\n# test versions in greeting string\nsub test_gs {\n    my $glu = shift;\n    my $res = ( $href->{GL_USER} eq $glu ? 1 : 'undef' );\n    try 'perl $_ = \"' . $res  . '\"; /1/';\n    $res = ( $href->{gitolite_version} =~ /^v3.[5-9]/ ? 1 : 'undef' );\n    try 'perl $_ = \"' . $res  . '\"; /1/';\n    $res = ( $href->{git_version} =~ /^1.[6-9]|^2./ ? 1 : 'undef' );\n    try 'perl $_ = \"' . $res  . '\"; /1/';\n}\n\n# test creator\nsub test_creator {\n    my ($r, $c, $exp) = @_;\n    my $res = ( ($href->{repos}{$r}{creator} || '') eq $c ? 1 : 'undef' );\n    try 'perl $_ = \"' . $res  . '\"; /' . $exp . '/';\n}\n"
  },
  {
    "path": "t/info.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\n# the info command\n# ----------------------------------------------------------------------\n\ntry 'plan 78';\n\ntry \"## info\";\n\nconfreset;confadd '\n    @t1 = t1\n    repo    @t1\n        RW              =   u1\n        R               =   u2\n    repo    t2\n        RW  =               u2\n        R   =               u1\n    repo    t3\n        RW  =   u3\n        R   =   u4\n\n    repo foo/..*\n        C   =   u1\n        RW  =   CREATOR u3\n';\n\ntry \"ADMIN_PUSH info; !/FATAL/\" or die text();\ntry \"\n                                        /Initialized.*empty.*t1.git/\n                                        /Initialized.*empty.*t2.git/\n                                        /Initialized.*empty.*t3.git/\n\";\n\n# GS == greeting string\ntry \"DEF GS = /hello %1, this is $ENV{USER}\\\\@.* running gitolite/\";\n\ntry \"\n    glt info u1; ok; GS u1\n        /C\\tfoo/\\\\.\\\\.\\\\*/\n        /R W *\\tt1/\n        /R   *\\tt2/\n        /R W *\\ttesting/\n        !/R W *\\tt3/\n    glt info u2; ok; GS u2\n        !/C\\tfoo/\n        /R   *\\tt1/\n        /R W *\\tt2/\n        /R W *\\ttesting/\n        !/R W *\\tt3/\n    glt info u3; ok; GS u3\n        /R W *\\tt3/\n        /R W *\\ttesting/\n        !/R   *\\tt1/\n        !/R W *\\tt2/\n    glt info u4; ok; GS u4\n        /R   *\\tt3/\n        /R W *\\ttesting/\n        !/R   *\\tt1/\n        !/R W *\\tt2/\n    glt info u5; ok; GS u5\n        /R W *\\ttesting/\n        !/R   *\\tt1/\n        !/R W *\\tt2/\n        !/R W *\\tt3/\n    glt info u6; ok; GS u6\n        /R W *\\ttesting/\n        !/R   *\\tt1/\n        !/R W *\\tt2/\n        !/R W *\\tt3/\n\";\n\ntry \"\n    glt ls-remote u1 file:///foo/one;   ok\n    glt info u1; ok; GS u1\n        /C\\tfoo/\\\\.\\\\.\\\\*/\n        /R W *\\tfoo/one/\n        !/R W *\\tfoo/one\\tu1/\n    glt info u2; ok; GS u2\n        !/C\\tfoo/\n        !/R W *\\tfoo/one/\n    glt info u3; ok; GS u3\n        !/C\\tfoo/\n        /R W *\\tfoo/one/\n        !/R W *\\tfoo/one\\tu1/\n\";\n\ntry \"\n    glt ls-remote u1 file:///foo/one;   ok\n    glt info u1 -lc; ok; GS u1\n        /C\\tfoo/\\\\.\\\\.\\\\*/\n        !/C\\tfoo.*u1/\n        /R W *\\tfoo/one\\tu1/\n    glt info u2 -lc; ok; GS u2\n        !/C\\tfoo/\n        !/R W *\\tfoo/one/\n    glt info u3 -lc; ok; GS u3\n        !/C\\tfoo/\n        /R W *\\tfoo/one\\tu1/\n\";\n"
  },
  {
    "path": "t/invalid-refnames-filenames.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\n# invalid refnames\n# ----------------------------------------------------------------------\n\ntry \"plan 56\";\ntry \"DEF POK = !/DENIED/; !/failed to push/\";\n\nconfreset; confadd '\n    repo aa\n        RW+                 =   @all\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"\n\ncd ..\nrm -rf aa\nglt clone u1 file:///aa\ncd aa\ntc v-869\n\nglt push u1 origin HEAD\n        /To file:///aa/\n        POK; /\\\\* \\\\[new branch\\\\]      HEAD -> master/\n\n# push file aa,bb ok\ntc  aa,bb\nglt push u1 origin HEAD\n        /To file:///aa/\n        POK; /HEAD -> master/\n\n# push file aa=bb ok\ntc  aa=bb\nglt push u1 origin HEAD\n        /To file:///aa/\n        POK; /HEAD -> master/\n\n# push to branch dd,ee ok\nglt push u1 origin master:dd,ee\n        /To file:///aa/\n        POK; /\\\\* \\\\[new branch\\\\]      master -> dd,ee/\n\n# push to branch dd=ee fail\nglt push u1 origin master:dd=ee\n        /invalid characters in ref or filename: \\\\'refs/heads/dd=ee/\n        reject\n\";\n\nconfreset; confadd '\n    repo aa\n        RW+                 =   @all\n        RW+ NAME/           =   @all\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"\n\ncd ..\nrm -rf aa\nglt clone u1 file:///aa\ncd aa\ntc  file-1\n\nglt push u1 origin HEAD\n        /To file:///aa/\n        POK; /\\\\* \\\\[new branch\\\\]      HEAD -> master/\n\n# push file aa,bb ok\ntc  aa,bb\nglt push u1 origin HEAD\n        /To file:///aa/\n        POK; /HEAD -> master/\n\n# push file aa=bb fail\ntc  aa=bb\nglt push u1 origin HEAD\n        /To file:///aa/\n        POK; /HEAD -> master/\n\n# push to branch dd,ee ok\ngit reset --hard HEAD^\ntc  some-file\nglt push u1 origin master:dd,ee\n        /To file:///aa/\n        POK; /\\\\* \\\\[new branch\\\\]      master -> dd,ee/\n\n# push to branch dd=ee fail\nglt push u1 origin master:dd=ee\n        /invalid characters in ref or filename: \\\\'refs/heads/dd=ee/\n        reject\n\";\n"
  },
  {
    "path": "t/keys/admin",
    "content": "-----BEGIN RSA PRIVATE KEY-----\nMIIEpQIBAAKCAQEA0/X7uwd7xOvC3UTZaAnFOR5xqhdgcyc8vk3d1bXXthiuUSmq\n5t4uhS9qj0ismcPX0YRNhSDElotG1KSWp8DceJpR2c7GYmELpqoE7ebVPnEBKY0c\nPX+G9KZNgbJyyx35QlpJmlO+LimM0oO8XarRphn3kc0jCTLKaI5ndEjGDHH4fsOe\nwlryW7a0RR/brMNiJYYzy5ADCOkAnyXQmbrQW4nROCPqFojBFTEBLpe8EuODlJXE\nmRHpa1k+k/grFgp/c1xbOrjox127LZT4vkLf5+lSwkhq8oyzWHUrQ+rUJZssi1LC\nGEZSudhX5reqksmIlTwX0GPIIwSwZFNVxhj51wIDAQABAoIBAFFLlzE0vZPZmPOk\n5H2ywaIWuyGxtZx1ACc9VkgRZprA/JrEkHfb35vVg9lQ1mJjavNA+zqERuI2qQQF\n3IKaxfS7u4j+dbhl4EIcE6frUP6R+RAmvx4XO3u6DSAhgUXGSUPZvUEjvV2XMhvL\nywNh8Ob0LrANLdLpWBiiBavj/ZHnsVZj7y+39GKEtLm8BbsH8L7GanPl4uQDNruR\nEf2L2pSEqml+Iva6yk5a22U293JCVZ/aqDdGvrnbjkaxqin5jBgL47D91A3xo4SW\nzFZkJR5SDYnFLdwnwTPvxSA9IXj6TZ2ZdnTNvI5Utpd0Wy5N4GlfXS3TBPBD4kP+\n+pS1vgECgYEA/D7k1IyOM2hGamHc0qG+sIxMHge6rJE8pYtW2suB2KX0bJvAeBY8\neHM+pPFMbjjZHlU7qB9qmGbZ++ZVlEv/SqqHizvwLzth0P4MJ6/UjAcmAdEUclV0\nYSzMRFk/g0J7aMlJb5NXgA5xlArHLsmV3Zc+QwFPECgzz5LHwD5nTMcCgYEA1x2Y\nqb7FXwcQPDcs4Qwux12tCUaExQMZbNoLHWrXw7ktHRfR9sI8TcEErLzc2wnZbdyZ\nav/GYSTR9UCeq12kUhmTL4SNryktHKNKEfDEvR7wK6sa9iffzZH8FDe5JktLXnu7\nOe5SNfLDHA5X7qQefz8s2658+xVJmdp+uasNOnECgYEAlzBXVbJ9VQCuG/tWMQVz\nVzxwLxuw3tgagprWz0NlK2ak7ygXn6KsUgG5TYG3ruTx9gVeQXG7IWecRiiTqNQ4\nSxeVMHYXiyfLhEmRHYR9IAT02efomnLv04LXWCwqLlF9yJvFIVQuAPonR3WCV1/K\nLMwHLIAvVF7UVxkCEw8UOWcCgYEAwiUH/0sZvuYVFQOHEaV5Ip286b4nXdeqPr+b\ngHVJPnAF81foO5iZ7GLj4TKi8V02SxzpqdQmKs6cX4huq6LcBuzmFeDALvIusMX+\nt6phJX6irAbFUpwyNMoog+a2x4T1BNUO6P3aXK44wT2AxvSAQb+2sJ4OVl2kC6NS\n9CcYzUECgYEAzqbWlJIbjJx5620Q95bu+lpessOUtoVcYryO6dQNZOiis8aDZjJk\nRKdB9qhJlcUeFqnvJS5L5gohaJoyx0wMSYVB7MrO6kAIMHo/OriEQ6CTsQOTqa8n\nq4cV9Wuk9pRb1b/x5eXCcHe8P7wBt8KKIh/VBB4aDyeIwGbO0NODYr4=\n-----END RSA PRIVATE KEY-----\n"
  },
  {
    "path": "t/keys/admin.pub",
    "content": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDT9fu7B3vE68LdRNloCcU5HnGqF2BzJzy+Td3Vtde2GK5RKarm3i6FL2qPSKyZw9fRhE2FIMSWi0bUpJanwNx4mlHZzsZiYQumqgTt5tU+cQEpjRw9f4b0pk2BsnLLHflCWkmaU74uKYzSg7xdqtGmGfeRzSMJMspojmd0SMYMcfh+w57CWvJbtrRFH9usw2IlhjPLkAMI6QCfJdCZutBbidE4I+oWiMEVMQEul7wS44OUlcSZEelrWT6T+CsWCn9zXFs6uOjHXbstlPi+Qt/n6VLCSGryjLNYdStD6tQlmyyLUsIYRlK52Ffmt6qSyYiVPBfQY8gjBLBkU1XGGPnX g3@sita-lt.atc.tcs.com\n"
  },
  {
    "path": "t/keys/config",
    "content": "host *\n    stricthostkeychecking no\nhost admin\n        identityfile ~/.ssh/admin\n\nhost u? admin\n\tuser %USER\n\thostname localhost\nhost u1\n\tidentityfile ~/.ssh/u1\nhost u2\n\tidentityfile ~/.ssh/u2\nhost u3\n\tidentityfile ~/.ssh/u3\nhost u4\n\tidentityfile ~/.ssh/u4\nhost u5\n\tidentityfile ~/.ssh/u5\nhost u6\n\tidentityfile ~/.ssh/u6\n"
  },
  {
    "path": "t/keys/u1",
    "content": "-----BEGIN RSA PRIVATE KEY-----\nMIIEpQIBAAKCAQEAuB8HmJ5UX30xFktmvlLgSrzsGIzSiYiAYH8eU6epJGr/xjYD\n9GE6G9EcL+/NTc0ziPhIUtVm+h+kFEHtQ1VeOFEuVuWAukPNXRFDrYOMfeR4U1h7\nolT58U3+IlctreKavXr+7bPPhbhvdB7FPM8xusaPfwT6BG4sTqHyOPL5a3eXW7Sp\ntuVD87KNHKo3skWcbb78EVQt7MfCMTam6X2O4Y0y1da51kOht6qRaeJHoaAjXB4V\npY9lJSQA+Km5uYu+FIwn89z7P4j2aUNZFq2UOSwuViekSR6lfHvortyh8YFrSRUs\nQ4berZUICDp0Ek2BiJirWiPXAp9uxwXms9UbvQIDAQABAoIBAAUTnfMAUpU7b3IM\n7C1NPa/x25SltVxjbh67AowN8GT3qku9y4geciq4Lk3ID+IYSVZ6egwGpEs7Ohvw\n4Wjc3rcwzdVJiK4aFnx9cF9FZEdIWGT76JTGQQn9O4eY3cKQn/GfhY3qSkuGlVQf\nURLnJ5jdxrEa4wXiP8h/QJ1/XY8v9en0uWf/18fMHyzImpd8dqgtTdomSQLjM2ie\n1k9Fllh/5Q6e1Kd5mn5QP1QPC65Z78IskOot9Wrg0sk19sWiFMsopgJkQg66BlnM\nFj8A4HPS8Yylt0oXJ5yytUYfvZNDRANZRiAz9mfgQw9oapJLnCLt3Awi5bcKJIVk\n/nTccEECgYEA8lSPFeTyzid0sIextXjjHvV4riSZKAHAa5M5DfsPkXLQfbEF4zog\nFLZ6c85jUCk7/vTzDRXr38XKaGbAg/1M3UJk7lS9shh1Zdo0+Hshq7rNICNLKz5H\n/u1/0gkxqqJcpXaoOHYN1hM7HJrP3uZFDIA5ZrB7JD20YDCQ/2PWrS0CgYEAwoHi\nqEKKXOol7FIiG1upTjPaWMTmxtmSs2/pobMVf+ZGDMPts0pbqDegXruaNFUrUQOG\n9yvrjA3a2QaKt7R5eDvHAafeMeu0WcHaqUWtIueTtEuduK4fXsCGONBPEGJu+Ct/\nBOCV/W8MAmzIOvffT7Jg1HWsZyAstoikPi1w4tECgYEAuvVmFxw1/7sNGgz2m+2S\nPJZh7uipiOYhEF3bTN//mNWd6PskcbSsf45xVttKX9QQR5mv0s6w1koA6R8tNCe+\nn43T1NRoLfkUyenZqENHLPjHvR29prU8Un/ld6REP0NYewfarQTXk+vuVRlTesLp\nTsW2g3Vw6/r3KKcPlxntzFkCgYEAqqkH1BY+DHQtPgJ6hoKQNFtuswBgdAymmOYS\nmZvlu0iyIbUvNGaDsT7NaRE1pcEstnJf0zMoAsSNRmpk//ZLteDNJXjCjg5/OVnL\nn0XROZTylfjatBWi1KIbonGzTW7warLPSdo8ABeU8/O6Y3Lk7qpWJ1PwJrOmR6nw\nYdXA/GECgYEAsSokOABGGLQ2zOmDYPDKrRenLho8cSe4g/CF5b6x5MXfJvvBfI/M\nhOS/2AFj7UkOSVM9B9QH607F67YJuBPNGvciCatqY/Bcs6ViuuyqG9U4O13OrrmA\noG8Cho3Zy2v3udaLJ6O5JYcpX+hdvkwoG5j/8hLrzkD/3AA12z6QnV0=\n-----END RSA PRIVATE KEY-----\n"
  },
  {
    "path": "t/keys/u1.pub",
    "content": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC4HweYnlRffTEWS2a+UuBKvOwYjNKJiIBgfx5Tp6kkav/GNgP0YTob0Rwv781NzTOI+EhS1Wb6H6QUQe1DVV44US5W5YC6Q81dEUOtg4x95HhTWHuiVPnxTf4iVy2t4pq9ev7ts8+FuG90HsU8zzG6xo9/BPoEbixOofI48vlrd5dbtKm25UPzso0cqjeyRZxtvvwRVC3sx8IxNqbpfY7hjTLV1rnWQ6G3qpFp4kehoCNcHhWlj2UlJAD4qbm5i74UjCfz3Ps/iPZpQ1kWrZQ5LC5WJ6RJHqV8e+iu3KHxgWtJFSxDht6tlQgIOnQSTYGImKtaI9cCn27HBeaz1Ru9 g3@sita-lt.atc.tcs.com\n"
  },
  {
    "path": "t/keys/u2",
    "content": "-----BEGIN RSA PRIVATE KEY-----\nMIIEpgIBAAKCAQEA4/t3WV4q98MlYV9Jbvbf7gE2Dzit6dD8xHsWBh2wTmggQM9I\n2RsPp1tTIoOpt4YdlTzV41577BKLVMvqG7AxnVljC7+m7PrT2YmxEGrrbcrHebHu\n+pwh0lkN/CIz6MHjWzLbFiRoHhKh9LyfSiKxCgJ3dyjFgAnA+wrXkwIfPRG8qOLk\nsb1KUsMdfYm0OUEC/mHU2dsIS5HIY6xhy5Q5BXWgkfYUK7LL7Eyw6ffLhvq4U9tv\nQv+u64Qowew4BY4B8rvyb73iEGcInIF2JRY0jVC8yJFejTJo2KKlXxu8MyAtAhth\ncHE6gA7xmn1d8TF7sxHDNqprvD9mLTjUVdz1owIDAQABAoIBAQDEGaWLZYioHV+l\n5gSQQiJT4w7RAPv3RyBlEUrcb+UbTE2R8brDpJdOaSuVYJM3nVEM8Ys5TChj43+d\nrNjugBvtMNoVXQEEjqxzThDUAmQHyIjUkMzzHCGrgZaZ7gGgkEY0SAZTgXVdiMFu\ndmC9sCGAbqa8BIH9pGYuiiDr/sNIDr3ekyqyuSA0Aa2JIrEx1TKFXF5JtGseU9S6\nbUfesCpoWGyVdulr3NbsLM26eDCsZo45OF5QdpTtU99xc9K4gsOre0ZtqEJMVGlR\n2nDQILCroH93GabSIW+fiUZD2lO9BxXAM0NA730ODQWyM8IgoWrqxGUuFz40l7X1\nteB7yRwBAoGBAPkkF//ZaEUUyCX6+a6TjaPQ1atemQCxHtIm1phfIM/u2uANqeOP\nZ+N3dM0TL53lRx/xbT0dO4sfF73XcF0sYkQj9rep28Q04W8Z6iC/I+jQAJJ0bYl5\nskUGTECxIPLmKOciQF7N5PUGvxhI4oq/0vgDYFc+NW18mow1Z66H1PkjAoGBAOpC\nP9EJXEFKZY1lK6ZL6wvJ6tJaPWAuiQlkOdj9wLvvzywQPlEdBJ1k0q+ndAqpR6WJ\neTlkP/bzDpLRi+l4PEVTsFlpxjcfVn19RRabsKTNIS0usl1el/uQP7u4rRimBCz5\nMO72GD4ARM5CgMZZMGU5AXmxKEM9feTcUNss3RmBAoGBALTYsmMRmVKr5y1KpPtI\nOER1TuR6Ym3SJCE/9/3a76KAK3j/8hYw/qRrDenex23CBIL3aOg31AUEqOMxA2te\n0GXOBUUEk3Y1PH69POpQVOymMAQfZ3OnVvQrwiYjbVtkHsTIZBltM4l5QDWMkoVN\nAQLu0HwDuBylmjm0enKCPuIpAoGBAObd257bprwB4gtzhY0ijMbVfENLA+nictN6\nnzgm/Oc68+XtLD0sZ/vl/W13jnljU2TlEz9oeVGbQOWY9lZlVKDOVaIJCHwSul56\nMriRP4lrUCMDPm2eaBJYmzcaTh1YoAzimUMn7cRM54KPL/JKu9NGVxnjala6J3SB\nXH5kvJIBAoGBAITZe45tIbVkGjK3jTjgBfaqFfhyws4L3QgRbjqpy2h9nLEGHMYV\nRkIt6bCkw6cy+8TnYB0iG9lcGP1S5E4C6zpTdldi/5tGl7uu9qfEz4hxRpRbJ4Q0\nnwZzUkgBaLxAiLHfntBpwk16UvHkCpo5hiKzSLzxfReXzQPUUudGRnsG\n-----END RSA PRIVATE KEY-----\n"
  },
  {
    "path": "t/keys/u2.pub",
    "content": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDj+3dZXir3wyVhX0lu9t/uATYPOK3p0PzEexYGHbBOaCBAz0jZGw+nW1Mig6m3hh2VPNXjXnvsEotUy+obsDGdWWMLv6bs+tPZibEQauttysd5se76nCHSWQ38IjPoweNbMtsWJGgeEqH0vJ9KIrEKAnd3KMWACcD7CteTAh89Ebyo4uSxvUpSwx19ibQ5QQL+YdTZ2whLkchjrGHLlDkFdaCR9hQrssvsTLDp98uG+rhT229C/67rhCjB7DgFjgHyu/JvveIQZwicgXYlFjSNULzIkV6NMmjYoqVfG7wzIC0CG2FwcTqADvGafV3xMXuzEcM2qmu8P2YtONRV3PWj g3@sita-lt.atc.tcs.com\n"
  },
  {
    "path": "t/keys/u3",
    "content": "-----BEGIN RSA PRIVATE KEY-----\nMIIEogIBAAKCAQEArK6uQkgoAnS+w6vs4DmvdOfcGdFUzh3ivHAXHug7sjjKGUB2\nKwcXNwcmJPtyNXM0BJ9ZoOJSqJo5cWLMl7Qn1HBubuyM02Id9EqeJu1Ytn/i1XFY\nNMp8fj4wma3LZTdeOy3ockbefkw6VQUq3cheXIeaVpT91jsuyIaE0ejWkjGMu596\nzXFQZYTSO28TIYghRvhXGq5W9hJ3V2k+ZAQ/AsWQqjK4XruICi+RGRpKj59ECI7V\nzIrq4MUEti+3LldaY6tyYsTGQLtFJYu+l/ZavkrM979cPOxLeoi8ZHPTPKh6asdr\nZXA2J6++IyIgNy2Q4sNxTmkIlU/EDysvTTGdMwIDAQABAoIBABF+NJr0UlFFYFnU\nHc/tKBAQuORIp22l62Upeb4gyoNYa2i5df8P3dMuPzf53Oz7OabKObspkjQQQ4dv\n+cfYcTx9E0LbZby4MM6hjHnnC1iZhfIXZFccuBXV2PiIeZVMUZhvIyAIe9uRf0tD\nlb8X4C9BcWoZ98ju/+NCdUwKaUov3jXc32hmsAhK+dtqBE+lwccX9keJQcncf+6j\n+2znpDAJdaF70dM0DidbkmXmOTgH6LjjqrYRTAUnVsvUyDsr5YhopwOHs0E95YB4\nRzO7V/DA8H7DQ+XE20Iqp2i6dSbRQQPxbQLvJG4BaITIqb1L8/WJ6N75O/uns4rE\nY8WVwWECgYEA1gDDP70DqvVMu6KDvn18pvfxzxJ3jccYcBZITV/E6xgj1AbH7fdA\n0iwvG6jQ26DTUBfLBquZ2fCCyI44OUpZ8GZu/wYBn5CQjYtr1vJ7zHKM3dVf+POT\ncGgOVDIHopCCX5Dwb74OpbkTV4g/WxouClvz0Ovobq8NncSkJJkyGEMCgYEAzpIF\noj2AVMWDd6NL+P8e+QXPYEvJ/trAHoAteI83Eof4ZOC/sBr7Gf3c6nM7ZJbCXGhJ\nNCCr4teHJMg9DThQ1KxKn9qEf9dWiAE+HCouaZU98Z0UcLQ+tgPeBh/Dw7rTF3M2\n7A/LtLYbg1MoPCZNj6V4qGjmNWCy2lku1ZGBUFECgYBD/4oKvqxjrf3rwP/Lj2QE\nSdRzz5JdYl3Jf8sJityvNsRropv0aRQXtCJjz4hNwRRj5quEOxJvxZRI1afXzGA3\nmtS6A9aQNQc5couZiQL9O4i3FA2itQKsPOQQrLTwWqqSYyOC3gkZb21N6uT2taLb\nd8xJHiyEvuq8rrbZSjQ4sQKBgEkUDZws58aVrYHYqlrnXny4mnm1tjtMBiWEMRHy\nkIgkxDJj9EyH7wdt8QacR4m5b/8jAarIWCbDGtNfZ4HSx33FigztUGytsLYiwmdS\nYOMHYkeky4NnsLvRuG0wNaB76ovkPazblbRTrH4UICrPXicQYhQqMC74C64FWPVD\nKZ1RAoGAE/vKCHCzPegTT9gr2aaIrhLPUUZboOF4gHajYr9Scr176nJhpIvP/0Y2\nyQtqfas5lID8ouqXb+oL0Q4Yi00hdu+TRYQHm3M+2UL7wgffR5H2vfhk24UUDfV5\n0qQjNKp3pNUWZdiZ2J+RGUszXt0THfWbWI/ntwnG5QchqXCqYEA=\n-----END RSA PRIVATE KEY-----\n"
  },
  {
    "path": "t/keys/u3.pub",
    "content": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCsrq5CSCgCdL7Dq+zgOa9059wZ0VTOHeK8cBce6DuyOMoZQHYrBxc3ByYk+3I1czQEn1mg4lKomjlxYsyXtCfUcG5u7IzTYh30Sp4m7Vi2f+LVcVg0ynx+PjCZrctlN147LehyRt5+TDpVBSrdyF5ch5pWlP3WOy7IhoTR6NaSMYy7n3rNcVBlhNI7bxMhiCFG+Fcarlb2EndXaT5kBD8CxZCqMrheu4gKL5EZGkqPn0QIjtXMiurgxQS2L7cuV1pjq3JixMZAu0Uli76X9lq+Ssz3v1w87Et6iLxkc9M8qHpqx2tlcDYnr74jIiA3LZDiw3FOaQiVT8QPKy9NMZ0z g3@sita-lt.atc.tcs.com\n"
  },
  {
    "path": "t/keys/u4",
    "content": "-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEA2Wg3bl7T0C8VuR8HdbAqmwvQH4/T/maaqlQeJqcATRgWQNDv\nVthEasW5Kx8DzcSVRWS0cJ5EpTLGvrs84aXgdvg6TwFZKO/ujrkFDZmw9hd4I/Dv\n0dp/Y7himS8vAvnnWfYyqJBiX4plEx9Kg8oWHwy8KK3HHKoO8jAWAHOWO3GMB8BV\n128VLovGB6Sp99GrgltzP9UhNRHt/doa3ve8+fDk782SandVTTR9MNLt7qhMSOKr\nbmoFWtL36W5hmVjFGTZC1ZNIU6PiqygUqPtyAYblwv/nZ35s72KmxP7Seag3SsuZ\nUPnRjM4PZ+7YE7tcPTOUxcct8xuTZXgjh2WiNwIDAQABAoIBADSrR8qIVJ452fRo\nLQF49UlsmjYbPQuDxfJ/wHIywSLsM+/t7h3G9QQ89Hga4mwGNPeDxycFYLH41Cc+\n6yfrbK7FwjKDrBr7zXpsHmpGEpX755Ile6QGYBhDgjeEM8pvynmD6I/nsr1cpNH2\nIbI90hAhoK/mMbejB03rEll3pyytCgEvJQsu847dTNTZN+PHsumPr9HERi/dDrbw\nJrDSH2tbOvYw4UW9HLFfZAB+IgMo34WXf6kcUY69wWQbxnv1e7KHnYkxIuLCGZ6x\nLc9APM97f4atlGt+mAtqK97CJB1AqoIE3KpPq1x+gpFSBNEE+9U9KnItuSqF3mG4\nvq/VjIkCgYEA+ASubOgzJaAldNz3dinLYK6MLB+V1R+RpkDc3+OgfF5mgg11ZtpE\n/DO1Ndpf5dOYB4JYGfhC9+xomHGsQmbOsIUprWaAR/xaO6Bgxw7cxkOBIadsrdwu\nMWJ6h3gN72zuhKPERpUVVH7ZH5KQfZwxEMgquUkGdEwumU4rMXeCFqsCgYEA4GdX\nqI/5UNXEPnXk3dDWNzNJO7gRoonU228IM18qz5ZKMRIKp6Sq+wIuO8+aQMr2K0rO\nRMQk+lLOZ17omaWh9ysDPzTCWRrjOiDOnYWDPCclTeqSnEk8uuWyppDGNXgQ6osM\nLnwJSeP8+1EDgkKf5zoiQfcyBc0v8PSRSdTfEqUCgYEA2PqHeqHd9UHY4xdZq1e/\nJLMv0H5Ff/GhY7iFQ54JziRsO8T4e+Xiyl2WYCnPEer+qzseRoIKXInHq+5uzJzS\noF2va5MsEU41xsp1QFDBVvbBpyapDqV9CBlmptOiJV/Af+wiD7nnskdTPqrjm/Ck\ngFEOB5Fagy4O6nIXmaw69AcCgYEAhVSBndKlZKUOa7oqmKzLipK7UXNFbxiL0zE+\nYx+JVTvLqyo4EHFjca5TABCSayrsZr6UngEYo27t2jdm5lumRzBURoq3aq/yEIiL\nmsZIOkZcANZ988QEBFwT8KmWSxCipGinfTsPXcrLdhslhZDGZ2GAF0ejfhTzBiyZ\n4o9LV00CgYBf46Z2M1fWI6Tc8HUKr9WoyUmTmUtHUFPt9IZ2CKm2czoltpku7cC7\nztlt4LmVPKv1UUavbC/nCz6s1ylOkY0rdm45FSYXKDYPMQqzQix1jG4GZJjM9En+\nM848LupnHBFsmHyQqyyRlsg1gb+wtvAw7Y44wcfAhGbiAT5DVX+zxg==\n-----END RSA PRIVATE KEY-----\n"
  },
  {
    "path": "t/keys/u4.pub",
    "content": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDZaDduXtPQLxW5Hwd1sCqbC9Afj9P+ZpqqVB4mpwBNGBZA0O9W2ERqxbkrHwPNxJVFZLRwnkSlMsa+uzzhpeB2+DpPAVko7+6OuQUNmbD2F3gj8O/R2n9juGKZLy8C+edZ9jKokGJfimUTH0qDyhYfDLworcccqg7yMBYAc5Y7cYwHwFXXbxUui8YHpKn30auCW3M/1SE1Ee392hre97z58OTvzZJqd1VNNH0w0u3uqExI4qtuagVa0vfpbmGZWMUZNkLVk0hTo+KrKBSo+3IBhuXC/+dnfmzvYqbE/tJ5qDdKy5lQ+dGMzg9n7tgTu1w9M5TFxy3zG5NleCOHZaI3 g3@sita-lt.atc.tcs.com\n"
  },
  {
    "path": "t/keys/u5",
    "content": "-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEA41A0bY6+0akNSJlR2PeRATNtncARXVOUar7CNaxwPqVXQR1+\nTmU9evmIEkRLf0kFAa7L3QDFroFu4sDiSJjvfYIkHdoxO4Fk128PJBhObIXaarKc\nUBIZ29/8I3dTedq5CY/YHL/AjaT+0VktWX7YwigvGDamrXAKqjnW1mWKp6TNj8bp\nvppBvj3yvdYoOLYvCs/SKfKdlayngiihTbKELPcRu8NzYxHiF2b/u0t31evdP0fA\n/apAslKhHdCm8ScZJuyIdztcogBFE5dGm0h3qlbJKvKT8JmTcgQ5TBBcmqPVmUkm\nnPvIzd2G7D1smbExG7LnqekHcS9dvaPnF0B3oQIDAQABAoIBAGl1e21crXDN0mjd\nINjdOnvpJTDru+KldRT0/VszbjvSL6H5EfFDDPvxqsx2vOQHt3fpZZFZ21yzlgND\nY3g0499BsonbAb5OsL82OjsPv8qfaw7XYKfRTgfxaaP2p1bAP9qMzsG/wJC2fLYZ\nfm2n6N5jED5WlIugkIIbJW4AXAycDB2ZU0xtPTHJ8nrSj1otDCsD2VbbVHXN7H6g\nHrTqP4RqD+uVDIxSrXllz4Udwe/I1wUrvY9HjH2qS6Liqb5kw8SOf4a2et18+KB2\nNNk6ZEAlmOx1ddC2eZPxm8XxAxdSwTggcwvtixCeoXR53OwTZAZ8BBzwusrMklZm\n/n5zPWUCgYEA88Lf4i0WFu9h4FnQ6qxCAKDS1XyRpCYt5cyTpZPMV3LuUV0DPS3K\n+EZeU689BSOiwav8omCtrrrOHtE9fHjOH85Gd4IRyOwUQWI7RLpFiI8Lbs4tMbP5\nk1UOzzTji++N47XfTTQVdwHbx4jac80LVavbRd3AKd6oRjc/gQOpgasCgYEA7rnr\nuoWqT76xVNLmE+g93x33hzES2HitgjHzvm5B2Cu6fwlXi7cSnLEWVn7W5QXEuhek\n6uhq4NC0ahL/qAyJsFhVve32qrR7yacDVlMWZ5iQPfqtvS9CsxyafADBWsgeN4L1\n5oqQofNlh0l+UvMFp8INNbKfxTOPKCMfGxIEd+MCgYEA7UsJky380PrbtwD4JVrn\nLaFhXL3VMYyRJaFPIeKNC5wwbzgyjP3lFme6L5Dpv/T+3bZFSvT+XpgvS0S5rFAV\nqFSvuGsAUS2wUi4EMFV8lwFZSdafnEDtdgVZU1DTKkhbQg6sgIVxV9aRUt7gedZj\ncFTKMms6RAgim6fww/ECs90CgYBdI1pt9jJhVHPZNUMgpy5ke0uUijfhDwwazKRd\nOqUj0sO7RojKcM2pJoohivEKf3qmZA0qvSzds2+AJxNpnCKoE364UDw5k5rsLOXn\naxlFp8c29zOLqQGr4c//60eExKjNXaHUpWESXmTRKIJJmJkvP01qEtu0043ZygIb\nzKbDowKBgHhacDR3aat3kkaTp/4AhekhDhMgZ1u2NIi0ycsA6zRlmFucHMwtKCM0\nVMuu40D9N1lTmcdndNKkTJx6CpbS7g/y0ctkyGwgFdmTjjHYl1nATt9G2oRzKx6I\nnQ+sBUwBPieIqEmiFh+KAsDox6plrtvhSSwp8FYLWBJXZHlLJIsd\n-----END RSA PRIVATE KEY-----\n"
  },
  {
    "path": "t/keys/u5.pub",
    "content": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDjUDRtjr7RqQ1ImVHY95EBM22dwBFdU5RqvsI1rHA+pVdBHX5OZT16+YgSREt/SQUBrsvdAMWugW7iwOJImO99giQd2jE7gWTXbw8kGE5shdpqspxQEhnb3/wjd1N52rkJj9gcv8CNpP7RWS1ZftjCKC8YNqatcAqqOdbWZYqnpM2Pxum+mkG+PfK91ig4ti8Kz9Ip8p2VrKeCKKFNsoQs9xG7w3NjEeIXZv+7S3fV690/R8D9qkCyUqEd0KbxJxkm7Ih3O1yiAEUTl0abSHeqVskq8pPwmZNyBDlMEFyao9WZSSac+8jN3YbsPWyZsTEbsuep6QdxL129o+cXQHeh g3@sita-lt.atc.tcs.com\n"
  },
  {
    "path": "t/keys/u6",
    "content": "-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEAxyRjRT8RoSDnAnbZdrTjXhBMrkfNfolWFqc3qAjAo8Tmp7Ns\nn7R+KCl31RDkC9u4ll4AOfF9bIdP9ovDVvXoTMoiOdPTYqsnaMBBpDH04vxID2U5\nrEOhSzbvTazzaSlYNFED2a9bMfULuF6WxchFPBQGhTZaC8cDAkS5YYXvjHXAn1GN\nkpv0k5qltD8vjJoM7Mg5JLm84WejPQ5CmwOXqsQj69ZUZEyA8J3oqWVYkEhpYkbK\nIuzaHkrTC0PUQJ8MS3wM8358bWp53zYFJMkyL1a/zJQPOMaDiFTXXj1Uue/5ZkIM\n/fkkOMLbaCgEFCMbL8HkVEq4Q0dLhJKl1IdzbQIDAQABAoIBACQd91shuyLMAtmx\nkHM1D1+J+T5Ki3x9j/1/ylpRbA7HsUWNBxBX/eFu0+ryq0lzSiELX2Mi5yp9yATh\nCEaHRuBWcKqoPlhQzk7zP3R2EwHv22nfY/xYL7KiffhKe8MA2pxybQ5X/WQsGzoO\n/a1VSylAQIZ8ewxTxbntmOmVDwMcLZdY5X4NAmzUw1lFD2TVOlHyhjvhgIzhO1tp\nfBvsX3OL+Pk0tTQebuhoqEy2R01BLc+0ZFAKAFZpZgualqZqjyIU0isQsEo+EK4s\nPn7Ccxy+156aWAEdgD5Aj7oMn3zA9YIt/JoX8muaceUOj3E7B5ZKBtYZkFPVnKO9\nrPMNTIkCgYEA/v5IeFDZjcAMLWqhuPekcUQYMXc+I0ZTn7vT3aksWxhARG96CPdG\nHNLMw4y8yZLnCAsdKUJGtrVcn4y4K0FzUYn0tDm9cmtFoFcQvLPp4mR1kB84urIG\n7qEwv4djeLhl0cYsqMpyl7qflbTVwKa09Fy7HX9ZFL58nXVX63uRXlMCgYEAx+2o\nL/GKkKgRPpCudsGoplECjzqP4SWHXaYVOupVzpnvxFKVcpBl6Un6p6U9V6W16k2C\nXUg9XqFdleawfAwGQ2D/Ip/u4r8GKOphv0QCjO88ld15Ky9mr9Sk4/Z2EAMUrmKg\nCS4hGBF7VIeA3FnzJwLkYL0+WQKpKBt/zojQLz8CgYEAnmtEgttYDeTeq+iviMbx\n9xyjGzhF9oxer8J1oiTUVdP/OYU4gBGAEbA1Xtg1AdauiiS9fUCbxi9u2AEI+naz\nOllHGiE1Pby/iRoOX+42xFw9XcjH6dVo0SB7tMJcXkfRmj5QyJzeDL35H301v3bS\nvW5PIchYg7bEnN6mPLqMWdkCgYBVWaX1Yb5v5vAFr6prVF11MxxOnQeTbHwPhLmH\nf0bGfn0XaNIYKID5SPXS3/4CDuJMdm5y+EYKwgS729H4AwIhfaUt2O0Yq8gra3Pz\nPUuBcxiAOh5iS0ghRDxofW0FhOstTzlW8fR62+u0uGxQpa3iN5/blK6rPTGNx7+W\nIl4N7QKBgHRTxUZraVt3n0kJ4+tdc+F8XK1wLyVC9PmtW+28tiyx14k8o8H/6W94\nr3lyI13sUnvW6zU0VMAALQujRcJDLac/zSUdFGmgU3P3QatU5yUm0Xpt1uFM49Zw\nxZLBTDJxe2Qrc3Z3SKReRqxLz6tTU1soH7TVw/S36tBovKjTw7Cc\n-----END RSA PRIVATE KEY-----\n"
  },
  {
    "path": "t/keys/u6.pub",
    "content": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDHJGNFPxGhIOcCdtl2tONeEEyuR81+iVYWpzeoCMCjxOans2yftH4oKXfVEOQL27iWXgA58X1sh0/2i8NW9ehMyiI509NiqydowEGkMfTi/EgPZTmsQ6FLNu9NrPNpKVg0UQPZr1sx9Qu4XpbFyEU8FAaFNloLxwMCRLlhhe+MdcCfUY2Sm/STmqW0Py+MmgzsyDkkubzhZ6M9DkKbA5eqxCPr1lRkTIDwneipZViQSGliRsoi7NoeStMLQ9RAnwxLfAzzfnxtannfNgUkyTIvVr/MlA84xoOIVNdePVS57/lmQgz9+SQ4wttoKAQUIxsvweRUSrhDR0uEkqXUh3Nt g3@sita-lt.atc.tcs.com\n"
  },
  {
    "path": "t/listers.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\n# the various list-* commands\n# ----------------------------------------------------------------------\n\ntry 'plan 30';\n\ntry \"## info\";\n\nconfreset;confadd '\n    @oss = git gitolite gitolite3\n    @prop = cc p4\n    @crypto = alice bob carol\n    @dilbert = alice wally ashok\n\n    repo    @oss\n        RW              =   u1 @crypto\n        R               =   u2 @dilbert\n    repo    @prop\n        RW  =               u2 @dilbert\n        R   =               u1\n    repo    t3\n                    RW  =   u3\n                    R   =   u4\n';\n\ntry \"ADMIN_PUSH info; !/FATAL/\" or die text();\ntry \"\n                                        /Initialized.*empty.*cc.git/\n                                        /Initialized.*empty.*p4.git/\n                                        /Initialized.*empty.*git.git/\n                                        /Initialized.*empty.*gitolite.git/\n                                        /Initialized.*empty.*gitolite3.git/\n                                        /Initialized.*empty.*t3.git/\n\";\n\ntry \"gitolite list-groups\"; cmp\n'@crypto\n@dilbert\n@oss\n@prop\n';\n\ntry \"gitolite list-users\"; cmp\n'@all\n@crypto\n@dilbert\nadmin\nu1\nu2\nu3\nu4\n';\ntry \"gitolite list-repos\"; cmp\n'@oss\n@prop\ngitolite-admin\nt3\ntesting\n';\n\ntry \"gitolite list-phy-repos\"; cmp\n'cc\ngit\ngitolite\ngitolite-admin\ngitolite3\np4\nt3\ntesting\n';\n\ntry \"gitolite list-memberships -u alice\"; cmp\n'@crypto\n@dilbert\n';\n\ntry \"gitolite list-memberships -u ashok\"; cmp\n'@dilbert\n';\n\ntry \"gitolite list-memberships -u carol\"; cmp\n'@crypto\n';\n\ntry \"gitolite list-memberships -r git\"; cmp\n'@oss\n';\n\ntry \"gitolite list-memberships -r gitolite\"; cmp\n'@oss\n';\n\ntry \"gitolite list-memberships -r gitolite3\"; cmp\n'@oss\n';\n\ntry \"gitolite list-memberships -r cc\"; cmp\n'@prop\n';\n\ntry \"gitolite list-memberships -r p4\"; cmp\n'@prop\n';\n\ntry \"gitolite list-members \\@crypto\"; cmp\n'alice\nbob\ncarol\n';\n\ntry \"gitolite list-members \\@dilbert\"; cmp\n'alice\nashok\nwally\n';\n\ntry \"gitolite list-members \\@oss\"; cmp\n'git\ngitolite\ngitolite3\n';\n\ntry \"gitolite list-members \\@prop\"; cmp\n'cc\np4\n';\n\n"
  },
  {
    "path": "t/manjaro-root-smart-http-test-setup",
    "content": "#!/bin/bash\n\n# gitolite http mode TESTING setup for Manjaro\n# - Probably works for Arch also; if someone tests it let me know\n# - Use the comments to create a version for your distro if needed\n\n# CAUTION: This script needs to be run as root, so you best eyeball it at\n# least once to make sure you know what changes it is making.\n\n# WARNING: clobbers /srv/http/gitolite-home, and also creates 7 http\n# users with trivial passwords FOR TESTING.\n\n# HOWEVER: if you remove some of that, especially the part that creates test\n# users, this *should* work as a quick \"setup gitolite http mode\" script.\n\n# CAUTION: This script assumes the httpd.conf file is pretty much the default\n# \"as shipped\" version.  If you fiddled with it, this script *may* break.\n# It's on you to determine if that is the case and manually simulate the\n# actions of this script.  It's not that hard, and anyway it's just once (for\n# a given server) so it's not too bad.\n\n# ----------------------------------------------------------------------\n# BEGIN APACHE CONF CHANGES\n\n# Unlike Fedora, Manjaro's default httpd.conf does not contain a wildcard\n# include for stuff in conf.d; they're all explicitly included, so we need to\n# include gitolite.conf.\ncd /etc/httpd/conf\ngrep ^Include.*gitolite.conf httpd.conf ||\n    printf \"\\n%s\\n%s\\n\" '# gitolite http mode' 'Include conf/extra/gitolite.conf' >> httpd.conf\n\n# Again, unlike Fedora, Manjaro's default conf does not come with cgi enabled.\n# In fact, the directive is both commented out *and* inside an \"IF\" block for\n# some other module.  Since I don't plan to be an expert on apache, I will\n# punt by including the required LoadModule line before the first LoadModule\n# line that is not in an \"if\" block (i.e., not indented).\ngrep '^LoadModule cgi_module modules/mod_cgi.so' httpd.conf ||\n    perl -i -pE 'say \"LoadModule cgi_module modules/mod_cgi.so\" if /^LoadModule/ and not $flag++' httpd.conf\n\n# END APACHE CONF CHANGES\n# ----------------------------------------------------------------------\n\ncd ~http\n# should be /srv/http; you may want to check just to be safe\nexport GITOLITE_HTTP_HOME=$PWD/gitolite-home\n# WARNING: do not add a trailing slash to the value of GITOLITE_HTTP_HOME\n\n[[ -d gitolite-home ]] && {\n    [[ $GITOLITE_TEST != y ]] && {\n        echo \"If you're OK with clobbering $GITOLITE_HTTP_HOME, please rerun with\nenvironment variable GITOLITE_TEST set to 'y'.\"\n        exit 1;\n    }\n}\n\nrm -rf gitolite-home\nmkdir gitolite-home\n\n# setup apache conf for gitolite\ncd /etc/httpd/conf/extra\n[[ -f gitolite.conf ]] || {\n    cat > gitolite.conf <<-EOF\n\t\tSetEnv GIT_PROJECT_ROOT $GITOLITE_HTTP_HOME/repositories\n\t\tScriptAlias /git/ $GITOLITE_HTTP_HOME/gitolite-source/src/gitolite-shell/\n\t\tScriptAlias /gitmob/ $GITOLITE_HTTP_HOME/gitolite-source/src/gitolite-shell/\n\t\tSetEnv GITOLITE_HTTP_HOME $GITOLITE_HTTP_HOME\n\t\tSetEnv GIT_HTTP_EXPORT_ALL\n\n\t\t<Location /git>\n\t\t    AuthType Basic\n\t\t    AuthName \"Private Git Access\"\n\t\t    Require valid-user\n\t\t    AuthUserFile $GITOLITE_HTTP_HOME/gitolite-http-authuserfile\n\t\t</Location>\n\tEOF\n}\n\n# get the gitolite sources\ncd $GITOLITE_HTTP_HOME\n\nif [[ -d /tmp/gitolite.git ]]; then\n    git clone /tmp/gitolite.git                      gitolite-source\n    # I do this because I have to test stuff *before* it gets to github, so I\n    # can't simply clone what's on github.  Instead, I use a local\n    # world-readable bare repo cloned from my dev environment.\nelse\n    git clone 'https://github.com/sitaramc/gitolite' gitolite-source\nfi\n\n# make the bin directory, and add it to PATH\ncd gitolite-source\nmkdir             $GITOLITE_HTTP_HOME/bin\n./install -ln     $GITOLITE_HTTP_HOME/bin\nexport PATH=$PATH:$GITOLITE_HTTP_HOME/bin\n\n# come back to base, then run setup.  Notice that you have to point HOME to\n# the right place, even if it is just for this command\ncd $GITOLITE_HTTP_HOME\nHOME=$GITOLITE_HTTP_HOME gitolite setup -a admin\n\n# insert some essential lines at the beginning of the rc file\necho '$ENV{PATH} .= \":$ENV{GITOLITE_HTTP_HOME}/bin\";'  > 1\necho >> 1\ncat .gitolite.rc >> 1\n\\mv 1 .gitolite.rc\n\n# create users \"admin\" and \"u1\" thru \"u6\" for testing\nhtpasswd -bc $GITOLITE_HTTP_HOME/gitolite-http-authuserfile admin admin\nseq 6 | xargs -I % htpasswd -b $GITOLITE_HTTP_HOME/gitolite-http-authuserfile u% u%\n\n# fix up ownership\nchown -R http:http $GITOLITE_HTTP_HOME\n\n# restart httpd to make it pick up all the new stuff\nsystemctl restart httpd\n"
  },
  {
    "path": "t/merge-check.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\n# merge check -- the M flag\n# ----------------------------------------------------------------------\n\ntry \"plan 55\";\n\nconfreset;confadd '\n    repo  foo\n          RW+M      =   u1\n          RW+       =   u2\n          RWM      .=   u3\n          RW        =   u4\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\n# setup a merged push\n\ntry \"\n    cd ..\n    [ -d foo ];         !ok\n    glt clone u1 file:///foo\n                        ok;     /Cloning into/\n                                /You appear to have cloned an empty/\n\";\n\ntry \"\n    cd foo;             ok\n    [ -d .git ];        ok\n    test-commit aa;     ok;     /1 file changed, 1 insertion/\n    tag start;          ok\n    glt push u1 origin master\n                        ok;     /new branch.*master.-..master/\n                                /create.delete ignored.*merge-check/\n    checkout -b new;    ok;     /Switched to a new branch 'new'/\n    test-commit bb cc;  ok\n    checkout master;    ok;     /Switched to branch 'master'/\n    test-commit dd ee;  ok\n    git merge new;      ok;     /Merge made/\n    test-commit ff;     ok\n    tag end;            ok\n\";\n\n# push by u4 should fail\ntry \"\n    glt push u4 file:///foo master\n                        !ok;    /WM refs/heads/master foo u4 DENIED by fallthru/\n                                /To file:///foo/\n                                /remote rejected.*hook declined/\n                                /failed to push some refs/\n\";\n\n# push by u3 should succeed\ntry \"\n    glt push u3 file:///foo master\n                        ok;     /To file:///foo/; /master.-..master/\n\";\n\n# rewind by u3 should fail\ntry \"\n    reset-h start;      ok;     /HEAD is now at .* aa /\n    glt push u3 file:///foo +master\n                         !ok;   /rejected.*hook declined/\n                                /failed to push some refs/\n\";\n\n# rewind by u2 should succeed\ntry \"\n    glt push u2 file:///foo +master\n                         ok;    /To file:///foo/\n                                /forced update/\n\";\n\n# push by u2 should fail\ntry \"\n    reset-h end;        ok;     /HEAD is now at .* ff /\n    glt push u2 file:///foo master\n                        !ok;    /WM refs/heads/master foo u2 DENIED by fallthru/\n                                /To file:///foo/\n                                /remote rejected.*hook declined/\n                                /failed to push some refs/\n\";\n\n# push by u1 should succeed\ntry \"\n    glt push u1 file:///foo master\n                        ok;     /master.-..master/\n\";\n"
  },
  {
    "path": "t/mirror-test",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# you need 3 disposable userids: sam, frodo, gollum.  Then the test user (say\n# \"g3\") needs to be able to sudo into them.  Put this in /etc/sudoers:\n\n#       g3 ALL = (sam,frodo,gollum) NOPASSWD: ALL\n\n$ENV{TSH_ERREXIT} = 1;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\nuse Cwd;\nmy $workdir = getcwd();\nmy $h = $ENV{HOME};\nmy ($t, $t2);   # temp vars\n\n# basic tests\n# ----------------------------------------------------------------------\n\ntry \"plan 152\";\n##  try \"DEF POK = !/DENIED/; !/failed to push/\";\n\n##  confreset;confadd '\n\n##  ';\n\n##  try \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\n# ----------------------------------------------------------------------\n\n# switch keys\nsub swk {\n    my $h = $ENV{HOME};\n    my $k = shift;\n    system(\"cp $h/.ssh/$k $h/.ssh/id_rsa\");\n    system(\"cp $h/.ssh/$k.pub $h/.ssh/id_rsa.pub\");\n}\n\nsub all {\n    try \"F \" . join(\" \", @_);\n    try \"S \" . join(\" \", @_);\n    try \"G \" . join(\" \", @_);\n}\n\ntry \"\n    DEF F   =   sudo -u frodo -i\n    DEF S   =   sudo -u sam -i\n    DEF G   =   sudo -u gollum -i\n\";\n\nmy $bd = `gitolite query-rc -n GL_BINDIR`;\n\ntry \"\n    $bd/../t/mirror-test-setup.sh;   ok or die mirror setup shell script failed\n        /hello server-frodo, this is frodo/\n        /hello server-sam, this is frodo/\n        /hello server-gollum, this is frodo/\n        /hello server-frodo, this is sam/\n        /hello server-sam, this is sam/\n        /hello server-gollum, this is sam/\n        /hello server-frodo, this is gollum/\n        /hello server-sam, this is gollum/\n        /hello server-gollum, this is gollum/\n        /hello admin, this is frodo/\n        /Initialized empty .*/gitolite-admin.git/\n        /Initialized empty .*/r1.git/\n        /Initialized empty .*/r2.git/\n        /Initialized empty .*/testing.git/\n        /Initialized empty .*/gitolite-admin.git/\n        /Initialized empty .*/r1.git/\n        /Initialized empty .*/r2.git/\n        /Initialized empty .*/testing.git/\n        /Initialized empty .*/gitolite-admin.git/\n        /Initialized empty .*/r1.git/\n        /Initialized empty .*/r2.git/\n        /Initialized empty .*/testing.git/\n\";\n\n# ----------------------------------------------------------------------\n# SECTION 1: gitolite-admin shenanigans\n\n# push to frodo and see sam and gollum change\ntry \"\n    git clone frodo\\@localhost:gitolite-admin fga\n        ok; /Cloning into 'fga'.../\n    cd fga;                             ok\n    cp $h/.ssh/u?.pub keydir;           ok\n    git add keydir;                     ok\n    git commit -m 6keys;                ok\n    git push;                           ok\n        /To localhost:gitolite-admin/\n        /master -> master/\n    sleep 5\n    git rev-parse HEAD\n\";\n\nchomp($t = text());\n\ntry \"\n    git ls-remote sam\\@localhost:gitolite-admin\n        ok; /$t/\n    git ls-remote gollum\\@localhost:gitolite-admin\n        ok; /$t/\n\";\n\ntry \"\n    cd ..\n\n\";\n\n# push to sam and see frodo and gollum change\ntry \"\n    git clone sam\\@localhost:gitolite-admin sga\n        ok; /Cloning into 'sga'.../\n    cd sga;                             ok\n    empty;                              ok\n    git push;                           ok\n        /To localhost:gitolite-admin/\n        /master -> master/\n    sleep 5\n    git rev-parse HEAD\n\";\n\nchomp($t = text());\n\ntry \"\n    git ls-remote frodo\\@localhost:gitolite-admin\n        ok; /$t/\n    git ls-remote gollum\\@localhost:gitolite-admin\n        ok; /$t/\n\";\n\ntry \"\n    cd ..\n\n\";\n\n# push to gollum and fail at gollum\ntry \"\n    git clone gollum\\@localhost:gitolite-admin gga\n        ok; /Cloning into 'gga'.../\n    cd gga;                             ok\n    empty;                              ok\n    git push;                           !ok\n        !/To localhost:gitolite-admin/\n        !/master -> master/\n        /gollum: pushing 'gitolite-admin' to copy 'gollum' not allowed/\n    git rev-parse HEAD\n\";\n\nchomp($t2 = text());\n\ntry \"\n    git ls-remote frodo\\@localhost:gitolite-admin\n        ok; /$t/; !/$t2/\n    git ls-remote sam\\@localhost:gitolite-admin\n        ok; /$t/; !/$t2/\n    git ls-remote gollum\\@localhost:gitolite-admin\n        ok; /$t/; !/$t2/\n\";\n\n# fake out the gollum failure to continue the redirected push and fail at frodo\ntry \"\n    sudo -u gollum -i gitolite git-config -r gitolite-admin .\n        ok\n        /redirectOK.*sam/\n        !/redirectOK.*gollum/\n\n    sudo -u gollum -i bash -c 'echo repo gitolite-admin > junk'\n    sudo -u gollum -i bash -c 'echo option mirror.redirectOK-1 = gollum   >> junk'\n    sudo -u gollum -i bash -c 'cat junk >> .gitolite/conf/gitolite.conf'\n    sudo -u gollum -i gitolite compile\n    sudo -u gollum -i gitolite git-config -r gitolite-admin .\n        ok\n        /redirectOK.*sam/\n        /redirectOK.*gollum/\n\n    git push;                           !ok\n        /frodo: redirection not allowed from 'gollum'/\n        !/To gollum\\@localhost:gitolite-admin/\n        !/master -> master/\n\";\n\n# reset gollum via frodo\ntry \"\n    cd ..\n    rm -rf fga\n    git clone frodo\\@localhost:gitolite-admin fga\n        ok; /Cloning into 'fga'.../\n    cd fga;                             ok\n    empty;                              ok\n    git push;                           ok\n        /To localhost:gitolite-admin/\n        /master -> master/\n    sleep 5\n\n    sudo -u gollum -i gitolite git-config -r gitolite-admin .\n        ok\n        /redirectOK.*sam/\n        !/redirectOK.*gollum/\n\n    git rev-parse HEAD\n\";\n\nchomp($t = text());\n\ntry \"\n    git ls-remote sam\\@localhost:gitolite-admin\n        ok; /$t/\n    git ls-remote gollum\\@localhost:gitolite-admin\n        ok; /$t/\n\";\n\n# ----------------------------------------------------------------------\n# user repo shenanigans\n\n# for a recap of the perms see t/mirror-test-setup.sh\n\ntry \"\n    cd ..\n    pwd\n    /tmp/tsh_tempdir/ or die not in the right place\n\" or die;\n\nswk('u1');\n\n# u1 sam r1, R ok, W ok\ntry \"\n    rm -rf fga sga gga\n\n    git clone sam\\@localhost:r1 sr1\n        /Cloning into 'sr1'.../\n        /warning: You appear to have cloned an empty repository/\n    cd sr1\n    empty\n    git push origin master\n        /new branch/;   /master -> master/\n    sleep 5\n    git rev-parse HEAD\n\";\nchomp($t = text());\n\n# u1 sam r1, W mirrors to frodo but not gollum\ntry \"\n    git ls-remote sam\\@localhost:r1\n        /$t/\n    git ls-remote frodo\\@localhost:r1\n        /$t/\n    git ls-remote gollum\\@localhost:r1\n        /gollum: 'r1' is mirrored but not here/\n\";\n\nswk(\"u2\");\ntry \"\n    empty\n    git rev-parse HEAD\n\";\nchomp($t2 = text());\n\n# u2 sam r2 W ok, mirrors to all\ntry \"\n    git push sam\\@localhost:r2 master\n        /new branch/;   /master -> master/\n        /master -> master/\n    sleep 5\n    git ls-remote frodo\\@localhost:r2\n        !/$t/\n        /$t2/\n    git ls-remote gollum\\@localhost:r2\n        !/$t/\n        /$t2/\n\";\n\nswk(\"u1\");\n\n# u1 gollum r1 -- \"known unknown\" :-)\n# u1 frodo r1 R ok, W not ok\n# u1 sam r1 R ok, W ok\ntry \"\n    cd ..\n    rm -rf sr1\n\n    git clone gollum\\@localhost:r1 fr1\n        /gollum: 'r1' is mirrored but not here/\n\n    git clone frodo\\@localhost:r1 fr1;       ok\n    cd fr1\n    empty\n    git push\n        /frodo: pushing 'r1' to copy 'frodo' not allowed/\n    cd ..\n    git clone sam\\@localhost:r1 sr1;         ok\n    cd sr1\n    empty\n    git push;                               ok\n        /master -> master/\n    sleep 5\n    git rev-parse HEAD\n\";\nchomp($t = text());\n\n# u1 sam r1 W mirrored to frodo but not gollum\ntry \"\n    git ls-remote sam\\@localhost:r1\n        /$t/\n    git ls-remote frodo\\@localhost:r1\n        /$t/\n\n    git ls-remote gollum\\@localhost:r1\n        /gollum: 'r1' is mirrored but not here/\n\n    git reset --hard HEAD^;                 ok\n    tc a\n    git push;                               !ok\n        /rejected/\n        /failed to push/\n\n    git push -f\n        /\\\\+ .......\\\\.\\\\.\\\\........ master -> master .forced update/\n    sleep 5\n\";\n\nswk(\"u2\");\n\n# u2 frodo r1 R ok, W not allowed (no redirectOK)\n# u2 frodo r2 W ok\ntry \"\n    cd ..\n    rm -rf fr1 sr1\n\n    git clone frodo\\@localhost:r1 fr1;       ok\n    cd fr1\n    tc b\n    git push\n        /frodo: pushing 'r1' to copy 'frodo' not allowed/\n    cd ..\n    git clone frodo\\@localhost:r2 fr2;       ok\n    cd fr2\n    tc c\n    git push\n        /master -> master/\n    sleep 5\n    git rev-parse HEAD\n\";\nchomp($t = text());\n\n# u2 frodo r2 W mirrors to sam and gollum\ntry \"\n    git ls-remote sam\\@localhost:r2\n        /$t/\n    git ls-remote gollum\\@localhost:r2\n        /$t/\n\n    git reset --hard HEAD^;                 ok\n    tc d\n    git push\n        /rejected/\n        /failed to push/\n\n    git push -f\n        /\\\\+ .......\\\\.\\\\.\\\\........ master -> master .forced update/\n    sleep 5\n\n    cd ..\n    rm -rf fr1 fr2\n\";\n\nswk(\"u3\");\n\n# u3 frodo r2 R ok W ok\ntry \"\n    git clone frodo\\@localhost:r2 fr2;       ok\n    cd fr2\n    tc e\n    git push;                               ok\n    sleep 5\n\n    git rev-parse HEAD\n\";\nchomp($t = text());\n\n# u3 frodo r2 W mirrors to sam and gollum\ntry \"\n    git ls-remote sam\\@localhost:r2\n        /$t/\n    git ls-remote gollum\\@localhost:r2\n        /$t/\n\n    git reset --hard HEAD^;                 ok\n    tc f\n    git push\n        /rejected/\n        /failed to push/\n\n    sleep 10\n    git push -f\n        /\\\\+ refs/heads/master r2 u3 DENIED by fallthru/\n        /hook declined/\n        /rejected/\n\";\n\n# ----------------------------------------------------------------------\n# all those vague edge cases where the two servers have totally wrong ideas\n# about each other\n\nswk('u1');\n\ntry \"sudo -u frodo -i ls .gitolite/logs\";\nchomp($t = text());\nmy $lfn = \".gitolite/logs/$t\";\n\ntry \"\n    ssh sam\\@localhost mirror push frodo lfrodo;  !ok\n    /FATAL: frodo: 'lfrodo' is local/\n\n    ssh sam\\@localhost mirror push frodo mboth;  !ok\n    /FATAL: frodo: 'mboth' is native/\n\n    ssh sam\\@localhost mirror push frodo mnotsam;  !ok\n    /FATAL: frodo: 'sam' is not the master for 'mnotsam'/\n\n    cd ..\n    git clone sam\\@localhost:lfrodo2 lfrodo2;   ok\n    cd lfrodo2\n    empty\n    git push origin master;                     !ok\n    /FATAL: frodo: 'lfrodo2' is local/\n\n    cd ..\n    git clone sam\\@localhost:nnfrodo nnfrodo;   ok\n    cd nnfrodo\n    empty\n    git push origin master;                     !ok\n    /FATAL: frodo: 'nnfrodo' is not native/\n\n    cd ..\n    git clone sam\\@localhost:nvsfrodo nvsfrodo; ok\n    cd nvsfrodo\n    empty\n    git push origin master;                     !ok\n    /FATAL: frodo: 'sam' is not a valid copy for 'nvsfrodo'/\n\";\n"
  },
  {
    "path": "t/mirror-test-rc",
    "content": "# This file is in perl syntax.  But you do NOT need to know perl to edit it --\n# just mind the commas, use single quotes unless you know what you're doing,\n# and make sure the brackets and braces stay matched up!\n\n# (Tip: perl allows a comma after the last item in a list also!)\n\n# HELP for commands (see COMMANDS list below) can be had by running the\n# command with \"-h\" as the sole argument.\n\n# HELP for all the other FEATURES can be found in the documentation (look for\n# \"list of non-core programs shipped with gitolite\" in the master index) or\n# directly in the corresponding source file.\n\n%RC = (\n\n    # ------------------------------------------------------------------\n\n    HOSTNAME                        =>  '%HOSTNAME',\n\n    # default umask gives you perms of '0700'; see the rc file docs for\n    # how/why you might change this\n    UMASK                           =>  0077,\n\n    # look in the \"GIT-CONFIG\" section in the README for what to do\n    GIT_CONFIG_KEYS                 =>  '',\n\n    # comment out if you don't need all the extra detail in the logfile\n    LOG_EXTRA                       =>  1,\n\n    # roles.  add more roles (like MANAGER, TESTER, ...) here.\n    #   WARNING: if you make changes to this hash, you MUST run 'gitolite\n    #   compile' afterward, and possibly also 'gitolite trigger POST_COMPILE'\n    ROLES => {\n        READERS                     =>  1,\n        WRITERS                     =>  1,\n    },\n    # uncomment (and change) this if you wish\n    # DEFAULT_ROLE_PERMS            =>  'READERS @all',\n\n    # CACHE => 'Redis',\n\n    # ------------------------------------------------------------------\n\n    # rc variables used by various features\n\n    # the 'info' command prints this as additional info, if it is set\n        # SITE_INFO                 =>  'Please see http://blahblah/gitolite for more help',\n\n    # the 'desc' command uses this\n        # WRITER_CAN_UPDATE_DESC    =>  1,\n\n    # the CpuTime feature uses these\n        # display user, system, and elapsed times to user after each git operation\n        # DISPLAY_CPU_TIME          =>  1,\n        # display a warning if total CPU times (u, s, cu, cs) crosses this limit\n        # CPU_TIME_WARN_LIMIT       =>  0.1,\n\n    # the Mirroring feature needs this\n        # HOSTNAME                  =>  \"foo\",\n\n    # if you enabled 'Shell', you need this\n        # SHELL_USERS_LIST          =>  \"$ENV{HOME}/.gitolite.shell-users\",\n\n    # ------------------------------------------------------------------\n\n    # List of commands and features to enable\n\n    ENABLE => [\n\n        # COMMANDS\n\n            # These are the commands enabled by default\n            'help',\n            'desc',\n            'info',\n            'perms',\n            'writable',\n\n            'mirror',\n\n            # Uncomment or add new commands here.\n            # 'create',\n            # 'fork',\n            # 'mirror',\n            # 'sskm',\n            # 'D',\n\n        # These FEATURES are enabled by default.\n\n            # essential (unless you're using smart-http mode)\n            'ssh-authkeys',\n\n            # creates git-config enties from gitolite.conf file entries like 'config foo.bar = baz'\n            'git-config',\n\n            # creates git-daemon-export-ok files; if you don't use git-daemon, comment this out\n            'daemon',\n\n            # creates projects.list file; if you don't use gitweb, comment this out\n            'gitweb',\n\n        # These FEATURES are disabled by default; uncomment to enable.  If you\n        # need to add new ones, ask on the mailing list :-)\n\n        # user-visible behaviour\n\n            # prevent wild repos auto-create on fetch/clone\n            # 'no-create-on-read',\n            # no auto-create at all (don't forget to enable the 'create' command!)\n            # 'no-auto-create',\n\n            # access a repo by another (possibly legacy) name\n            # 'Alias',\n\n            # give some users direct shell access\n            # 'Shell',\n\n        # system admin stuff\n\n            # enable mirroring (don't forget to set the HOSTNAME too!)\n            'Mirroring',\n\n            # allow people to submit pub files with more than one key in them\n            # 'ssh-authkeys-split',\n\n            # selective read control hack\n            # 'partial-copy',\n\n            # manage local, gitolite-controlled, copies of read-only upstream repos\n            # 'upstream',\n\n            # updates 'description' file instead of 'gitweb.description' config item\n            # 'cgit',\n\n        # performance, logging, monitoring...\n\n            # be nice\n            # 'renice 10',\n\n            # log CPU times (user, system, cumulative user, cumulative system)\n            # 'CpuTime',\n\n        # syntactic_sugar for gitolite.conf and included files\n\n            # allow backslash-escaped continuation lines in gitolite.conf\n            # 'continuation-lines',\n\n            # create implicit user groups from directory names in keydir/\n            # 'keysubdirs-as-groups',\n\n    ],\n\n);\n\n# ------------------------------------------------------------------------------\n# per perl rules, this should be the last line in such a file:\n1;\n\n# Local variables:\n# mode: perl\n# End:\n# vim: set syn=perl:\n"
  },
  {
    "path": "t/mirror-test-setup.sh",
    "content": "#!/bin/bash\n\nset -e\nhosts=\"frodo sam gollum\"\nmainhost=frodo\n\n# setup software\nbd=`gitolite query-rc -n GL_BINDIR`\nmkdir -p /tmp/g3\nrm -rf /tmp/g3/src\ncp -a $bd /tmp/g3/src\nchmod -R go+rX /tmp/g3\n\n# setup symlinks in frodo, sam, and gollum's accounts\nfor h in $hosts\ndo\n    sudo -u $h -i bash -c \"rm -rf *.pub bin .ssh projects.list repositories .gitolite .gitolite.rc\"\ndone\n\n[ \"$1\" = \"clear\" ] && exit\n\ncd /tmp/g3\n[ -d keys ] || {\n    mkdir keys\n    cd keys\n    for h in $hosts\n    do\n        ssh-keygen -N '' -q -f server-$h  -C $h\n        chmod go+r /tmp/g3/keys/server-$h\n    done\n    cp $bd/../t/mirror-test-ssh-config ssh-config\n}\nchmod -R go+rX /tmp/g3\n\nfor h in $hosts\ndo\n    sudo -u $h -i bash -c \"mkdir -p bin; ln -sf /tmp/g3/src/gitolite bin; mkdir -p .ssh; chmod 0700 .ssh\"\n\n    sudo -u $h -i cp /tmp/g3/keys/ssh-config    .ssh/config\n    sudo -u $h -i cp /tmp/g3/keys/server-$h     .ssh/id_rsa\n    sudo -u $h -i cp /tmp/g3/keys/server-$h.pub .ssh/id_rsa.pub\n    sudo -u $h -i chmod go-rwx                  .ssh/id_rsa .ssh/config\n\ndone\n\n# add all pubkeys to all servers\nfor h in $hosts\ndo\n    sudo -u $h -i gitolite setup -a admin\n    for j in $hosts\n    do\n        sudo -u $h -i gitolite setup -pk /tmp/g3/keys/server-$j.pub\n        echo sudo _u $j _i ssh $h@localhost info\n        sudo -u $j -i ssh -o StrictHostKeyChecking=no $h@localhost info\n    done\n    echo ----\ndone\n\n# now copy our admin key to the main host\ncd;cd .ssh\ncp admin id_rsa; cp admin.pub id_rsa.pub\ncp admin.pub /tmp/g3/keys; chmod go+r /tmp/g3/keys/admin.pub\nsudo -u $mainhost -i gitolite setup -pk /tmp/g3/keys/admin.pub\nssh $mainhost@localhost info\n\nlines=\"\nrepo gitolite-admin\n    option mirror.master = frodo\n    option mirror.copies-1 = sam gollum\n    option mirror.redirectOK = sam\n\nrepo r1\n    RW+     =   u1\n    RW      =   u2\n    R       =   u3\n    option mirror.master = sam\n    option mirror.copies-1 = frodo\n\nrepo r2\n    RW+     =   u2\n    RW      =   u3\n    R       =   u4\n    option mirror.master = sam\n    option mirror.copies-1 = frodo gollum\n    option mirror.redirectOK = all\n\ninclude \\\"%HOSTNAME.conf\\\"\n\"\n\nlines2=\"\nrepo l-%HOSTNAME\nRW  =   u1\n\"\n\n# for each server, set the HOSTNAME to the rc, add the mirror options to the\n# conf file, and compile\nfor h in $hosts\ndo\n    cat $bd/../t/mirror-test-rc | perl -pe \"s/%HOSTNAME/$h/\" > /tmp/g3/temp\n    chmod go+rX /tmp/g3/temp\n    sudo -u $h -i cp /tmp/g3/temp .gitolite.rc\n    echo \"$lines\"  | sudo -u $h -i sh -c 'cat >> .gitolite/conf/gitolite.conf'\n    echo \"$lines2\" | sudo -u $h -i sh -c \"cat >> .gitolite/conf/$h.conf\"\n    sudo -u $h -i gitolite setup\ndone\n\n# goes on frodo\nlines=\"\n# local to frodo but sam thinks frodo is a copy\nrepo lfrodo\nRW  =   u1\n\n# both think they're master\nrepo mboth\nRW  =   u1\noption mirror.master = frodo\noption mirror.copies = sam\n\n# frodo thinks someone else is the master but sam thinks he is\nrepo mnotsam\nRW  =   u1\noption mirror.master = merry\noption mirror.copies = frodo\n\n# local to frodo but sam thinks frodo is a master and redirect is OK\nrepo lfrodo2\nRW  =   u1\n\n# non-native to frodo but sam thinks frodo is master\nrepo nnfrodo\nRW  =   u1\noption mirror.master = gollum\noption mirror.copies = frodo\noption mirror.redirectOK = all\n\n# sam is not a valid copy to send stuff to frodo\nrepo nvsfrodo\nRW  =   u1\noption mirror.master = frodo\noption mirror.copies = gollum\noption mirror.redirectOK = all\n\"\n\necho \"$lines\" | sudo -u frodo -i sh -c \"cat >> .gitolite/conf/frodo.conf\"\n\n# goes on sam\nlines=\"\n# local to frodo but sam thinks frodo is a copy\nrepo lfrodo\nRW  =   u1\noption mirror.master = sam\noption mirror.copies = frodo\n\n# both think they're master\nrepo mboth\nRW  =   u1\noption mirror.master = sam\noption mirror.copies = frodo\n\n# frodo thinks someone else is the master but sam thinks he is\nrepo mnotsam\nRW  =   u1\noption mirror.master = sam\noption mirror.copies = frodo\n\n# local to frodo but sam thinks frodo is a master and redirect is OK\nrepo lfrodo2\nRW  =   u1\noption mirror.master = frodo\noption mirror.copies = sam\noption mirror.redirectOK = all\n\n# non-native to frodo but sam thinks frodo is master\nrepo nnfrodo\nRW  =   u1\noption mirror.master = frodo\noption mirror.copies = sam\noption mirror.redirectOK = all\n\n# sam is not a valid copy to send stuff to frodo\nrepo nvsfrodo\nRW  =   u1\noption mirror.master = frodo\noption mirror.copies = sam\noption mirror.redirectOK = all\n\"\n\necho \"$lines\" | sudo -u sam -i sh -c \"cat >> .gitolite/conf/sam.conf\"\n\nfor h in $hosts\ndo\n    sudo -u $h -i gitolite setup\ndone\n\n# that ends the setup phase\necho ======================================================================\n"
  },
  {
    "path": "t/mirror-test-ssh-config",
    "content": "host frodo\n    user frodo\n    hostname localhost\n\nhost sam\n    user sam\n    hostname localhost\n\nhost gollum\n    user gollum\n    hostname localhost\n"
  },
  {
    "path": "t/partial-copy.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\n# test script for partial copy feature\n# ----------------------------------------------------------------------\n\ntry \"plan 82\";\ntry \"DEF POK = !/DENIED/; !/failed to push/\";\nmy $h = $ENV{HOME};\n\ntry \"\n    cat $h/.gitolite.rc\n    perl s/GIT_CONFIG_KEYS.*/GIT_CONFIG_KEYS => '.*',/\n    perl s/# 'partial-copy'/'partial-copy'/\n    put $h/.gitolite.rc\n\";\n\nconfreset;confadd '\n    repo foo\n            RW+                 =   u1 u2\n\n    repo foo-pc\n            -   secret-1$       =   u4\n            R                   =   u4  # marker 01\n            RW  next            =   u4\n            RW+ dev/USER/       =   u4\n            RW  refs/tags/USER/ =   u4\n\n            -   VREF/partial-copy   =   @all\n            config gitolite.partialCopyOf = foo\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"\n        /Init.*empty.*foo\\\\.git/\n        /Init.*empty.*foo-pc\\\\.git/\n\";\n\ntry \"\n    cd ..\n\n    ## populate repo foo, by user u1\n    # create foo with a bunch of branches and tags\n    CLONE u1 foo\n        /appear.*cloned/\n    cd foo\n    tc a1 a2\n    checkout -b dev/u1/foo; tc f1 f2\n    checkout master; tc m1 m2\n    checkout master; checkout -b next; tc n1 n2; tag nt1\n    checkout -b secret-1; tc s11 s12; tag s1t1\n    checkout next; checkout -b secret-2; tc s21 s22; tag s2t1\n    glt push u1 --all\n        /new branch/; /secret-1/; /secret-2/\n    glt push u1 --tags\n        /new tag/; /s1t1/; /s2t1/\n\n    ## user u4 tries foo, fails, tries foo-pc\n    cd ..\n    CLONE u4 foo foo4; !ok\n        /R any foo u4 DENIED by fallthru/\n    CLONE u4 foo-pc ; ok;\n        /Cloning into 'foo-pc'/\n        /new branch.* dev/u1/foo .* dev/u1/foo/\n        /new branch.* master .* master/\n        /new branch.* next .* next/\n        /new branch.* secret-2 .* secret-2/\n        !/new branch.* secret-1 .* secret-1/\n        /new tag.* nt1 .* nt1/\n        /new tag.* s2t1 .* s2t1/\n        !/new tag.* s1t1 .* s1t1/\n\n    ## user u4 pushes to foo-pc\n    cd foo-pc\n    checkout master\n    tc u4m1 u4m2; PUSH u4; !ok\n        /W refs/heads/master foo-pc u4 DENIED by fallthru/\n        /hook declined to update refs/heads/master/\n        /To file:///foo-pc/\n        /remote rejected/\n        /failed to push some refs to 'file:///foo-pc'/\n\n    checkout next\n    tc u4n1 u4n2\n    PUSH u4 next; ok\n        /To .*/foo.git/\n        /new reference\\\\]   ca3787119b7e8b9914bc22c939cefc443bc308da -> refs/partial/br-\\\\d+/\n        /file:///foo-pc/\n        /52c7716..ca37871  next -> next/\n    tag u4/nexttag; glt push u4 --tags\n        /To file:///foo-pc/\n        /\\\\[new tag\\\\]         u4/nexttag +-> +u4/nexttag/\n        /\\\\[new reference\\\\]   ca3787119b7e8b9914bc22c939cefc443bc308da -> refs/partial/br-\\\\d+/\n\n    checkout master\n    checkout -b dev/u4/u4master\n    tc devu4m1 devu4m2\n    PUSH u4 HEAD; ok\n        /To .*/foo.git/\n        /new reference\\\\]   228353950557ed1eb13679c1fce4d2b4718a2060 -> refs/partial/br-\\\\d+/\n        /file:///foo-pc/\n        /new branch.* HEAD -> dev/u4/u4master/\n\n    ## user u1 gets u4's updates, makes some more\n    cd ../foo\n    glt fetch u1\n        /From file:///foo/\n        /new branch\\\\]      dev/u4/u4master -> origin/dev/u4/u4master/\n        /new tag\\\\]         u4/nexttag +-> +u4/nexttag/\n        /52c7716..ca37871  next +-> +origin/next/\n    checkout master; tc u1ma1 u1ma2;\n        /\\\\[master 8ab1ff5\\\\] u1ma2 at Thu Jul  7 06:23:20 2011/\n    tag mt2; PUSH u1 master; ok\n    checkout secret-1; tc u1s1b1 u1s1b2\n        /\\\\[secret-1 5f96cb5\\\\] u1s1b2 at Thu Jul  7 06:23:20 2011/\n    tag s1t2; PUSH u1 HEAD; ok\n    checkout secret-2; tc u1s2b1 u1s2b2\n        /\\\\[secret-2 1ede682\\\\] u1s2b2 at Thu Jul  7 06:23:20 2011/\n    tag s2t2; PUSH u1 HEAD; ok\n    glt push u1 --tags; ok\n\n    glt ls-remote u1 origin\n        /8ab1ff512faf5935dc0fbff357b6f453b66bb98b\\trefs/tags/mt2/\n        /5f96cb5ff73c730fb040eb2d01981f7677ca6dba\\trefs/tags/s1t2/\n        /1ede6829ec7b75a53cd6acb7da64e5a8011e6050\\trefs/tags/s2t2/\n\n    ## u4 gets updates but without the tag in secret-1\n    cd ../foo-pc\n    glt ls-remote u4 origin\n        !/ refs/heads/secret-1/; !/s1t1/; !/s1t2/\n        /8ab1ff512faf5935dc0fbff357b6f453b66bb98b\\tHEAD/\n        /8ced4a374b3935bac1a5ba27ef8dd950bd867d47\\trefs/heads/dev/u1/foo/\n        /228353950557ed1eb13679c1fce4d2b4718a2060\\trefs/heads/dev/u4/u4master/\n        /8ab1ff512faf5935dc0fbff357b6f453b66bb98b\\trefs/heads/master/\n        /ca3787119b7e8b9914bc22c939cefc443bc308da\\trefs/heads/next/\n        /1ede6829ec7b75a53cd6acb7da64e5a8011e6050\\trefs/heads/secret-2/\n        /8ab1ff512faf5935dc0fbff357b6f453b66bb98b\\trefs/tags/mt2/\n        /52c7716c6b029963dd167c647c1ff6222a366499\\trefs/tags/nt1/\n        /01f04ece6519e7c0e6aea3d26c7e75e9c4e4b06d\\trefs/tags/s2t1/\n        /1ede6829ec7b75a53cd6acb7da64e5a8011e6050\\trefs/tags/s2t2/\n\n    glt fetch u4\n        /3ea704d..8ab1ff5  master     -> origin/master/\n        /01f04ec..1ede682  secret-2   -> origin/secret-2/\n        /\\\\[new tag\\\\]         mt2        -> mt2/\n        /\\\\[new tag\\\\]         s2t2       -> s2t2/\n        !/ refs/heads/secret-1/; !/s1t1/; !/s1t2/\n\";\n__END__\n\n# last words...\nglt ls-remote u4 file:///foo-pc\n\ncd ../gitolite-admin\ncat conf/gitolite.conf\nperl s/.*marker 01.*//;\nput conf/gitolite.conf\nadd conf; commit -m erdel; ok; PUSH admin; ok\n\nglt ls-remote u4 file:///foo-pc\n# see rant below at this point\n\ncd $h/repositories/foo-pc.git\ngit branch -D secret-2\ngit tag -d s2t1 s2t2\ngit gc --prune=now\nglt ls-remote u4 file:///foo-pc\n# only *now* does the rant get addressed\n\n__END__\n\nRANT...\n\nThis is where things go all screwy.  Because we still have the *objects*\npointed to by tags s2t1 and s2t2, we still get them back from the main repo.\n"
  },
  {
    "path": "t/perm-default-roles.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\n# permissions using role names\n# ----------------------------------------------------------------------\n\ntry \"plan 33\";\ntry \"DEF POK = !/DENIED/; !/failed to push/\";\n\nmy $rb = `gitolite query-rc -n GL_REPO_BASE`;\n\ntry \"pwd\";\nmy $od = text();\nchomp($od);\n\nmy $t;\n\nconfreset; confadd '\n    @g1 = u1\n    @g2 = u2\n    @g3 = u3\n    @g4 = u4\n        repo foo/CREATOR/..*\n          C                 =   @g1 @g2\n          RW+               =   CREATOR\n          -     refs/tags/  =   WRITERS\n          RW                =   WRITERS\n          R                 =   READERS\n\n        repo bar/CREATOR/..*\n          C                 =   @g3 @g4\n          RW+               =   CREATOR\n          -     refs/tags/  =   WRITERS\n          RW                =   WRITERS\n          R                 =   READERS\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\n# create repos - 1; no gl-perms files expected\ntry \"\n\ncd ..\n\n# make foo/u1/u1r1\nglt clone u1 file:///foo/u1/u1r1\n        /Initialized empty Git repository in .*/foo/u1/u1r1.git//\n\n# make bar/u3/u3r1\nglt clone u3 file:///bar/u3/u3r1\n        /Initialized empty Git repository in .*/bar/u3/u3r1.git//\n\ncd u3r1\n\";\n\ntry \"cd $rb; find . -name gl-perms; cd $od\"; cmp text(), '';\n\n# enable set-default-roles feature\ntry \"\n    cat $ENV{HOME}/.gitolite.rc\n    perl s/# 'set-default-roles'/'set-default-roles'/\n    put $ENV{HOME}/.gitolite.rc\n\";\n\n# create repos - 2; empty gl-perms files expected\ntry \"\n\ncd ..\n\n# make foo/u1/u1r2\nglt clone u1 file:///foo/u1/u1r2\n        /Initialized empty Git repository in .*/foo/u1/u1r2.git//\n\n# make bar/u3/u3r2\nglt clone u3 file:///bar/u3/u3r2\n        /Initialized empty Git repository in .*/bar/u3/u3r2.git//\n\ncd u3r2\n\";\n\ntry \"cd $rb; find . -name gl-perms\";\n$t = md5sum(sort (lines()));\ncmp $t, 'd41d8cd98f00b204e9800998ecf8427e  ./bar/u3/u3r2.git/gl-perms\nd41d8cd98f00b204e9800998ecf8427e  ./foo/u1/u1r2.git/gl-perms\n';\ntry \"cd $od\";\n\n# enable per repo default roles\nconfadd '\n        repo foo/CREATOR/..*\n        option default.roles-1  =   READERS u3\n        option default.roles-2  =   WRITERS u4\n\n        repo bar/CREATOR/..*\n        option default.roles-1  =   READERS u5\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\n# create repos - 3; filled gl-perms expected\ntry \"\n\ncd ..\n\ngitolite access foo/u1/u1r3 u4 W\n        !ok\n        !/refs/../\n        /W any foo/u1/u1r3 u4 DENIED by fallthru/\n\n# make foo/u1/u1r3\nglt clone u1 file:///foo/u1/u1r3\n        /Initialized empty Git repository in .*/foo/u1/u1r3.git//\n\ngitolite access foo/u1/u1r3 u4 W\n        ok\n        /refs/../\n        !/W any foo/u1/u1r3 u4 DENIED by fallthru/\n\n# make bar/u3/u3r3\nglt clone u3 file:///bar/u3/u3r3\n        /Initialized empty Git repository in .*/bar/u3/u3r3.git//\n\ncd u3r3\n\";\n\ntry \"cd $rb; find . -name gl-perms\";\n$t = md5sum(sort (lines()));\ncmp $t, 'd41d8cd98f00b204e9800998ecf8427e  ./bar/u3/u3r2.git/gl-perms\nb09856c1addc8e46f6ce0d21a666a633  ./bar/u3/u3r3.git/gl-perms\nd41d8cd98f00b204e9800998ecf8427e  ./foo/u1/u1r2.git/gl-perms\n1b5af29692fad391318573bbe633b476  ./foo/u1/u1r3.git/gl-perms\n';\ntry \"cd $od\";\n\n# add perms to an old repo\ntry \"\necho WRITERS \\@h1 | glt perms u1 -c foo/u1/u1r1\n\";\n\ntry \"cd $rb; find . -name gl-perms\";\n$t = md5sum(sort (lines()));\ncmp $t, 'd41d8cd98f00b204e9800998ecf8427e  ./bar/u3/u3r2.git/gl-perms\nb09856c1addc8e46f6ce0d21a666a633  ./bar/u3/u3r3.git/gl-perms\nf8f0fd8e139ddb64cd5572914b98750a  ./foo/u1/u1r1.git/gl-perms\nd41d8cd98f00b204e9800998ecf8427e  ./foo/u1/u1r2.git/gl-perms\n1b5af29692fad391318573bbe633b476  ./foo/u1/u1r3.git/gl-perms\n';\ntry \"cd $od\";\n\n# add perms to a new repo\ntry \"\necho WRITERS \\@h2 | glt perms u1 -c foo/u1/u1r4\n\";\n\ntry \"cd $rb; find . -name gl-perms\";\n$t = md5sum(sort (lines()));\ncmp $t, 'd41d8cd98f00b204e9800998ecf8427e  ./bar/u3/u3r2.git/gl-perms\nb09856c1addc8e46f6ce0d21a666a633  ./bar/u3/u3r3.git/gl-perms\nf8f0fd8e139ddb64cd5572914b98750a  ./foo/u1/u1r1.git/gl-perms\nd41d8cd98f00b204e9800998ecf8427e  ./foo/u1/u1r2.git/gl-perms\n1b5af29692fad391318573bbe633b476  ./foo/u1/u1r3.git/gl-perms\ndf17cd2d47e4d99642d7c5ce4093d115  ./foo/u1/u1r4.git/gl-perms\n';\ntry \"cd $od\";\n"
  },
  {
    "path": "t/perm-roles.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\n# permissions using role names\n# ----------------------------------------------------------------------\n\ntry \"plan 91\";\ntry \"DEF POK = !/DENIED/; !/failed to push/\";\n\nconfreset; confadd '\n    @g1 = u1\n    @g2 = u2\n    @g3 = u3\n    @g4 = u4\n        repo foo/CREATOR/..*\n          C                 =   @g1\n          RW+               =   CREATOR\n          -     refs/tags/  =   WRITERS\n          RW                =   WRITERS\n          R                 =   READERS\n          RW+D              =   MANAGERS\n          RW    refs/tags/  =   TESTERS\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"\n\ncd ..\n\n# make foo/u1/u1r1\nrm -rf ~/td/u1r1\nglt clone u1 file:///foo/u1/u1r1\n        /Initialized empty Git repository in .*/foo/u1/u1r1.git//\ncd u1r1\n\n# CREATOR can push\ntc e-549 e-550\nglt push u1 file:///foo/u1/u1r1 master:master\n        POK; /master -> master/\n# CREATOR can create branch\ntc w-277 w-278\nglt push u1 file:///foo/u1/u1r1 master:b1\n        POK; /master -> b1/\n# CREATOR can rewind branch\ngit reset --hard HEAD^\ntc d-987 d-988\nglt push u1 file:///foo/u1/u1r1 +master:b1\n        POK; /master -> b1 \\\\(forced update\\\\)/\n# CREATOR cannot delete branch\nglt push u1 file:///foo/u1/u1r1 :b1\n        /D refs/heads/b1 foo/u1/u1r1 u1 DENIED by fallthru/\n        reject\n\n# CREATOR can push a tag\ngit tag t1 HEAD^^\nglt push u1 file:///foo/u1/u1r1 t1\n        POK; /\\\\[new tag\\\\]         t1 -> t1/\n\n# add u2 to WRITERS\necho WRITERS \\@g2 | glt perms u1 -c foo/u1/u1r1\nglt perms u1 foo/u1/u1r1 -l\n        /WRITERS \\@g2/\n\nglt fetch u1\ngit reset --hard origin/master\n\n# WRITERS can push\ntc j-185 j-186\nglt push u2 file:///foo/u1/u1r1 master:master\n        POK; /master -> master/\n# WRITERS can create branch\ntc u-420 u-421\nglt push u2 file:///foo/u1/u1r1 master:b2\n        POK; /master -> b2/\n# WRITERS cannot rewind branch\ngit reset --hard HEAD^\ntc l-136 l-137\nglt push u2 file:///foo/u1/u1r1 +master:b2\n        /\\\\+ refs/heads/b2 foo/u1/u1r1 u2 DENIED by fallthru/\n        reject\n# WRITERS cannot delete branch\nglt push u2 file:///foo/u1/u1r1 :b2\n        /D refs/heads/b2 foo/u1/u1r1 u2 DENIED by fallthru/\n        reject\n# WRITERS cannot push a tag\ngit tag t2 HEAD^^\nglt push u2 file:///foo/u1/u1r1 t2\n        /W refs/tags/t2 foo/u1/u1r1 u2 DENIED by refs/tags//\n        reject\n\n# change u2 to READERS\necho READERS u2 | glt perms u1 -c foo/u1/u1r1\nglt perms u1 foo/u1/u1r1 -l\n        /READERS u2/\n\nglt fetch u1\ngit reset --hard origin/master\n\n# READERS cannot push at all\ntc v-753 v-754\nglt push u2 file:///foo/u1/u1r1 master:master\n        /W any foo/u1/u1r1 u2 DENIED by fallthru/\n\n# add invalid category MANAGERS\n    /usr/bin/printf 'READERS u6\\\\nMANAGERS u2\\\\n' | glt perms u1 -c foo/u1/u1r1\n        !ok\n        /Invalid role 'MANAGERS'/\n\";\n\n# make MANAGERS valid\nput \"$ENV{HOME}/g3trc\", \"\\$rc{ROLES}{MANAGERS} = 1;\\n\";\n\n# add u2 to now valid MANAGERS\ntry \"\n    ENV G3T_RC=$ENV{HOME}/g3trc\n    gitolite compile;   ok or die compile failed\n    /usr/bin/printf 'READERS u6\\\\nMANAGERS u2\\\\n' | glt perms u1 -c foo/u1/u1r1\n                            ok;    !/Invalid role 'MANAGERS'/\n    glt perms u1 foo/u1/u1r1 -l\n\";\n\ncmp 'READERS u6\nMANAGERS u2\n';\n\ntry \"\nglt fetch u1\ngit reset --hard origin/master\n\n# MANAGERS can push\ntc d-714 d-715\nglt push u2 file:///foo/u1/u1r1 master:master\n        POK; /master -> master/\n\n# MANAGERS can create branch\ntc n-614 n-615\nglt push u2 file:///foo/u1/u1r1 master:b3\n        POK; /master -> b3/\n# MANAGERS can rewind branch\ngit reset --hard HEAD^\ntc a-511 a-512\nglt push u2 file:///foo/u1/u1r1 +master:b3\n        POK; /master -> b3 \\\\(forced update\\\\)/\n# MANAGERS cannot delete branch\nglt push u2 file:///foo/u1/u1r1 :b3\n        / - \\\\[deleted\\\\]         b3/\n# MANAGERS can push a tag\ngit tag t3 HEAD^^\nglt push u2 file:///foo/u1/u1r1 t3\n        POK; /\\\\[new tag\\\\]         t3 -> t3/\n\n# add invalid category TESTERS\necho TESTERS u2 | glt perms u1 -c foo/u1/u1r1\n        !ok\n        /Invalid role 'TESTERS'/\n\";\n\n# make TESTERS valid\nput \"|cat >> $ENV{HOME}/g3trc\", \"\\$rc{ROLES}{TESTERS} = 1;\\n\";\n\ntry \"\ngitolite compile;   ok or die compile failed\n# add u2 to now valid TESTERS\necho TESTERS u2 | glt perms u1 -c foo/u1/u1r1\n        !/Invalid role 'TESTERS'/\nglt perms u1 foo/u1/u1r1 -l\n\";\n\ncmp 'TESTERS u2\n';\n\ntry \"\nglt fetch u1\ngit reset --hard origin/master\n\n# TESTERS cannot push\ntc d-134 d-135\nglt push u2 file:///foo/u1/u1r1 master:master\n        /W refs/heads/master foo/u1/u1r1 u2 DENIED by fallthru/\n        reject\n# TESTERS cannot create branch\ntc p-668 p-669\nglt push u2 file:///foo/u1/u1r1 master:b4\n        /W refs/heads/b4 foo/u1/u1r1 u2 DENIED by fallthru/\n        reject\n# TESTERS cannot delete branch\nglt push u2 file:///foo/u1/u1r1 :b2\n        /D refs/heads/b2 foo/u1/u1r1 u2 DENIED by fallthru/\n        reject\n# TESTERS can push a tag\ngit tag t4 HEAD^^\nglt push u2 file:///foo/u1/u1r1 t4\n        POK; /\\\\[new tag\\\\]         t4 -> t4/\n\";\n\n# make TESTERS invalid again\nput \"$ENV{HOME}/g3trc\", \"\\$rc{ROLES}{MANAGERS} = 1;\\n\";\n\ntry \"\ngitolite compile;   ok or die compile failed\n# CREATOR can push\nglt fetch u1\ngit reset --hard origin/master\ntc y-626 y-627\nglt push u1 file:///foo/u1/u1r1 master:master\n        POK; /master -> master/\n# TESTERS is an invalid category\ngit tag t5 HEAD^^\nglt push u2 file:///foo/u1/u1r1 t5\n        /role 'TESTERS' not allowed, ignoring/\n        /W any foo/u1/u1r1 u2 DENIED by fallthru/\n\";\n"
  },
  {
    "path": "t/perms-groups.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\n# assigning roles to groups instead of users\n# ----------------------------------------------------------------------\n\ntry \"plan 31\";\n\ntry \"DEF POK = !/DENIED/; !/failed to push/\";\n\nconfreset; confadd '\n    @leads = u1 u2\n    @devs = u1 u2 u3 u4\n\n    @gbar = bar/CREATOR/..*\n    repo    @gbar\n        C               =   @leads\n        RW+             =   CREATOR\n        RW              =   WRITERS\n        R               =   READERS\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"\n\n    # u1 auto-creates a repo\n    glt ls-remote u1 file:///bar/u1/try1\n        /Initialized empty Git repository in .*/bar/u1/try1.git//\n    # default permissions for u2 and u4\n    glt info u1 -lc\n        /R W *\\tbar/u1/try1\\tu1/\n    glt info u2 -lc\n        !/R W *\\tbar/u1/try1\\tu1/\n    glt info u4 -lc\n        !/R W *\\tbar/u1/try1\\tu1/\n\n    # \\@leads can RW try1\n    echo WRITERS \\@leads | glt perms u1 -c bar/u1/try1; ok\n    glt info u1 -lc\n        /R W *\\tbar/u1/try1\\tu1/\n    glt info u2 -lc\n        /R W *\\tbar/u1/try1\\tu1/\n    glt info u4 -lc\n        !/R W *\\tbar/u1/try1\\tu1/\n\n    # \\@devs can R try1\n    echo READERS \\@devs | glt perms u1 -c bar/u1/try1; ok\n    glt perms u1 bar/u1/try1 -l\n        /READERS \\@devs/\n        !/WRITERS \\@leads/\n\n    glt info u1 -lc\n        /R W *\\tbar/u1/try1\\tu1/\n\n    glt info u2 -lc\n        !/R W *\\tbar/u1/try1\\tu1/\n        /R *\\tbar/u1/try1\\tu1/\n\n    glt info u4 -lc\n        !/R W *\\tbar/u1/try1\\tu1/\n        /R *\\tbar/u1/try1\\tu1/\n\n# combo of previous 2\n    /usr/bin/printf 'READERS \\@devs\\\\nWRITERS \\@leads\\\\n' | glt perms u1 -c bar/u1/try1; ok\n    glt perms u1 bar/u1/try1 -l\n        /READERS \\@devs/\n        /WRITERS \\@leads/\n    glt info u1 -lc\n        /R W *\\tbar/u1/try1\\tu1/\n    glt info u2 -lc\n        /R W *\\tbar/u1/try1\\tu1/\n    glt info u4 -lc\n        !/R W *\\tbar/u1/try1\\tu1/\n        /R *\\tbar/u1/try1\\tu1/\n\";\n"
  },
  {
    "path": "t/personal-branches.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\n# personal branches\n# ----------------------------------------------------------------------\n\ntry \"plan 64\";\n\nconfreset;confadd '\n    @admins     =   admin dev1\n    repo gitolite-admin\n        RW+     =   admin\n\n    repo testing\n        RW+     =   @all\n\n    @g1 = t1\n    repo @g1\n        R               =   u2\n        RW              =   u3\n        RW+             =   u4\n        RW  a/USER/     =   @all\n        RW+ p/USER/     =   u1 u6\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"\n\n    gitolite access t1 u1;                              ok;     /refs/heads/p/u1//; !/DENIED/\n    gitolite access t1 u5;                              !ok;    /\\\\+ any t1 u5 DENIED by fallthru/\n    gitolite access \\@g1 u5 W;                          ok;     /refs/heads/a/u5//; !/DENIED/\n\n    gitolite access t1 u1 W refs/heads/a/user1/foo;     !ok;    /W refs/heads/a/user1/foo t1 u1 DENIED by fallthru/\n    gitolite access \\@g1 u1 + refs/heads/a/user1/foo;   !ok;    /\\\\+ refs/heads/a/user1/foo \\@g1 u1 DENIED by fallthru/\n    gitolite access t1 u1 W refs/heads/p/user1/foo;     !ok;    /W refs/heads/p/user1/foo t1 u1 DENIED by fallthru/\n    gitolite access \\@g1 u1 + refs/heads/p/user1/foo;   !ok;    /\\\\+ refs/heads/p/user1/foo \\@g1 u1 DENIED by fallthru/\n\n    gitolite access \\@g1 u1 W refs/heads/a/u1/foo;      ok;     /refs/heads/a/u1//; !/DENIED/\n    gitolite access t1 u1 + refs/heads/a/u1/foo;        !ok;    /\\\\+ refs/heads/a/u1/foo t1 u1 DENIED by fallthru/\n    gitolite access \\@g1 u1 W refs/heads/p/u1/foo;      ok;     /refs/heads/p/u1//; !/DENIED/\n    gitolite access t1 u1 + refs/heads/p/u1/foo;        ok;     /refs/heads/p/u1//; !/DENIED/\n\n    gitolite access \\@g1 u1 W refs/heads/p/u2/foo;      !ok;    /W refs/heads/p/u2/foo \\@g1 u1 DENIED by fallthru/\n    gitolite access t1 u1 + refs/heads/p/u2/foo;        !ok;    /\\\\+ refs/heads/p/u2/foo t1 u1 DENIED by fallthru/\n\";\n\nconfreset; confadd '\n    @staff = u1 u2 u3 u4 u5 u6\n    @gfoo = foo\n    repo  @gfoo\n          RW+                       = u1 u2\n          RW+   p/USER/             = u3 u4\n          RW    temp                = u5 u6\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"\n    DEF OK  =   gitolite access foo %1 %2 refs/heads/%3;    ok\n    DEF NOK =   gitolite access foo %1 %2 refs/heads/%3;    !ok\n\";\n\ntry \"\n\n# u1 and u2 can push\n    OK  u1  W   master\n    OK  u2  W   master\n    OK  u2  W   p/u1/foo\n    OK  u1  W   p/u2/foo\n    OK  u1  W   p/u3/foo\n\n# u3 cant push u1/u4 personal branches\n    NOK u3  W   p/u1/foo\n    NOK u3  W   p/u4/doo\n\n# u4 can push u4 personal branch\n    OK  u4  W   p/u4/foo\n# u5 push temp\n    OK  u5  W   temp\n\n# u1 and u2 can rewind\n    OK  u1  +   master\n    OK  u2  +   p/u1/foo\n    OK  u1  +   p/u2/foo\n    OK  u1  +   p/u3/foo\n\n# u3 cant rewind u1/u4 personal branches\n    NOK u3  +   p/u1/foo\n    NOK u3  +   p/u4/foo\n# u4 can rewind u4 personal branch\n    OK  u4  +   p/u4/foo\n# u5 cant rewind temp\n    NOK u5  +   temp\n\";\n"
  },
  {
    "path": "t/reference.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\nmy $h = $ENV{HOME};\n\n# fork command\n# ----------------------------------------------------------------------\n\ntry \"plan 16\";\n\nmy $rb = `gitolite query-rc -n GL_REPO_BASE`;\n\ntry \"sed -ie 's%.Mirroring.,%\\\"Mirroring\\\",\\\\n\\\"create-with-reference\\\",%' ~/.gitolite.rc\";\n\nconfreset;confadd '\n\n    repo source\n        RW+ = u1 u2\n\n    repo fork\n        RW+ = u1 u2\n    option reference.repo = source\n\n    repo multifork\n        RW+ = u1 u2\n    option reference.repo-1 = source\n    option reference.repo-2 = fork\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \" # Verify files\n    # source doesn't have alternates\n    ls $rb/source.git/objects/info/alternates;  !ok\n\n    # fork has source as an alternate\n    ls $rb/fork.git/objects/info/alternates;   ok\n    cat $rb/fork.git/objects/info/alternates;  ok;  /$rb/source.git/objects/\n\n    # multifork has multiple alternates\n    ls $rb/multifork.git/objects/info/alternates;   ok\n    cat $rb/multifork.git/objects/info/alternates;  ok;  /$rb/source.git/objects/\n                                                         /$rb/fork.git/objects/\n\";\n"
  },
  {
    "path": "t/refex-expr-test-1",
    "content": "#!/bin/bash\n\n# not part of the official test suite (yet); just some q&d testing\n\n# to be run from ~/gitolite as ./$0\n\nset -e\nexec 3>&2\nexec > /dev/null\nexec 2> /dev/null\nprint2() { echo -n \"$@\" >&3; }\nsay2() { echo \"$@\" >&3; }\ndie() { echo FATAL: \"$@\" >&3; exit 1; }\n\nexport od=$PWD\nexport tmp=$(mktemp -d)\necho $tmp >&3\ntrap \"rm -rf $tmp\" 0\ncd $tmp\n\nprint2 setting up...\n( cd $od; t/reset )\necho \"push @{ \\$RC{ENABLE} }, 'refex-expr';\" >> ~/.gitolite.rc\ncat <<EOF >> ~/.gitolite/conf/gitolite.conf\n\nrepo r1\n    RW+                                 =   u1 u2   # line 1\n\n    RW+ master                          =   u3 u4   # line 2\n    RW+                                 =   u3 u4   # line 3\n    RW+ VREF/NAME/Makefile              =   u3 u4   # line 4\n    -   master and VREF/NAME/Makefile   =   u3 u4   # line 5\n\nEOF\ngitolite setup\nsay2 done\n\n# ----------------------------------------------------------------------\n\nrm -rf u1\ngit clone u1:r1 u1\ncd u1\ntsh 'tc f1'\ngit push u1:r1 master\ntsh 'tc f2'\ngit push u2:r1 master\ntsh 'tc f3'\ngit push u3:r1 master\ntsh 'tc f4'\ngit push u4:r1 master\nsay2 everyone master no Makefile\n\ntsh 'tc f5 Makefile'\ngit push u1:r1 master\ntsh 'tc f5 Makefile'\ngit push u1:r1 master:m1\nsay2 u1 Makefile master\n\ntsh 'tc f5 Makefile'\ngit push u3:r1 master && die u3 r1 master should have failed\ngit push u3:r1 master:m2\nsay2 u3 Makefile master fail m2 pass\n"
  },
  {
    "path": "t/refex-expr-test-2",
    "content": "#!/bin/bash\n\n# not part of the official test suite (yet); just some q&d testing\n\n# to be run from ~/gitolite as ./$0\n\nset -e\nexec 3>&2\nexec > /dev/null\nexec 2> /dev/null\nprint2() { echo -n \"$@\" >&3; }\nsay2() { echo \"$@\" >&3; }\ndie() { echo FATAL: \"$@\" >&3; exit 1; }\n\nexport od=$PWD\nexport tmp=$(mktemp -d)\necho $tmp >&3\ntrap \"rm -rf $tmp\" 0\ncd $tmp\n\nprint2 setting up...\n( cd $od; t/reset )\necho \"push @{ \\$RC{ENABLE} }, 'refex-expr';\" >> ~/.gitolite.rc\ncat <<EOF >> ~/.gitolite/conf/gitolite.conf\n\n    repo    r2\n        RW+                         =   @all\n\n        RW+ VREF/NAME/doc/                      =   u2\n        RW+ VREF/NAME/src/                      =   u2\n        -   VREF/NAME/doc/ and VREF/NAME/src/   =   u2\n\nEOF\ngitolite setup\nsay2 done\n\n# ----------------------------------------------------------------------\n\ngit clone u2:r2\ncd r2\n\ntsh 'tc aa'\ngit push origin master\nsay2 aa pass\n\nmkdir doc src\n\ntsh 'tc doc/d1'\ngit push origin master\nsay2 doc pass\n\ntsh 'tc src/s1'\ntsh 'tc src/s2'\ngit push origin master\nsay2 src src pass\n\ntsh 'tc doc/d2 src/s3'\ngit push origin master && die 1\ngit push u1:r2 master\nsay2 doc src u2 fail u1 pass\n"
  },
  {
    "path": "t/refex-expr-test-3",
    "content": "#!/bin/bash\n\n# not part of the official test suite (yet); just some q&d testing\n\n# to be run from ~/gitolite as ./$0\n\nset -e\nexec 3>&2\nexec > /dev/null\nexec 2> /dev/null\nprint2() { echo -n \"$@\" >&3; }\nsay2() { echo \"$@\" >&3; }\ndie() { echo FATAL: \"$@\" >&3; exit 1; }\n\nexport od=$PWD\nexport tmp=$(mktemp -d)\necho $tmp >&3\ntrap \"rm -rf $tmp\" 0\ncd $tmp\n\nprint2 setting up...\n( cd $od; t/reset )\necho \"push @{ \\$RC{ENABLE} }, 'refex-expr';\" >> ~/.gitolite.rc\ncat <<EOF >> ~/.gitolite/conf/gitolite.conf\n\n    repo    r3\n        RW+                         =   u1 u2 u3\n\n        RW+ VREF/NAME/conf/         =   u3\n        -   VREF/NAME/conf/ -gt 2   =   u3\n\nEOF\ngitolite setup\nsay2 done\n\n# ----------------------------------------------------------------------\n\ngit clone u3:r3\ncd r3\n\ntsh 'tc aa'\ngit push origin master\nsay2 aa pass\n\nmkdir doc conf\n\ntsh 'tc doc/d1 doc/d2 doc/d3 doc/d4 conf/c1'\ngit push origin master\nsay2 4 doc 1 conf pass\n\ntsh 'tc conf/c2 conf/c3 conf/c4'\ngit push origin master && die 1\n\ngit push u2:r3 master\nsay2 3 conf u3 fail u2 pass\n"
  },
  {
    "path": "t/refex-expr-test-9",
    "content": "#!/bin/bash\n\n# not part of the official test suite (yet); just some q&d testing\n\n# to be run from ~/gitolite as ./$0\n\nset -e\nexec 3>&2\nexec > /dev/null\nexec 2> /dev/null\nprint2() { echo -n \"$@\" >&3; }\nsay2() { echo \"$@\" >&3; }\ndie() { echo FATAL: \"$@\" >&3; exit 1; }\n\nexport od=$PWD\nexport tmp=$(mktemp -d)\necho $tmp >&3\ntrap \"rm -rf $tmp\" 0\ncd $tmp\n\nprint2 setting up...\n( cd $od; t/reset )\necho \"push @{ \\$RC{ENABLE} }, 'refex-expr';\" >> ~/.gitolite.rc\ncat <<EOF >> ~/.gitolite/conf/gitolite.conf\n\nrepo r9\n\n    RW+                         =   u3 u4\n\n    # u1 and u2 have some restrictions\n\n    # cant push master\n    -   master                  =   u1 u2\n    # cant push versioned tags, but other tags are fine\n    -   refs/tags/v[0-9]        =   u1 u2\n    # everything else is fine, but we need to recognise when they're pushing\n    # tags, so that the refex expr will have the correct info\n    RW+ refs/tags/              =   u1 u2\n    RW+                         =   u1 u2\n\n    # can push files in \"foo/\" only to a tag\n    RW+ VREF/NAME/foo/          =   u1 u2\n\n    RW+ VREF/NAME/foo/ and refs/tags/  =   u1 u2\n    -   VREF/NAME/foo/ and not refs/tags/ = u1 u2\n\nEOF\ngitolite setup\nsay2 done\n\n# ----------------------------------------------------------------------\n\n# make sure u3 is not constrained in any way\n\ngit clone u3:r9 refex-test.repo\ncd refex-test.repo\n\ntsh 'tc u3-f1'\ngit pom\n\nmkdir bar foo\ntsh 'tc bar/thr'\ngit pom\ngit tag v3\ngit push origin v3\ntsh 'tc foo/rht'\ngit pom\ngit tag 3v\ngit push origin 3v\n\nsay2 u3 no limits\n\n# now test u1's constraints\n\ncd ..\nrm -rf refex-test.repo\n\nrm -rf ~/repositories/r9.git\ngitolite setup\n\ngit clone u1:r9 refex-test.repo\ncd refex-test.repo\n\ntsh 'tc u1-f1'\n# cant push master\ngit pom && die 1\n# can push other branches\ngit push origin master:m1\nsay2 master fail m1 pass\n\nmkdir bar foo\ntsh 'tc bar/one'\ngit push origin master:m1\ngit tag v1\n# cant push v-tag\ngit push origin v1 && die 2\nsay2 v-tag fail\n\n# cant push foo/ to a branch\ntsh 'tc foo/eno'\ngit push origin master:m1 && die 3\nsay2 foo/ m1 fail\n\n# but can push to a non-v-tag\ngit tag 1v\ngit push origin 1v\nsay2 foo/ non-v-tag pass\n"
  },
  {
    "path": "t/repo-specific-hooks.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\n# test script for partial copy feature\n# ----------------------------------------------------------------------\n\ntry \"plan 128\";\nmy $h = $ENV{HOME};\nmy $rb = `gitolite query-rc -n GL_REPO_BASE`;\n\ntry 'cd tsh_tempdir; mkdir -p local/hooks/repo-specific';\n\nforeach my $h (qw/first second/) {\n    put \"local/hooks/repo-specific/$h\", \"#!/bin/sh\necho \\$0\nif [ \\$# -ne 0 ]; then\n    echo \\$0 has args: \\$@\nelse\n    echo \\$0 has stdin: `cat`\nfi\n\";\n}\ntry 'chmod +x local/hooks/repo-specific/*';\n\ntry 'pwd';\nmy $tempdir = join(\"\\n\", sort (lines()));\ntry 'cd gitolite-admin';\n\ntry \"# Enable LOCAL_CODE and repo-specific-hooks\n    cat $h/.gitolite.rc\n    perl s/# 'repo-specific-hooks'/'repo-specific-hooks'/\n    perl s%# LOCAL_CODE%LOCAL_CODE => '$tempdir/local', #%\n    put $h/.gitolite.rc\n\";\n\nconfreset;confadd '\n    repo foo\n            RW+                 =   @all\n\n    repo bar\n            RW+                 =   @all\n\n    repo baz\n            RW+                 =   @all\n\n    repo frob\n            RW+                 =   @all\n';\n\ntry \"ADMIN_PUSH repo-specific-hooks-0; !/FATAL/\" or die text();\n\ntry \"\n    /Init.*empty.*foo\\\\.git/\n    /Init.*empty.*bar\\\\.git/\n    /Init.*empty.*baz\\\\.git/\n    /Init.*empty.*frob\\\\.git/\n\";\n\nmy $failing_hook = \"#!/bin/sh\nexit 1\n\";\n\n# Place a existing hooks in repos\nput \"$rb/foo.git/hooks/post-recieve\", $failing_hook;\nput \"$rb/bar.git/hooks/pre-recieve\", $failing_hook;\nput \"$rb/baz.git/hooks/post-update\", $failing_hook;\nput \"$rb/frob.git/hooks/post-update\", $failing_hook;\n\ntry \"# Verify hooks\n    ls -l $rb/foo.git/hooks/*;  ok;     !/post-receive -. .*local/hooks/multi-hook-driver/\n    ls -l $rb/bar.git/hooks/*;  ok;     !/pre-receive -. .*local/hooks/multi-hook-driver/\n    ls -l $rb/baz.git/hooks/*;  ok;     !/post-update -. .*local/hooks/multi-hook-driver/\n    ls -l $rb/frob.git/hooks/*; ok;     !/post-update -. .*local/hooks/multi-hook-driver/\n\";\n\nconfreset;confadd '\n    repo foo\n            RW+                 =   @all\n            option hook.post-receive =  first\n\n    repo bar\n            RW+                 =   @all\n            option hook.pre-receive =  first second\n\n    repo baz\n            RW+                 =   @all\n            option hook.post-receive =  first\n            option hook.post-update =  first second\n\n    repo frob\n            RW+                 =   @all\n            option hook.post-receive.b      =   first\n            option hook.post-receive.a      =   second\n\n    repo gitolite-admin\n            option hook.post-receive = second\n';\n\n\ntry \"ADMIN_PUSH repo-specific-hooks-1; !/FATAL/\" or die text();\n\ntry \"# Verify hooks\n    ls -l $rb/foo.git/hooks/*;  ok;     /post-receive.h00-first/\n                                       !/post-receive.h01/\n                                        /post-receive -. .*local/hooks/multi-hook-driver/\n    ls -l $rb/bar.git/hooks/*;  ok;     /pre-receive.h00-first/\n                                        /pre-receive.h01-second/\n                                        /pre-receive -. .*local/hooks/multi-hook-driver/\n    ls -l $rb/baz.git/hooks/*;  ok;     /post-receive.h00-first/\n                                        /post-update.h00-first/\n                                        /post-update.h01-second/\n                                        /post-update -. .*local/hooks/multi-hook-driver/\n    ls -l $rb/frob.git/hooks/*; ok;     /post-receive.h00-second/\n                                        /post-receive.h01-first/\n                                        /post-receive -. .*local/hooks/multi-hook-driver/\n    ls -l $rb/gitolite-admin.git/hooks/*\n                                ok;     /post-receive.h/\n                                        /post-receive -. .*local/hooks/multi-hook-driver/\n                                       !/post-update -. .*local/hooks/multi-hook-driver/\n\";\n\ntry \"\n    cd ..\n\n    # Single hook still works\n    [ -d foo ];            !ok;\n    CLONE admin foo;        ok; /empty/; /cloned/\n    cd foo\n    tc a1;                  ok; /ee47f8b/\n    PUSH admin master;      ok; /new.*master -. master/\n                                /hooks/post-receive.h00-first/\n                                !/post-receive.*has args:/\n                                /post-receive.h00-first has stdin: 0000000000000000000000000000000000000000 ee47f8b6be2160ad1a3f69c97a0cb3d488e6657e refs/heads/master/\n\n    cd ..\n\n    # Multiple hooks fired\n    [ -d bar ];            !ok;\n    CLONE admin bar;        ok; /empty/; /cloned/\n    cd bar\n    tc a2;                  ok; /cfc8561/\n    PUSH admin master;      ok; /new.*master -. master/\n                                /hooks/pre-receive.h00-first/\n                                !/hooks/pre-recieve.*has args:/\n                                /hooks/pre-receive.h00-first has stdin: 0000000000000000000000000000000000000000 cfc8561c7827a8b94df6c5dad156383d4cb210f5 refs/heads/master/\n                                /hooks/pre-receive.h01-second/\n                                !/hooks/pre-receive.h01.*has args:/\n                                /hooks/pre-receive.h01-second has stdin: 0000000000000000000000000000000000000000 cfc8561c7827a8b94df6c5dad156383d4cb210f5 refs/heads/master/\n\n    cd ..\n\n    # Post-update has stdin instead of arguments\n    [ -d baz ];            !ok;\n    CLONE admin baz;        ok; /empty/; /cloned/\n    cd baz\n    tc a3;                  ok; /2863617/\n    PUSH admin master;      ok; /new.*master -. master/\n                                /hooks/post-receive.h00-first/\n                                !/hooks/post-receive.h00.*has args:/\n                                /hooks/post-receive.h00-first has stdin: 0000000000000000000000000000000000000000 28636171ae703f42fb17c312c6b6a078ed07a2cd refs/heads/master/\n                                /hooks/post-update.h00-first/\n                                /hooks/post-update.h00-first has args: refs/heads/master/\n                                !/hooks/post-update.h00.*has stdin:/\n                                /hooks/post-update.h01-second/\n                                /hooks/post-update.h01-second has args: refs/heads/master/\n                                !/hooks/post-update.h01.*has stdin:/\n\";\n\n# Verify hooks are removed properly\n\nconfadd '\n    repo foo\n            RW+                 =   @all\n            option hook.post-receive = \"\"\n\n    repo bar\n            RW+                 =   @all\n            option hook.pre-receive =  second\n\n    repo baz\n            RW+                 =   @all\n            option hook.post-receive = \"\"\n            option hook.post-update =  second\n';\n\ntry \"ADMIN_PUSH repo-specific-hooks-02; !/FATAL/\" or die text();\n\ntry \"\n    ls $rb/foo.git/hooks/*;  ok;    !/post-receive.h0/\n    ls $rb/bar.git/hooks/*;  ok;    !/pre-receive.*first/\n                                     /pre-receive.h00-second/\n    ls $rb/baz.git/hooks/*;  ok;    !/post-receive.h0/\n                                    !/post-update.*first/\n                                     /post-update.h00-second/\n\";\n\ntry \"\n    cd ..\n\n    # Foo has no hooks\n    cd foo\n    tc b1;                  ok; /7ef69de/\n    PUSH admin master;      ok; /master -. master/\n                                !/hooks/post-receive/\n\n    cd ..\n\n    # Bar only has the second hook\n    cd bar\n    tc b2;                  ok; /cc7808f/\n    PUSH admin master;      ok; /master -. master/\n                                /hooks/pre-receive.h00-second/\n                                !/hooks/pre-receive.*has args:/\n                                /hooks/pre-receive.h00-second has stdin: cfc8561c7827a8b94df6c5dad156383d4cb210f5 cc7808f77c7c7d705f82dc54dc3152146175768f refs/heads/master/\n\n    cd ..\n\n    # Baz has no post-receive and keeps the second hook for post-update\n    cd baz\n    tc b3;                  ok; /8d20101/\n    PUSH admin master;      ok; /master -. master/\n                                !/hooks/post-receive.*/\n                                /hooks/post-update.h00-second/\n                                /hooks/post-update.h00-second has args: refs/heads/master/\n                                !/hooks/post-update.*has stdin/\n\";\n"
  },
  {
    "path": "t/reset",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nBEGIN {\n    unlink \"$ENV{HOME}/.ssh/authorized_keys\";\n}\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\nuse Cwd;\nmy $workdir = getcwd();\n\nconfreset;confadd '\nrepo foo/..*\n    C   =   u1 u2 u3\n    RW+ =   CREATOR\n    RW  =   WRITERS\n    R   =   READERS\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"\n    mkdir -p keydir\n    cp \\$HOME/.ssh/u*.pub keydir\n    cp \\$HOME/.ssh/admin.pub keydir\n    git add keydir\n    git commit -m 6k\n    glt push admin origin\n\";\n"
  },
  {
    "path": "t/rule-seq.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\n# rule sequence\n# ----------------------------------------------------------------------\n\n# this is the specific example in commit 32056e0 of g2\n\ntry \"plan 27\";\n\ntry \"DEF POK = !/DENIED/; !/failed to push/\";\n\nconfreset; confadd '\n    @private-owners = u1 u2\n    @experienced-private-owners = u3 u4\n\n    repo CREATOR/.*\n      C   = @private-owners @experienced-private-owners\n      RWD = CREATOR\n      RW  = WRITERS\n      R   = READERS\n      -   = @private-owners\n      RW+D = CREATOR\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"\n    cd ..\n    glt clone u1 file:///u1/r1\n        /Initialized empty Git repository in .*/u1/r1.git//\n    cd r1\n    tc h-395\n    glt push u1 origin master\n    git checkout -b br1\n    tc m-367\n    tc i-747\n\n    # u1 create branch\n    glt push u1 origin br1\n        /\\\\* \\\\[new branch\\\\]      br1 -> br1/\n        POK; /br1 -> br1/\n\n    # u1 rewind branch\n    git reset --hard HEAD^\n    tc e-633\n    glt push u1 origin +br1\n        /\\\\+ refs/heads/br1 u1/r1 u1 DENIED by refs//\n        /error: hook declined to update refs/heads/br1/\n        reject\n\n    # u1 delete branch\n    glt push u1 origin :br1\n        /\\\\[deleted\\\\]         br1/\n\n    cd ..\n    rm -rf r1\n    glt clone u3 file:///u3/r1\n        /Initialized empty Git repository in .*/u3/r1.git//\n    cd r1\n    tc p-274\n    glt push u3 origin master\n    git checkout -b br1\n    tc s-613\n    tc k-988\n\n    # u3 create branch\n    glt push u3 origin br1\n        /\\\\* \\\\[new branch\\\\]      br1 -> br1/\n        POK; /br1 -> br1/\n\n    # u3 rewind branch\n    git reset --hard HEAD^\n    tc n-919\n    glt push u3 origin +br1\n        /To file:///u3/r1/\n        /\\\\+ .......\\\\.\\\\.\\\\........ br1 -> br1 \\\\(forced update\\\\)/\n\n    # u3 delete branch\n    glt push u3 origin :br1\n        /\\\\[deleted\\\\]         br1/\n\";\n"
  },
  {
    "path": "t/sequence.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\n# uhh, seems to be another rule sequence test\n# ----------------------------------------------------------------------\n\ntry \"plan 48\";\n\nconfreset;confadd '\n    @staff = u1 u2 u3\n    @gfoo = foo/CREATOR/..*\n    repo  @gfoo\n          C       = u1\n          RW+     = CREATOR\n          RW      = WRITERS\n          -       = @staff\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"\n    cd ..\n    glt clone u1 file:///foo/u1/bar;    ok\n        /Initialized empty Git repository in .*/foo/u1/bar.git//\n\n    cd bar\n    tc p-906\n    glt push u1 origin master\n        /To file:///foo/u1/bar/\n        /\\\\[new branch\\\\]      master -> master/\n    echo WRITERS u2 | glt perms u1 -c foo/u1/bar\n    glt perms u1 foo/u1/bar -l\n        /WRITERS u2/\n    # expand\n    glt info u2\n        /R W *\\tfoo/u1/bar/\n        /R W *\\ttesting/\n\n    # push\n    cd ..\n    glt clone u2 file:///foo/u1/bar u2bar\n        /Cloning into 'u2bar'.../\n    cd u2bar\n    tc p-222\n    glt push u2\n        /master -> master/\n        !/DENIED/\n        !/failed to push/\n\";\n\nconfreset;confadd '\n    @staff = u1 u2 u3\n    @gfoo = foo/CREATOR/..*\n    repo  @gfoo\n          C       = u1\n          RW+     = CREATOR\n          -       = @staff\n          RW      = WRITERS\n          R       = READERS\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"\n    cd ..\n    rm -rf bar u2bar\n    glt clone u1 file:///foo/u1/bar;    ok\n        /Initialized empty Git repository in .*/foo/u1/bar.git//\n\n    cd bar\n    tc p-906\n    glt push u1 origin master\n        /To file:///foo/u1/bar/\n        /\\\\[new branch\\\\]      master -> master/\n    echo WRITERS u2 | glt perms u1 -c foo/u1/bar\n    glt perms u1 foo/u1/bar -l\n        /WRITERS u2/\n    # expand\n    glt info u2\n        !/R W *\\tfoo/u1/baz/\n        /R W *\\tfoo/u1/bar/\n        /R W *\\ttesting/\n\n    # push\n    cd ..\n    glt clone u2 file:///foo/u1/bar u2bar\n        /Cloning into 'u2bar'.../\n    cd u2bar\n    tc p-222\n    glt push u2\n        !ok\n        reject\n        /W refs/heads/master foo/u1/bar u2 DENIED by refs/\\\\.\\\\*/\n\n    # auto-create using perms fail\n    echo READERS u5 | glt perms u4 -c foo/u4/baz\n        !/Initialized empty Git repository in .*/foo/u4/baz.git/\n        /FATAL: repo does not exist, or you are not authorised/\n\n    # auto-create using perms\n    echo READERS u2 | glt perms u1 -c foo/u1/baz\n        /Initialized empty Git repository in .*/foo/u1/baz.git/\n\n    glt perms u1 foo/u1/baz -l\n        /READERS u2/\n    # expand\n    glt info u2\n        /R   *\\tfoo/u1/baz/\n        /R W *\\tfoo/u1/bar/\n        /R W *\\ttesting/\n\";\n"
  },
  {
    "path": "t/smart-http",
    "content": "#!/bin/bash\n\ndie() { echo \"$@\"; exit 1; }\n\n# git clone `url u1 r1`\nurl() {\n    echo http://$1:$1@localhost/git/$2.git\n}\n\n# `cmd sitaram info`\ncmd() {\n    c=\"curl http://$1:$1@localhost/git\"\n    shift\n    c=\"$c/$1\"\n    shift\n\n    if [ -n \"$1\" ]\n    then\n        c=\"$c?$1\"\n        shift\n    fi\n    while [ -n \"$1\" ]\n    do\n        c=\"$c+$1\"\n        shift\n    done\n\n    echo $c\n}\n\nexport tmp=$(mktemp -d);\ntrap \"rm -rf $tmp\" 0;\ncd $tmp\n\ntsh \"plan 28\"\n\ntsh \"\n    ## ls-remote admin admin\n    git ls-remote `url admin gitolite-admin`\n        ok\n        /HEAD/\n        /refs.heads.master/\n    ## clone\n    git clone `url admin gitolite-admin`\n        ok\n        /Cloning into/\n    ls -al gitolite-admin/conf\n        /gitolite.conf/\n\" || die \"step 1\"\n\ncd gitolite-admin\necho repo t2 >> conf/gitolite.conf\necho 'RW+  = u1 u2' >> conf/gitolite.conf\n\ntsh \"\n    ## add, commit, push\n    git add conf/gitolite.conf\n        ok\n        !/./\n    git commit -m t2\n        ok\n        /1 file.*changed/\n    git push\n        ok\n        /Initialized.*gitolite-home.repositories.t2.git/\n        /To http:..localhost.git.gitolite-admin.git/\n        /master -. master/\n    ## various ls-remotes\n    git ls-remote `url u1 gitolite-admin`\n        !ok\n        /FATAL: R any gitolite-admin u1 DENIED by fallthru/\n    git ls-remote `url u1 t2`\n        ok\n        !/./\n    git ls-remote `url u2 t2`\n        ok\n        !/./\n    git ls-remote `url u3 t2`\n        !ok\n        /FATAL: R any t2 u3 DENIED by fallthru/\n    ## push to u1:t2\n    git push      `url u1 t2` master:master\n        ok\n        /To http:..localhost.git.t2.git/\n        /master -. master/\n    git ls-remote `url u2 t2`\n        ok\n        /HEAD/\n        /refs.heads.master/\n\" || die \"step 2\"\n"
  },
  {
    "path": "t/smart-http.root-setup",
    "content": "#!/bin/bash\n\n# ----------------------------------------------------------------------\n# please do not even LOOK at this file without reading doc/http.mkd\n# ----------------------------------------------------------------------\n\ndie() { echo \"$@\"; exit 1; }\n\n# scare the sh*t out of people who run it blindly\n[ -f /tmp/gitolite-smart-http-test-OK ] || {\n    # scary message\n    echo '+ rm -rf /'\n    # lots of disk activity\n    find / >/dev/null 2>/dev/null\n    # and it he's still clueless, God bless!\n    echo 'root file system erased successfully.  Goodbye and God bless!'\n    exit 1\n}\n\n# ----------------------------------------------------------------------\n# are we *BSD or Linux?\nuname_s=`uname -s`  # could be Linux or FreeBSD or some other BSD\nif [ \"$uname_s\" = \"Linux\" ]\nthen\n    bsd=:\nelse\n    lnx=:\nfi\n\n# ----------------------------------------------------------------------\n# main\n\n[ $EUID = 0 ] || die \"you must run this as root\"\n\n# delete any existing apache conf for gitolite\n$lnx rm /etc/httpd/conf.d/gitolite.conf\n$bsd rm /usr/local/etc/apache24/Includes/gitolite.conf\n\n# build your \"home within a home\"\n$lnx cd ~apache\n$bsd rm -rf /tmp/usr.share.httpd\n$bsd mkdir -p /tmp/usr.share.httpd\n$bsd chown www:www /tmp/usr.share.httpd\n$bsd cd /tmp/usr.share.httpd\n\nrm -rf gitolite-home\nmkdir gitolite-home\nexport GITOLITE_HTTP_HOME=$PWD/gitolite-home\n# WARNING: do not add a trailing slash to the value of GITOLITE_HTTP_HOME\n\n# get the gitolite sources\ncd gitolite-home\ngit clone /tmp/gitolite.git gitolite-source\n# NOTE: I use a bare repo in /tmp for convenience; you'd use\n# 'https://github.com/sitaramc/gitolite'\n\n# make the bin directory, and add it to PATH\ncd gitolite-source\nmkdir         $GITOLITE_HTTP_HOME/bin\n./install -ln $GITOLITE_HTTP_HOME/bin\nexport PATH=$PATH:$GITOLITE_HTTP_HOME/bin\n\n# come back to base, then run setup.  Notice that you have to point HOME to\n# the right place, even if it is just for this command\ncd $GITOLITE_HTTP_HOME\nHOME=$GITOLITE_HTTP_HOME gitolite setup -a admin\n\n# insert some essential lines at the beginning of the rc file\necho '$ENV{PATH} .= \":$ENV{GITOLITE_HTTP_HOME}/bin\";'  >> 1\necho >> 1\ncat .gitolite.rc >> 1\n\\mv 1 .gitolite.rc\n\n# fix up ownership\n$lnx chown -R apache:apache $GITOLITE_HTTP_HOME\n$bsd chown -R www:www $GITOLITE_HTTP_HOME\n\n# create the apache config.  Note the trailing slashes on the 2 ScriptAlias\n# lines.  (The second one is optional for most sites).  NOTE: you also need to\n# give the AuthUserFile a better name/location than what I have below.\ncat <<EOF1 > 1\nSetEnv GIT_PROJECT_ROOT $GITOLITE_HTTP_HOME/repositories\nScriptAlias /git/ $GITOLITE_HTTP_HOME/gitolite-source/src/gitolite-shell/\nScriptAlias /gitmob/ $GITOLITE_HTTP_HOME/gitolite-source/src/gitolite-shell/\nSetEnv GITOLITE_HTTP_HOME $GITOLITE_HTTP_HOME\nSetEnv GIT_HTTP_EXPORT_ALL\n\n<Location /git>\n    AuthType Basic\n    AuthName \"Private Git Access\"\n    Require valid-user\n    AuthUserFile $GITOLITE_HTTP_HOME/gitolite-http-authuserfile\n</Location>\nEOF1\n$lnx mv 1 /etc/httpd/conf.d/gitolite.conf\n$bsd mv 1 /usr/local/etc/apache24/Includes/gitolite.conf\n\n# NOTE: this is for testing only\nhtpasswd -bc $GITOLITE_HTTP_HOME/gitolite-http-authuserfile admin admin\nmap \"htpasswd -b $GITOLITE_HTTP_HOME/gitolite-http-authuserfile % %\" u{1..6}\n$lnx chown apache:apache $GITOLITE_HTTP_HOME/gitolite-http-authuserfile\n$bsd chown www:www $GITOLITE_HTTP_HOME/gitolite-http-authuserfile\n\n# restart httpd to make it pick up all the new stuff\n$lnx service httpd restart\n$bsd /usr/local/etc/rc.d/apache24 restart\n"
  },
  {
    "path": "t/ssh-authkeys.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\n# testing the (separate) authkeys handler\n# ----------------------------------------------------------------------\n\n$ENV{GL_BINDIR} = \"$ENV{PWD}/src\";\n\nmy $ak = \"$ENV{HOME}/.ssh/authorized_keys\";\nmkdir(\"$ENV{HOME}/.ssh\", 0700) if not -d \"$ENV{HOME}/.ssh\";\nmy $kd = `gitolite query-rc -n GL_ADMIN_BASE` . \"/keydir\";\n\ntry \"plan 49\";\n\nmy $pgm = \"gitolite ../triggers/post-compile/ssh-authkeys\";\n\ntry \"\n    # prep\n    rm -rf $ak;                 ok\n\n    $pgm;                       ok\n    mkdir $kd;                  ok\n    cd $kd;                     ok\n    $pgm;                       ok;     /authorized_keys missing/\n                                        /creating/\n    wc < $ak;                   ok;     /2 *6 *32/\n    # some gl keys\n    ssh-keygen -N '' -q -f alice -C alice\n    ssh-keygen -N '' -q -f bob   -C bob\n    ssh-keygen -N '' -q -f carol -C carol\n    ssh-keygen -N '' -q -f dave  -C dave    -t rsa\n    ssh-keygen -N '' -q -f eve   -C eve\n    rm alice bob carol dave eve\n    ls -a;                      ok;     /alice.pub/; /bob.pub/; /carol.pub/; /dave.pub/; /eve.pub/\n    $pgm;                       ok;\n    wc    < $ak;                ok;     /^ *7 .*/;\n    grep gitolite $ak;          ok;     /start/\n                                        /end/\n\n    # some normal keys\n    mv alice.pub $ak;           ok\n    cat carol.pub >> $ak;       ok\n    $pgm;                       ok;     /carol.pub duplicates.*non-gitolite key/\n    wc < $ak;                   ok;     /^ *8 .*/;\n\n    # moving normal keys up\n    mv dave.pub dave\n    $pgm;                       ok\n    cat dave >> $ak;            ok\n    grep -n dave $ak;           ok;     /8:ssh-rsa/\n    mv dave dave.pub\n    $pgm;                       ok;     /carol.pub duplicates.*non-gitolite key/\n                                         /dave.pub duplicates.*non-gitolite key/\n    grep -n dave $ak;           ok;     /3:ssh-rsa/\n\n    # a bad key\n    ls -al > bad.pub\n    $pgm;                       !ok;    /fingerprinting failed for \\\\'keydir/bad.pub\\\\'/\n    wc < $ak;                   ok;     /^ *9 .*/;\n    # a good key doesn't get added\n    ssh-keygen -N '' -q -f good\n    $pgm;                       !ok;    /fingerprinting failed for \\\\'keydir/bad.pub\\\\'/\n    wc < $ak;                   ok;     /^ *9 .*/;\n    # till the bad key is removed\n    rm bad.pub\n    $pgm;                       ok;\n    wc < $ak;                   ok;     /^ *10 .*/;\n\n    # duplicate gl key\n    cp bob.pub robert.pub\n    $pgm;                       ok;     /robert.pub duplicates.*bob.pub/\n\";\n"
  },
  {
    "path": "t/ssh-basic.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Common;\nuse Gitolite::Test;\n\n# basic tests using ssh\n# ----------------------------------------------------------------------\n\nmy $bd = `gitolite query-rc -n GL_BINDIR`;\nmy $h  = $ENV{HOME};\nmy $ab = `gitolite query-rc -n GL_ADMIN_BASE`;\numask 0077;\n\ntry \"\n    plan 26\n\n    # reset stuff\n    rm -f $h/.ssh/authorized_keys;          ok or die 1\n\n    cp $bd/../t/keys/u[1-6]* $h/.ssh;       ok or die 2\n    cp $bd/../t/keys/admin*  $h/.ssh;       ok or die 3\n    cp $bd/../t/keys/config  $h/.ssh;       ok or die 4\n        cat $h/.ssh/config\n        perl s/%USER/$ENV{USER}/\n        put $h/.ssh/config\n\n    mkdir                  $ab/keydir;      ok or die 5\n    cp $bd/../t/keys/*.pub $ab/keydir;      ok or die 6\n\";\n\nsystem(\"gitolite ../triggers/post-compile/ssh-authkeys\");\n\n# basic tests\n# ----------------------------------------------------------------------\n\nconfreset; confadd '\n    @g1 = u1\n    @g2 = u2\n    repo foo\n        RW = @g1 u3\n        R  = @g2 u4\n';\n\ntry \"ADMIN_PUSH set3; !/FATAL/\" or die text();\n\ntry \"\n    ssh u1 info;                ok;     /R W\\tfoo/\n    ssh u2 info;                ok;     /R  \\tfoo/\n    ssh u3 info;                ok;     /R W\\tfoo/\n    ssh u4 info;                ok;     /R  \\tfoo/\n    ssh u5 info;                ok;     !/foo/\n    ssh u6 info;                ok;     !/foo/\n\"\n"
  },
  {
    "path": "t/templates.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\nuse 5.10.0;\nuse Data::Dumper;\n\n# this is hardcoded; change it if needed\nuse lib \"$ENV{PWD}/src/lib\";\n\nuse Gitolite::Test;\n\nBEGIN {\n    $ENV{G3T_RC} = \"$ENV{HOME}/g3trc\";\n    put \"$ENV{G3T_RC}\", \"\\$rc{ROLES} = {\n        FORCERS => 1,\n        MASTERS => 1,\n        READERS => 1,\n        ROOT => 1,\n        TEAM => 1,\n        WRITERS => 1\n    }\";\n}\n\nuse Gitolite::Rc;\nuse Gitolite::Common;\nuse Gitolite::Conf::Load;\n\n# permissions using role names\n# ----------------------------------------------------------------------\n\ntry \"plan 1163\";\ntry \"DEF POK = !/DENIED/; !/failed to push/\";\n\n# basic push admin repo\nconfreset; confadd '\n# order is important for these next few repo group definitions, because an\n# individual repo may pick and choose any combination of them, and they should\n# apply sensibly.  In this example, \"BASE\" is pretty much required; the others\n# are optional.\n\n# if you want someone to have \"ultimate\" power over all refs in the repo,\n# add them to the ROOT role.\nrepo @BASE\n    RW+CD                       =   ROOT\n\n# add this to the repo group list to allow personal branches\nrepo @PERSONAL\n    RW+CD   dev/USER/           =   TEAM\n    -       dev/                =   TEAM\n    RW+CD   refs/tags/dev/USER/ =   TEAM\n    -       refs/tags/dev/      =   TEAM\n\n# add this to the repo group list to control tagging for release versions\nrepo @RELEASES\n    RWC refs/tags/v[0-9]        =   RELEASERS\n    -   refs/tags/v[0-9]        =   @all\n\n# (the basic set of access rules continues)\nrepo @BASE\n    # Note that \"FORCERS\" here, even though they have RW+CD,\n    #   1.  cannot touch other users personal branches or tags if you added\n    #       PER_BR to the repo group list, and\n    #   2.  create a release tag unless they are also in RELEASE_TAGGERS if\n    #       you added TAGS to the repo group list\n    RW+CD                       =   FORCERS\n    RWC master                  =   MASTERS\n    -   master                  =   @all\n    RWC                         =   RELEASERS MASTERS WRITERS\n    # Note you can define \"@all\" to have the READERS role, and then this will\n    # effectively be public (albeit authenticated public) readable.\n    R                           =   READERS\n\n=begin template-data\n\nrepo base = BASE\n    FORCERS = u1\n    MASTERS = u2\n    WRITERS = u3\n    READERS = u4\n\nrepo baseroot = BASE\n    ROOT    = admin\n    FORCERS = u1\n    MASTERS = u2\n    WRITERS = u3\n    READERS = u4\n\nrepo basepers = BASE PERSONAL\n    FORCERS = u1\n    MASTERS = u2\n    WRITERS = u3\n    READERS = u4 u5\n    TEAM    = u1 u2 u3 u5 u6\n\nrepo baserel  = BASE RELEASES\n    FORCERS = u1\n    MASTERS = u2\n    WRITERS = u3\n    READERS = u4 u5\n    TEAM    = u1 u2 u3 u5 u6\n\nrepo baseall = BASE PERSONAL RELEASES\n    ROOT    = admin\n    FORCERS = u1\n    MASTERS = u2\n    WRITERS = u3\n    READERS = u4 u5\n    TEAM    = u1 u2 u3 u5 u6\n\n=end\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\n# now we step outside tsh, into pure perl\n\nsub _access {\n    push @_, 'any' if @_ < 4;\n    my $ref = pop;\n    $ref =~ s(^)(refs/heads/) if $ref ne 'any' and $ref !~ m(^(refs|VREF)/);\n    push @_, $ref;\n\n    return access(@_);\n}\n\nsub ok {\n    say STDOUT (_access(@_) !~ /DENIED/ ? \"ok\" : \"not ok\");\n}\nsub nok {\n    say STDOUT (_access(@_) =~ /DENIED/ ? \"ok\" : \"not ok\");\n}\n\nnok qw( base admin R );\nnok qw( base admin W master );\nnok qw( base admin W notmaster );\nnok qw( base admin W refs/tags/boo );\nnok qw( base admin W refs/tags/v1 );\nnok qw( base admin W dev/admin/foo );\nnok qw( base admin W refs/tags/dev/admin/foo );\nnok qw( base admin W dev/alice/foo );\nnok qw( base admin W refs/tags/dev/alice/foo );\nnok qw( base admin + master );\nnok qw( base admin + notmaster );\nnok qw( base admin + refs/tags/boo );\nnok qw( base admin + refs/tags/v1 );\nnok qw( base admin + dev/admin/foo );\nnok qw( base admin + refs/tags/dev/admin/foo );\nnok qw( base admin + dev/alice/foo );\nnok qw( base admin + refs/tags/dev/alice/foo );\nnok qw( base admin C master );\nnok qw( base admin C notmaster );\nnok qw( base admin C refs/tags/boo );\nnok qw( base admin C refs/tags/v1 );\nnok qw( base admin C dev/admin/foo );\nnok qw( base admin C refs/tags/dev/admin/foo );\nnok qw( base admin C dev/alice/foo );\nnok qw( base admin C refs/tags/dev/alice/foo );\nnok qw( base admin D master );\nnok qw( base admin D notmaster );\nnok qw( base admin D refs/tags/boo );\nnok qw( base admin D refs/tags/v1 );\nnok qw( base admin D dev/admin/foo );\nnok qw( base admin D refs/tags/dev/admin/foo );\nnok qw( base admin D dev/alice/foo );\nnok qw( base admin D refs/tags/dev/alice/foo );\n\nok  qw( base u1 R );\nok  qw( base u1 W master );\nok  qw( base u1 W notmaster );\nok  qw( base u1 W refs/tags/boo );\nok  qw( base u1 W refs/tags/v1 );\nok  qw( base u1 W dev/u1/foo );\nok  qw( base u1 W refs/tags/dev/u1/foo );\nok  qw( base u1 W dev/alice/foo );\nok  qw( base u1 W refs/tags/dev/alice/foo );\nok  qw( base u1 + master );\nok  qw( base u1 + notmaster );\nok  qw( base u1 + refs/tags/boo );\nok  qw( base u1 + refs/tags/v1 );\nok  qw( base u1 + dev/u1/foo );\nok  qw( base u1 + refs/tags/dev/u1/foo );\nok  qw( base u1 + dev/alice/foo );\nok  qw( base u1 + refs/tags/dev/alice/foo );\nok  qw( base u1 C master );\nok  qw( base u1 C notmaster );\nok  qw( base u1 C refs/tags/boo );\nok  qw( base u1 C refs/tags/v1 );\nok  qw( base u1 C dev/u1/foo );\nok  qw( base u1 C refs/tags/dev/u1/foo );\nok  qw( base u1 C dev/alice/foo );\nok  qw( base u1 C refs/tags/dev/alice/foo );\nok  qw( base u1 D master );\nok  qw( base u1 D notmaster );\nok  qw( base u1 D refs/tags/boo );\nok  qw( base u1 D refs/tags/v1 );\nok  qw( base u1 D dev/u1/foo );\nok  qw( base u1 D refs/tags/dev/u1/foo );\nok  qw( base u1 D dev/alice/foo );\nok  qw( base u1 D refs/tags/dev/alice/foo );\n\nok  qw( base u2 R );\nok  qw( base u2 W master );\nok  qw( base u2 W notmaster );\nok  qw( base u2 W refs/tags/boo );\nok  qw( base u2 W refs/tags/v1 );\nok  qw( base u2 W dev/u2/foo );\nok  qw( base u2 W refs/tags/dev/u2/foo );\nok  qw( base u2 W dev/alice/foo );\nok  qw( base u2 W refs/tags/dev/alice/foo );\nnok qw( base u2 + master );\nnok qw( base u2 + notmaster );\nnok qw( base u2 + refs/tags/boo );\nnok qw( base u2 + refs/tags/v1 );\nnok qw( base u2 + dev/u2/foo );\nnok qw( base u2 + refs/tags/dev/u2/foo );\nnok qw( base u2 + dev/alice/foo );\nnok qw( base u2 + refs/tags/dev/alice/foo );\nok  qw( base u2 C master );\nok  qw( base u2 C notmaster );\nok  qw( base u2 C refs/tags/boo );\nok  qw( base u2 C refs/tags/v1 );\nok  qw( base u2 C dev/u2/foo );\nok  qw( base u2 C refs/tags/dev/u2/foo );\nok  qw( base u2 C dev/alice/foo );\nok  qw( base u2 C refs/tags/dev/alice/foo );\nnok qw( base u2 D master );\nnok qw( base u2 D notmaster );\nnok qw( base u2 D refs/tags/boo );\nnok qw( base u2 D refs/tags/v1 );\nnok qw( base u2 D dev/u2/foo );\nnok qw( base u2 D refs/tags/dev/u2/foo );\nnok qw( base u2 D dev/alice/foo );\nnok qw( base u2 D refs/tags/dev/alice/foo );\n\nok  qw( base u3 R );\nnok qw( base u3 W master );\nok  qw( base u3 W notmaster );\nok  qw( base u3 W refs/tags/boo );\nok  qw( base u3 W refs/tags/v1 );\nok  qw( base u3 W dev/u3/foo );\nok  qw( base u3 W refs/tags/dev/u3/foo );\nok  qw( base u3 W dev/alice/foo );\nok  qw( base u3 W refs/tags/dev/alice/foo );\nnok qw( base u3 + master );\nnok qw( base u3 + notmaster );\nnok qw( base u3 + refs/tags/boo );\nnok qw( base u3 + refs/tags/v1 );\nnok qw( base u3 + dev/u3/foo );\nnok qw( base u3 + refs/tags/dev/u3/foo );\nnok qw( base u3 + dev/alice/foo );\nnok qw( base u3 + refs/tags/dev/alice/foo );\nnok qw( base u3 C master );\nok  qw( base u3 C notmaster );\nok  qw( base u3 C refs/tags/boo );\nok  qw( base u3 C refs/tags/v1 );\nok  qw( base u3 C dev/u3/foo );\nok  qw( base u3 C refs/tags/dev/u3/foo );\nok  qw( base u3 C dev/alice/foo );\nok  qw( base u3 C refs/tags/dev/alice/foo );\nnok qw( base u3 D master );\nnok qw( base u3 D notmaster );\nnok qw( base u3 D refs/tags/boo );\nnok qw( base u3 D refs/tags/v1 );\nnok qw( base u3 D dev/u3/foo );\nnok qw( base u3 D refs/tags/dev/u3/foo );\nnok qw( base u3 D dev/alice/foo );\nnok qw( base u3 D refs/tags/dev/alice/foo );\n\nok  qw( base u4 R );\nnok qw( base u4 W master );\nnok qw( base u4 W notmaster );\nnok qw( base u4 W refs/tags/boo );\nnok qw( base u4 W refs/tags/v1 );\nnok qw( base u4 W dev/u4/foo );\nnok qw( base u4 W refs/tags/dev/u4/foo );\nnok qw( base u4 W dev/alice/foo );\nnok qw( base u4 W refs/tags/dev/alice/foo );\nnok qw( base u4 + master );\nnok qw( base u4 + notmaster );\nnok qw( base u4 + refs/tags/boo );\nnok qw( base u4 + refs/tags/v1 );\nnok qw( base u4 + dev/u4/foo );\nnok qw( base u4 + refs/tags/dev/u4/foo );\nnok qw( base u4 + dev/alice/foo );\nnok qw( base u4 + refs/tags/dev/alice/foo );\nnok qw( base u4 C master );\nnok qw( base u4 C notmaster );\nnok qw( base u4 C refs/tags/boo );\nnok qw( base u4 C refs/tags/v1 );\nnok qw( base u4 C dev/u4/foo );\nnok qw( base u4 C refs/tags/dev/u4/foo );\nnok qw( base u4 C dev/alice/foo );\nnok qw( base u4 C refs/tags/dev/alice/foo );\nnok qw( base u4 D master );\nnok qw( base u4 D notmaster );\nnok qw( base u4 D refs/tags/boo );\nnok qw( base u4 D refs/tags/v1 );\nnok qw( base u4 D dev/u4/foo );\nnok qw( base u4 D refs/tags/dev/u4/foo );\nnok qw( base u4 D dev/alice/foo );\nnok qw( base u4 D refs/tags/dev/alice/foo );\n\nnok qw( base u5 R );\nnok qw( base u5 W master );\nnok qw( base u5 W notmaster );\nnok qw( base u5 W refs/tags/boo );\nnok qw( base u5 W refs/tags/v1 );\nnok qw( base u5 W dev/u5/foo );\nnok qw( base u5 W refs/tags/dev/u5/foo );\nnok qw( base u5 W dev/alice/foo );\nnok qw( base u5 W refs/tags/dev/alice/foo );\nnok qw( base u5 + master );\nnok qw( base u5 + notmaster );\nnok qw( base u5 + refs/tags/boo );\nnok qw( base u5 + refs/tags/v1 );\nnok qw( base u5 + dev/u5/foo );\nnok qw( base u5 + refs/tags/dev/u5/foo );\nnok qw( base u5 + dev/alice/foo );\nnok qw( base u5 + refs/tags/dev/alice/foo );\nnok qw( base u5 C master );\nnok qw( base u5 C notmaster );\nnok qw( base u5 C refs/tags/boo );\nnok qw( base u5 C refs/tags/v1 );\nnok qw( base u5 C dev/u5/foo );\nnok qw( base u5 C refs/tags/dev/u5/foo );\nnok qw( base u5 C dev/alice/foo );\nnok qw( base u5 C refs/tags/dev/alice/foo );\nnok qw( base u5 D master );\nnok qw( base u5 D notmaster );\nnok qw( base u5 D refs/tags/boo );\nnok qw( base u5 D refs/tags/v1 );\nnok qw( base u5 D dev/u5/foo );\nnok qw( base u5 D refs/tags/dev/u5/foo );\nnok qw( base u5 D dev/alice/foo );\nnok qw( base u5 D refs/tags/dev/alice/foo );\n\nnok qw( base u6 R );\nnok qw( base u6 W master );\nnok qw( base u6 W notmaster );\nnok qw( base u6 W refs/tags/boo );\nnok qw( base u6 W refs/tags/v1 );\nnok qw( base u6 W dev/u6/foo );\nnok qw( base u6 W refs/tags/dev/u6/foo );\nnok qw( base u6 W dev/alice/foo );\nnok qw( base u6 W refs/tags/dev/alice/foo );\nnok qw( base u6 + master );\nnok qw( base u6 + notmaster );\nnok qw( base u6 + refs/tags/boo );\nnok qw( base u6 + refs/tags/v1 );\nnok qw( base u6 + dev/u6/foo );\nnok qw( base u6 + refs/tags/dev/u6/foo );\nnok qw( base u6 + dev/alice/foo );\nnok qw( base u6 + refs/tags/dev/alice/foo );\nnok qw( base u6 C master );\nnok qw( base u6 C notmaster );\nnok qw( base u6 C refs/tags/boo );\nnok qw( base u6 C refs/tags/v1 );\nnok qw( base u6 C dev/u6/foo );\nnok qw( base u6 C refs/tags/dev/u6/foo );\nnok qw( base u6 C dev/alice/foo );\nnok qw( base u6 C refs/tags/dev/alice/foo );\nnok qw( base u6 D master );\nnok qw( base u6 D notmaster );\nnok qw( base u6 D refs/tags/boo );\nnok qw( base u6 D refs/tags/v1 );\nnok qw( base u6 D dev/u6/foo );\nnok qw( base u6 D refs/tags/dev/u6/foo );\nnok qw( base u6 D dev/alice/foo );\nnok qw( base u6 D refs/tags/dev/alice/foo );\n\nok  qw( baseroot admin R );\nok  qw( baseroot admin W master );\nok  qw( baseroot admin W notmaster );\nok  qw( baseroot admin W refs/tags/boo );\nok  qw( baseroot admin W refs/tags/v1 );\nok  qw( baseroot admin W dev/admin/foo );\nok  qw( baseroot admin W refs/tags/dev/admin/foo );\nok  qw( baseroot admin W dev/alice/foo );\nok  qw( baseroot admin W refs/tags/dev/alice/foo );\nok  qw( baseroot admin + master );\nok  qw( baseroot admin + notmaster );\nok  qw( baseroot admin + refs/tags/boo );\nok  qw( baseroot admin + refs/tags/v1 );\nok  qw( baseroot admin + dev/admin/foo );\nok  qw( baseroot admin + refs/tags/dev/admin/foo );\nok  qw( baseroot admin + dev/alice/foo );\nok  qw( baseroot admin + refs/tags/dev/alice/foo );\nok  qw( baseroot admin C master );\nok  qw( baseroot admin C notmaster );\nok  qw( baseroot admin C refs/tags/boo );\nok  qw( baseroot admin C refs/tags/v1 );\nok  qw( baseroot admin C dev/admin/foo );\nok  qw( baseroot admin C refs/tags/dev/admin/foo );\nok  qw( baseroot admin C dev/alice/foo );\nok  qw( baseroot admin C refs/tags/dev/alice/foo );\nok  qw( baseroot admin D master );\nok  qw( baseroot admin D notmaster );\nok  qw( baseroot admin D refs/tags/boo );\nok  qw( baseroot admin D refs/tags/v1 );\nok  qw( baseroot admin D dev/admin/foo );\nok  qw( baseroot admin D refs/tags/dev/admin/foo );\nok  qw( baseroot admin D dev/alice/foo );\nok  qw( baseroot admin D refs/tags/dev/alice/foo );\n\nok  qw( baseroot u1 R );\nok  qw( baseroot u1 W master );\nok  qw( baseroot u1 W notmaster );\nok  qw( baseroot u1 W refs/tags/boo );\nok  qw( baseroot u1 W refs/tags/v1 );\nok  qw( baseroot u1 W dev/u1/foo );\nok  qw( baseroot u1 W refs/tags/dev/u1/foo );\nok  qw( baseroot u1 W dev/alice/foo );\nok  qw( baseroot u1 W refs/tags/dev/alice/foo );\nok  qw( baseroot u1 + master );\nok  qw( baseroot u1 + notmaster );\nok  qw( baseroot u1 + refs/tags/boo );\nok  qw( baseroot u1 + refs/tags/v1 );\nok  qw( baseroot u1 + dev/u1/foo );\nok  qw( baseroot u1 + refs/tags/dev/u1/foo );\nok  qw( baseroot u1 + dev/alice/foo );\nok  qw( baseroot u1 + refs/tags/dev/alice/foo );\nok  qw( baseroot u1 C master );\nok  qw( baseroot u1 C notmaster );\nok  qw( baseroot u1 C refs/tags/boo );\nok  qw( baseroot u1 C refs/tags/v1 );\nok  qw( baseroot u1 C dev/u1/foo );\nok  qw( baseroot u1 C refs/tags/dev/u1/foo );\nok  qw( baseroot u1 C dev/alice/foo );\nok  qw( baseroot u1 C refs/tags/dev/alice/foo );\nok  qw( baseroot u1 D master );\nok  qw( baseroot u1 D notmaster );\nok  qw( baseroot u1 D refs/tags/boo );\nok  qw( baseroot u1 D refs/tags/v1 );\nok  qw( baseroot u1 D dev/u1/foo );\nok  qw( baseroot u1 D refs/tags/dev/u1/foo );\nok  qw( baseroot u1 D dev/alice/foo );\nok  qw( baseroot u1 D refs/tags/dev/alice/foo );\n\nok  qw( baseroot u2 R );\nok  qw( baseroot u2 W master );\nok  qw( baseroot u2 W notmaster );\nok  qw( baseroot u2 W refs/tags/boo );\nok  qw( baseroot u2 W refs/tags/v1 );\nok  qw( baseroot u2 W dev/u2/foo );\nok  qw( baseroot u2 W refs/tags/dev/u2/foo );\nok  qw( baseroot u2 W dev/alice/foo );\nok  qw( baseroot u2 W refs/tags/dev/alice/foo );\nnok qw( baseroot u2 + master );\nnok qw( baseroot u2 + notmaster );\nnok qw( baseroot u2 + refs/tags/boo );\nnok qw( baseroot u2 + refs/tags/v1 );\nnok qw( baseroot u2 + dev/u2/foo );\nnok qw( baseroot u2 + refs/tags/dev/u2/foo );\nnok qw( baseroot u2 + dev/alice/foo );\nnok qw( baseroot u2 + refs/tags/dev/alice/foo );\nok  qw( baseroot u2 C master );\nok  qw( baseroot u2 C notmaster );\nok  qw( baseroot u2 C refs/tags/boo );\nok  qw( baseroot u2 C refs/tags/v1 );\nok  qw( baseroot u2 C dev/u2/foo );\nok  qw( baseroot u2 C refs/tags/dev/u2/foo );\nok  qw( baseroot u2 C dev/alice/foo );\nok  qw( baseroot u2 C refs/tags/dev/alice/foo );\nnok qw( baseroot u2 D master );\nnok qw( baseroot u2 D notmaster );\nnok qw( baseroot u2 D refs/tags/boo );\nnok qw( baseroot u2 D refs/tags/v1 );\nnok qw( baseroot u2 D dev/u2/foo );\nnok qw( baseroot u2 D refs/tags/dev/u2/foo );\nnok qw( baseroot u2 D dev/alice/foo );\nnok qw( baseroot u2 D refs/tags/dev/alice/foo );\n\nok  qw( baseroot u3 R );\nnok qw( baseroot u3 W master );\nok  qw( baseroot u3 W notmaster );\nok  qw( baseroot u3 W refs/tags/boo );\nok  qw( baseroot u3 W refs/tags/v1 );\nok  qw( baseroot u3 W dev/u3/foo );\nok  qw( baseroot u3 W refs/tags/dev/u3/foo );\nok  qw( baseroot u3 W dev/alice/foo );\nok  qw( baseroot u3 W refs/tags/dev/alice/foo );\nnok qw( baseroot u3 + master );\nnok qw( baseroot u3 + notmaster );\nnok qw( baseroot u3 + refs/tags/boo );\nnok qw( baseroot u3 + refs/tags/v1 );\nnok qw( baseroot u3 + dev/u3/foo );\nnok qw( baseroot u3 + refs/tags/dev/u3/foo );\nnok qw( baseroot u3 + dev/alice/foo );\nnok qw( baseroot u3 + refs/tags/dev/alice/foo );\nnok qw( baseroot u3 C master );\nok  qw( baseroot u3 C notmaster );\nok  qw( baseroot u3 C refs/tags/boo );\nok  qw( baseroot u3 C refs/tags/v1 );\nok  qw( baseroot u3 C dev/u3/foo );\nok  qw( baseroot u3 C refs/tags/dev/u3/foo );\nok  qw( baseroot u3 C dev/alice/foo );\nok  qw( baseroot u3 C refs/tags/dev/alice/foo );\nnok qw( baseroot u3 D master );\nnok qw( baseroot u3 D notmaster );\nnok qw( baseroot u3 D refs/tags/boo );\nnok qw( baseroot u3 D refs/tags/v1 );\nnok qw( baseroot u3 D dev/u3/foo );\nnok qw( baseroot u3 D refs/tags/dev/u3/foo );\nnok qw( baseroot u3 D dev/alice/foo );\nnok qw( baseroot u3 D refs/tags/dev/alice/foo );\n\nok  qw( baseroot u4 R );\nnok qw( baseroot u4 W master );\nnok qw( baseroot u4 W notmaster );\nnok qw( baseroot u4 W refs/tags/boo );\nnok qw( baseroot u4 W refs/tags/v1 );\nnok qw( baseroot u4 W dev/u4/foo );\nnok qw( baseroot u4 W refs/tags/dev/u4/foo );\nnok qw( baseroot u4 W dev/alice/foo );\nnok qw( baseroot u4 W refs/tags/dev/alice/foo );\nnok qw( baseroot u4 + master );\nnok qw( baseroot u4 + notmaster );\nnok qw( baseroot u4 + refs/tags/boo );\nnok qw( baseroot u4 + refs/tags/v1 );\nnok qw( baseroot u4 + dev/u4/foo );\nnok qw( baseroot u4 + refs/tags/dev/u4/foo );\nnok qw( baseroot u4 + dev/alice/foo );\nnok qw( baseroot u4 + refs/tags/dev/alice/foo );\nnok qw( baseroot u4 C master );\nnok qw( baseroot u4 C notmaster );\nnok qw( baseroot u4 C refs/tags/boo );\nnok qw( baseroot u4 C refs/tags/v1 );\nnok qw( baseroot u4 C dev/u4/foo );\nnok qw( baseroot u4 C refs/tags/dev/u4/foo );\nnok qw( baseroot u4 C dev/alice/foo );\nnok qw( baseroot u4 C refs/tags/dev/alice/foo );\nnok qw( baseroot u4 D master );\nnok qw( baseroot u4 D notmaster );\nnok qw( baseroot u4 D refs/tags/boo );\nnok qw( baseroot u4 D refs/tags/v1 );\nnok qw( baseroot u4 D dev/u4/foo );\nnok qw( baseroot u4 D refs/tags/dev/u4/foo );\nnok qw( baseroot u4 D dev/alice/foo );\nnok qw( baseroot u4 D refs/tags/dev/alice/foo );\n\nnok qw( baseroot u5 R );\nnok qw( baseroot u5 W master );\nnok qw( baseroot u5 W notmaster );\nnok qw( baseroot u5 W refs/tags/boo );\nnok qw( baseroot u5 W refs/tags/v1 );\nnok qw( baseroot u5 W dev/u5/foo );\nnok qw( baseroot u5 W refs/tags/dev/u5/foo );\nnok qw( baseroot u5 W dev/alice/foo );\nnok qw( baseroot u5 W refs/tags/dev/alice/foo );\nnok qw( baseroot u5 + master );\nnok qw( baseroot u5 + notmaster );\nnok qw( baseroot u5 + refs/tags/boo );\nnok qw( baseroot u5 + refs/tags/v1 );\nnok qw( baseroot u5 + dev/u5/foo );\nnok qw( baseroot u5 + refs/tags/dev/u5/foo );\nnok qw( baseroot u5 + dev/alice/foo );\nnok qw( baseroot u5 + refs/tags/dev/alice/foo );\nnok qw( baseroot u5 C master );\nnok qw( baseroot u5 C notmaster );\nnok qw( baseroot u5 C refs/tags/boo );\nnok qw( baseroot u5 C refs/tags/v1 );\nnok qw( baseroot u5 C dev/u5/foo );\nnok qw( baseroot u5 C refs/tags/dev/u5/foo );\nnok qw( baseroot u5 C dev/alice/foo );\nnok qw( baseroot u5 C refs/tags/dev/alice/foo );\nnok qw( baseroot u5 D master );\nnok qw( baseroot u5 D notmaster );\nnok qw( baseroot u5 D refs/tags/boo );\nnok qw( baseroot u5 D refs/tags/v1 );\nnok qw( baseroot u5 D dev/u5/foo );\nnok qw( baseroot u5 D refs/tags/dev/u5/foo );\nnok qw( baseroot u5 D dev/alice/foo );\nnok qw( baseroot u5 D refs/tags/dev/alice/foo );\n\nnok qw( baseroot u6 R );\nnok qw( baseroot u6 W master );\nnok qw( baseroot u6 W notmaster );\nnok qw( baseroot u6 W refs/tags/boo );\nnok qw( baseroot u6 W refs/tags/v1 );\nnok qw( baseroot u6 W dev/u6/foo );\nnok qw( baseroot u6 W refs/tags/dev/u6/foo );\nnok qw( baseroot u6 W dev/alice/foo );\nnok qw( baseroot u6 W refs/tags/dev/alice/foo );\nnok qw( baseroot u6 + master );\nnok qw( baseroot u6 + notmaster );\nnok qw( baseroot u6 + refs/tags/boo );\nnok qw( baseroot u6 + refs/tags/v1 );\nnok qw( baseroot u6 + dev/u6/foo );\nnok qw( baseroot u6 + refs/tags/dev/u6/foo );\nnok qw( baseroot u6 + dev/alice/foo );\nnok qw( baseroot u6 + refs/tags/dev/alice/foo );\nnok qw( baseroot u6 C master );\nnok qw( baseroot u6 C notmaster );\nnok qw( baseroot u6 C refs/tags/boo );\nnok qw( baseroot u6 C refs/tags/v1 );\nnok qw( baseroot u6 C dev/u6/foo );\nnok qw( baseroot u6 C refs/tags/dev/u6/foo );\nnok qw( baseroot u6 C dev/alice/foo );\nnok qw( baseroot u6 C refs/tags/dev/alice/foo );\nnok qw( baseroot u6 D master );\nnok qw( baseroot u6 D notmaster );\nnok qw( baseroot u6 D refs/tags/boo );\nnok qw( baseroot u6 D refs/tags/v1 );\nnok qw( baseroot u6 D dev/u6/foo );\nnok qw( baseroot u6 D refs/tags/dev/u6/foo );\nnok qw( baseroot u6 D dev/alice/foo );\nnok qw( baseroot u6 D refs/tags/dev/alice/foo );\n\nnok qw( basepers admin R );\nnok qw( basepers admin W master );\nnok qw( basepers admin W notmaster );\nnok qw( basepers admin W refs/tags/boo );\nnok qw( basepers admin W refs/tags/v1 );\nnok qw( basepers admin W dev/admin/foo );\nnok qw( basepers admin W refs/tags/dev/admin/foo );\nnok qw( basepers admin W dev/alice/foo );\nnok qw( basepers admin W refs/tags/dev/alice/foo );\nnok qw( basepers admin + master );\nnok qw( basepers admin + notmaster );\nnok qw( basepers admin + refs/tags/boo );\nnok qw( basepers admin + refs/tags/v1 );\nnok qw( basepers admin + dev/admin/foo );\nnok qw( basepers admin + refs/tags/dev/admin/foo );\nnok qw( basepers admin + dev/alice/foo );\nnok qw( basepers admin + refs/tags/dev/alice/foo );\nnok qw( basepers admin C master );\nnok qw( basepers admin C notmaster );\nnok qw( basepers admin C refs/tags/boo );\nnok qw( basepers admin C refs/tags/v1 );\nnok qw( basepers admin C dev/admin/foo );\nnok qw( basepers admin C refs/tags/dev/admin/foo );\nnok qw( basepers admin C dev/alice/foo );\nnok qw( basepers admin C refs/tags/dev/alice/foo );\nnok qw( basepers admin D master );\nnok qw( basepers admin D notmaster );\nnok qw( basepers admin D refs/tags/boo );\nnok qw( basepers admin D refs/tags/v1 );\nnok qw( basepers admin D dev/admin/foo );\nnok qw( basepers admin D refs/tags/dev/admin/foo );\nnok qw( basepers admin D dev/alice/foo );\nnok qw( basepers admin D refs/tags/dev/alice/foo );\n\nok  qw( basepers u1 R );\nok  qw( basepers u1 W master );\nok  qw( basepers u1 W notmaster );\nok  qw( basepers u1 W refs/tags/boo );\nok  qw( basepers u1 W refs/tags/v1 );\nok  qw( basepers u1 W dev/u1/foo );\nok  qw( basepers u1 W refs/tags/dev/u1/foo );\nnok qw( basepers u1 W dev/alice/foo );\nnok qw( basepers u1 W refs/tags/dev/alice/foo );\nok  qw( basepers u1 + master );\nok  qw( basepers u1 + notmaster );\nok  qw( basepers u1 + refs/tags/boo );\nok  qw( basepers u1 + refs/tags/v1 );\nok  qw( basepers u1 + dev/u1/foo );\nok  qw( basepers u1 + refs/tags/dev/u1/foo );\nnok qw( basepers u1 + dev/alice/foo );\nnok qw( basepers u1 + refs/tags/dev/alice/foo );\nok  qw( basepers u1 C master );\nok  qw( basepers u1 C notmaster );\nok  qw( basepers u1 C refs/tags/boo );\nok  qw( basepers u1 C refs/tags/v1 );\nok  qw( basepers u1 C dev/u1/foo );\nok  qw( basepers u1 C refs/tags/dev/u1/foo );\nnok qw( basepers u1 C dev/alice/foo );\nnok qw( basepers u1 C refs/tags/dev/alice/foo );\nok  qw( basepers u1 D master );\nok  qw( basepers u1 D notmaster );\nok  qw( basepers u1 D refs/tags/boo );\nok  qw( basepers u1 D refs/tags/v1 );\nok  qw( basepers u1 D dev/u1/foo );\nok  qw( basepers u1 D refs/tags/dev/u1/foo );\nnok qw( basepers u1 D dev/alice/foo );\nnok qw( basepers u1 D refs/tags/dev/alice/foo );\n\nok  qw( basepers u2 R );\nok  qw( basepers u2 W master );\nok  qw( basepers u2 W notmaster );\nok  qw( basepers u2 W refs/tags/boo );\nok  qw( basepers u2 W refs/tags/v1 );\nok  qw( basepers u2 W dev/u2/foo );\nok  qw( basepers u2 W refs/tags/dev/u2/foo );\nnok qw( basepers u2 W dev/alice/foo );\nnok qw( basepers u2 W refs/tags/dev/alice/foo );\nnok qw( basepers u2 + master );\nnok qw( basepers u2 + notmaster );\nnok qw( basepers u2 + refs/tags/boo );\nnok qw( basepers u2 + refs/tags/v1 );\nok  qw( basepers u2 + dev/u2/foo );\nok  qw( basepers u2 + refs/tags/dev/u2/foo );\nnok qw( basepers u2 + dev/alice/foo );\nnok qw( basepers u2 + refs/tags/dev/alice/foo );\nok  qw( basepers u2 C master );\nok  qw( basepers u2 C notmaster );\nok  qw( basepers u2 C refs/tags/boo );\nok  qw( basepers u2 C refs/tags/v1 );\nok  qw( basepers u2 C dev/u2/foo );\nok  qw( basepers u2 C refs/tags/dev/u2/foo );\nnok qw( basepers u2 C dev/alice/foo );\nnok qw( basepers u2 C refs/tags/dev/alice/foo );\nnok qw( basepers u2 D master );\nnok qw( basepers u2 D notmaster );\nnok qw( basepers u2 D refs/tags/boo );\nnok qw( basepers u2 D refs/tags/v1 );\nok  qw( basepers u2 D dev/u2/foo );\nok  qw( basepers u2 D refs/tags/dev/u2/foo );\nnok qw( basepers u2 D dev/alice/foo );\nnok qw( basepers u2 D refs/tags/dev/alice/foo );\n\nok  qw( basepers u3 R );\nnok qw( basepers u3 W master );\nok  qw( basepers u3 W notmaster );\nok  qw( basepers u3 W refs/tags/boo );\nok  qw( basepers u3 W refs/tags/v1 );\nok  qw( basepers u3 W dev/u3/foo );\nok  qw( basepers u3 W refs/tags/dev/u3/foo );\nnok qw( basepers u3 W dev/alice/foo );\nnok qw( basepers u3 W refs/tags/dev/alice/foo );\nnok qw( basepers u3 + master );\nnok qw( basepers u3 + notmaster );\nnok qw( basepers u3 + refs/tags/boo );\nnok qw( basepers u3 + refs/tags/v1 );\nok  qw( basepers u3 + dev/u3/foo );\nok  qw( basepers u3 + refs/tags/dev/u3/foo );\nnok qw( basepers u3 + dev/alice/foo );\nnok qw( basepers u3 + refs/tags/dev/alice/foo );\nnok qw( basepers u3 C master );\nok  qw( basepers u3 C notmaster );\nok  qw( basepers u3 C refs/tags/boo );\nok  qw( basepers u3 C refs/tags/v1 );\nok  qw( basepers u3 C dev/u3/foo );\nok  qw( basepers u3 C refs/tags/dev/u3/foo );\nnok qw( basepers u3 C dev/alice/foo );\nnok qw( basepers u3 C refs/tags/dev/alice/foo );\nnok qw( basepers u3 D master );\nnok qw( basepers u3 D notmaster );\nnok qw( basepers u3 D refs/tags/boo );\nnok qw( basepers u3 D refs/tags/v1 );\nok  qw( basepers u3 D dev/u3/foo );\nok  qw( basepers u3 D refs/tags/dev/u3/foo );\nnok qw( basepers u3 D dev/alice/foo );\nnok qw( basepers u3 D refs/tags/dev/alice/foo );\n\nok  qw( basepers u4 R );\nnok qw( basepers u4 W master );\nnok qw( basepers u4 W notmaster );\nnok qw( basepers u4 W refs/tags/boo );\nnok qw( basepers u4 W refs/tags/v1 );\nnok qw( basepers u4 W dev/u4/foo );\nnok qw( basepers u4 W refs/tags/dev/u4/foo );\nnok qw( basepers u4 W dev/alice/foo );\nnok qw( basepers u4 W refs/tags/dev/alice/foo );\nnok qw( basepers u4 + master );\nnok qw( basepers u4 + notmaster );\nnok qw( basepers u4 + refs/tags/boo );\nnok qw( basepers u4 + refs/tags/v1 );\nnok qw( basepers u4 + dev/u4/foo );\nnok qw( basepers u4 + refs/tags/dev/u4/foo );\nnok qw( basepers u4 + dev/alice/foo );\nnok qw( basepers u4 + refs/tags/dev/alice/foo );\nnok qw( basepers u4 C master );\nnok qw( basepers u4 C notmaster );\nnok qw( basepers u4 C refs/tags/boo );\nnok qw( basepers u4 C refs/tags/v1 );\nnok qw( basepers u4 C dev/u4/foo );\nnok qw( basepers u4 C refs/tags/dev/u4/foo );\nnok qw( basepers u4 C dev/alice/foo );\nnok qw( basepers u4 C refs/tags/dev/alice/foo );\nnok qw( basepers u4 D master );\nnok qw( basepers u4 D notmaster );\nnok qw( basepers u4 D refs/tags/boo );\nnok qw( basepers u4 D refs/tags/v1 );\nnok qw( basepers u4 D dev/u4/foo );\nnok qw( basepers u4 D refs/tags/dev/u4/foo );\nnok qw( basepers u4 D dev/alice/foo );\nnok qw( basepers u4 D refs/tags/dev/alice/foo );\n\nok  qw( basepers u5 R );\nnok qw( basepers u5 W master );\nnok qw( basepers u5 W notmaster );\nnok qw( basepers u5 W refs/tags/boo );\nnok qw( basepers u5 W refs/tags/v1 );\nok  qw( basepers u5 W dev/u5/foo );\nok  qw( basepers u5 W refs/tags/dev/u5/foo );\nnok qw( basepers u5 W dev/alice/foo );\nnok qw( basepers u5 W refs/tags/dev/alice/foo );\nnok qw( basepers u5 + master );\nnok qw( basepers u5 + notmaster );\nnok qw( basepers u5 + refs/tags/boo );\nnok qw( basepers u5 + refs/tags/v1 );\nok  qw( basepers u5 + dev/u5/foo );\nok  qw( basepers u5 + refs/tags/dev/u5/foo );\nnok qw( basepers u5 + dev/alice/foo );\nnok qw( basepers u5 + refs/tags/dev/alice/foo );\nnok qw( basepers u5 C master );\nnok qw( basepers u5 C notmaster );\nnok qw( basepers u5 C refs/tags/boo );\nnok qw( basepers u5 C refs/tags/v1 );\nok  qw( basepers u5 C dev/u5/foo );\nok  qw( basepers u5 C refs/tags/dev/u5/foo );\nnok qw( basepers u5 C dev/alice/foo );\nnok qw( basepers u5 C refs/tags/dev/alice/foo );\nnok qw( basepers u5 D master );\nnok qw( basepers u5 D notmaster );\nnok qw( basepers u5 D refs/tags/boo );\nnok qw( basepers u5 D refs/tags/v1 );\nok  qw( basepers u5 D dev/u5/foo );\nok  qw( basepers u5 D refs/tags/dev/u5/foo );\nnok qw( basepers u5 D dev/alice/foo );\nnok qw( basepers u5 D refs/tags/dev/alice/foo );\n\nok  qw( basepers u6 R );\nnok qw( basepers u6 W master );\nnok qw( basepers u6 W notmaster );\nnok qw( basepers u6 W refs/tags/boo );\nnok qw( basepers u6 W refs/tags/v1 );\nok  qw( basepers u6 W dev/u6/foo );\nok  qw( basepers u6 W refs/tags/dev/u6/foo );\nnok qw( basepers u6 W dev/alice/foo );\nnok qw( basepers u6 W refs/tags/dev/alice/foo );\nnok qw( basepers u6 + master );\nnok qw( basepers u6 + notmaster );\nnok qw( basepers u6 + refs/tags/boo );\nnok qw( basepers u6 + refs/tags/v1 );\nok  qw( basepers u6 + dev/u6/foo );\nok  qw( basepers u6 + refs/tags/dev/u6/foo );\nnok qw( basepers u6 + dev/alice/foo );\nnok qw( basepers u6 + refs/tags/dev/alice/foo );\nnok qw( basepers u6 C master );\nnok qw( basepers u6 C notmaster );\nnok qw( basepers u6 C refs/tags/boo );\nnok qw( basepers u6 C refs/tags/v1 );\nok  qw( basepers u6 C dev/u6/foo );\nok  qw( basepers u6 C refs/tags/dev/u6/foo );\nnok qw( basepers u6 C dev/alice/foo );\nnok qw( basepers u6 C refs/tags/dev/alice/foo );\nnok qw( basepers u6 D master );\nnok qw( basepers u6 D notmaster );\nnok qw( basepers u6 D refs/tags/boo );\nnok qw( basepers u6 D refs/tags/v1 );\nok  qw( basepers u6 D dev/u6/foo );\nok  qw( basepers u6 D refs/tags/dev/u6/foo );\nnok qw( basepers u6 D dev/alice/foo );\nnok qw( basepers u6 D refs/tags/dev/alice/foo );\n\nnok qw( baserel admin R );\nnok qw( baserel admin W master );\nnok qw( baserel admin W notmaster );\nnok qw( baserel admin W refs/tags/boo );\nnok qw( baserel admin W refs/tags/v1 );\nnok qw( baserel admin W dev/admin/foo );\nnok qw( baserel admin W refs/tags/dev/admin/foo );\nnok qw( baserel admin W dev/alice/foo );\nnok qw( baserel admin W refs/tags/dev/alice/foo );\nnok qw( baserel admin + master );\nnok qw( baserel admin + notmaster );\nnok qw( baserel admin + refs/tags/boo );\nnok qw( baserel admin + refs/tags/v1 );\nnok qw( baserel admin + dev/admin/foo );\nnok qw( baserel admin + refs/tags/dev/admin/foo );\nnok qw( baserel admin + dev/alice/foo );\nnok qw( baserel admin + refs/tags/dev/alice/foo );\nnok qw( baserel admin C master );\nnok qw( baserel admin C notmaster );\nnok qw( baserel admin C refs/tags/boo );\nnok qw( baserel admin C refs/tags/v1 );\nnok qw( baserel admin C dev/admin/foo );\nnok qw( baserel admin C refs/tags/dev/admin/foo );\nnok qw( baserel admin C dev/alice/foo );\nnok qw( baserel admin C refs/tags/dev/alice/foo );\nnok qw( baserel admin D master );\nnok qw( baserel admin D notmaster );\nnok qw( baserel admin D refs/tags/boo );\nnok qw( baserel admin D refs/tags/v1 );\nnok qw( baserel admin D dev/admin/foo );\nnok qw( baserel admin D refs/tags/dev/admin/foo );\nnok qw( baserel admin D dev/alice/foo );\nnok qw( baserel admin D refs/tags/dev/alice/foo );\n\nok  qw( baserel u1 R );\nok  qw( baserel u1 W master );\nok  qw( baserel u1 W notmaster );\nok  qw( baserel u1 W refs/tags/boo );\nnok qw( baserel u1 W refs/tags/v1 );\nok  qw( baserel u1 W dev/u1/foo );\nok  qw( baserel u1 W refs/tags/dev/u1/foo );\nok  qw( baserel u1 W dev/alice/foo );\nok  qw( baserel u1 W refs/tags/dev/alice/foo );\nok  qw( baserel u1 + master );\nok  qw( baserel u1 + notmaster );\nok  qw( baserel u1 + refs/tags/boo );\nnok qw( baserel u1 + refs/tags/v1 );\nok  qw( baserel u1 + dev/u1/foo );\nok  qw( baserel u1 + refs/tags/dev/u1/foo );\nok  qw( baserel u1 + dev/alice/foo );\nok  qw( baserel u1 + refs/tags/dev/alice/foo );\nok  qw( baserel u1 C master );\nok  qw( baserel u1 C notmaster );\nok  qw( baserel u1 C refs/tags/boo );\nnok qw( baserel u1 C refs/tags/v1 );\nok  qw( baserel u1 C dev/u1/foo );\nok  qw( baserel u1 C refs/tags/dev/u1/foo );\nok  qw( baserel u1 C dev/alice/foo );\nok  qw( baserel u1 C refs/tags/dev/alice/foo );\nok  qw( baserel u1 D master );\nok  qw( baserel u1 D notmaster );\nok  qw( baserel u1 D refs/tags/boo );\nnok qw( baserel u1 D refs/tags/v1 );\nok  qw( baserel u1 D dev/u1/foo );\nok  qw( baserel u1 D refs/tags/dev/u1/foo );\nok  qw( baserel u1 D dev/alice/foo );\nok  qw( baserel u1 D refs/tags/dev/alice/foo );\n\nok  qw( baserel u2 R );\nok  qw( baserel u2 W master );\nok  qw( baserel u2 W notmaster );\nok  qw( baserel u2 W refs/tags/boo );\nnok qw( baserel u2 W refs/tags/v1 );\nok  qw( baserel u2 W dev/u2/foo );\nok  qw( baserel u2 W refs/tags/dev/u2/foo );\nok  qw( baserel u2 W dev/alice/foo );\nok  qw( baserel u2 W refs/tags/dev/alice/foo );\nnok qw( baserel u2 + master );\nnok qw( baserel u2 + notmaster );\nnok qw( baserel u2 + refs/tags/boo );\nnok qw( baserel u2 + refs/tags/v1 );\nnok qw( baserel u2 + dev/u2/foo );\nnok qw( baserel u2 + refs/tags/dev/u2/foo );\nnok qw( baserel u2 + dev/alice/foo );\nnok qw( baserel u2 + refs/tags/dev/alice/foo );\nok  qw( baserel u2 C master );\nok  qw( baserel u2 C notmaster );\nok  qw( baserel u2 C refs/tags/boo );\nnok qw( baserel u2 C refs/tags/v1 );\nok  qw( baserel u2 C dev/u2/foo );\nok  qw( baserel u2 C refs/tags/dev/u2/foo );\nok  qw( baserel u2 C dev/alice/foo );\nok  qw( baserel u2 C refs/tags/dev/alice/foo );\nnok qw( baserel u2 D master );\nnok qw( baserel u2 D notmaster );\nnok qw( baserel u2 D refs/tags/boo );\nnok qw( baserel u2 D refs/tags/v1 );\nnok qw( baserel u2 D dev/u2/foo );\nnok qw( baserel u2 D refs/tags/dev/u2/foo );\nnok qw( baserel u2 D dev/alice/foo );\nnok qw( baserel u2 D refs/tags/dev/alice/foo );\n\nok  qw( baserel u3 R );\nnok qw( baserel u3 W master );\nok  qw( baserel u3 W notmaster );\nok  qw( baserel u3 W refs/tags/boo );\nnok qw( baserel u3 W refs/tags/v1 );\nok  qw( baserel u3 W dev/u3/foo );\nok  qw( baserel u3 W refs/tags/dev/u3/foo );\nok  qw( baserel u3 W dev/alice/foo );\nok  qw( baserel u3 W refs/tags/dev/alice/foo );\nnok qw( baserel u3 + master );\nnok qw( baserel u3 + notmaster );\nnok qw( baserel u3 + refs/tags/boo );\nnok qw( baserel u3 + refs/tags/v1 );\nnok qw( baserel u3 + dev/u3/foo );\nnok qw( baserel u3 + refs/tags/dev/u3/foo );\nnok qw( baserel u3 + dev/alice/foo );\nnok qw( baserel u3 + refs/tags/dev/alice/foo );\nnok qw( baserel u3 C master );\nok  qw( baserel u3 C notmaster );\nok  qw( baserel u3 C refs/tags/boo );\nnok qw( baserel u3 C refs/tags/v1 );\nok  qw( baserel u3 C dev/u3/foo );\nok  qw( baserel u3 C refs/tags/dev/u3/foo );\nok  qw( baserel u3 C dev/alice/foo );\nok  qw( baserel u3 C refs/tags/dev/alice/foo );\nnok qw( baserel u3 D master );\nnok qw( baserel u3 D notmaster );\nnok qw( baserel u3 D refs/tags/boo );\nnok qw( baserel u3 D refs/tags/v1 );\nnok qw( baserel u3 D dev/u3/foo );\nnok qw( baserel u3 D refs/tags/dev/u3/foo );\nnok qw( baserel u3 D dev/alice/foo );\nnok qw( baserel u3 D refs/tags/dev/alice/foo );\n\nok  qw( baserel u4 R );\nnok qw( baserel u4 W master );\nnok qw( baserel u4 W notmaster );\nnok qw( baserel u4 W refs/tags/boo );\nnok qw( baserel u4 W refs/tags/v1 );\nnok qw( baserel u4 W dev/u4/foo );\nnok qw( baserel u4 W refs/tags/dev/u4/foo );\nnok qw( baserel u4 W dev/alice/foo );\nnok qw( baserel u4 W refs/tags/dev/alice/foo );\nnok qw( baserel u4 + master );\nnok qw( baserel u4 + notmaster );\nnok qw( baserel u4 + refs/tags/boo );\nnok qw( baserel u4 + refs/tags/v1 );\nnok qw( baserel u4 + dev/u4/foo );\nnok qw( baserel u4 + refs/tags/dev/u4/foo );\nnok qw( baserel u4 + dev/alice/foo );\nnok qw( baserel u4 + refs/tags/dev/alice/foo );\nnok qw( baserel u4 C master );\nnok qw( baserel u4 C notmaster );\nnok qw( baserel u4 C refs/tags/boo );\nnok qw( baserel u4 C refs/tags/v1 );\nnok qw( baserel u4 C dev/u4/foo );\nnok qw( baserel u4 C refs/tags/dev/u4/foo );\nnok qw( baserel u4 C dev/alice/foo );\nnok qw( baserel u4 C refs/tags/dev/alice/foo );\nnok qw( baserel u4 D master );\nnok qw( baserel u4 D notmaster );\nnok qw( baserel u4 D refs/tags/boo );\nnok qw( baserel u4 D refs/tags/v1 );\nnok qw( baserel u4 D dev/u4/foo );\nnok qw( baserel u4 D refs/tags/dev/u4/foo );\nnok qw( baserel u4 D dev/alice/foo );\nnok qw( baserel u4 D refs/tags/dev/alice/foo );\n\nok  qw( baserel u5 R );\nnok qw( baserel u5 W master );\nnok qw( baserel u5 W notmaster );\nnok qw( baserel u5 W refs/tags/boo );\nnok qw( baserel u5 W refs/tags/v1 );\nnok qw( baserel u5 W dev/u5/foo );\nnok qw( baserel u5 W refs/tags/dev/u5/foo );\nnok qw( baserel u5 W dev/alice/foo );\nnok qw( baserel u5 W refs/tags/dev/alice/foo );\nnok qw( baserel u5 + master );\nnok qw( baserel u5 + notmaster );\nnok qw( baserel u5 + refs/tags/boo );\nnok qw( baserel u5 + refs/tags/v1 );\nnok qw( baserel u5 + dev/u5/foo );\nnok qw( baserel u5 + refs/tags/dev/u5/foo );\nnok qw( baserel u5 + dev/alice/foo );\nnok qw( baserel u5 + refs/tags/dev/alice/foo );\nnok qw( baserel u5 C master );\nnok qw( baserel u5 C notmaster );\nnok qw( baserel u5 C refs/tags/boo );\nnok qw( baserel u5 C refs/tags/v1 );\nnok qw( baserel u5 C dev/u5/foo );\nnok qw( baserel u5 C refs/tags/dev/u5/foo );\nnok qw( baserel u5 C dev/alice/foo );\nnok qw( baserel u5 C refs/tags/dev/alice/foo );\nnok qw( baserel u5 D master );\nnok qw( baserel u5 D notmaster );\nnok qw( baserel u5 D refs/tags/boo );\nnok qw( baserel u5 D refs/tags/v1 );\nnok qw( baserel u5 D dev/u5/foo );\nnok qw( baserel u5 D refs/tags/dev/u5/foo );\nnok qw( baserel u5 D dev/alice/foo );\nnok qw( baserel u5 D refs/tags/dev/alice/foo );\n\nnok qw( baserel u6 R );\nnok qw( baserel u6 W master );\nnok qw( baserel u6 W notmaster );\nnok qw( baserel u6 W refs/tags/boo );\nnok qw( baserel u6 W refs/tags/v1 );\nnok qw( baserel u6 W dev/u6/foo );\nnok qw( baserel u6 W refs/tags/dev/u6/foo );\nnok qw( baserel u6 W dev/alice/foo );\nnok qw( baserel u6 W refs/tags/dev/alice/foo );\nnok qw( baserel u6 + master );\nnok qw( baserel u6 + notmaster );\nnok qw( baserel u6 + refs/tags/boo );\nnok qw( baserel u6 + refs/tags/v1 );\nnok qw( baserel u6 + dev/u6/foo );\nnok qw( baserel u6 + refs/tags/dev/u6/foo );\nnok qw( baserel u6 + dev/alice/foo );\nnok qw( baserel u6 + refs/tags/dev/alice/foo );\nnok qw( baserel u6 C master );\nnok qw( baserel u6 C notmaster );\nnok qw( baserel u6 C refs/tags/boo );\nnok qw( baserel u6 C refs/tags/v1 );\nnok qw( baserel u6 C dev/u6/foo );\nnok qw( baserel u6 C refs/tags/dev/u6/foo );\nnok qw( baserel u6 C dev/alice/foo );\nnok qw( baserel u6 C refs/tags/dev/alice/foo );\nnok qw( baserel u6 D master );\nnok qw( baserel u6 D notmaster );\nnok qw( baserel u6 D refs/tags/boo );\nnok qw( baserel u6 D refs/tags/v1 );\nnok qw( baserel u6 D dev/u6/foo );\nnok qw( baserel u6 D refs/tags/dev/u6/foo );\nnok qw( baserel u6 D dev/alice/foo );\nnok qw( baserel u6 D refs/tags/dev/alice/foo );\n\nok  qw( baseall admin R );\nok  qw( baseall admin W master );\nok  qw( baseall admin W notmaster );\nok  qw( baseall admin W refs/tags/boo );\nok  qw( baseall admin W refs/tags/v1 );\nok  qw( baseall admin W dev/admin/foo );\nok  qw( baseall admin W refs/tags/dev/admin/foo );\nok  qw( baseall admin W dev/alice/foo );\nok  qw( baseall admin W refs/tags/dev/alice/foo );\nok  qw( baseall admin + master );\nok  qw( baseall admin + notmaster );\nok  qw( baseall admin + refs/tags/boo );\nok  qw( baseall admin + refs/tags/v1 );\nok  qw( baseall admin + dev/admin/foo );\nok  qw( baseall admin + refs/tags/dev/admin/foo );\nok  qw( baseall admin + dev/alice/foo );\nok  qw( baseall admin + refs/tags/dev/alice/foo );\nok  qw( baseall admin C master );\nok  qw( baseall admin C notmaster );\nok  qw( baseall admin C refs/tags/boo );\nok  qw( baseall admin C refs/tags/v1 );\nok  qw( baseall admin C dev/admin/foo );\nok  qw( baseall admin C refs/tags/dev/admin/foo );\nok  qw( baseall admin C dev/alice/foo );\nok  qw( baseall admin C refs/tags/dev/alice/foo );\nok  qw( baseall admin D master );\nok  qw( baseall admin D notmaster );\nok  qw( baseall admin D refs/tags/boo );\nok  qw( baseall admin D refs/tags/v1 );\nok  qw( baseall admin D dev/admin/foo );\nok  qw( baseall admin D refs/tags/dev/admin/foo );\nok  qw( baseall admin D dev/alice/foo );\nok  qw( baseall admin D refs/tags/dev/alice/foo );\n\nok  qw( baseall u1 R );\nok  qw( baseall u1 W master );\nok  qw( baseall u1 W notmaster );\nok  qw( baseall u1 W refs/tags/boo );\nnok qw( baseall u1 W refs/tags/v1 );\nok  qw( baseall u1 W dev/u1/foo );\nok  qw( baseall u1 W refs/tags/dev/u1/foo );\nnok qw( baseall u1 W dev/alice/foo );\nnok qw( baseall u1 W refs/tags/dev/alice/foo );\nok  qw( baseall u1 + master );\nok  qw( baseall u1 + notmaster );\nok  qw( baseall u1 + refs/tags/boo );\nnok qw( baseall u1 + refs/tags/v1 );\nok  qw( baseall u1 + dev/u1/foo );\nok  qw( baseall u1 + refs/tags/dev/u1/foo );\nnok qw( baseall u1 + dev/alice/foo );\nnok qw( baseall u1 + refs/tags/dev/alice/foo );\nok  qw( baseall u1 C master );\nok  qw( baseall u1 C notmaster );\nok  qw( baseall u1 C refs/tags/boo );\nnok qw( baseall u1 C refs/tags/v1 );\nok  qw( baseall u1 C dev/u1/foo );\nok  qw( baseall u1 C refs/tags/dev/u1/foo );\nnok qw( baseall u1 C dev/alice/foo );\nnok qw( baseall u1 C refs/tags/dev/alice/foo );\nok  qw( baseall u1 D master );\nok  qw( baseall u1 D notmaster );\nok  qw( baseall u1 D refs/tags/boo );\nnok qw( baseall u1 D refs/tags/v1 );\nok  qw( baseall u1 D dev/u1/foo );\nok  qw( baseall u1 D refs/tags/dev/u1/foo );\nnok qw( baseall u1 D dev/alice/foo );\nnok qw( baseall u1 D refs/tags/dev/alice/foo );\n\nok  qw( baseall u2 R );\nok  qw( baseall u2 W master );\nok  qw( baseall u2 W notmaster );\nok  qw( baseall u2 W refs/tags/boo );\nnok qw( baseall u2 W refs/tags/v1 );\nok  qw( baseall u2 W dev/u2/foo );\nok  qw( baseall u2 W refs/tags/dev/u2/foo );\nnok qw( baseall u2 W dev/alice/foo );\nnok qw( baseall u2 W refs/tags/dev/alice/foo );\nnok qw( baseall u2 + master );\nnok qw( baseall u2 + notmaster );\nnok qw( baseall u2 + refs/tags/boo );\nnok qw( baseall u2 + refs/tags/v1 );\nok  qw( baseall u2 + dev/u2/foo );\nok  qw( baseall u2 + refs/tags/dev/u2/foo );\nnok qw( baseall u2 + dev/alice/foo );\nnok qw( baseall u2 + refs/tags/dev/alice/foo );\nok  qw( baseall u2 C master );\nok  qw( baseall u2 C notmaster );\nok  qw( baseall u2 C refs/tags/boo );\nnok qw( baseall u2 C refs/tags/v1 );\nok  qw( baseall u2 C dev/u2/foo );\nok  qw( baseall u2 C refs/tags/dev/u2/foo );\nnok qw( baseall u2 C dev/alice/foo );\nnok qw( baseall u2 C refs/tags/dev/alice/foo );\nnok qw( baseall u2 D master );\nnok qw( baseall u2 D notmaster );\nnok qw( baseall u2 D refs/tags/boo );\nnok qw( baseall u2 D refs/tags/v1 );\nok  qw( baseall u2 D dev/u2/foo );\nok  qw( baseall u2 D refs/tags/dev/u2/foo );\nnok qw( baseall u2 D dev/alice/foo );\nnok qw( baseall u2 D refs/tags/dev/alice/foo );\n\nok  qw( baseall u3 R );\nnok qw( baseall u3 W master );\nok  qw( baseall u3 W notmaster );\nok  qw( baseall u3 W refs/tags/boo );\nnok qw( baseall u3 W refs/tags/v1 );\nok  qw( baseall u3 W dev/u3/foo );\nok  qw( baseall u3 W refs/tags/dev/u3/foo );\nnok qw( baseall u3 W dev/alice/foo );\nnok qw( baseall u3 W refs/tags/dev/alice/foo );\nnok qw( baseall u3 + master );\nnok qw( baseall u3 + notmaster );\nnok qw( baseall u3 + refs/tags/boo );\nnok qw( baseall u3 + refs/tags/v1 );\nok  qw( baseall u3 + dev/u3/foo );\nok  qw( baseall u3 + refs/tags/dev/u3/foo );\nnok qw( baseall u3 + dev/alice/foo );\nnok qw( baseall u3 + refs/tags/dev/alice/foo );\nnok qw( baseall u3 C master );\nok  qw( baseall u3 C notmaster );\nok  qw( baseall u3 C refs/tags/boo );\nnok qw( baseall u3 C refs/tags/v1 );\nok  qw( baseall u3 C dev/u3/foo );\nok  qw( baseall u3 C refs/tags/dev/u3/foo );\nnok qw( baseall u3 C dev/alice/foo );\nnok qw( baseall u3 C refs/tags/dev/alice/foo );\nnok qw( baseall u3 D master );\nnok qw( baseall u3 D notmaster );\nnok qw( baseall u3 D refs/tags/boo );\nnok qw( baseall u3 D refs/tags/v1 );\nok  qw( baseall u3 D dev/u3/foo );\nok  qw( baseall u3 D refs/tags/dev/u3/foo );\nnok qw( baseall u3 D dev/alice/foo );\nnok qw( baseall u3 D refs/tags/dev/alice/foo );\n\nok  qw( baseall u4 R );\nnok qw( baseall u4 W master );\nnok qw( baseall u4 W notmaster );\nnok qw( baseall u4 W refs/tags/boo );\nnok qw( baseall u4 W refs/tags/v1 );\nnok qw( baseall u4 W dev/u4/foo );\nnok qw( baseall u4 W refs/tags/dev/u4/foo );\nnok qw( baseall u4 W dev/alice/foo );\nnok qw( baseall u4 W refs/tags/dev/alice/foo );\nnok qw( baseall u4 + master );\nnok qw( baseall u4 + notmaster );\nnok qw( baseall u4 + refs/tags/boo );\nnok qw( baseall u4 + refs/tags/v1 );\nnok qw( baseall u4 + dev/u4/foo );\nnok qw( baseall u4 + refs/tags/dev/u4/foo );\nnok qw( baseall u4 + dev/alice/foo );\nnok qw( baseall u4 + refs/tags/dev/alice/foo );\nnok qw( baseall u4 C master );\nnok qw( baseall u4 C notmaster );\nnok qw( baseall u4 C refs/tags/boo );\nnok qw( baseall u4 C refs/tags/v1 );\nnok qw( baseall u4 C dev/u4/foo );\nnok qw( baseall u4 C refs/tags/dev/u4/foo );\nnok qw( baseall u4 C dev/alice/foo );\nnok qw( baseall u4 C refs/tags/dev/alice/foo );\nnok qw( baseall u4 D master );\nnok qw( baseall u4 D notmaster );\nnok qw( baseall u4 D refs/tags/boo );\nnok qw( baseall u4 D refs/tags/v1 );\nnok qw( baseall u4 D dev/u4/foo );\nnok qw( baseall u4 D refs/tags/dev/u4/foo );\nnok qw( baseall u4 D dev/alice/foo );\nnok qw( baseall u4 D refs/tags/dev/alice/foo );\n\nok  qw( baseall u5 R );\nnok qw( baseall u5 W master );\nnok qw( baseall u5 W notmaster );\nnok qw( baseall u5 W refs/tags/boo );\nnok qw( baseall u5 W refs/tags/v1 );\nok  qw( baseall u5 W dev/u5/foo );\nok  qw( baseall u5 W refs/tags/dev/u5/foo );\nnok qw( baseall u5 W dev/alice/foo );\nnok qw( baseall u5 W refs/tags/dev/alice/foo );\nnok qw( baseall u5 + master );\nnok qw( baseall u5 + notmaster );\nnok qw( baseall u5 + refs/tags/boo );\nnok qw( baseall u5 + refs/tags/v1 );\nok  qw( baseall u5 + dev/u5/foo );\nok  qw( baseall u5 + refs/tags/dev/u5/foo );\nnok qw( baseall u5 + dev/alice/foo );\nnok qw( baseall u5 + refs/tags/dev/alice/foo );\nnok qw( baseall u5 C master );\nnok qw( baseall u5 C notmaster );\nnok qw( baseall u5 C refs/tags/boo );\nnok qw( baseall u5 C refs/tags/v1 );\nok  qw( baseall u5 C dev/u5/foo );\nok  qw( baseall u5 C refs/tags/dev/u5/foo );\nnok qw( baseall u5 C dev/alice/foo );\nnok qw( baseall u5 C refs/tags/dev/alice/foo );\nnok qw( baseall u5 D master );\nnok qw( baseall u5 D notmaster );\nnok qw( baseall u5 D refs/tags/boo );\nnok qw( baseall u5 D refs/tags/v1 );\nok  qw( baseall u5 D dev/u5/foo );\nok  qw( baseall u5 D refs/tags/dev/u5/foo );\nnok qw( baseall u5 D dev/alice/foo );\nnok qw( baseall u5 D refs/tags/dev/alice/foo );\n\nok  qw( baseall u6 R );\nnok qw( baseall u6 W master );\nnok qw( baseall u6 W notmaster );\nnok qw( baseall u6 W refs/tags/boo );\nnok qw( baseall u6 W refs/tags/v1 );\nok  qw( baseall u6 W dev/u6/foo );\nok  qw( baseall u6 W refs/tags/dev/u6/foo );\nnok qw( baseall u6 W dev/alice/foo );\nnok qw( baseall u6 W refs/tags/dev/alice/foo );\nnok qw( baseall u6 + master );\nnok qw( baseall u6 + notmaster );\nnok qw( baseall u6 + refs/tags/boo );\nnok qw( baseall u6 + refs/tags/v1 );\nok  qw( baseall u6 + dev/u6/foo );\nok  qw( baseall u6 + refs/tags/dev/u6/foo );\nnok qw( baseall u6 + dev/alice/foo );\nnok qw( baseall u6 + refs/tags/dev/alice/foo );\nnok qw( baseall u6 C master );\nnok qw( baseall u6 C notmaster );\nnok qw( baseall u6 C refs/tags/boo );\nnok qw( baseall u6 C refs/tags/v1 );\nok  qw( baseall u6 C dev/u6/foo );\nok  qw( baseall u6 C refs/tags/dev/u6/foo );\nnok qw( baseall u6 C dev/alice/foo );\nnok qw( baseall u6 C refs/tags/dev/alice/foo );\nnok qw( baseall u6 D master );\nnok qw( baseall u6 D notmaster );\nnok qw( baseall u6 D refs/tags/boo );\nnok qw( baseall u6 D refs/tags/v1 );\nok  qw( baseall u6 D dev/u6/foo );\nok  qw( baseall u6 D refs/tags/dev/u6/foo );\nnok qw( baseall u6 D dev/alice/foo );\nnok qw( baseall u6 D refs/tags/dev/alice/foo );\n\n"
  },
  {
    "path": "t/vrefs-1.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\n# VREFs - part 1\n# ----------------------------------------------------------------------\n\ntry \"plan 88\";\n\nput \"conf/gitolite.conf\", \"\n    repo gitolite-admin\n        RW+     =   admin\n\n    \\@gfoo = foo\n    \\@lead = u1\n    \\@dev2 = u2\n    \\@dev4 = u4\n    \\@devs = \\@dev2 \\@dev4 u6\n    repo  \\@gfoo\n          RW+                   =   \\@lead \\@devs\n          # intentional mis-spelling\n          -     VREF/MISCOUNT/2    =   \\@dev2\n          -     VREF/MISCOUNT/4    =   \\@dev4\n          -     VREF/MISCOUNT/3/NEWFILES   =   u6\n          -     VREF/MISCOUNT/6            =   u6\n\";\n\ntry \"\n    ADMIN_PUSH vr1a\n    cd ..\n    [ -d foo ];                 !ok\n    CLONE u1 foo;               ok;     /Cloning into/\n                                        /You appear to have cloned an empty/\n    cd foo;                     ok\n    [ -d .git ];                ok\n\n    # VREF not called for u1\n    tc a1 a2 a3 a4 a5;          ok;     /aaf9e8e/\n    PUSH u1 master;             ok;     /new branch.*master -. master/\n                                        !/helper program missing/\n                                        !/hook declined/\n                                        !/remote rejected/\n    # VREF is called for u2\n    tc b1;                      ok;     /1f440d3/\n    PUSH u2;                    !ok;    /helper program missing/\n                                        /hook declined/\n                                        /remote rejected/\n\";\n\nput \"../gitolite-admin/conf/gitolite.conf\", \"\n    repo gitolite-admin\n        RW+     =   admin\n\n    \\@gfoo = foo\n    \\@lead = u1\n    \\@dev2 = u2\n    \\@dev4 = u4\n    \\@devs = \\@dev2 \\@dev4 u6\n    repo  \\@gfoo\n          RW+                   =   \\@lead \\@devs\n          -     VREF/COUNT/2    =   \\@dev2\n          -     VREF/COUNT/4    =   \\@dev4\n          -     VREF/COUNT/3/NEWFILES   =   u6\n          -     VREF/COUNT/6            =   u6\n\";\n\ntry \"\n    ADMIN_PUSH vr1b\n    cd ../foo;                  ok\n\n    # u2 1 file\n    PUSH u2;                    ok;     /aaf9e8e..1f440d3.*master -. master/\n\n    # u2 2 files\n    tc b2 b3;                   ok;     /c3397f7/\n    PUSH u2;                    ok;     /1f440d3..c3397f7.*master -. master/\n\n    # u2 3 files\n    tc c1 c2 c3;                ok;     /be242d7/\n    PUSH u2;                    !ok;    /W VREF/COUNT/2 foo u2 DENIED by VREF/COUNT/2/\n                                        /too many changed files in this push/\n                                        /hook declined/\n                                        /remote rejected/\n\n    # u4 3 files\n    PUSH u4;                    ok;     /c3397f7..be242d7.*master -. master/\n\n    # u4 4 files\n    tc d1 d2 d3 d4;             ok;     /88d80e2/\n    PUSH u4;                    ok;     /be242d7..88d80e2.*master -. master/\n\n    # u4 5 files\n    tc d5 d6 d7 d8 d9;          ok;     /e9c60b0/\n    PUSH u4;                    !ok;    /W VREF/COUNT/4 foo u4 DENIED by VREF/COUNT/4/\n                                        /too many changed files in this push/\n                                        /hook declined/\n                                        /remote rejected/\n\n    # u1 all files\n    PUSH u1;                    ok;     /88d80e2..e9c60b0.*master -. master/\n\n    # u6 6 old files\n    test-tick\n    tc d1 d2 d3 d4 d5 d6\n                                ok;     /2773f0a/\n    PUSH u6;                    ok;     /e9c60b0..2773f0a.*master -. master/\n    tag six\n\n    # u6 updates 7 old files\n    test-tick; test-tick\n    tc d1 d2 d3 d4 d5 d6 d7\n                                ok;     /d3fb574/\n    PUSH u6;                    !ok;    /W VREF/COUNT/6 foo u6 DENIED by VREF/COUNT/6/\n                                        /too many changed files in this push/\n                                        /hook declined/\n                                        /remote rejected/\n    reset-h six;                ok;     /HEAD is now at 2773f0a/\n\n    # u6 4 new 2 old files\n    test-tick; test-tick\n    tc d1 d2 n1 n2 n3 n4\n                                ok;     /9e90848/\n    PUSH u6;                    !ok;    /W VREF/COUNT/3/NEWFILES foo u6 DENIED by VREF/COUNT/3/NEWFILES/\n                                        /too many new files in this push/\n                                        /hook declined/\n                                        /remote rejected/\n    reset-h six;                ok;     /HEAD is now at 2773f0a/\n\n    # u6 3 new 3 old files\n    test-tick; test-tick\n    tc d1 d2 d3 n1 n2 n3\n                                ok;     /e47ff5d/\n    PUSH u6;                    ok;     /2773f0a..e47ff5d.*master -. master/\n\";\n"
  },
  {
    "path": "t/vrefs-2.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\n# VREFs - part 2\n# ----------------------------------------------------------------------\n\ntry \"plan 72\";\n\nput \"../gitolite-admin/conf/gitolite.conf\", \"\n    \\@gfoo = foo\n    \\@lead = u1\n    \\@senior_devs = u2 u3\n    \\@junior_devs = u4 u5 u6\n    repo  \\@gfoo\n\n        RW+                                 =   \\@all\n\n        RW+ VREF/COUNT/2/NO_SIGNOFF         =   \\@lead\n        -   VREF/COUNT/2/NO_SIGNOFF         =   \\@all\n\n        -   VREF/COUNT/10/NEWFILES          =   \\@junior_devs\n\n        -   VREF/FILETYPE/AUTOGENERATED     =   \\@all\n\";\n\ntry \"\n    ADMIN_PUSH vr2a\n    cd ..\n    # setup\n    [ -d foo ];                 !ok\n    CLONE u1 foo;               ok;     /Cloning into/\n                                        /You appear to have cloned an empty/\n    cd foo;                     ok\n    [ -d .git ];                ok\n\n    # u1 push 15 new files\n    tc a b c d e f g h i j k l m n o\n                                ok;     /d8c0392/\n    PUSH u1 master;             ok;     /new branch.*master -. master/\n\n    # u2 push 2 new 10 old without signoff\n    tc a b c d e f g h i j u2a u2b\n                                ok;     /6787ac9/\n    PUSH u2;                    ok;     /d8c0392..6787ac9.*master -. master/\n\n    # u2 fail to push 3 new files without signoff\n    tc u2c u2d u2e;             ok;     /a74562b/\n    PUSH u2;                    !ok;    /W VREF/COUNT/2/NO_SIGNOFF foo u2 DENIED by VREF/COUNT/2/NO_SIGNOFF/\n                                        /top commit message should include the text .3 new files signed-off by: tester.example.com./\n                                        /hook declined/\n                                        /remote rejected/\n    # u2 push 15 new files with signoff\n    tc u2f u2g u2h u2i u2j u2k u2l u2m u2n u2o u2p u2q\n                                ok;     /8dd31aa/\n    git commit --allow-empty -m '15 new files signed-off by: tester\\@example.com'\n                                ok;     /.master 6126489. 15 new files signed-off by: tester.example.com/\n    PUSH u2;                    ok;     /6787ac9..6126489.*master -. master/\n\n    # u4 push 2 new 10 old files without signoff\n    tc u4a u4b a b c d e f g h i j\n                                ok;     /76c5593/\n    PUSH u4;                    ok;     /6126489..76c5593.*master -. master/\n\n    # u4 fail push 3 new files withoug signoff\n    tc u4c u4d u4e;             ok;     /2a84398/\n    PUSH u4;                    !ok;    /W VREF/COUNT/2/NO_SIGNOFF foo u4 DENIED by VREF/COUNT/2/NO_SIGNOFF/\n                                        /top commit message should include the text .3 new files signed-off by: tester.example.com./\n                                        /hook declined/\n                                        /remote rejected/\n\n    # u4 push 10 new 5 old with signoff\n    tc u4f u4g u4h u4i u4j u4k u4l a b c d e\n                                ok;     /09b646a/\n    git commit --allow-empty -m '10 new files signed-off by: tester\\@example.com'\n                                ok;     /.master 47f84b0. 10 new files signed-off by: tester.example.com/\n    PUSH u4;                    ok;     /76c5593..47f84b0.*master -. master/\n\n    # u4 fail push 11 new files even with signoff\n    tc u4ab u4ac u4ad u4ae u4af u4ag u4ah u4ai u4aj u4ak u4al\n                                ok;     /90e7344/\n    git commit --allow-empty -m '11 new files signed-off by: tester\\@example.com'\n                                ok;     /.master 1f36537. 11 new files signed-off by: tester.example.com/\n    PUSH u4;                    !ok;    /W VREF/COUNT/10/NEWFILES foo u4 DENIED by VREF/COUNT/10/NEWFILES/\n                                        /too many new files in this push/\n                                        /hook declined/\n                                        /remote rejected/\n\n    # test AUTOGENERATED vref\n    glt fetch u1 origin;        ok;\n    reset-h origin/master;      ok;\n    tc not-really.java;         ok;     /0f88b2e/\n    PUSH u4;                    ok;     /47f84b0..0f88b2e.*master -. master/\n\";\n\nput \"|cat >> not-really.java\", \"\n    Generated by the protocol buffer compiler.  DO NOT EDIT\n\";\n\ntry \"\n    commit -am pbc;             ok;     /b2df6ef/\n    PUSH u4;                    !ok;    /W VREF/FILETYPE/AUTOGENERATED foo u4 DENIED by VREF/FILETYPE/AUTOGENERATED/\n                                        /hook declined/\n                                        /remote rejected/\n\";\n"
  },
  {
    "path": "t/wild-1.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\n# wild repos - part 1\n# ----------------------------------------------------------------------\n\ntry \"plan 66\";\n\nconfreset;confadd '\n    @prof       =   u1\n    @TAs        =   u2 u3\n    @students   =   u4 u5 u6\n\n    @gfoo = foo/CREATOR/a[0-9][0-9]\n    repo    @gfoo\n        C   =   @all\n        RW+ =   CREATOR\n        RW  =   WRITERS @TAs\n        R   =   READERS @prof\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"\n# reasonably complex setup; we'll do everything from one repo though\ncd ..\n\n# u1 create success\nglt clone u1 file:///foo/u1/a01;        ok;     /Initialized empty Git repository in .*/foo/u1/a01.git//\n\n# u2 create success\nglt clone u2 file:///foo/u2/a02;        ok;     /Initialized empty Git repository in .*/foo/u2/a02.git//\n\n# u4 tries to create u2 repo\nglt clone u4 file:///foo/u2/a12;        !ok;    /R any foo/u2/a12 u4 DENIED by fallthru/\n\n# line anchored regexes\nglt clone u4 file:///foo/u4/a1234;      !ok;    /R any foo/u4/a1234 u4 DENIED by fallthru/\n\n# u4 tries to create his own repo\nglt clone u4 file:///foo/u4/a12;        ok;     /Initialized empty Git repository in .*/foo/u4/a12.git//\n                                                /warning: You appear to have cloned an empty repository./\n\n# u4 push success\ncd a12\ntc p-728 p-729 p-730 p-731;             ok\nglt push u4 origin master;              ok;     /To file:///foo/u4/a12/\n                                                /\\\\* \\\\[new branch\\\\]      master -> master/\n\n# u1 clone success\ncd ..\nglt clone u1 file:///foo/u4/a12 u1a12;  ok;     /Cloning into 'u1a12'.../\n\n# u1 push fail\ncd u1a12\ntc m-778 m-779;                         ok;\nglt push u1 origin;                     !ok;    /W any foo/u4/a12 u1 DENIED by fallthru/\n\n# u2 clone success\ncd ..\nglt clone u2 file:///foo/u4/a12 u2a12;  ok;     /Cloning into 'u2a12'.../\n\n# u2 push success\ncd u2a12\ntc s-708 s-709;                         ok;\nglt push u2 origin;                     ok;     /To file:///foo/u4/a12/\n                                                /master -> master/\n\n# u2 rewind fail\nglt push u2 -f origin master^:master;   !ok;    /\\\\+ refs/heads/master foo/u4/a12 u2 DENIED by fallthru/\n                                                reject\n\n# u4 pull to sync up\ncd ../a12\nglt pull u4;                            ok;     /Fast-forward/\n                                                /From file:///foo/u4/a12/\n                                                /master     -> origin/master/\n\n# u4 rewind success\ngit reset --hard HEAD^;                 ok\nglt push u4 -f;                         ok;     /To file:///foo/u4/a12/\n                                                /\\\\+ .* master -> master \\\\(forced update\\\\)/\n\n# u5 clone fail\ncd ..\nglt clone u5 file:///foo/u4/a12 u5a12;  !ok;    /R any foo/u4/a12 u5 DENIED by fallthru/\n\nglt perms u4 foo/u4/a12 + READERS u5\nglt perms u4 foo/u4/a12 + WRITERS u6\n\nglt perms u4 foo/u4/a12 -l\n\";\n\ncmp 'READERS u5\nWRITERS u6\n';\n\ntry \"\n# u5 clone success\nglt clone u5 file:///foo/u4/a12 u5a12;  ok;     /Cloning into 'u5a12'.../\n\n# u5 push fail\ncd u5a12\ntc y-743 y-744;                         ok\nglt push u5;                            !ok;    /W any foo/u4/a12 u5 DENIED by fallthru/\n\n# u6 clone success\ncd ..\nglt clone u6 file:///foo/u4/a12 u6a12;  ok;     /Cloning into 'u6a12'.../\n\n# u6 push success\ncd u6a12\ntc k-68 k-69;                           ok\nglt push u6 file:///foo/u4/a12;         ok;     /To file:///foo/u4/a12/\n                                                /master -> master/\n\n# u6 rewind fail\nglt push u6 -f file:///foo/u4/a12 master^:master\n                                        !ok;    /\\\\+ refs/heads/master foo/u4/a12 u6 DENIED by fallthru/\n                                                reject\n\";\n"
  },
  {
    "path": "t/wild-2.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\n# wild repos - part 2\n# ----------------------------------------------------------------------\n\ntry \"plan 65\";\n\nconfreset;confadd '\n    @prof       =   u1\n    @TAs        =   u2 u3\n    @students   =   u4 u5 u6\n\n    @gfoo = foo/CREATOR/a[0-9][0-9]\n    repo    @gfoo\n        C   =   @students\n        RW+ =   CREATOR\n        RW  =   WRITERS @TAs\n        R   =   READERS @prof\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"\ncd ..\n\n# u1 create fail\nglt clone u1 file:///foo/u1/a01;        !ok;    /R any foo/u1/a01 u1 DENIED by fallthru/\n\n# u2 create fail\nglt clone u2 file:///foo/u2/a02;        !ok;    /R any foo/u2/a02 u2 DENIED by fallthru/\n\n# u4 tries to create u2 repo\nglt clone u4 file:///foo/u2/a12;        !ok;    /R any foo/u2/a12 u4 DENIED by fallthru/\n\n# line anchored regexes\nglt clone u4 file:///foo/u4/a1234;      !ok;    /R any foo/u4/a1234 u4 DENIED by fallthru/\n\n# u4 tries to create his own repo\nglt clone u4 file:///foo/u4/a12;        ok;     /Initialized empty Git repository in .*/foo/u4/a12.git//\n                                                /warning: You appear to have cloned an empty repository./\n\n# u4 push success\ncd a12\ntc n-770 n-771 n-772 n-773;             ok\nglt push u4 origin master;              ok;     /To file:///foo/u4/a12/\n                                                /\\\\* \\\\[new branch\\\\]      master -> master/\n\n# u1 clone success\ncd ..\nglt clone u1 file:///foo/u4/a12 u1a12;  ok;     /Cloning into 'u1a12'.../\n\n# u1 push fail\ncd u1a12\ntc c-442 c-443;                         ok\nglt push u1;                            !ok;    /W any foo/u4/a12 u1 DENIED by fallthru/\n\n# u2 clone success\ncd ..\nglt clone u2 file:///foo/u4/a12 u2a12;  ok;     /Cloning into 'u2a12'.../\n\n# u2 push success\ncd u2a12\ntc e-393 e-394;                         ok;\nglt push u2;                            ok;     /To file:///foo/u4/a12/\n                                                /master -> master/\n\n# u2 rewind fail\nglt push u2 -f origin master^:master;   !ok;    /\\\\+ refs/heads/master foo/u4/a12 u2 DENIED by fallthru/\n                                                reject\n\n# u4 pull to sync up\ncd ../a12\nglt pull u4;                            ok;     /Fast-forward/\n                                                /From file:///foo/u4/a12/\n                                                /master     -> origin/master/\n\n# u4 rewind success\ngit reset --hard HEAD^;                 ok\nglt push u4 -f;                         ok;     /To file:///foo/u4/a12/\n                                                /\\\\+ .* master -> master \\\\(forced update\\\\)/\n\n# u5 clone fail\ncd ..\nglt clone u5 file:///foo/u4/a12 u5a12;  !ok;    /R any foo/u4/a12 u5 DENIED by fallthru/\n\n# setperm\nglt perms u4 foo/u4/a12 + READERS u5\nglt perms u4 foo/u4/a12 + WRITERS u6\n\n# getperms\nglt perms u4 foo/u4/a12 -l\n\";\n\ncmp 'READERS u5\nWRITERS u6\n';\n\ntry \"\n# u5 clone success\nglt clone u5 file:///foo/u4/a12 u5a12;  ok;     /Cloning into 'u5a12'.../\n\n# u5 push fail\ncd u5a12\ntc g-809 g-810;                         ok\nglt push u5;                            !ok;    /W any foo/u4/a12 u5 DENIED by fallthru/\n\n# u6 clone success\ncd ..\nglt clone u6 file:///foo/u4/a12 u6a12;  ok;     /Cloning into 'u6a12'.../\n\n# u6 push success\ncd u6a12\ntc f-912 f-913\nglt push u6 file:///foo/u4/a12;         ok;     /To file:///foo/u4/a12/\n                                                /master -> master/\n\n# u6 rewind fail\nglt push u6 -f file:///foo/u4/a12 master^:master\n                                        !ok;    /\\\\+ refs/heads/master foo/u4/a12 u6 DENIED by fallthru/\n                                                reject\n\n\";\n"
  },
  {
    "path": "t/writable.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\nuse Cwd;\nmy $workdir = getcwd();\n\n# 'gitolite writable' command\n# ----------------------------------------------------------------------\n\nmy $sf = \".gitolite.down\";\n\ntry \"plan 66\";\ntry \"DEF POK = !/DENIED/; !/failed to push/\";\n\n# delete the down file\nunlink \"$ENV{HOME}/$sf\";\n\n# add foo, bar/..* repos to the config and push\nconfreset;confadd '\n    repo foo\n        RW  =   u1\n        R   =   u2\n\n    repo bar/..*\n        C   =   u2 u4 u6\n        RW  =   CREATOR u3\n';\n\ntry \"ADMIN_PUSH set1; !/FATAL/\" or die text();\n\ntry \"\n    # clone and push to foo\n    CLONE u1 foo;               ok\n    cd foo;                     ok\n    tc f1;                      ok\n    PUSH u1 master;             ok;     /new branch/\n\n    # auto-clone and push to bar/u2\n    cd ..\n    CLONE u2 bar/u2;            ok;     /appear to have cloned an empty/\n                                        /Initialized empty/\n    cd u2;\n    tc f2\n    PUSH u2 master;             ok;\n\n    # disable site with some message\n    gitolite writable \\@all off testing site-wide disable; ok\n\n    # try push foo and see fail + message\n    cd ../foo;                  ok\n    tc f3;                      ok\n    PUSH u1;                    !ok;    /testing site-wide disable/\n    # try push bar/u2 and ...\n    cd ../u2;                   ok\n    tc f4;                      ok\n    PUSH u2;                    !ok;    /testing site-wide disable/\n\n    # try auto-create push bar/u4 and this works!!\n    cd ..\n    CLONE u4 bar/u4;            ok;     /appear to have cloned an empty/\n                                        /Initialized empty/\n                                        !/testing site-wide disable/\n    cd u4;                      ok\n\n    # enable site\n    gitolite writable \\@all on; ok\n\n    # try same 3 again\n\n    # try push foo and see fail + message\n    cd ../foo;                  ok\n    tc g3;                      ok\n    PUSH u1;                    ok;    /master -> master/\n    # try push bar/u2 and ...\n    cd ../u2;                   ok\n    tc g4;                      ok\n    PUSH u2;                    ok;    /master -> master/\n\n    # try auto-create push bar/u4 and this works!!\n    cd ..\n    CLONE u6 bar/u6;            ok;     /appear to have cloned an empty/\n                                        /Initialized empty/\n                                        !/testing site-wide disable/\n    cd u6;                      ok\n\n    # disable just foo\n    gitolite writable foo off foo down\n\n    # try push foo and see the message\n    cd ../foo;                  ok\n    tc g3;                      ok\n    PUSH u1;                    !ok;    /foo down/\n                                        !/testing site-wide disable/\n    # push bar/u2 ok\n    cd ../u2\n    tc g4\n    PUSH u2;                    ok;     /master -> master/\n\n    # enable foo, disable bar/u2\n    gitolite writable foo on\n    gitolite writable bar/u2 off the bar is closed\n\n    # try both\n    cd ../foo;                  ok\n    tc h3;                      ok\n    PUSH u1;                    ok;     /master -> master/\n    # push bar/u2 ok\n    cd ../u2\n    tc h4\n    PUSH u2;                    !ok;    /the bar is closed/\n\n    ssh u3 writable bar/u2 on;  !ok;    /you are not authorized/\n    ssh u3 writable \\@all on;   !ok;    /you are not authorized/\n\n    ssh u2 writable bar/u2 on;  ok\n    ssh u2 writable \\@all on;   !ok;    /you are not authorized/\n\n    ssh admin writable \\@all on;\n                                ok\n\";\n"
  },
  {
    "path": "t/z-end.t",
    "content": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n# this is hardcoded; change it if needed\nuse lib \"src/lib\";\nuse Gitolite::Test;\n\ntry \"plan 1; cd $ENV{PWD}; git status -s -uno; !/./ or die\" or die \"dirty tree\";\ntry \"git log -1 --format='%h %ai %s'\";\nput \"|cat >> prove.log\", text();\n\n\n\n"
  }
]