@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add a Herald pre-commit field for detecting LFS usage

Summary: Depends on D18825. Ref T7789. See PHI131. Allows installs to selectively disable LFS by adding Herald rules to block commits that use LFS.

Test Plan:
- Wrote an LFS rule ("When commit uses git lfs, block commit").
- Pushed an LFS commit: rejected.
- Pushed a non-lFS commit: success.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T7789

Differential Revision: https://secure.phabricator.com/D18827

+43
+2
src/__phutil_library_map__.php
··· 821 821 'DiffusionPreCommitRefRepositoryHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitRefRepositoryHeraldField.php', 822 822 'DiffusionPreCommitRefRepositoryProjectsHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitRefRepositoryProjectsHeraldField.php', 823 823 'DiffusionPreCommitRefTypeHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitRefTypeHeraldField.php', 824 + 'DiffusionPreCommitUsesGitLFSHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitUsesGitLFSHeraldField.php', 824 825 'DiffusionPullEventGarbageCollector' => 'applications/diffusion/garbagecollector/DiffusionPullEventGarbageCollector.php', 825 826 'DiffusionPushCapability' => 'applications/diffusion/capability/DiffusionPushCapability.php', 826 827 'DiffusionPushEventViewController' => 'applications/diffusion/controller/DiffusionPushEventViewController.php', ··· 5881 5882 'DiffusionPreCommitRefRepositoryHeraldField' => 'DiffusionPreCommitRefHeraldField', 5882 5883 'DiffusionPreCommitRefRepositoryProjectsHeraldField' => 'DiffusionPreCommitRefHeraldField', 5883 5884 'DiffusionPreCommitRefTypeHeraldField' => 'DiffusionPreCommitRefHeraldField', 5885 + 'DiffusionPreCommitUsesGitLFSHeraldField' => 'DiffusionPreCommitContentHeraldField', 5884 5886 'DiffusionPullEventGarbageCollector' => 'PhabricatorGarbageCollector', 5885 5887 'DiffusionPushCapability' => 'PhabricatorPolicyCapability', 5886 5888 'DiffusionPushEventViewController' => 'DiffusionPushLogController',
+41
src/applications/diffusion/herald/DiffusionPreCommitUsesGitLFSHeraldField.php
··· 1 + <?php 2 + 3 + final class DiffusionPreCommitUsesGitLFSHeraldField 4 + extends DiffusionPreCommitContentHeraldField { 5 + 6 + const FIELDCONST = 'diffusion.pre.commit.git-lfs'; 7 + 8 + public function getHeraldFieldName() { 9 + return pht('Commit uses Git LFS'); 10 + } 11 + 12 + public function getFieldGroupKey() { 13 + return DiffusionChangeHeraldFieldGroup::FIELDGROUPKEY; 14 + } 15 + 16 + public function getHeraldFieldValue($object) { 17 + $map = $this->getAdapter()->getDiffContent('+'); 18 + 19 + // At the time of writing, all current Git LFS files begin with this 20 + // line, verbatim: 21 + // 22 + // version https://git-lfs.github.com/spec/v1 23 + // 24 + // ...but we don't try to match the specific version here, in the hopes 25 + // that this might also detect future versions. 26 + $pattern = '(^version\s*https://git-lfs.github.com/spec/)i'; 27 + 28 + foreach ($map as $path => $content) { 29 + if (preg_match($pattern, $content)) { 30 + return true; 31 + } 32 + } 33 + 34 + return false; 35 + } 36 + 37 + protected function getHeraldFieldStandardType() { 38 + return self::STANDARD_BOOL; 39 + } 40 + 41 + }