From: Bart Trojanowski <bart@jukie.net>
To: Git Mailing List <git@vger.kernel.org>
Subject: [PATCH] prevent checkout from creating branches that start with a dash
Date: Wed, 2 Jul 2008 11:01:28 -0400 [thread overview]
Message-ID: <20080702150128.GH26300@jukie.net> (raw)
It was previously possible to create a -f branch with git-checkout, which
could not be used or deleted.
$ git checkout -b -f master
Switched to a new branch "-f"
Signed-off-by: Bart Trojanowski <bart@jukie.net>
---
branch.c | 11 +++++++++++
branch.h | 5 +++++
builtin-checkout.c | 4 ++++
3 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/branch.c b/branch.c
index 56e9492..c25e362 100644
--- a/branch.c
+++ b/branch.c
@@ -170,3 +170,14 @@ void remove_branch_state(void)
unlink(git_path("MERGE_MSG"));
unlink(git_path("SQUASH_MSG"));
}
+
+int validate_branch_name(const char *branch_name)
+{
+ if (!*branch_name)
+ return -1;
+
+ if (*branch_name == '-')
+ return -1;
+
+ return 0;
+}
diff --git a/branch.h b/branch.h
index 9f0c2a2..13999ba 100644
--- a/branch.h
+++ b/branch.h
@@ -21,4 +21,9 @@ void create_branch(const char *head, const char *name, const char *start_name,
*/
void remove_branch_state(void);
+/*
+ * Check if the branch name given is well formed. Returns 0 on success.
+ */
+int validate_branch_name(const char *branch_name);
+
#endif
diff --git a/builtin-checkout.c b/builtin-checkout.c
index 93ea69b..f425646 100644
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
@@ -553,6 +553,10 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
if (opts.force && opts.merge)
die("git checkout: -f and -m are incompatible");
+ if (opts.new_branch && validate_branch_name(opts.new_branch))
+ die("git checkout: '%s' does not look like a valid branch name",
+ opts.new_branch);
+
if (argc) {
const char **pathspec = get_pathspec(prefix, argv);
--
1.5.6.1.109.ga974cd.dirty
next reply other threads:[~2008-07-02 15:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-02 15:01 Bart Trojanowski [this message]
2008-07-02 15:22 ` [PATCH] prevent checkout from creating branches that start with a dash Brian Gernhardt
2008-07-02 15:38 ` Johannes Sixt
2008-07-02 16:34 ` Bart Trojanowski
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=20080702150128.GH26300@jukie.net \
--to=bart@jukie.net \
--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).