Skip to content

Integrate with core Git subcommand authoring features.#43

Open
tomeon wants to merge 23 commits into
PotatoLabs:masterfrom
tomeon:git-sh-setup-integration
Open

Integrate with core Git subcommand authoring features.#43
tomeon wants to merge 23 commits into
PotatoLabs:masterfrom
tomeon:git-sh-setup-integration

Conversation

@tomeon
Copy link
Copy Markdown

@tomeon tomeon commented Sep 8, 2023

Thank you for this handy tool!

This PR introduces integration with git-sh-setup, a library included with the
core Git distribution. It provides conveniences for authoring shell-based Git
subcommands.

Summary of features:

  1. Added help text (git redate -h).
  2. Added CLI options sanitation (git redate now bails upon unrecognized options).
  3. Updated to use $GIT_EDITOR / git var GIT_EDITOR for editing the re-dating specification file. This is a breaking change, though one that's likely to align git redate with the user's already-expressed preference (e.g. whatever they've defined as core.editor) rather than prompting them to express a preference interactively.
  4. Added support for specifying git redate preferences in the Git client configuration file.
  5. Added support for specifying arbitrary commit ranges.

Miscellaneous other changes:

  1. Streamlined some code (e.g. removing repeated checks of the value of $ALL, $DEBUG, etc., instead using conditionally-defined functions).
  2. Prevent trying to shift any arguments when $@ is already empty.
  3. Added a dry-run mode, which was helpful for testing the other changes and perhaps useful for end users before re-dating For Real.
  4. Fixed some shellcheck linting issues.
  5. Formatted the code with shfmt.
  6. Relocated the temporary file used for specifying date edits to the .git directory.

Thanks for your consideration!

rather than non-portable `/bin/bash`
with POSIX-compatible code.
@iitzrohan
Copy link
Copy Markdown

@tomeon Thanks for updating the tool.Can you add two more features.

  1. Don't change the hash when redating.
  2. Make it possible to sign commits with redating.

@tomeon
Copy link
Copy Markdown
Author

tomeon commented Nov 3, 2023

Hello @iitzrohan -- thanks for your feedback/requests.

Don't change the hash when redating.

This is not possible.

Make it possible to sign commits with redating.

Done.

@tomeon tomeon force-pushed the git-sh-setup-integration branch from e270ba1 to e694418 Compare November 6, 2023 13:41
@tomeon
Copy link
Copy Markdown
Author

tomeon commented Nov 6, 2023

@iitzrohan --

The latest changes doesn't opens the editor configured through gitconfig. Instead it uses the default editor nano.

I am unable to reproduce this; for me, git redate respects core.editor.

fatal: ambiguous argument [...]

Thanks; should be fixed now. I've updated git-redate to check the number of commits reachable from HEAD and choose the lower of (a) that number and (b) the number provided with git redate -c <count>. I've also updated git-redate to exit with nonzero status in case the provided commit range is invalid, or valid but causes git rev-list to emit no commits.

Comment thread git-redate Outdated
for features like CLI options processing and "am I in a git repo?"
sanity-checks.
That is, remove redundant `shift` calls in the `--debug` and `--all`
cases.
by conditionally defining a `debug` function based on whether the
`-d/--debug` option was provided.  If debugging is not enabled, the
`debug` function is a NOP; otherwise, it echoes its arguments to stderr.
BREAKING CHANGE: diagnostic output no longer goes to stdout.
rather than custom editor selection code.
BREAKING CHANGE: introduces type-checking of `COMMITS`, `DEBUG`, and
friends.
that provides a default value for the `COMMITS` variable.  This variable
is already guaranteed to be set to a positive integer (or else `git
redate` will have exited).
within the body of the loop that applies the redate logic.  Instead,
conditionally define an `apply_redate` function depending on whether we
saw `--all`, then call this function from within the loop.
rather than numbers of commits starting from HEAD (or all commits).
when generating the interactive commit selection list.
by passing the `-S`/`--gpg-sign` flag through to `commit-tree`.
by loading them via `git -c <name>=<value> --get <name>`.
BREAKING CHANGE: `git redate` exits with nonzero status in case no
commits were identified.
@tomeon tomeon force-pushed the git-sh-setup-integration branch from e694418 to 96e51ea Compare November 10, 2023 20:33
@tomeon
Copy link
Copy Markdown
Author

tomeon commented Apr 19, 2024

SiteRelEnby added a commit to SiteRelEnby/git-redate that referenced this pull request May 18, 2026
Adopt git-sh-setup and OPTIONS_SPEC for argument parsing. Benefits:

- `git redate -h` now prints proper help text with examples.
- Unknown options are rejected with a clear error rather than silently
  ignored (so typos like `--commmits` get caught).
- Short flags can be combined: `-ad` works as `--all --debug`.
- Every boolean flag gains a `--no-X` opt-out form, which is handy
  for shell aliases that bake in defaults.
- The script can now be invoked from any subdirectory of the working
  tree, not just the repo root.

Replace the bespoke interactive editor prompt and `~/.redate-settings`
file with `git_editor`, which defers to the standard chain: $GIT_EDITOR,
core.editor, $VISUAL, $EDITOR, then git's compiled fallback. Anyone who
relied on the prompt is already covered by setting any of those.

Reimplemented on top of our current base rather than cherry-picked
because upstream PR PotatoLabs#43 also includes a bash->sh portability rewrite
and a different signing implementation that would conflict with the
touched-only signing scope from 80e8910. Original idea and most of the
OPTIONS_SPEC layout from upstream PR PotatoLabs#43 by tomeon.
SiteRelEnby added a commit to SiteRelEnby/git-redate that referenced this pull request May 18, 2026
Prints the commits that would be rewritten and the exact filter-branch
invocation that would run, then exits without making changes. Mostly
for sanity-checking the scope-narrowing logic before letting it loose
on a repo. Idea borrowed from upstream PR PotatoLabs#43 by tomeon.
SiteRelEnby added a commit to SiteRelEnby/git-redate that referenced this pull request May 18, 2026
Persistent defaults under redate.*, with CLI flags as overrides. Useful
for setting up a global "always sign rewritten commits" preference, or
a per-repo "default to -c 10" without aliasing.

Supported keys: redate.all, redate.commits, redate.debug, redate.dryRun,
redate.iKnowWhatImDoing, redate.sign, redate.signNow. The tri-state
redate.sign maps true->yes, false->no, unset->auto (which then resolves
against commit.gpgsign as before).

Idea borrowed from upstream PR PotatoLabs#43 by tomeon.
SiteRelEnby added a commit to SiteRelEnby/git-redate that referenced this pull request May 18, 2026
`git redate HEAD~10..HEAD~5` (or any other rev-list expression) now
opens an editor showing exactly those commits. Useful for surgically
editing a window of history rather than always counting back from HEAD.

Precedence: positional rev args > --all > -c N for choosing what to
show. The filter-branch range is still derived from the oldest commit
the user actually edited, so descendants between the top of the range
and HEAD are necessarily rewritten (parent hashes change). Filter-branch
can't avoid that without leaving the tip orphaned.

Idea borrowed from upstream PR PotatoLabs#43 by tomeon, with different range
semantics: theirs passes the range directly to filter-branch; ours
treats it as editor scope and lets the existing oldest-touched logic
decide the rewrite range.
SiteRelEnby added a commit to SiteRelEnby/git-redate that referenced this pull request May 18, 2026
No behavioural change for the happy path; the tr fix and the exit-code
propagation are the only ones with any user-visible effect.

- `tr -d '[[:space:]]'` was deleting literal `[` and `]` as well as
  whitespace. Replaced with the correct `tr -d '[:space:]'`. Hashes and
  ISO dates never contain brackets so it happened to work, but the
  intent was wrong.
- Propagate filter-branch's exit code instead of always returning 0,
  so callers can detect failures.
- Quote `$tmpfile` everywhere it's used as a redirect target or argument.
- Backtick command substitution replaced with `$()`.
- `read -r` everywhere so backslashes survive.
- Replace the unused `message` variable with `_`.
- Drop one useless `$(echo "$x")`.
- Add shellcheck disables for two intentional patterns: OPTIONS_KEEPDASHDASH
  (consumed by sourced git-sh-setup) and the single-quoted COMMIT_FILTER
  strings (deliberately deferred expansion).

The shellcheck pass itself is inspired by upstream PR PotatoLabs#43 by tomeon, who
ran shfmt and addressed lints in a more sweeping reformat. We took just
the substantive fixes and skipped the formatting reflow.
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.

3 participants