Re: Feature request: prevent push -f from pushing all branches at once

2013-07-04 Thread Matthieu Moy
Dany  writes:

> Again, I think the case where one intends to force push many branches
> is certainly not as common as the case where one intends to force push
> one branch, so why does git's default behavior leave the user in the
> position of fscking himself over pretty badly?

I don't think the case of "force push" is very different from the
"non-force push". If you're surprised that "git push -f" pushes
everything, most likely you didn't want a plain "git push" to push
everything either.

There are already several measures against this. The first is mentionned
in Jonathan's message: Git 2.0 will only push one branch by default (-f
or not). You can already get this behavior by setting push.default (if
your Git version is too old, set it to "current" for example, read "git
config --help").

Another measure is a better documentation. We've just merged the change
below. In short: don't run "git push -f", but run e.g. "git push origin
+master".

commit 70495b556f5685afe0e41988e42d48b2331d77a0
Author: Matthieu Moy 
Date:   Mon Jun 17 19:52:41 2013 +0200

Documentation/git-push.txt: explain better cases where --force is dangerous

The behavior of "git push --force" is rather clear when it updates only
one remote ref, but running it when pushing several branches can really
be dangerous. Warn the users a bit more and give them the alternative to
push only one branch.

Signed-off-by: Matthieu Moy 
Signed-off-by: Junio C Hamano 

diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt
index 8b637d3..28a17c3 100644
--- a/Documentation/git-push.txt
+++ b/Documentation/git-push.txt
@@ -124,6 +124,15 @@ no `push.default` configuration variable is set.
not an ancestor of the local ref used to overwrite it.
This flag disables the check.  This can cause the
remote repository to lose commits; use it with care.
+   Note that `--force` applies to all the refs that are pushed,
+   hence using it with `push.default` set to `matching` or with
+   multiple push destinations configured with `remote.*.push`
+   may overwrite refs other than the current branch (including
+   local refs that are strictly behind their remote counterpart).
+   To force a push to only one branch, use a `+` in front of the
+   refspec to push (e.g `git push origin +master` to force a push
+   to the `master` branch). See the `...` section above
+   for details.
 
 --repo=::
This option is only relevant if no  argument is


-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Feature request: prevent push -f from pushing all branches at once

2013-07-03 Thread Jonathan Nieder
Hi Dany,

Dany wrote:

> I had a pretty sucky thing happen to me today: while remote tracking
> a non-master branch, I force pushed. This had the intended effect of
> force pushing the branch I was working on, but also the unintended
> function of force pushing all branches I wasn't on.

Yeah, I agree that this is lousy.

When you run "git push" or "git push -f" without further arguments,
current versions of git print a long message:

| $ git push
| warning: push.default is unset; its implicit value is changing in
| Git 2.0 from 'matching' to 'simple'. To squelch this message
| and maintain the current behavior after the default changes, use:
| 
|   git config --global push.default matching
| 
| To squelch this message and adopt the new behavior now, use:
| 
|   git config --global push.default simple
| 
| See 'git help config' and search for 'push.default' for further information.
| (the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
| 'current' instead of 'simple' if you sometimes use older versions of Git)

This is intended as a warning that git is not necessarily going to
push the branches that you intended, with instructions for teaching
git what you actually meant.  For historical reasons (to support
habits and scripts) the current default is the "push matching
branches" behavior you ran into, but in the future the default will be
a more conservative "push the current branch, and only if it is
configured to pull from the matching branch", allowing this long
message to go away.

What version of git are you using?  Any ideas about how that message
could be improved?  (Perhaps it is too long to work as an effective
warning.)

Thanks and hope that helps,
Jonathan
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html