Skip to content

feat(record): add --allow-empty flag#1612

Draft
claytonrcarter wants to merge 4 commits into
arxanas:masterfrom
claytonrcarter:record-allow-empty
Draft

feat(record): add --allow-empty flag#1612
claytonrcarter wants to merge 4 commits into
arxanas:masterfrom
claytonrcarter:record-allow-empty

Conversation

@claytonrcarter
Copy link
Copy Markdown
Collaborator

This adds --allow-empty support to git record. This is not very interesting on it's own, but the fun starts when you pass --insert, at which point this should behave as a short hand for git commit --allow-empty -m ... ; git move -s 'siblings(@)'.

As is, this change will only create an empty commit if there are no changes at all (staged or in the working copy). Eventually, it would be nice to have "real" support for record --new to create an empty commit regardless of what changes are currently staged or in the working copy, but I don't intend to tackle that at this time.

DUMMY_DATE is used to populate GIT_AUTHOR_DATE and GIT_COMMITTER_DATE, both of
which expect dates in RFC2822 format, but DUMMY_DATE was itselt not in RFC2822
format, and it was made less so by appending a 2 digit timezone offset.

This has not been an issue thus far because we were only passing the date to
git as a string, and git seems to be fairly liberal when parsing dates. `git
record --new` seems to be the first time we're actually creating wholey new
commits (vs just modifying existing commits), so we need to set a current time
on these new commits. To do so, we need to parse DUMMY_DATE into a SystemTime
with chrono, and chrono is not lenient when parsing dates, leading to various
errors:

1. The existing format yielded Invalid, because of the time/year order.
2. Fixing the order of the year led to TooShort, because of the 2 digit
   timezone offset.
3. Fixing the timezone offset yielded Impossible, because 2020-10-29 was
   not a Wednesday.

Fun! Regardless, I don't expect these changes to have any impact outside of
the upcoming tests for `record --new`.

Old format: Wed 29 Oct 12:34:56 2020 PDT -02
New format: Thu, 29 Oct 2020 12:34:56 -0200

Ref: https://github.com/git/git/blob/master/Documentation/date-formats.adoc
Ref: https://www.rfc-editor.org/rfc/rfc2822#section-3.3
`record --new` is the first feature in which we create entirely new
commits (vs rewriting or splitting existing commits) and I was running
into test failures in CI that seemed to only differ by timezone.
Explicitly setting the time zone in the test git environment resolved
the issue.
Fixes various defects encountered during testing.
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.

1 participant