IDEX-1579 Fixed branches deletion

+1 And Can you add test for it?