git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tay Ray Chuan <rctay89@gmail.com>
To: "Git Mailing List" <git@vger.kernel.org>
Subject: [PATCH 3/3] builtin/checkout: DWIM with -f -b
Date: Mon, 21 Jun 2010 00:33:12 +0800	[thread overview]
Message-ID: <1277051592-4552-4-git-send-email-rctay89@gmail.com> (raw)
In-Reply-To: <1277051592-4552-3-git-send-email-rctay89@gmail.com>

Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
---
 Documentation/git-checkout.txt |    3 +++
 builtin/checkout.c             |    4 ++--
 t/t2018-checkout-branch.sh     |    6 +++---
 3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt
index 261dd90..d15d224 100644
--- a/Documentation/git-checkout.txt
+++ b/Documentation/git-checkout.txt
@@ -74,6 +74,9 @@ entries; instead, unmerged entries are ignored.
 -b::
 	Create a new branch named <new_branch> and start it at
 	<start_point>; see linkgit:git-branch[1] for details.
++
+When used with `-f`, the branch is reset; changes in the index or the
+working tree are thrown away too.
 
 -t::
 --track::
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 1994be9..962d938 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -511,7 +511,7 @@ static void update_refs_for_switch(struct checkout_opts *opts,
 			}
 		}
 		else
-			create_branch(old->name, opts->new_branch, new->name, 0,
+			create_branch(old->name, opts->new_branch, new->name, opts->force,
 				      opts->new_branch_log, opts->track);
 		new->name = opts->new_branch;
 		setup_branch_path(new);
@@ -858,7 +858,7 @@ no_reference:
 		if (strbuf_check_branch_ref(&buf, opts.new_branch))
 			die("git checkout: we do not like '%s' as a branch name.",
 			    opts.new_branch);
-		if (!get_sha1(buf.buf, rev))
+		if (!get_sha1(buf.buf, rev) && !opts.force)
 			die("git checkout: branch %s already exists", opts.new_branch);
 		strbuf_release(&buf);
 	}
diff --git a/t/t2018-checkout-branch.sh b/t/t2018-checkout-branch.sh
index e6c0f8c..9895ff5 100755
--- a/t/t2018-checkout-branch.sh
+++ b/t/t2018-checkout-branch.sh
@@ -63,19 +63,19 @@ test_expect_success 'checkout -b to an existing branch fails' '
 	test_must_fail do_checkout branch2 $HEAD2
 '
 
-test_expect_failure 'checkout -f -b to an existing branch resets branch' '
+test_expect_success 'checkout -f -b to an existing branch resets branch' '
 	git checkout branch1 &&
 
 	do_checkout branch2 "" -f
 '
 
-test_expect_failure 'checkout -f -b to an existing branch resets branch (explicit ref)' '
+test_expect_success 'checkout -f -b to an existing branch resets branch (explicit ref)' '
 	git checkout branch1 &&
 
 	do_checkout branch2 $HEAD1 -f
 '
 
-test_expect_failure 'checkout -f -b to an existing branch resets branch (dirty) ' '
+test_expect_success 'checkout -f -b to an existing branch resets branch (dirty) ' '
 	git checkout branch1 &&
 
 	setup_dirty &&
-- 
1.7.1.513.g4f18

  reply	other threads:[~2010-06-20 16:33 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-20 16:33 [PATCH 0/3] DWIM with "git checkout -f -b" Tay Ray Chuan
2010-06-20 16:33 ` [PATCH 1/3] add tests for checkout -b Tay Ray Chuan
2010-06-20 16:33   ` [PATCH 2/3] t2018-checkout-branch.sh: show that checkout -f -b doesn't DWIM Tay Ray Chuan
2010-06-20 16:33     ` Tay Ray Chuan [this message]
2010-06-20 19:12       ` [PATCH 3/3] builtin/checkout: DWIM with -f -b Junio C Hamano
2010-06-20 20:11         ` Jeff King
2010-06-20 21:07           ` Clemens Buchacher
2010-06-20 21:10           ` Junio C Hamano
2010-06-20 21:16             ` Jeff King
2010-06-21  0:09               ` Junio C Hamano
2010-06-21  1:08                 ` Tay Ray Chuan
2010-06-21  5:15                   ` Junio C Hamano
2010-06-21 17:19                     ` [PATCH 0/3] teach git-checkout -B WAS " Tay Ray Chuan
2010-06-21 17:19                       ` [PATCH 1/3] add tests for checkout -b Tay Ray Chuan
2010-06-21 17:19                         ` [PATCH 2/3] builtin/checkout: change -b from an OPTION_STRING to a OPTION_SET_INT Tay Ray Chuan
2010-06-21 17:19                           ` [PATCH 3/3] builtin/checkout: learn -B Tay Ray Chuan
2010-06-23 18:36                             ` Junio C Hamano
2010-06-23 19:13                               ` Tay Ray Chuan
2010-06-21 23:04                           ` [PATCH 2/3] builtin/checkout: change -b from an OPTION_STRING to a OPTION_SET_INT Erick Mattos
2010-06-23 19:04                             ` Tay Ray Chuan
2010-06-23 21:37                               ` Erick Mattos
2010-06-21 17:24                       ` [PATCH 0/3] teach git-checkout -B WAS builtin/checkout: DWIM with -f -b Tay Ray Chuan
2010-06-21 21:30                         ` Erick Mattos
2010-06-23 19:28                       ` [PATCH v2 " Tay Ray Chuan
2010-06-23 19:28                         ` [PATCH v2 1/3] add tests for checkout -b Tay Ray Chuan
2010-06-23 19:28                           ` [PATCH v2 2/3] builtin/checkout: reword hint for -b Tay Ray Chuan
2010-06-23 19:29                             ` [PATCH v2 3/3] builtin/checkout: learn -B Tay Ray Chuan
2010-06-21  2:58               ` [PATCH 3/3] builtin/checkout: DWIM with -f -b Michel Lespinasse
2010-06-21  4:09                 ` Michel Lespinasse

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=1277051592-4552-4-git-send-email-rctay89@gmail.com \
    --to=rctay89@gmail.com \
    --cc=git@vger.kernel.org \
    /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).