Fix unreliable child.exitstatus being set in git command execution

Adding a child.close() will guarantee that child.exitstatus will be set
properly.

Also add the raise exception back in.