]> git.proxmox.com Git - libgit2.git/commitdiff
Parse shorthand refspecs as valid
authorCarlos Martín Nieto <cmn@dwim.me>
Sun, 28 Apr 2013 12:16:45 +0000 (14:16 +0200)
committerCarlos Martín Nieto <cmn@dwim.me>
Sun, 28 Apr 2013 12:21:10 +0000 (14:21 +0200)
Relax the ONELEVEL ref naming rules so the refspec parsing code can
ask for 'master' to be considered valid.

include/git2/refs.h
src/refs.c
src/refspec.c
tests-clar/network/refspecs.c

index 1ff0d45447a49148ed5fcb8e386ab3204184f43b..e1d425352c37234391d7fa49e33ed343ae3f6a8f 100644 (file)
@@ -422,6 +422,13 @@ typedef enum {
         * (e.g., foo/<star>/bar but not foo/bar<star>).
         */
        GIT_REF_FORMAT_REFSPEC_PATTERN = (1 << 1),
+
+       /**
+        * Interpret the name as part of a refspec in shorthand form
+        * so the `ONELEVEL` naming rules aren't enforced and 'master'
+        * becomes a valid name.
+        */
+       GIT_REF_FORMAT_REFSPEC_SHORTHAND = (1 << 2),
 } git_reference_normalize_t;
 
 /**
index 9c6684a5a00933613f0c18c342098d633234ee83..2faa4cb835f758eadcffa6efc7661f751ebdb21e 100644 (file)
@@ -752,6 +752,7 @@ int git_reference__normalize_name(
                goto cleanup;
 
        if ((segments_count == 1 ) &&
+           !(flags & GIT_REF_FORMAT_REFSPEC_SHORTHAND) &&
                !(is_all_caps_and_underscore(name, (size_t)segment_len) ||
                        ((flags & GIT_REF_FORMAT_REFSPEC_PATTERN) && !strcmp("*", name))))
                        goto cleanup;
index fbdea9d93e8985224f7b786f15706a47edde198d..256540819e23e0fe6957566fa807e04bd48a6071 100644 (file)
@@ -60,7 +60,7 @@ int git_refspec__parse(git_refspec *refspec, const char *input, bool is_fetch)
 
        refspec->pattern = is_glob;
        refspec->src = git__strndup(lhs, llen);
-       flags = GIT_REF_FORMAT_ALLOW_ONELEVEL
+       flags = GIT_REF_FORMAT_ALLOW_ONELEVEL | GIT_REF_FORMAT_REFSPEC_SHORTHAND
                | (is_glob ? GIT_REF_FORMAT_REFSPEC_PATTERN : 0);
 
        if (is_fetch) {
index b3d80fb858b6cc991ec218a5471909dd14f0dc9d..676a1fa996a919bf4a96e0c53a645747e51707f5 100644 (file)
@@ -81,4 +81,7 @@ void test_network_refspecs__parsing(void)
 
        assert_refspec(GIT_DIRECTION_FETCH, "refs/heads/*/for-linus:refs/remotes/mine/*", true);
        assert_refspec(GIT_DIRECTION_PUSH, "refs/heads/*/for-linus:refs/remotes/mine/*", true);
+
+       assert_refspec(GIT_DIRECTION_FETCH, "master", true);
+       assert_refspec(GIT_DIRECTION_PUSH, "master", true);
 }