From 02c3200867b1ee2309c74bde226d096648b9999c Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 10 Jul 2014 10:17:17 -0700 Subject: [PATCH] Respond more gracefully when a git push deletes a nonexistent ref Summary: Fixes T5534. If you `git push origin :refs/tags/doesnotexist` (for some non-existing tag), we get a change where both the old and new refs are empty. We incorrectly call this an "add", because the old ref is empty. Instead, call this a "delete", but skip the logic which would normally mark it dangerous. (Possibly we should just reject these outright, but Git allows them, so stick with that for now.) Test Plan: Pushed nonexistent refs: ``` $ git push origin :refs/tags/doesnotexist remote: warning: Allowing deletion of corrupt ref. To ssh://dweller@localhost/diffusion/POEMS/ - [deleted] doesnotexist $ ``` Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T5534 Differential Revision: https://secure.phabricator.com/D9800 --- .../diffusion/engine/DiffusionCommitHookEngine.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/applications/diffusion/engine/DiffusionCommitHookEngine.php b/src/applications/diffusion/engine/DiffusionCommitHookEngine.php index 98bd78bc77..ae1423cc21 100644 --- a/src/applications/diffusion/engine/DiffusionCommitHookEngine.php +++ b/src/applications/diffusion/engine/DiffusionCommitHookEngine.php @@ -477,7 +477,12 @@ final class DiffusionCommitHookEngine extends Phobject { $ref_flags = 0; $dangerous = null; - if ($ref_old === self::EMPTY_HASH) { + if (($ref_old === self::EMPTY_HASH) && ($ref_new === self::EMPTY_HASH)) { + // This happens if you try to delete a tag or branch which does not + // exist by pushing directly to the ref. Git will warn about it but + // allow it. Just call it a delete, without flagging it as dangerous. + $ref_flags |= PhabricatorRepositoryPushLog::CHANGEFLAG_DELETE; + } else if ($ref_old === self::EMPTY_HASH) { $ref_flags |= PhabricatorRepositoryPushLog::CHANGEFLAG_ADD; } else if ($ref_new === self::EMPTY_HASH) { $ref_flags |= PhabricatorRepositoryPushLog::CHANGEFLAG_DELETE;