mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-30 02:32:42 +01:00
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
This commit is contained in:
parent
e34b4bbd90
commit
8e416474c0
2 changed files with 43 additions and 0 deletions
|
@ -821,6 +821,7 @@ phutil_register_library_map(array(
|
||||||
'DiffusionPreCommitRefRepositoryHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitRefRepositoryHeraldField.php',
|
'DiffusionPreCommitRefRepositoryHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitRefRepositoryHeraldField.php',
|
||||||
'DiffusionPreCommitRefRepositoryProjectsHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitRefRepositoryProjectsHeraldField.php',
|
'DiffusionPreCommitRefRepositoryProjectsHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitRefRepositoryProjectsHeraldField.php',
|
||||||
'DiffusionPreCommitRefTypeHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitRefTypeHeraldField.php',
|
'DiffusionPreCommitRefTypeHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitRefTypeHeraldField.php',
|
||||||
|
'DiffusionPreCommitUsesGitLFSHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitUsesGitLFSHeraldField.php',
|
||||||
'DiffusionPullEventGarbageCollector' => 'applications/diffusion/garbagecollector/DiffusionPullEventGarbageCollector.php',
|
'DiffusionPullEventGarbageCollector' => 'applications/diffusion/garbagecollector/DiffusionPullEventGarbageCollector.php',
|
||||||
'DiffusionPushCapability' => 'applications/diffusion/capability/DiffusionPushCapability.php',
|
'DiffusionPushCapability' => 'applications/diffusion/capability/DiffusionPushCapability.php',
|
||||||
'DiffusionPushEventViewController' => 'applications/diffusion/controller/DiffusionPushEventViewController.php',
|
'DiffusionPushEventViewController' => 'applications/diffusion/controller/DiffusionPushEventViewController.php',
|
||||||
|
@ -5881,6 +5882,7 @@ phutil_register_library_map(array(
|
||||||
'DiffusionPreCommitRefRepositoryHeraldField' => 'DiffusionPreCommitRefHeraldField',
|
'DiffusionPreCommitRefRepositoryHeraldField' => 'DiffusionPreCommitRefHeraldField',
|
||||||
'DiffusionPreCommitRefRepositoryProjectsHeraldField' => 'DiffusionPreCommitRefHeraldField',
|
'DiffusionPreCommitRefRepositoryProjectsHeraldField' => 'DiffusionPreCommitRefHeraldField',
|
||||||
'DiffusionPreCommitRefTypeHeraldField' => 'DiffusionPreCommitRefHeraldField',
|
'DiffusionPreCommitRefTypeHeraldField' => 'DiffusionPreCommitRefHeraldField',
|
||||||
|
'DiffusionPreCommitUsesGitLFSHeraldField' => 'DiffusionPreCommitContentHeraldField',
|
||||||
'DiffusionPullEventGarbageCollector' => 'PhabricatorGarbageCollector',
|
'DiffusionPullEventGarbageCollector' => 'PhabricatorGarbageCollector',
|
||||||
'DiffusionPushCapability' => 'PhabricatorPolicyCapability',
|
'DiffusionPushCapability' => 'PhabricatorPolicyCapability',
|
||||||
'DiffusionPushEventViewController' => 'DiffusionPushLogController',
|
'DiffusionPushEventViewController' => 'DiffusionPushLogController',
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class DiffusionPreCommitUsesGitLFSHeraldField
|
||||||
|
extends DiffusionPreCommitContentHeraldField {
|
||||||
|
|
||||||
|
const FIELDCONST = 'diffusion.pre.commit.git-lfs';
|
||||||
|
|
||||||
|
public function getHeraldFieldName() {
|
||||||
|
return pht('Commit uses Git LFS');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFieldGroupKey() {
|
||||||
|
return DiffusionChangeHeraldFieldGroup::FIELDGROUPKEY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHeraldFieldValue($object) {
|
||||||
|
$map = $this->getAdapter()->getDiffContent('+');
|
||||||
|
|
||||||
|
// At the time of writing, all current Git LFS files begin with this
|
||||||
|
// line, verbatim:
|
||||||
|
//
|
||||||
|
// version https://git-lfs.github.com/spec/v1
|
||||||
|
//
|
||||||
|
// ...but we don't try to match the specific version here, in the hopes
|
||||||
|
// that this might also detect future versions.
|
||||||
|
$pattern = '(^version\s*https://git-lfs.github.com/spec/)i';
|
||||||
|
|
||||||
|
foreach ($map as $path => $content) {
|
||||||
|
if (preg_match($pattern, $content)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getHeraldFieldStandardType() {
|
||||||
|
return self::STANDARD_BOOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue