-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve handling of empty or detached Git repositories. #148
Conversation
I'm kind of on the fence whether the fields in the JSON object should be omitted or set to null. I went with the latter for now, but I'm open to change that. Once we agree on what to do I will need to make a change to the upstream schema first before merging this PR. |
Set to |
|
||
branch <- gert::git_branch(repo = repo) | ||
if (is.null(branch) || identical(branch, "HEAD")) { | ||
# NULL can be returned when working in a repo that has no commits yet. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it's worth having sentinel values for these - could be (empty)
for no commits and (detached)
for detached head, or tracking this though something in the metadata? Probably not worth getting too wound up about though
ab26972
to
5ab11b1
Compare
When orderly runs a report from a Git repository, it records information about the current state of the repository in the packet metadata. This includes the current commit hash and the name of the current branch. It is possible for either of these to not exist, in which case we need to make sure orderly behaves gracefully. The commit hash will be missing on a brand new repository which hasn't had any commits yet (or equivalently, an existing repository where `git checkout --orphan` was used. The branch name would be missing if the repository is in a "detached HEAD" state, in other words the user checked out a specific commit hash instead of a named branch. The first situation, of an empty repository, was not supported by orderly at all. It would throw an error and fail to run the report entirely. In the second case, when on a detached HEAD, the Git library we use reports the branch name as "HEAD", and that is what we were recording in the metadata. This is a bit misleading since it is not an actual branch name. Both cases have been modified to work without errors and to omit the missing values from the metadata.
5ab11b1
to
13ee4a7
Compare
When orderly runs a report from a Git repository, it records information about the current state of the repository in the packet metadata. This includes the current commit hash and the name of the current branch.
It is possible for either of these to not exist, in which case we need to make sure orderly behaves gracefully. The commit hash will be missing on a brand new repository which hasn't had any commits yet (or equivalently, an existing repository where
git checkout --orphan
was used. The branch name would be missing if the repository is in a "detached HEAD" state, in other words the user checked out a specific commit hash instead of a named branch.The first situation, of an empty repository, was not supported by orderly at all. It would throw an error and fail to run the report entirely. In the second case, when on a detached HEAD, the Git library we use reports the branch name as "HEAD", and that is what we were recording in the metadata. This is a bit misleading since it is not an actual branch name.
Both cases have been modified to work without errors and to omit the missing values from the metadata.