Commit Diff


commit - 3190d68a817b96cbbd668a8a241ad3ba38e6c9b8
commit + d164438156e369fe982c409f32bc5568578de040
blob - 1da3e4d16811a6f59a07fba917970f48915013c5
blob + f1cf05099aba625e95492a9375bc08baa4bf08fc
--- got/got.c
+++ got/got.c
@@ -2071,6 +2071,14 @@ add_ref(struct got_repository *repo, const char *refna
 	const struct got_error *err = NULL;
 	struct got_object_id *id;
 	struct got_reference *ref = NULL;
+
+	/*
+	 * Don't let the user create a reference named '-'.
+	 * While technically a valid reference name, this case is usually
+	 * an unintended typo.
+	 */
+	if (refname[0] == '-' && refname[1] == '\0')
+		return got_error(GOT_ERR_BAD_REF_NAME);
 
 	err = got_repo_match_object_id_prefix(&id, target, GOT_OBJ_TYPE_ANY,
 	    repo);