Commit d3f84d51c4443f621486b49558aa86b4e5c45a04

Stefan Sperling 2019-07-11T21:12:49

catch and prevent 'got branch -'; I've done this often enough now...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
diff --git a/got/got.c b/got/got.c
index 60dad83..b141b03 100644
--- a/got/got.c
+++ b/got/got.c
@@ -2285,6 +2285,14 @@ add_branch(struct got_repository *repo, const char *branch_name,
 	char *base_refname = NULL, *refname = NULL;
 	struct got_reference *base_ref;
 
+	/*
+	 * Don't let the user create a branch named '-'.
+	 * While technically a valid reference name, this case is usually
+	 * an unintended typo.
+	 */
+	if (branch_name[0] == '-' && branch_name[1] == '\0')
+		return got_error(GOT_ERR_BAD_REF_NAME);
+
 	if (strcmp(GOT_REF_HEAD, base_branch) == 0) {
 		base_refname = strdup(GOT_REF_HEAD);
 		if (base_refname == NULL)