Skip to content
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

Merged
merged 4 commits into from
Jul 10, 2024

Conversation

plietar
Copy link
Member

@plietar plietar commented Jun 27, 2024

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.

@plietar plietar requested a review from richfitz June 27, 2024 16:38
@plietar
Copy link
Member Author

plietar commented Jun 27, 2024

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.

@richfitz
Copy link
Member

richfitz commented Jul 4, 2024

I'm kind of on the fence whether the fields in the JSON object should be omitted or set to null

Set to null I think. If we can detect the empty commit that would be worth capturing perhaps though?


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.
Copy link
Member

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

inst/schema/outpack/git.json Show resolved Hide resolved
@plietar plietar force-pushed the mrc-5479-git-empty branch from ab26972 to 5ab11b1 Compare July 8, 2024 13:52
plietar added 3 commits July 10, 2024 10:44
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.
@plietar plietar force-pushed the mrc-5479-git-empty branch from 5ab11b1 to 13ee4a7 Compare July 10, 2024 09:46
@plietar plietar merged commit 0044ba1 into main Jul 10, 2024
9 checks passed
@plietar plietar deleted the mrc-5479-git-empty branch July 10, 2024 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants