Lately I have noticed a number of users are forgetting that they
have uncommitted changes in their working directory when they switch
to another branch. This causes the user to accidentally carry those
changes into the new branch, which is usually not where they wanted
to commit them. A correlation does appear to exist between the user
being interrupted in the middle of their task and the branch switch,
indicating they simply got distracted and forgot what was going on.
Git shouldn't cause the user to make mistakes when it can help to
prevent them. So now users may set checkout.requireCleanDirectory
to true in their config file to have git-checkout verify the working
directory is clean before switching branches.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
Documentation/config.txt | 8 ++++++++
git-checkout.sh | 10 ++++++++++
t/t3200-branch.sh | 11 +++++++++++
3 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 9d754c8..f10e8ac 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -136,6 +136,14 @@ checkout.requireSourceBranch::
be the source version if only one argument is supplied.
Default is false, to stay compatible with prior behavior.
+checkout.requireCleanDirectory::
+ If true tells git-checkout to verify there are no uncommitted
+ changes still in the index or working directory before
+ switching branches. If uncommitted changes exist the -m
+ flag can be used to skip the check if the user really wanted
+ to carry those onto the new branch. Default is false,
+ to stay compatible with prior behavior.
+
pager.color::
A boolean to enable/disable colored output when the pager is in
use (default is true).
diff --git a/git-checkout.sh b/git-checkout.sh
index 5f9fb6e..c04b8c1 100755
--- a/git-checkout.sh
+++ b/git-checkout.sh
@@ -171,6 +171,16 @@ then
git-read-tree --reset -u $new
else
git-update-index --refr...