diff: Fix rename pretty-print when suffix and prefix overlap
[gitweb.git] / builtin / check-ref-format.c
index 8707ee935a0ef8c6b6859c0f078c6d51b2269af2..0723cf245e52e6c0ab99cbe92c74010f9f7d7167 100644 (file)
@@ -12,8 +12,8 @@ static const char builtin_check_ref_format_usage[] =
 "   or: git check-ref-format --branch <branchname-shorthand>";
 
 /*
- * Replace each run of adjacent slashes in src with a single slash,
- * and write the result to dst.
+ * Remove leading slashes and replace each run of adjacent slashes in
+ * src with a single slash, and write the result to dst.
  *
  * This function is similar to normalize_path_copy(), but stripped down
  * to meet check_ref_format's simpler needs.
@@ -21,7 +21,7 @@ static const char builtin_check_ref_format_usage[] =
 static void collapse_slashes(char *dst, const char *src)
 {
        char ch;
-       char prev = '\0';
+       char prev = '/';
 
        while ((ch = *src++) != '\0') {
                if (prev == '/' && ch == prev)
@@ -36,7 +36,9 @@ static void collapse_slashes(char *dst, const char *src)
 static int check_ref_format_branch(const char *arg)
 {
        struct strbuf sb = STRBUF_INIT;
+       int nongit;
 
+       setup_git_directory_gently(&nongit);
        if (strbuf_check_branch_ref(&sb, arg))
                die("'%s' is not a valid branch name", arg);
        printf("%s\n", sb.buf + 11);