From: "Shawn O. Pearce" <spearce@spearce.org>
To: Junio C Hamano <junkio@cox.net>
Cc: git@vger.kernel.org
Subject: [PATCH 1/2] Allow users to require source branch on git-checkout -b.
Date: Thu, 7 Dec 2006 05:01:52 -0500 [thread overview]
Message-ID: <20061207100152.GA12966@spearce.org> (raw)
I have recently observed a rather large number of users who forget
to specify the base revision when they start a new branch with
git-checkout -b. Many of these users are shocked many hours and
commits later when their prior branch is now also part of the new
branch. Nasty words about Git usually follow the discovery.
This introduces a new config option: checkout.requireSourceBranch,
which the user can set to make git-checkout -b require them to supply
not only the new branch name but also the initial version for that
branch. This prevents the command from assuming the user meant HEAD
when they omitted an argument by accident.
To keep behavior backwards compatible with any existing scripts
this option is currently disabled by default, but it would be more
friendly to new users if the option was enabled by default.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
Documentation/config.txt | 6 ++++++
git-checkout.sh | 12 +++++++++++-
t/t3200-branch.sh | 14 ++++++++++++++
3 files changed, 31 insertions(+), 1 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 9090762..9d754c8 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -130,6 +130,12 @@ branch.<name>.merge::
When in branch <name>, it tells `git fetch` the default remote branch
to be merged.
+checkout.requireSourceBranch::
+ If true tells git-checkout -b to require the user to
+ supply two arguments, rather than assuming HEAD should
+ be the source version if only one argument is supplied.
+ 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 737abd0..5f9fb6e 100755
--- a/git-checkout.sh
+++ b/git-checkout.sh
@@ -137,7 +137,17 @@ then
cd "$cdup"
fi
-[ -z "$new" ] && new=$old && new_name="$old_name"
+# If we have no new name default to 'HEAD', unless we are
+# making a new branch and the user told us not to assume.
+if [ -z "$new" ]; then
+ if [ "$newbranch" ] &&
+ [ Xtrue = "X`git-repo-config --bool checkout.requireSourceBranch`" ]
+ then
+ die "A source branch is required when creating a branch."
+ fi
+ new=$old
+ new_name="$old_name"
+fi
# If we don't have an old branch that we're switching to,
# and we don't have a new branch name for the target we
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index acb54b6..7e0c48b 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -70,4 +70,18 @@ test_expect_success \
git-branch -d l/m &&
git-branch l'
+test_expect_success \
+ 'git checkout -b M works if checkout.requireSourceBranch not set' \
+ 'git-checkout -b M'
+
+test_expect_failure \
+ 'git checkout -b N fails if checkout.requireSourceBranch is set' \
+ 'git-repo-config checkout.requireSourceBranch true
+ git-checkout -b N'
+
+test_expect_success \
+ 'git checkout -b N works if checkout.requireSourceBranch is false' \
+ 'git-repo-config checkout.requireSourceBranch false
+ git-checkout -b N'
+
test_done
--
1.4.4.2.gb772
next reply other threads:[~2006-12-07 10:02 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-12-07 10:01 Shawn O. Pearce [this message]
2006-12-07 19:48 ` [PATCH 1/2] Allow users to require source branch on git-checkout -b Junio C Hamano
2006-12-07 19:57 ` Shawn Pearce
2006-12-07 21:23 ` Junio C Hamano
2006-12-07 21:40 ` J. Bruce Fields
2006-12-07 21:59 ` Shawn Pearce
2006-12-08 4:45 ` J. Bruce Fields
2006-12-08 5:59 ` Shawn Pearce
2006-12-08 6:08 ` J. Bruce Fields
2006-12-08 6:19 ` Shawn Pearce
2006-12-08 6:31 ` Junio C Hamano
2006-12-08 15:39 ` J. Bruce Fields
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20061207100152.GA12966@spearce.org \
--to=spearce@spearce.org \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).