Commit e560b7e0e2efbbf43870b8d112d4279ca7df5535

Stefan Sperling 2019-11-28T04:59:19

prevent 'got import' from creating a branch called "-"

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 11985c8..ef77dfc 100644
--- a/got/got.c
+++ b/got/got.c
@@ -654,6 +654,14 @@ cmd_import(int argc, char *argv[])
 	if (error)
 		return error;
 
+	/*
+	 * 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_path(branch_name, GOT_ERR_BAD_REF_NAME);
+
 	if (asprintf(&refname, "refs/heads/%s", branch_name) == -1) {
 		error = got_error_from_errno("asprintf");
 		goto done;