Skip to contentSkip to conversation

Git feature request: Option to force Git to abort a checkout if working directory is dirty (i.e. disregarding the check for conflicts)

DISCUSSION Jonas Bang 2 participants 7 messages Jun 15, 2016

lore
Share & tools
lore

Jonas Bang

author
#0 lore raw

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

#1 lore raw
Quoted 5 lines · Jonas Bang

Hi Git developers,

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

Quoted 7 lines

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

Quoted 1 line

*False behavior:*

What is "false"?

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

Quoted 12 lines

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 
Quoted 8 lines

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?

Quoted 10 lines

*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 
Quoted 4 lines

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.

author
#2 lore raw

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

Quoted 15 lines
Quoted 5 lines · Jonas Bang

Hi Git developers,

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

Quoted 7 lines

*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

Quoted 6 lines

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.

Quoted 4 lines

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.

Quoted 5 lines
Quoted 1 line

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

Quoted 20 lines
Quoted 20 lines

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'
Quoted 6 lines
Quoted 1 line

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.

Quoted 4 lines
Quoted 4 lines

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

Quoted 10 lines
Quoted 9 lines
$ 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).

Quoted 8 lines

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

Quoted 2 lines

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.

Quoted 8 lines

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.

#3 lore raw
Quoted 9 lines · Jonas Bang
Quoted 8 lines

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

Quoted 5 lines

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

author
#4 lore raw
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

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

Quoted 9 lines

paths are except from this new check".

Quoted 6 lines

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

Quoted 1 line

feature will not help them in any way, it is just that we will make sure

it does

Quoted 1 line

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?

#5 lore raw
Quoted 12 lines · Jonas Bang
Quoted 12 lines
Quoted 11 lines
Quoted 5 lines

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

Quoted 5 lines
Quoted 3 lines

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.

Quoted 1 line

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.

author
#6 lore raw
Quoted 14 lines
Quoted 12 lines · Jonas Bang
Quoted 12 lines
Quoted 11 lines
Quoted 5 lines

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

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

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

Quoted 3 lines

an escape hatch ;-)

It is perfectly fine to answer to "I wonder if there are things you could

do?"

Quoted 1 line

with "No, I am not going to help them with this series; I only make sure I

do

Quoted 7 lines

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.

Quoted 7 lines
Quoted 1 line

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