This will never be true, because you are doing reference equality on two temporarily allocated strings.

Instead you need to say c.equals(o).  But that only works on current master.  So rebase this patch to pick up that fix.  But that point you can simplify the loop:

  if (!remoteShallowCommits.contains(o))
    packOut.writeString("shallow " + o.name());