<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/reset.c, branch v2.36.2</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.36.2</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.36.2'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2022-02-18T21:53:27Z</updated>
<entry>
<title>Merge branch 'pw/use-in-process-checkout-in-rebase'</title>
<updated>2022-02-18T21:53:27Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2022-02-18T21:53:27Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=bcd020f88e1e22f38422ac3f73ab06b34ec4bef1'/>
<id>urn:sha1:bcd020f88e1e22f38422ac3f73ab06b34ec4bef1</id>
<content type='text'>
Use an internal call to reset_head() helper function instead of
spawning "git checkout" in "rebase", and update code paths that are
involved in the change.

* pw/use-in-process-checkout-in-rebase:
  rebase -m: don't fork git checkout
  rebase --apply: set ORIG_HEAD correctly
  rebase --apply: fix reflog
  reset_head(): take struct rebase_head_opts
  rebase: cleanup reset_head() calls
  create_autostash(): remove unneeded parameter
  reset_head(): make default_reflog_action optional
  reset_head(): factor out ref updates
  reset_head(): remove action parameter
  rebase --apply: don't run post-checkout hook if there is an error
  rebase: do not remove untracked files on checkout
  rebase: pass correct arguments to post-checkout hook
  t5403: refactor rebase post-checkout hook tests
  rebase: factor out checkout for up to date branch
</content>
</entry>
<entry>
<title>rebase --apply: set ORIG_HEAD correctly</title>
<updated>2022-01-26T20:08:53Z</updated>
<author>
<name>Phillip Wood</name>
<email>phillip.wood@dunelm.org.uk</email>
</author>
<published>2022-01-26T13:05:48Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=cd1528ef8ef9847fc27cff4016bf073f04729504'/>
<id>urn:sha1:cd1528ef8ef9847fc27cff4016bf073f04729504</id>
<content type='text'>
At the start of a rebase, ORIG_HEAD is updated to the tip of the
branch being rebased. Unfortunately reset_head() always uses the
current value of HEAD for this which is incorrect if the rebase is
started with "git rebase &lt;upstream&gt; &lt;branch&gt;" as in that case
ORIG_HEAD should be updated to &lt;branch&gt;. This only affects the "apply"
backend as the "merge" backend does not yet use reset_head() for the
initial checkout. Fix this by passing in orig_head when calling
reset_head() and add some regression tests.

Signed-off-by: Phillip Wood &lt;phillip.wood@dunelm.org.uk&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>rebase --apply: fix reflog</title>
<updated>2022-01-26T20:08:53Z</updated>
<author>
<name>Phillip Wood</name>
<email>phillip.wood@dunelm.org.uk</email>
</author>
<published>2022-01-26T13:05:47Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=7700ab087b82f71d19134141045b95063e407344'/>
<id>urn:sha1:7700ab087b82f71d19134141045b95063e407344</id>
<content type='text'>
move_to_original_branch() passes the message intended for the branch
reflog as `orig_head_msg`. Fix this by adding a `branch_msg` member to
struct reset_head_opts and add a regression test.  Note that these
reflog messages do not respect GIT_REFLOG_ACTION. They are not alone
in that and will be fixed in a future series.

The "merge" backend already has tests that check both the branch and
HEAD reflogs.

Signed-off-by: Phillip Wood &lt;phillip.wood@dunelm.org.uk&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>reset_head(): take struct rebase_head_opts</title>
<updated>2022-01-26T20:08:53Z</updated>
<author>
<name>Phillip Wood</name>
<email>phillip.wood@dunelm.org.uk</email>
</author>
<published>2022-01-26T13:05:46Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=6ae8086161d81a707ff36dfdc07f57e4f473e0fd'/>
<id>urn:sha1:6ae8086161d81a707ff36dfdc07f57e4f473e0fd</id>
<content type='text'>
This function takes a confusingly large number of parameters which
makes it difficult to remember which order to pass them in. The
following commits will add a couple more parameters which makes the
problem worse. To address this change the function to take a struct of
options. Using a struct means that it is no longer necessary to
remember which order to pass the parameters in and anyone reading the
code can easily see which value is passed to each parameter.

Signed-off-by: Phillip Wood &lt;phillip.wood@dunelm.org.uk&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>reset_head(): make default_reflog_action optional</title>
<updated>2022-01-26T20:08:53Z</updated>
<author>
<name>Phillip Wood</name>
<email>phillip.wood@dunelm.org.uk</email>
</author>
<published>2022-01-26T13:05:43Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=1526d0fcfd20efca24bc96a4bc14c8d5459ec470'/>
<id>urn:sha1:1526d0fcfd20efca24bc96a4bc14c8d5459ec470</id>
<content type='text'>
This parameter is only needed when a ref is going to be updated and
the caller does not pass an explicit reflog message. Callers that are
only discarding uncommitted changes in the working tree such as such
as "rebase --skip" or create_autostash() do not update any refs so
should not have to worry about passing this parameter.

This change is not intended to have any user visible changes. The
pointer comparison between `oid` and `&amp;head_oid` checks that the
caller did not pass an oid to be checked out. As no callers pass
RESET_HEAD_RUN_POST_CHECKOUT_HOOK without passing an oid there are
no changes to when the post-checkout hook is run. As update_ref() only
updates the ref if the oid passed to it differs from the current ref
there are no changes to when HEAD is updated.

Signed-off-by: Phillip Wood &lt;phillip.wood@dunelm.org.uk&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>reset_head(): factor out ref updates</title>
<updated>2022-01-26T20:08:53Z</updated>
<author>
<name>Phillip Wood</name>
<email>phillip.wood@dunelm.org.uk</email>
</author>
<published>2022-01-26T13:05:42Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=d6a9f5ea8e97dd9435e5fa02cc129c1b241934f2'/>
<id>urn:sha1:d6a9f5ea8e97dd9435e5fa02cc129c1b241934f2</id>
<content type='text'>
In the next commit we will stop trying to update HEAD when we are
removing uncommitted changes from the working tree. Move the code that
updates the refs to its own function in preparation for that.

Signed-off-by: Phillip Wood &lt;phillip.wood@dunelm.org.uk&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>reset_head(): remove action parameter</title>
<updated>2022-01-26T20:08:53Z</updated>
<author>
<name>Phillip Wood</name>
<email>phillip.wood@dunelm.org.uk</email>
</author>
<published>2022-01-26T13:05:41Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=1946d45844c65ede4e3a514a5decf16612ad79f0'/>
<id>urn:sha1:1946d45844c65ede4e3a514a5decf16612ad79f0</id>
<content type='text'>
The only use of the action parameter is to setup the error messages
for unpack_trees(). All but two cases pass either "checkout" or
"reset". The case that passes "reset --hard" would be better passing
"reset" so that the error messages match the builtin reset command
like all the other callers that are doing a reset. The case that
passes "Fast-forwarded" is only updating HEAD and so the parameter is
unused in that case as it does not call unpack_trees(). The value to
pass to setup_unpack_trees_porcelain() can be determined by checking
whether flags contains RESET_HEAD_HARD without the caller having to
specify it.

Signed-off-by: Phillip Wood &lt;phillip.wood@dunelm.org.uk&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>rebase --apply: don't run post-checkout hook if there is an error</title>
<updated>2022-01-26T20:08:53Z</updated>
<author>
<name>Phillip Wood</name>
<email>phillip.wood@dunelm.org.uk</email>
</author>
<published>2022-01-26T13:05:40Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=4840002a5f44a4c256c55f70c59d3b0506d14e21'/>
<id>urn:sha1:4840002a5f44a4c256c55f70c59d3b0506d14e21</id>
<content type='text'>
The hook should only be run if the worktree and refs were successfully
updated. This primarily affects "rebase --apply" but also "rebase
--merge" when it fast-forwards.

Signed-off-by: Phillip Wood &lt;phillip.wood@dunelm.org.uk&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>rebase: do not remove untracked files on checkout</title>
<updated>2022-01-26T20:08:52Z</updated>
<author>
<name>Phillip Wood</name>
<email>phillip.wood@dunelm.org.uk</email>
</author>
<published>2022-01-26T13:05:39Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=ab2fba0868860e610619f885031217d9cc63097a'/>
<id>urn:sha1:ab2fba0868860e610619f885031217d9cc63097a</id>
<content type='text'>
If "git rebase [--apply|--merge] &lt;upstream&gt; &lt;branch&gt;" detects that
&lt;upstream&gt; is an ancestor of &lt;branch&gt; then it will fast-forward and
checkout &lt;branch&gt;. Normally a checkout or picking a commit during a
rebase will refuse to overwrite untracked files, however rebase does
overwrite untracked files when checking out &lt;branch&gt;.

The fix is to only set reset in `unpack_tree_opts` if flags contains
`RESET_HEAD_HARD`. t5403 may seem like an odd home for the new test
but it will be extended in the next commit to check that the
post-checkout hook is not run when the checkout fails.

The test for `!detach_head` dates back to the
original implementation of reset_head() in
ac7f467fef ("builtin/rebase: support running "git rebase &lt;upstream&gt;"",
2018-08-07) and was correct until e65123a71d
("builtin rebase: support `git rebase &lt;upstream&gt; &lt;switch-to&gt;`",
2018-09-04) started using reset_head() to checkout &lt;switch-to&gt; when
fast-forwarding.

Note that 480d3d6bf9 ("Change unpack_trees' 'reset' flag into an
enum", 2021-09-27) also fixes this bug as it changes reset_head() to
never remove untracked files. I think this fix is still worthwhile as
it makes it clear that the same settings are used for detached and
non-detached checkouts.

Signed-off-by: Phillip Wood &lt;phillip.wood@dunelm.org.uk&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>rebase: pass correct arguments to post-checkout hook</title>
<updated>2022-01-26T20:08:52Z</updated>
<author>
<name>Phillip Wood</name>
<email>phillip.wood@dunelm.org.uk</email>
</author>
<published>2022-01-26T13:05:38Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=69f4c23009ee30faeb61a831f4265791c945783e'/>
<id>urn:sha1:69f4c23009ee30faeb61a831f4265791c945783e</id>
<content type='text'>
If a rebase started with "rebase [--apply|--merge] &lt;upstream&gt; &lt;branch&gt;"
detects that &lt;upstream&gt; is an ancestor of &lt;branch&gt; then it fast-forwards
and checks out &lt;branch&gt;. Unfortunately in that case it passed the null
oid as the first argument to the post-checkout hook rather than the oid
of HEAD.

A side effect of this change is that the call to update_ref() which
updates HEAD now always receives the old value of HEAD. This provides
protection against another process updating HEAD during the checkout.

Signed-off-by: Phillip Wood &lt;phillip.wood@dunelm.org.uk&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
