git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Git feature request: Option to force Git to abort a checkout if working directory is dirty (i.e. disregarding the check for conflicts)
@ 2014-03-27 16:15 Jonas Bang
  2014-03-27 17:46 ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: Jonas Bang @ 2014-03-27 16:15 UTC (permalink / raw)
  To: git

Hi Git developers, 

This is my first Git feature request, I hope it won’t get me hanged on the
gallows ;o) 

*Git feature request:*
Add an option to Git config to configure the criteria for when a "git
checkout" should abort. 

*Name proposal and options:*
checkout.clean false <default> 
checkout.clean true 

*False behavior:*
As is: 
When doing a checkout then Git will check if your working directory is
dirty, and if so check if the checkout will result in any conflicts, and if
so abort the checkout with a message: 

$ git checkout some_branch
error: Your local changes to the following files would be overwritten by
checkout:
       some_file
Please, commit your changes or stash them before you can switch branches.
Aborting 

If no conflicts then: 

$ git checkout some_branch
M       some_file
M       some_other_file
Switched to branch 'some_branch' 

I.e. it will only abort if there are conflicts. 

*True behavior:*
When doing a checkout then Git will check if your working directory is dirty
(checking for both modified and added untracked files), and if so abort the
checkout with a message: 

$ git checkout some_branch
error: Your working directory is not clean.
Please, commit your changes or stash them before you can switch branches.
Aborting 

I.e. it will abort if working directory is dirty (checking for both modified
and added untracked files). 
I.e. you can only do checkout if you get "nothing to commit, working
directory clean" when running "git status" (ignoring ignored files though). 

*Usecase in short:*
If you use an IDE (like e.g. Eclipse) and do a checkout
of 'some_branch' with a dirty working directory which will not result in any
conflicts, then you will not be nicely notified (as you would in Git Bash)
that the changes you were working on in 'previous_branch' are still present
in your working directory after changing to 'some_branch'. I.e. when you
compile your code your uncommitted changes from 'previous_branch' are still
present in your working directory on 'some_branch'. 

As I see it Git is extremely strong in context switching (i.e. working on
multiple issues on multiple branches), and I could see a use for a setting
which setup a strict check for if working directory is not clean
(disregarding the check for conflicts). This would mean that your changes
created while on branch #1 will not be carried over when changing to branch
#2, i.e. you will work strictly context based always. 

*Usecase also described here:*
http://stackoverflow.com/questions/22609566/how-to-force-git-to-abort-a-chec
kout-if-working-directory-is-not-clean-i-e-dis 

Br, 
Jonas Bang Christensen

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

* Re: Git feature request: Option to force Git to abort a checkout if working directory is dirty (i.e. disregarding the check for conflicts)
  2014-03-27 16:15 Git feature request: Option to force Git to abort a checkout if working directory is dirty (i.e. disregarding the check for conflicts) Jonas Bang
@ 2014-03-27 17:46 ` Junio C Hamano
  2014-03-29 11:49   ` Jonas Bang
  0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2014-03-27 17:46 UTC (permalink / raw)
  To: Jonas Bang; +Cc: git

"Jonas Bang" <email@jonasbang.dk> writes:

> Hi Git developers, 
>
> This is my first Git feature request, I hope it won’t get me hanged on the
> gallows ;o) 
>
> *Git feature request:*
> Add an option to Git config to configure the criteria for when a "git
> checkout" should abort. 
>
> *Name proposal and options:*
> checkout.clean false <default> 
> checkout.clean true 

A configuration variable without command line override will make the
system unusable.  When thinking about a new feature, please make it
a habit to first add a command line option and then if that option
turns out to be useful in the real world (not in the imaginary world
in which you had such a feature, where even you haven't lived in
yet), then think about also adding configuration variables to
control the default.

Also, a useful definition of "clean"-ness may have to change over
time as we gain experience with the feature.  And also as a user
personally gains experience with using Git.  It is somewhat
implausible that a boolean true/false may remain sufficient.


> *False behavior:*

What is "false"?

Ah, when the configuration is set to "false", which will be the
default?

> As is: 
> When doing a checkout then Git will check if your working directory is
> dirty, and if so check if the checkout will result in any conflicts, and if
> so abort the checkout with a message: 
>
> $ git checkout some_branch
> error: Your local changes to the following files would be overwritten by
> checkout:
>        some_file
> Please, commit your changes or stash them before you can switch branches.
> Aborting 
>
> If no conflicts then: 
>
> $ git checkout some_branch
> M       some_file
> M       some_other_file
> Switched to branch 'some_branch' 
>
> I.e. it will only abort if there are conflicts. 

Sensible.  This is the behaviour that is very often depended upon by
people who use Git with multiple branches.  Are you thinking about
changing it in any way when the new configuration is set to "false",
or is the above just a summary of what happens in the current
system?


> *True behavior:*
> When doing a checkout then Git will check if your working directory is dirty
> (checking for both modified and added untracked files), and if so abort the
> checkout with a message: 
>
> $ git checkout some_branch
> error: Your working directory is not clean.
> Please, commit your changes or stash them before you can switch branches.
> Aborting 
>
> I.e. it will abort if working directory is dirty (checking for both modified
> and added untracked files). 
> I.e. you can only do checkout if you get "nothing to commit, working
> directory clean" when running "git status" (ignoring ignored files though). 

The above two say very different things.  For some people, having
many throw away untracked files is a norm that they do not consider
it is even worth their time to list them in .gitignore and they do
not want to be reminded in "git status" output, and the latter
definition of "checkout.clean=true will kill checkout when status
says there are some things that could be committed" would suit them,
while the former definition "checkout.clean=true will kill checkout
when there is any untracked files" would be totally useless.

So I can understand the latter, but I do not see how the former
could be a useful addition.

For some people it is also a norm to keep files that have been
modified from HEAD and/or index without committing for a long time
(e.g. earlier, Linus said that the version in Makefile is updated
and kept modified in the working tree long before a new release is
committed with that change).  The default behaviour would cover
their use case so your proposal would not hurt them, but I wonder if
there are things you could do to help them as well, perhaps by
allowing this new configuration to express something like "local
changes in these paths are except from this new check".

I dunno.

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

* RE: Git feature request: Option to force Git to abort a checkout if working directory is dirty (i.e. disregarding the check for conflicts)
  2014-03-27 17:46 ` Junio C Hamano
@ 2014-03-29 11:49   ` Jonas Bang
  2014-03-31 17:13     ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: Jonas Bang @ 2014-03-29 11:49 UTC (permalink / raw)
  To: 'Junio C Hamano'; +Cc: git

Thanks for your feedback, Junio, I have added more details and tried to simplify the request.

> "Jonas Bang" <email@jonasbang.dk> writes:
> 
> > Hi Git developers,
> >
> > This is my first Git feature request, I hope it won’t get me hanged on
> > the gallows ;o)
> >
> > *Git feature request:*
> > Add an option to Git config to configure the criteria for when a "git
> > checkout" should abort.
> >
> > *Name proposal and options:*
> > checkout.clean false <default>
> > checkout.clean true
> 
> A configuration variable without command line override will make the system
> unusable.  When thinking about a new feature, please make it a habit to first
> add a command line option and then if that option turns out to be useful in
> the real world (not in the imaginary world in which you had such a feature,
> where even you haven't lived in yet), then think about also adding
> configuration variables to control the default.

Proposal for "git checkout" command line option:
--clean false|true|include-untracked|all

If the 'false' option is used then 'git checkout' will work as today. This should be the default behavior and it is not needed to use this command line option, nor set the configuration variable. The need for the '--clean false' option is if the configuration variable is set to 'true', ' include-untracked' or 'all' in global or local config then it is possible to override this configuration from command line by using '--clean false'.

If the 'true' option is used then 'git checkout' will abort if the index or the working tree differs from HEAD.

If the 'include-untracked' option is used then 'git checkout' will abort if there are any untracked files, or if the index or the working tree differs from HEAD.

If the 'all' option is used then 'git checkout' will abort if there are any ignored files added, or if there are any untracked files, or if the index or the working tree differs from HEAD.

Proposal is also to add this as a configuration variable (e.g. checkout.clean false|true|include-untracked|all), as the usecase is most relevant for people using 3rd party IDE or GUI which calls the standard "git checkout" command.

> Also, a useful definition of "clean"-ness may have to change over time as we
> gain experience with the feature.  And also as a user personally gains
> experience with using Git.  It is somewhat implausible that a boolean
> true/false may remain sufficient.

I have added more options to specify more precisely the definition of "clean"-ness.
 
> > *False behavior:*
> 
> What is "false"?
> 
> Ah, when the configuration is set to "false", which will be the default?

Yes, exactly, this was what I meant.

> > As is:
> > When doing a checkout then Git will check if your working directory is
> > dirty, and if so check if the checkout will result in any conflicts,
> > and if so abort the checkout with a message:
> >
> > $ git checkout some_branch
> > error: Your local changes to the following files would be overwritten
> > by
> > checkout:
> >        some_file
> > Please, commit your changes or stash them before you can switch branches.
> > Aborting
> >
> > If no conflicts then:
> >
> > $ git checkout some_branch
> > M       some_file
> > M       some_other_file
> > Switched to branch 'some_branch'
> >
> > I.e. it will only abort if there are conflicts.
> 
> Sensible.  This is the behaviour that is very often depended upon by people
> who use Git with multiple branches.  Are you thinking about changing it in
> any way when the new configuration is set to "false", or is the above just a
> summary of what happens in the current system?

This was just meant as a summary.

> > *True behavior:*
> > When doing a checkout then Git will check if your working directory is
> > dirty (checking for both modified and added untracked files), and if
> > so abort the checkout with a message:

This will in fact be the 'include-untracked' option where all untracked files are also checked in addition to the index and the working tree.

> > $ git checkout some_branch
> > error: Your working directory is not clean.
> > Please, commit your changes or stash them before you can switch branches.
> > Aborting
> >
> > I.e. it will abort if working directory is dirty (checking for both
> > modified and added untracked files).
> > I.e. you can only do checkout if you get "nothing to commit, working
> > directory clean" when running "git status" (ignoring ignored files though).
> 
> The above two say very different things.  For some people, having many
> throw away untracked files is a norm that they do not consider it is even
> worth their time to list them in .gitignore and they do not want to be
> reminded in "git status" output, and the latter definition of
> "checkout.clean=true will kill checkout when status says there are some
> things that could be committed" would suit them, while the former definition
> "checkout.clean=true will kill checkout when there is any untracked files"
> would be totally useless.

Regarding those who has many throw away untracked files, they can either not change the configuration (i.e. keep the 'git checkout' functionality as it is), or optionally use the 'true' option which only checks the index and the working tree (i.e. not checking on untracked files).

> So I can understand the latter, but I do not see how the former could be a
> useful addition.

By changing my original behavior of 'true', and by adding 'include-untracked' and 'all', I believe I have taken into account the scenarios you describe.

> For some people it is also a norm to keep files that have been modified from
> HEAD and/or index without committing for a long time (e.g. earlier, Linus said
> that the version in Makefile is updated and kept modified in the working tree
> long before a new release is committed with that change).  The default
> behaviour would cover their use case so your proposal would not hurt them,
> but I wonder if there are things you could do to help them as well, perhaps
> by allowing this new configuration to express something like "local changes in
> these paths are except from this new check".

Yes, those people would probably use the default 'false' behavior as it is already. If they however would like to use e.g. the 'true' or 'include-untracked' setting as a configuration variable, then they can use the command line option 'false' if they wish to do a 'git checkout' even with modified files in the working tree.

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

* Re: Git feature request: Option to force Git to abort a checkout if working directory is dirty (i.e. disregarding the check for conflicts)
  2014-03-29 11:49   ` Jonas Bang
@ 2014-03-31 17:13     ` Junio C Hamano
  2014-04-01 17:57       ` Jonas Bang
  0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2014-03-31 17:13 UTC (permalink / raw)
  To: Jonas Bang; +Cc: git

"Jonas Bang" <email@jonasbang.dk> writes:

>> For some people it is also a norm to keep files that have been modified from
>> HEAD and/or index without committing for a long time (e.g. earlier, Linus said
>> that the version in Makefile is updated and kept modified in the working tree
>> long before a new release is committed with that change).  The default
>> behaviour would cover their use case so your proposal would not hurt them,
>> but I wonder if there are things you could do to help them as well, perhaps
>> by allowing this new configuration to express something like "local changes in
>> these paths are except from this new check".
>
> Yes, those people would probably use the default 'false' behavior
> as it is already. If they however would like to use e.g. the
> 'true' or 'include-untracked' setting as a configuration variable,
> then they can use the command line option 'false' if they wish to
> do a 'git checkout' even with modified files in the working tree.

So in short, you are saying that "The added code necessary to
implement this feature will not help them in any way, it is just
that we will make sure it does not hurt them".

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

* RE: Git feature request: Option to force Git to abort a checkout if working directory is dirty (i.e. disregarding the check for conflicts)
  2014-03-31 17:13     ` Junio C Hamano
@ 2014-04-01 17:57       ` Jonas Bang
  2014-04-02 17:55         ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: Jonas Bang @ 2014-04-01 17:57 UTC (permalink / raw)
  To: 'Junio C Hamano'; +Cc: git

> >> For some people it is also a norm to keep files that have been
> >> modified from HEAD and/or index without committing for a long time
> >> (e.g. earlier, Linus said that the version in Makefile is updated and
> >> kept modified in the working tree long before a new release is
> >> committed with that change).  The default behaviour would cover their
> >> use case so your proposal would not hurt them, but I wonder if there
> >> are things you could do to help them as well, perhaps by allowing
> >> this new configuration to express something like "local changes in
these
> paths are except from this new check".
> >
> > Yes, those people would probably use the default 'false' behavior as
> > it is already. If they however would like to use e.g. the 'true' or
> > 'include-untracked' setting as a configuration variable, then they can
> > use the command line option 'false' if they wish to do a 'git
> > checkout' even with modified files in the working tree.
> 
> So in short, you are saying that "The added code necessary to implement
this
> feature will not help them in any way, it is just that we will make sure
it does
> not hurt them".

I didn't realize they needed help. Based on what you describe it seems that
they are quite happy about their current workmode. The feature request I'm
proposing is to aid a different workmode used by a different group of users.

I did try to give it some thought to figure out if it would be possible to
address also your mentioned users workmode, but it didn't seem straight
forward to solve in combination with my feature request, and the solution
wouldn't end up being as simple. However I did already manage to include
proposals on how to address your other comments, I believe.

I have focused primarily on proposing a feature request which is as simple
as possible and which addresses an issue with a workmode for a group of
users, and which in the same time doesn't "hurt" others.

What are your thoughts on that part?
How and who to decide if this is a reasonable feature request to accept?

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

* Re: Git feature request: Option to force Git to abort a checkout if working directory is dirty (i.e. disregarding the check for conflicts)
  2014-04-01 17:57       ` Jonas Bang
@ 2014-04-02 17:55         ` Junio C Hamano
  2014-04-03 18:42           ` Jonas Bang
  0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2014-04-02 17:55 UTC (permalink / raw)
  To: Jonas Bang; +Cc: git

"Jonas Bang" <email@jonasbang.dk> writes:

>> >> ...  The default behaviour would cover their
>> >> use case so your proposal would not hurt them, but I wonder if there
>> >> are things you could do to help them as well, perhaps by allowing
>> >> this new configuration to express something like "local changes in
>> >> these paths are excempt from this new check".
>> >
>> > Yes, those people would probably use the default 'false' behavior as
>> > it is already. If they however would like to use e.g. the 'true' or
>> > 'include-untracked' setting as a configuration variable, then they can
>> > use the command line option 'false' if they wish to do a 'git
>> > checkout' even with modified files in the working tree.
>> 
>> So in short, you are saying that "The added code necessary to implement
>> this feature will not help them in any way, it is just that we
>> will make sure it does not hurt them".
>
> I didn't realize they needed help.

If so, then you could have just stated that way, instead of saying
they have an escape hatch ;-)

It is perfectly fine to answer to "I wonder if there are things you
could do?" with "No, I am not going to help them with this series; I
only make sure I do not hurt them."  and that is perfectly fine, as
long as:

 - you do not directly hurt them with your series; and

 - you do not make it harder for those who are interested in helping
   them to build on top of your work in the future.

> How and who to decide if this is a reasonable feature request to accept?

As this project primarily works on "scratch your own itch" basis,
somebody who (1) thinks that the proposed feature is worth having in
our system and (2) is interested in working on it will pick it up.

If nobody is interested, then usually nothing happens.

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

* RE: Git feature request: Option to force Git to abort a checkout if working directory is dirty (i.e. disregarding the check for conflicts)
  2014-04-02 17:55         ` Junio C Hamano
@ 2014-04-03 18:42           ` Jonas Bang
  0 siblings, 0 replies; 7+ messages in thread
From: Jonas Bang @ 2014-04-03 18:42 UTC (permalink / raw)
  To: 'Junio C Hamano'; +Cc: git

> "Jonas Bang" <email@jonasbang.dk> writes:
> 
> >> >> ...  The default behaviour would cover their use case so your
> >> >> proposal would not hurt them, but I wonder if there are things you
> >> >> could do to help them as well, perhaps by allowing this new
> >> >> configuration to express something like "local changes in these
> >> >> paths are excempt from this new check".
> >> >
> >> > Yes, those people would probably use the default 'false' behavior
> >> > as it is already. If they however would like to use e.g. the 'true'
> >> > or 'include-untracked' setting as a configuration variable, then
> >> > they can use the command line option 'false' if they wish to do a
> >> > 'git checkout' even with modified files in the working tree.
> >>
> >> So in short, you are saying that "The added code necessary to
> >> implement this feature will not help them in any way, it is just that
> >> we will make sure it does not hurt them".
> >
> > I didn't realize they needed help.
> 
> If so, then you could have just stated that way, instead of saying they
have
> an escape hatch ;-)
> 
> It is perfectly fine to answer to "I wonder if there are things you could
do?"
> with "No, I am not going to help them with this series; I only make sure I
do
> not hurt them."  and that is perfectly fine, as long as:
> 
>  - you do not directly hurt them with your series; and
> 
>  - you do not make it harder for those who are interested in helping
>    them to build on top of your work in the future.
> 
> > How and who to decide if this is a reasonable feature request to accept?
> 
> As this project primarily works on "scratch your own itch" basis, somebody
> who (1) thinks that the proposed feature is worth having in our system and
> (2) is interested in working on it will pick it up.
> 
> If nobody is interested, then usually nothing happens.

Thanks for your replies and your time.

I'll cross my fingers for someone other than me and my identified group of
users seeing the benefit of this feature request.

Br,
Jonas

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

end of thread, other threads:[~2014-04-03 18:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-27 16:15 Git feature request: Option to force Git to abort a checkout if working directory is dirty (i.e. disregarding the check for conflicts) Jonas Bang
2014-03-27 17:46 ` Junio C Hamano
2014-03-29 11:49   ` Jonas Bang
2014-03-31 17:13     ` Junio C Hamano
2014-04-01 17:57       ` Jonas Bang
2014-04-02 17:55         ` Junio C Hamano
2014-04-03 18:42           ` Jonas Bang

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).