Docs feedback: Add examples of Prohibited file name rules to end of push rules page
https://docs.gitlab.com/13.4/ee/push_rules/push_rules.html
Our documentation on push rules could be enhanced by providing some simple examples of different ways to use the Prohibited file names capability to prevent adding files to a repository. A link to these examples should also be added to the Prohibited file names row in the options table to allow readers to quickly navigate to the examples. Sharing an md formatted section proposal that could be added to the end of this documentation page.
I found in testing this feature that it does not apply to files that already exist in the repository. This is not addressed in our documentation, so sharing a replacement row for Prohibited file names in the options table with additional language addressing this limitation and a link to the proposed new section.
If approved, I would be happy to create a corresponding MR for this addition.
EDIT NOTE MR created: !43232 (merged)
Replacement for row in options table
Push rule | GitLab version | Description |
---|---|---|
Prohibited file names | Starter 7.10 | Any committed filenames that match this regular expression and do not already exist in the repository are not allowed to be pushed. Leave empty to allow any filenames. See common examples. |
New section for the end of the page
Prohibited file names
Each file name contained in a git push is compared to the regular expression in this field. Filenames in git consist of both the file's name and any directory that may precede it. A singular regular expression can contain multiple independent matches used as exclusions. File names can be broadly matched to any location in the repository, or restricted to specific locations. Filenames can also be partial matches used to exclude file types by extension.
Note: Note:
These examples make use of regex string boundary characters which match the beginning of a string ^
, and the end $
. They also include instances where either the directory path or the filename can include .
or /
. Both of these special regex characters have to be escaped with a backslash \
to be used as normal characters in a match condition.
Example: prevent pushing any .exe files to any location in the repository. This is an example of a partial match, which can match any filename that contains .exe
at the end.
\.exe$
Example: prevent a specific configuration file in the repository root from being pushed.
^config\.yml$
Example: prevent a specific configuration file in a known directory from being pushed.
^directory-name\/config\.yml$
Example: prevent the specific file named install.exe
from being pushed to any location in the repository. Note that the parenthesized expression (^|\/)
will match either a file following a directory separator or a file in the repository root.
(^|\/)install\.exe$
Example: combining all of the above in a single expression. Note that all of the preceding expressions rely on the end of string character $
, so we can move that part of each expression to the end of the grouped collection of match conditions where it will be appended to all matches.
(\.exe|^config\.yml|^directory-name\/config\.yml|(^|\/)install\.exe)$