From 6f2f2a6baae128cd4f8111d91bdcfb7b76e39b97 Mon Sep 17 00:00:00 2001
From: Douwe Maan <douwe@selenight.nl>
Date: Thu, 18 Aug 2016 14:19:13 -0500
Subject: [PATCH] Fix behavior of label_ids and add/remove_label_ids

---
 app/services/issuable_base_service.rb | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/app/services/issuable_base_service.rb b/app/services/issuable_base_service.rb
index 57286f255f4..3100bd58818 100644
--- a/app/services/issuable_base_service.rb
+++ b/app/services/issuable_base_service.rb
@@ -80,18 +80,19 @@ class IssuableBaseService < BaseService
     params[key] = project.labels.where(id: params[key]).pluck(:id)
   end
 
-  def process_label_ids(attributes, existing_label_ids: [])
+  def process_label_ids(attributes, existing_label_ids: nil)
     label_ids = attributes.delete(:label_ids)
     add_label_ids = attributes.delete(:add_label_ids)
     remove_label_ids = attributes.delete(:remove_label_ids)
 
-    new_label_ids = existing_label_ids
+    new_label_ids = existing_label_ids || label_ids || []
 
-    override_existing = new_label_ids.empty? || (add_label_ids.blank? && remove_label_ids.blank?)
-    new_label_ids = label_ids if label_ids && override_existing
-
-    new_label_ids |= add_label_ids if add_label_ids
-    new_label_ids -= remove_label_ids if remove_label_ids
+    if add_label_ids.blank? && remove_label_ids.blank?
+      new_label_ids = label_ids if label_ids
+    else
+      new_label_ids |= add_label_ids if add_label_ids
+      new_label_ids -= remove_label_ids if remove_label_ids
+    end
 
     new_label_ids
   end
-- 
2.30.9