git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* suggestion for a simple addition: git update-ref --ff-only
@ 2013-03-01 23:18 David Madore
  2013-03-01 23:33 ` Junio C Hamano
  2013-03-02  1:10 ` Jeff King
  0 siblings, 2 replies; 3+ messages in thread
From: David Madore @ 2013-03-01 23:18 UTC (permalink / raw)
  To: git

Hi list,

I'd like to suggest a very simple, but IMHO quite useful, additional
option to git-update-ref: an option --ff-only which would cause the
command to refuse unless the current ref is an ancestor of the new
one.

The reason I think it would be useful: I occasionally wish to perform
a trivial (i.e., fast-forward) merge of some branch into another
(e.g., after a git-fetch) without checking it out.  Now git-update-ref
is perfect for that, but there is always the possibility of getting
something wrong (which one would not have with git merge --ff-only,
but the latter requires checking out the branch), and this option
would avoid tedious verifications.

Happy hacking,

-- 
     David A. Madore
   ( http://www.madore.org/~david/ )

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

* Re: suggestion for a simple addition: git update-ref --ff-only
  2013-03-01 23:18 suggestion for a simple addition: git update-ref --ff-only David Madore
@ 2013-03-01 23:33 ` Junio C Hamano
  2013-03-02  1:10 ` Jeff King
  1 sibling, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2013-03-01 23:33 UTC (permalink / raw)
  To: David Madore; +Cc: git

David Madore <david+news@madore.org> writes:

> Hi list,
>
> I'd like to suggest a very simple, but IMHO quite useful, additional
> option to git-update-ref: an option --ff-only which would cause the
> command to refuse unless the current ref is an ancestor of the new
> one.

Mild NAK.

What you want may be "git push . new_commit:refs/heads/foo", by the
way.

The "update-ref" plumbing does not want any such frill.

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

* Re: suggestion for a simple addition: git update-ref --ff-only
  2013-03-01 23:18 suggestion for a simple addition: git update-ref --ff-only David Madore
  2013-03-01 23:33 ` Junio C Hamano
@ 2013-03-02  1:10 ` Jeff King
  1 sibling, 0 replies; 3+ messages in thread
From: Jeff King @ 2013-03-02  1:10 UTC (permalink / raw)
  To: David Madore; +Cc: git

On Sat, Mar 02, 2013 at 12:18:59AM +0100, David Madore wrote:

> I'd like to suggest a very simple, but IMHO quite useful, additional
> option to git-update-ref: an option --ff-only which would cause the
> command to refuse unless the current ref is an ancestor of the new
> one.
> 
> The reason I think it would be useful: I occasionally wish to perform
> a trivial (i.e., fast-forward) merge of some branch into another
> (e.g., after a git-fetch) without checking it out.  Now git-update-ref
> is perfect for that, but there is always the possibility of getting
> something wrong (which one would not have with git merge --ff-only,
> but the latter requires checking out the branch), and this option
> would avoid tedious verifications.

The update-ref command is plumbing, which is supposed to do one small,
well-defined job. But you can compose many plumbing commands to do what
you want:

  # input
  ref=refs/heads/master
  new=$some_sha1

  # where are we now?
  old=`git rev-parse --verify $ref` || exit 1

  # is it a fast-forward?
  if ! git merge-base --is-ancestor $old $new; then
    echo >&2 "Not a fast-forward"
    exit 1
  fi

  # update it; we do not have to worry about race conditions because
  # update-ref will abort if somebody touched the ref in the meantime
  git update-ref $ref $new $old

Yes, it's three commands instead of one, but it's much more flexible
(you get to write your own message, you can use the same "merge-base" to
handle the "already up to date" case, etc).

-Peff

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

end of thread, other threads:[~2013-03-02  1:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-01 23:18 suggestion for a simple addition: git update-ref --ff-only David Madore
2013-03-01 23:33 ` Junio C Hamano
2013-03-02  1:10 ` Jeff King

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 NNTP newsgroup(s).