threads / discuss / 9394

How to figure out what 'git push' would do?

Subject: How to figure out what 'git push' would do?

## tl;dr

6 messages between Aug 5, 2007 and Aug 5, 2007.

replies: 5people: 4as markdown or json

David Kastrup· Aug 5, 2007, 11:42 UTC · re: Steffen Prohaska · lore

Re: How to figure out what 'git push' would do?

Steffen Prohaska <prohaska@zib.de> writes:
Show 5 quoted lines
> How can I check what a 'git push' would do, without
> actually doing it?
>
> Is there something like 'git push --dry-run', similar
> to 'rsync --dry-run'?
Wel, you could put

#!/bin/sh cat >/tmp/dryrun exit 1

into
$GIT_DIR/hooks/pre-receive
on the receiving side.  Or maybe the update hook.
-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum
Alex Riesen· Aug 5, 2007, 17:33 UTC · re: Steffen Prohaska · lore

Re: How to figure out what 'git push' would do?

Steffen Prohaska, Sun, Aug 05, 2007 13:37:34 +0200:
Show 5 quoted lines
> How can I check what a 'git push' would do, without
> actually doing it?
> 
> Is there something like 'git push --dry-run', similar
> to 'rsync --dry-run'?

No. It is often safe to just do git-push, unless you have naive developers doing pull every time some ref in your shared repo changes *and* expecting the result to compile (typical for CVS way of work). git-push will not overwrite anything, it always only forwards history.

For the case you really want to know what the changes on remote repo will be it is possible to fetch them into the local repo first and compare with what you will push:

    $ git fetch git://remote/path/REPO master:refs/remotes/REPO/master
    $ gitk local..REPO/master

It gives you all possible information, which may be worth that bit of work. Or, if you have all the remote configuration ready, it can be just:

    $ git fetch
    $ gitk local..REPO/master
Julian Phillips· Aug 5, 2007, 17:45 UTC · re: Alex Riesen · lore

Re: How to figure out what 'git push' would do?

On Sun, 5 Aug 2007, Alex Riesen wrote:
Show 11 quoted lines
> Steffen Prohaska, Sun, Aug 05, 2007 13:37:34 +0200:
>> How can I check what a 'git push' would do, without
>> actually doing it?
>>
>> Is there something like 'git push --dry-run', similar
>> to 'rsync --dry-run'?
>
> No. It is often safe to just do git-push, unless you have naive
> developers doing pull every time some ref in your shared repo changes
> *and* expecting the result to compile (typical for CVS way of work).
> git-push will not overwrite anything, it always only forwards history.

Not strictly true. You _can_ push out non fastforward changes, unless you have receive.denyNonFastforwards in the repote repo - so you may well be able to push out something that is completely unrelated to the last commit the ref pointed to.

-- 
Julian

  ---
You never get a second chance to make a first impression.
Steffen Prohaska· Aug 5, 2007, 19:56 UTC · re: Alex Riesen · lore

Re: How to figure out what 'git push' would do?

On Aug 5, 2007, at 7:33 PM, Alex Riesen wrote:
Show 26 quoted lines
> Steffen Prohaska, Sun, Aug 05, 2007 13:37:34 +0200:
>> How can I check what a 'git push' would do, without
>> actually doing it?
>>
>> Is there something like 'git push --dry-run', similar
>> to 'rsync --dry-run'?
>
> No. It is often safe to just do git-push, unless you have naive
> developers doing pull every time some ref in your shared repo changes
> *and* expecting the result to compile (typical for CVS way of work).
> git-push will not overwrite anything, it always only forwards history.
>
> For the case you really want to know what the changes on remote repo
> will be it is possible to fetch them into the local repo first and
> compare with what you will push:
>
>     $ git fetch git://remote/path/REPO master:refs/remotes/REPO/master
>     $ gitk local..REPO/master
>
> It gives you all possible information, which may be worth that bit of
> work. Or, if you have all the remote configuration ready, it can be
> just:
>
>     $ git fetch
>     $ gitk local..REPO/master
>

That applies only for a single branch. If I prepared a couple of branches for pushing and somehow want to double check what I prepared, 'git push --dry-run' would be quite handy. I know how to handle the situation and could write a custom script that does all necessary checks. But I haven't found an out-of-the-box solution for double checking right before 'git push'

	Steffen
Alex Riesen· Aug 5, 2007, 22:09 UTC · re: Steffen Prohaska · lore

Re: How to figure out what 'git push' would do?

Steffen Prohaska, Sun, Aug 05, 2007 21:56:37 +0200:
Show 11 quoted lines
> >
> >    $ git fetch
> >    $ gitk local..REPO/master
> >
> 
> That applies only for a single branch. If I prepared a couple of
> branches for pushing and somehow want to double check what I prepared,
> 'git push --dry-run' would be quite handy. I know how to handle the
> situation and could write a custom script that does all necessary
> checks. But I haven't found an out-of-the-box solution for double
> checking right before 'git push'

Well, you can do gitk local1..REPO/remote1 local2..REPO/remote2, of course, but yes, there is not out-of-the-box solution.

And a straight-forward implementation of "git-push --dry-run" doesn't look simple... The remote sides git-receive-pack still have to be called for any useful information, like the references updated and the SHA-1s they get. IOW, if you can update your system easily to support --dry-run, it still does not mean the server admin will do that just as readily. And AFAICS, receive-pack dies if given a parameter it does not know (it dies on every command line argument which begins with "-", as it looks). Maybe we should change that first for a very slow start...

It is simplier to modify git-ls-remote of git-remote to just compare reference on local and remote side.

← back to recent threads