Integrate with core Git subcommand authoring features.#43
Conversation
rather than non-portable `/bin/bash`
with POSIX-compatible code.
|
@tomeon Thanks for updating the tool.Can you add two more features.
|
|
Hello @iitzrohan -- thanks for your feedback/requests.
This is not possible.
Done. |
e270ba1 to
e694418
Compare
|
@iitzrohan --
I am unable to reproduce this; for me,
Thanks; should be fixed now. I've updated |
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).
in help text
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.
e694418 to
96e51ea
Compare
|
Ping @AaronVasquez @EdmundMai -- this changeset, besides being (IMHO 😉) worthwhile on its own merits, also likely fixes a number of issues. For instance:
It also addresses or obviates several merge requests:
Is there anything I can do to help get this over the finish line? Thanks! |
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.
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.
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.
`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.
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.
Thank you for this handy tool!
This PR introduces integration with
git-sh-setup, a library included with thecore Git distribution. It provides conveniences for authoring shell-based Git
subcommands.
Summary of features:
git redate -h).git redatenow bails upon unrecognized options).$GIT_EDITOR/git var GIT_EDITORfor editing the re-dating specification file. This is a breaking change, though one that's likely to aligngit redatewith the user's already-expressed preference (e.g. whatever they've defined ascore.editor) rather than prompting them to express a preference interactively.git redatepreferences in the Git client configuration file.Miscellaneous other changes:
$ALL,$DEBUG, etc., instead using conditionally-defined functions).shiftany arguments when$@is already empty.shellchecklinting issues.shfmt..gitdirectory.Thanks for your consideration!