stgit
stgit copied to clipboard
0.20: support `git rebase --committer-date-is-author-date`
There are some use cases where stg edit <some-earlier-patch>
should keep all following timestamps intact, because let's say some system /etc
configuration tracking automation failed and you just want to fixup a couple of errors, without altering anything else.
This is probably related. According to:
https://stackoverflow.com/questions/2973996/git-rebase-without-changing-commit-timestamps/11179245
"git rebase" by default does not alter Author Dates. "stg rebase" does, but perhaps should not.
The problem appears to be trans.push_patch (and its subroutines), not in 'stg rebase'.
- If the parent commit is unchanged and 'stg push' does not modify the patch, currently the Author date remains the same. This is the correct behavior.
- If the parent commit has changed, then currently push_patch updates Author date, even if the pushed patch itself is not modified by the push operation. This is a common situation during a rebase. I suggest that Author date should not be changed in this case.
- If the parent commit is unchanged and 'stg push' modifies the pushed patch, then currently the Author date remains the same. I suggest that in this case, the Author date should be refreshed.
After updating to stgit-0.22, "stg rebase" and "stg push" behave correctly. Ignore my comments above, thanks.
I'm triaging old issues and trying to make sense of this one. Do we believe, @lkraav @chucklever, that there is a change needed for StGit?
If there is a bug, what would be most helpful for me is a test case that illustrates the bug. As things stand, I'm not sure the scenarios in which stg edit
does or does not alter the author date in a way that is not desired.
My original issue is not about a bug, more of a feature.
I'd like to occasionally fix up a commit somewhere mid-tree with stg edit
, without altering any date information for following commits as they are pushed back on the stack.
Is this a fair example of the behavior you are interested in:
$ for p in a b c; do stg new -m $p; sleep 3; done
Now at patch "a"
Now at patch "b"
Now at patch "c"
$ for p in a b c; do echo "$p:"; stg show --diff-opts=--pretty=fuller $p | rg Date; done
a:
AuthorDate: Mon Apr 20 08:30:25 2020 -0400
CommitDate: Mon Apr 20 08:30:25 2020 -0400
b:
AuthorDate: Mon Apr 20 08:30:28 2020 -0400
CommitDate: Mon Apr 20 08:30:28 2020 -0400
c:
AuthorDate: Mon Apr 20 08:30:31 2020 -0400
CommitDate: Mon Apr 20 08:30:31 2020 -0400
$ stg edit -m "edit a" a
Popped c -- b
Pushing patch "b" ... done (empty)
Pushing patch "c" ... done (empty)
$ for p in a b c; do echo "$p:"; stg show --diff-opts=--pretty=fuller $p | rg Date; done
a:
AuthorDate: Mon Apr 20 08:30:25 2020 -0400
CommitDate: Mon Apr 20 08:30:58 2020 -0400 <-- New CommitDate
b:
AuthorDate: Mon Apr 20 08:30:28 2020 -0400
CommitDate: Mon Apr 20 08:30:58 2020 -0400 <-- New CommitDate
c:
AuthorDate: Mon Apr 20 08:30:31 2020 -0400
CommitDate: Mon Apr 20 08:30:58 2020 -0400 <-- New CommitDate
When editing patch at the bottom of the stack (patch a
), all of the AuthorDate
s are preserved, but the CommitDate
s are all updated.
You are asking for an option to forge the CommitDate
to remain the same as the AuthorDate
. (Sorry to be so slow on the uptake)
I also see that --committer-date-is-author-date
comes from git am
and is also used by git rebase
. It makes sense that if StGit was to have an option for this, we would use this name.
My next question is to which commands should have the --committer-date-is-author-date
option? Any command that alters an existing patch, I think. So these commands:
-
stg edit
-
stg refresh
-
stg import
-
stg rebase
-
stg pull
-
stg pick
-
stg fold
I buy this as a valid and useful StGit feature. I cannot promise when I may implement it though.
:+1: yep that looks correct.
stg edit
and refresh
get by far the most use here.
rebase
is solid 3rd place, but I haven't found myself needing to alter default date arrangement there very much if at all.
For whatever it is worth, I have a small little shell wrapper around stg
to workaround this (and do a few other things); it determines the commit date before editing and uses that to forcibly set the commit date using $GIT_COMMITTER_DATE
when editing. Here is the relevant snippet from the wrapper:
function cmd_edit() {
local rc=0
# we only do this to workaround a problem where stgit v1.3 always
# updates the commit date even if there are not textual changes
# skip past the "edit" parameter
shift
# make sure we have at least one patch applied
stg top >& /dev/null || return $?
# try to find the commit date
local commit=""
local commit_date=""
for i in "$@"; do
stg id $i >& /dev/null
rc=$?
if [[ $rc -eq 0 ]]; then
commit=$i
break;
fi
done
[[ $rc -ne 0 ]] && commit=$(stg top)
commit_date=$(git show -s --format=%ci $(stg id $commit) 2> /dev/null)
[[ -z $commit_date ]] && return 1
# do the edit but force the commit date to the current value
GIT_COMMITTER_DATE="$commit_date" stg edit "$@"
return $?
}