git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* On writing builtin-reset.c, a question about git-reset.sh
@ 2007-08-19 23:45 Carlos Rica
  2007-08-20  0:24 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Carlos Rica @ 2007-08-19 23:45 UTC (permalink / raw
  To: git, Johannes Schindelin

Hi, I'm writing builtin-reset.c and
I'm really stuck with a little code in
git-reset.sh:

if orig=$(git rev-parse --verify HEAD 2>/dev/null)
then
	echo "$orig" >"$GIT_DIR/ORIG_HEAD"
else
	rm -f "$GIT_DIR/ORIG_HEAD"
fi

My question is about when this condition
could fail (and then the rm executed), and
if you would be able to reproduce it in tests.
I couldn't, and asking for this in the IRC
didn't help me at all.

This code was introduced in 45d197, when
different reset types were introduced,
and it seems that there was a reason for
doing it that way, looking at the change.

Thanks in advance for your support.

--
Carlos

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: On writing builtin-reset.c, a question about git-reset.sh
  2007-08-19 23:45 On writing builtin-reset.c, a question about git-reset.sh Carlos Rica
@ 2007-08-20  0:24 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2007-08-20  0:24 UTC (permalink / raw
  To: Carlos Rica; +Cc: git, Johannes Schindelin

Carlos Rica <jasampler@gmail.com> writes:

> Hi, I'm writing builtin-reset.c and
> I'm really stuck with a little code in
> git-reset.sh:
>
> if orig=$(git rev-parse --verify HEAD 2>/dev/null)
> then
> 	echo "$orig" >"$GIT_DIR/ORIG_HEAD"
> else
> 	rm -f "$GIT_DIR/ORIG_HEAD"
> fi
>
> My question is about when this condition
> could fail (and then the rm executed),...

When orig does not exist.  That is, when HEAD is a symref that
point at an unborn branch (e.g. between "git init" and your
first "git commit").  After "git reset" of any kind, we would
want to make sure that GIT_DIR/ORIG_HEAD points at the commit
you were previously at, and if orig is not there we do not want
anything in that file.

Another possibility would be if somebody wants to add an
unrelated branch to the repository [*1*].  This is against
recommended practice, but you could make your HEAD point at an
unborn branch using plumbing commands, or even by hand:

	$ echo 'ref: refs/heads/unrelated' >.git/HEAD

Your next commit will make a root commit that is pointed by
'refs/heads/unrelated' ref, but before that happens, we would
not want to have GIT_DIR/ORIG_HEAD if you did git-reset.

Now, you might wonder if "git reset" makes any sense from such a
state, and actually it does ;-)

	$ git init
        $ git remote add -f friend ../neighbour.git/
        $ git reset --hard friend/master

[Footnote]

*1* People often seem to want to do something like the html, man, and
todo branches in my public repository that do not share any history
with the primary development branches.  Perhaps they think it is cool
to do so, but it is not.  These independent branches originate from
different repositories, and are published in the same repository only
for easier distribution.  There is no reason for you (nor me) to
create such unrelated branches in a single originating repository.

A recommended procedure to publish independent branches in a single
repository is to push into one from separate, independent
repositories.  Starting an independent history in an existing
repository, like the main body of this message shows you how, is not
recommended.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-08-20  0:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-19 23:45 On writing builtin-reset.c, a question about git-reset.sh Carlos Rica
2007-08-20  0:24 ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).