Commit Graph

575 Commits

Author SHA1 Message Date
Joel Brobecker
fabfa23a8a Reject early attempts to delete refs/meta/config
This is a followup on T227-003, where we enhanced the hooks to take
refs/meta/config updates into account right away. A small side-effect
of that change is that the error message when trying to delete the
refs/meta/config reference changed from...

    | This type of update (refs/meta/config,delete) is currently unsupported

... to ...

    | Unable to find the file project.config in refs/meta/config.
    |
    | Your repository appears to be incorrectly set up. Please contact
    | your repository's administrator to set your project.config file up.

The former wasn't all that great, but understandable. The new one
is not incorrect, but not very helpful. This patch therefore enhances
the hooks to provide a clear error message:

    | Deleting the reference refs/meta/config is not allowed.
    |
    | This reference provides important configuration information
    | and thus must not be deleted.

A new testcase is added to make sure we continue verifying
the error message in that situation.

Change-Id: I5178b40c0d003fbf8ffeb456592750ec38a9a047
2020-06-15 11:32:45 -07:00
Joel Brobecker
199add7429 use refs/meta/config:project.config hooks configuration immediately
This commit enhances the hooks to read the repository's configuration
from the most recent version. In particular, if an update is updating
the refs/meta/config reference, then read the configuration from that
update, instead of reading from the existing refs/meta/config reference.
For updates of all other references, the behavior remains unchanged.

A testcase (T227-003__meta_config_is_immediate) is added to verify
that refs/meta/config reference creation works as expected.

Following that change, various testcases also needed to be adapted
as follow:

  - MC27-006__meta_config_branch_create: Creating the refs/meta/config
    reference now works;

  - QC13-022__checker_config_on_its_own: This testcase was pushing
    a local branch called "meta-config" to refs/meta/config. This
    update introduced a style-checker-config-file configuration. Since
    the configuration is now taken into account right away, the update
    is was rejected due to the file not existing.

    The branch "meta-config" is renamed to "meta-config-missing",
    and a new branch "meta-config" was created, containg the missing
    file in addition to the configuration changes above.

    We first try to push the "meta-config-missing" to verify
    that this is rejected. We then try to push the (new) "meta-config"
    branch, verifying that the presence of the config file allows
    the push to be accepted.

  - T209-001__update_hook_not_found: A similar situation to the above,
    but with the update hook. The added comments in the testcase
    should make the changes self-explanatory.

  - T209-001__update_hook_reject: Modify the update-hook, which is
    called during reference updates, to not reject the refs/meta/config
    update the testcase is doing as part of the preliminary setup phase.

Change-Id: I0bd7bc0801ba08cd281a751759bba8c48ba0c454
TN: T227-003
2020-06-15 11:32:45 -07:00
Joel Brobecker
907ae1d0d4 drop support for legacy config file (untracked file located in bare repo)
When initially created, these hooks were reading the repository's
configuration from an untracked file, installed in the repository.
In December 2013, this method of configuring the hooks became obsolete,
in favor of getting the information from a file which is checked in.
However, to ease the transition, support for the untracked config
file was kept as a fallback, with a large warning asking the user
to contact the repository's admin to perform the transition.

At this point, it is believed that all repositories have now
transitioned, and therefore keeping this fallback is no longer
necessary.

This commit therefore removes support for that functionality.
A couple of testcases are adjusted accordingly. As a side-effect,
this caused the testing of branch creations for branches whose name
does not follow the standard naming scheme to no longer be tested.
This commit therefore adds one using a reference name which is not
refs/meta/config, thus ensuring that testing coverage remains at 100%.

Change-Id: I3e9c176f46e831ea82cdc930d32f7f22913a4fbc
TN: T314-004
2020-06-15 11:32:45 -07:00
Joel Brobecker
632028320b Introduce a pre-receive hook
The main purpose of that pre-receive hook is to ensure that any push
updating the refs/meta/config reference only updates that one reference.
A large comment was added to the code to explain why (in short, this is
a pre-requisite for being able to use the git-hooks config at the same
time the config changes are being pushed).

While at it, to be consistent with the other hooks, support for
a repository-specific pre-receive hook is added. One side-effect
of this is that we end up trying to query the hooks configuration,
which triggers a check for the existence of the refs/meta/config
branch. As a result, an extra copy of the same warning gets generated
when the reference doesn't exist. This is not super elegant, but
isn't a problem in practice, since this is part of handling a deprecated
feature that we'll try to remove support for hopefully soon. In the
meantime, this isn't blocking to adding support for the pre-receive
option.

Since this commit increased the number of times `refs/meta/config`
was spelled out (aka "hardcoded"), this commit introduces a new
constant to avoid duplicating that special reference name.

Change-Id: Ib4fc0a32f639fe693e4d43269baf8c0838fc9214
TN: T227-003
2020-06-15 11:32:45 -07:00
Joel Brobecker
8d422d55f5 README.md: Fix small typos in hooks.post-receive-hook documentation
Found (by Thomas Quinot) while working on T227-003

Change-Id: Ibe15874a39193328ad13814033b84c7be6c088ed
2020-06-15 11:32:45 -07:00
Joel Brobecker
611eb6e110 post_update.py: Make the command-line and stdin handling a little clearer
This commit is only there to simplify the logic behind handing
the data passed when calling the post_receive.py script. In particular,
this script receives information:
  - via the command-line, with the optional --submitter-email option;
  - via stdin, with one line per reference being updated.

I don't know what I was thinking at the time, but somehow, the way
I chose to handle this was by appending to each entry from stdin
the arguments from the command-line, and then use an ArgumentParser
to pass each stdin entry. It works, but in practice, the it makes
the code more difficult to understand. In fact, when I read this code
again recently, I missed the tiny "+ sys.argv[1:]" and so it made me
(wrongly) believe that the command-line arguments were entirely ignored!

So, this commit simplifies this by clearly separating the phase
of parsing the command-line, and the phase of processing each
entry passed via stdin by git.

Change-Id: I2e01a99e7c1931a56e9b95f196a2f73f9be70a2e
TN: T223-004
2020-06-15 11:32:45 -07:00
Joel Brobecker
41cfa82181 minor cleanup: Use enum.Enum class in updates/factory.py
This commit rewrites some code that was building a poor-man's version
of an enum type by an enum.Enum subclass. No functional change.

Seen while working on T209-003 (allowing custom ref naming)

Change-Id: I5dbe9b69a421c980b98f52896b6048d53dc1f764
2020-06-15 11:32:45 -07:00
Joel Brobecker
55be81f225 Add support for hooks.update-hook configuration option
This option allows users to specify a script to be run at update time,
for each reference being updated. This script can then be used to perform
additional checks on top of the standard checks already provided by
our git-hooks.

Change-Id: Iff527f1c9c0ba516ea5181c5f8c066c5175ef0ee
TN: T209-001
2020-06-15 11:32:45 -07:00
Joel Brobecker
123dc3f7db fix "bare 'except'" pycodestyle error in emails.py and utils.py
Change-Id: I839ca83142d5a07d8e986c06656825aaad9822ea
2020-06-15 11:32:45 -07:00
Joel Brobecker
05636d6c06 Remove gnatpython.fileutils wildcard import in testsuite/lib/support.py
Just import the one symbol that's actually used by the various
testcases in its place. This allows us to pass all current
style checks at AdaCore for Python files.

Change-Id: I458060771e18684e097e98131f292e09690a2e6d
2020-06-15 11:32:45 -07:00
Joel Brobecker
3256a04b2b make the summary-of-changes email (a lot) shorter
Add a comment in the function implementing this feature explaining
the reason behind the choices made for that email.

Change-Id: I267f52ea651218b461e3d6c3c79882b887184c9b
TN: T209-007
2020-06-15 11:32:45 -07:00
Joel Brobecker
d1a76a87a8 Change the hooks.non-fast-forward config to match the entire ref name
This lifts a limitation where non-fast-forward updates could only be
allowed for references whose name start with 'refs/heads/' (the
standard namespace for branches). As it happens, GCC is using branch
names in a different namespace. So this commit changes this config
option to match the entire reference name, rather than just the branch
name. There is a break in compatibility for the repositories already
using this configuration, but this change takes care of detecting
this situation and provide an informative message explaining the likely
situation.

Change-Id: I330d15ccef448e815c94a620f008275f1e1914db
TN: T209-002
2020-06-15 11:32:45 -07:00
Joel Brobecker
847eca781b [testsuite] do not ignore whitespaces when computing diffs
When a test wants to verify the output of a given command, it normally
does this as follow:

    self.assertRunOutputEqual(p, expected_out)

What this does is verify that the command's output matches, and if it
does not, then it not only reports and error, but also provides a diff
at the end, so as to facilitate the analysis.

However, while writing a test where that was unexpected failing
an output comparison, the diff in the error message was empty.
After investigation, it turned out that the function used to compute
that diff has a parameter ignore_white_chars set to True, which is
not what we want, here, and explains the discrepancy.

This commit fixes that by explicitly setting that parameter to False.
In the situation described above, this allowed the difference to
be shown in the diff section.

Change-Id: Ie5df10bcd7990eab928fc6f7fed3f41eaaa5d469
2020-06-15 11:32:45 -07:00
Joel Brobecker
4f536c6afd Avoid uncovered line of code in CommitInfo.base_rev_for_display
This line of code was highlighted as uncovered by the testsuite's
coverage analysis, and reveals that we never call this method with
a CommitInfo object whose `parent_revs' attribute is None.

This attribute is first set during the class's initialization
(__init__) to the value of the parameter of the same name. And
the reason why we check for None here is because the __init__
routine documents this paramenter as allowing None, signifying
that the actual value hasn't been computed yet. The purpose of
this is to allow users who know that they don't need the parents
to skip computing them just for the sake of creating an object
of this class.

Upon investigation, it turns out that the only place where objects
of this class are instantiated is in function commit_info_list, where
the list of parents is actually computed and provided to the class.
This shows that, as of today, this uncovered code is actually
unreachable.

There were several options:
  (a) It is conceivable that some callers might find it useful
      that the parents get automagically computed on demand,
      arguing in favor of keeping that code. If we keep the code,
      we can cover it via Unit Testing.
  (b) Document that the instantiators of this class must always
      provide the list of parents at instantiation, thus making
      the check for None moot, allowing us to simply remove it.
  (c) Continue to allow the use of None for the list of parents,
      but still removing the code, transfering the responsibility
      to the users to be sure that it is not None before calling it.

In the end, it felt better to follow what is true today rather than
what "might be" tomorrow, so this commit rejects option (a).
Option (b) is simplest, but has the drawback of reducing flexibility
in terms of performance tweaking.  This is why this commit chose
option (c), especially since it's trivial for users to handle this,
as it's just a matter of calling one function.

Change-Id: I3a01ab52c06ae36f249e0c01fbc7ea59616e6ded
2020-06-15 11:32:45 -07:00
Thomas Quinot
d5b93a65bd Do not let user's .gitconfig affect testsuite output
The testsuite depends on git running with default configuration.
Customizations in the user's global configuration ($HOME/.gitconfig)
should be ignored.

Change-Id: Iff4b3ba49294fd78bb1d5a78a908a9308ae0b5d8
2020-06-15 11:32:45 -07:00
Joel Brobecker
7eec2e0c01 Add .gitreview file to faciliate use of Gerrit reviews
Change-Id: If427d4d91cf365e7d7b35eb5381a3d8c11cbc1ff
TN: S425-012
2020-06-15 11:32:45 -07:00
Thomas Quinot
56f3ed28a7 Minor error message rewording 2020-06-15 11:32:45 -07:00
Thomas Quinot
46b874ca6d Merge pull request #3 from brobecke/WIP/add-users-guide
Add user documentation README.md
2019-09-26 11:03:46 +02:00
Joel Brobecker
141df74400 Add user documentation README.md
This also removes the README file, which is now superseded by
the new readme.
2019-09-16 20:52:06 -07:00
Thomas Quinot
0dc094118b Merge pull request #2 from brobecke/master
Improve format of note update notifications
2019-07-26 09:44:45 +02:00
Thomas Quinot
e9bacb490c Improve format of note update notifications
Include original commit name and note ref name (if not default)
in subject.

Minor wording tweaks.

for S724-027

Change-Id: I9660c19876627c1259e9b7a42ea7b2f9f9669f43
2019-07-25 07:54:10 -07:00
Thomas Quinot
0029b5d08b Merge pull request #1 from brobecke/master
Allow pushing notes other than "commits"
2019-07-24 17:55:10 +02:00
Thomas Quinot
f7d1f809e3 Allow pushing notes other than "commits"
For S724-017

Change-Id: Iff69884adb194dece85c900d8553a2073b38e540
2019-07-24 08:43:09 -07:00
Joel Brobecker
7644236b43 show correct location when identifying non-ISO-8859-15 characters in rev log
There was a bug when returning an error message indicating that
the revision contains non-ISO-8859-15, that would always show
the first line has having the unwanted character, even when
that characters was actually on a different line.

And while at it, I improved the error message to include the line
number as well. Just in case showing the text itself is either not
sufficient or just not as efficient.

Credit for finding the bug: Thomas Quinot (thank you!).

Followup on QB25-001.
2018-01-10 15:41:06 +04:00
Joel Brobecker
24ebc361d6 Add support for hooks.style-checker-config-file config
For QC13-022.
2017-12-13 17:35:05 +04:00