$OpenBSD: patch-tag_c,v 1.1 2011/01/19 12:41:08 dcoppa Exp $
--- tag.c.orig	Mon Jan 17 12:38:13 2011
+++ tag.c	Wed Jan 19 13:11:52 2011
@@ -363,7 +363,26 @@ luaA_tag_clients(lua_State *L)
     {
         luaA_checktable(L, 2);
         foreach(c, tag->clients)
-            untag_client(*c, tag);
+        {
+            /* Only untag if we aren't going to add this tag again */
+            bool found = false;
+            lua_pushnil(L);
+            while(lua_next(L, 2))
+            {
+                client_t *tc = luaA_checkudata(L, -1, &client_class);
+                /* Pop the value from lua_next */
+                lua_pop(L, 1);
+                if (tc != *c)
+                    continue;
+
+                /* Pop the key from lua_next */
+                lua_pop(L, 1);
+                found = true;
+                break;
+            }
+            if(!found)
+                untag_client(*c, tag);
+        }
         lua_pushnil(L);
         while(lua_next(L, 2))
         {
