Add current_branch() with a test; fix bug where write_study() returned a SHA with a trailing newline