summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 58a05c7)
raw | patch | inline | side by side (parent: 58a05c7)
author | Junio C Hamano <gitster@pobox.com> | |
Mon, 12 Oct 2009 23:39:43 +0000 (16:39 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 12 Oct 2009 23:39:59 +0000 (16:39 -0700) |
Tolerating empty path components in ref names means each ref does
not have a unique name. This creates difficulty for porcelains
that want to see if two branches are equal. Add a helper associating
to each ref a canonical name.
If a user asks a porcelain to create a ref "refs/heads//master",
the porcelain can run "git check-ref-format --print refs/heads//master"
and only deal with "refs/heads/master" from then on.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
not have a unique name. This creates difficulty for porcelains
that want to see if two branches are equal. Add a helper associating
to each ref a canonical name.
If a user asks a porcelain to create a ref "refs/heads//master",
the porcelain can run "git check-ref-format --print refs/heads//master"
and only deal with "refs/heads/master" from then on.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-check-ref-format.txt | patch | blob | history | |
builtin-check-ref-format.c | patch | blob | history | |
t/t1402-check-ref-format.sh | patch | blob | history |
index 0b7982ea76633e45b8d3073cd275ea74a757c0eb..211ae1c3fadeb4436725a9cce80cd8583fd2a140 100644 (file)
--------
[verse]
'git check-ref-format' <refname>
+'git check-ref-format' --print <refname>
'git check-ref-format' [--branch] <branchname-shorthand>
DESCRIPTION
. at-open-brace `@{` is used as a notation to access a reflog entry.
+With the `--print` option, if 'refname' is acceptable, it prints the
+canonicalized name of a hypothetical reference with that name. That is,
+it prints 'refname' with any extra `/` characters removed.
+
With the `--branch` option, it expands a branch name shorthand and
prints the name of the branch the shorthand refers to.
-EXAMPLE
--------
-
-git check-ref-format --branch @{-1}::
-
-Print the name of the previous branch.
+EXAMPLES
+--------
+* Print the name of the previous branch:
++
+------------
+$ git check-ref-format --branch @{-1}
+------------
+
+* Determine the reference name to use for a new branch:
++
+------------
+$ ref=$(git check-ref-format --print "refs/heads/$newbranch") ||
+die "we do not like '$newbranch' as a branch name."
+------------
GIT
---
index f9381e07eaeda673e91ef6250eca4027c5ba0278..b97b61a0a4d957d6e2cb59eb314e49c06c8d70d8 100644 (file)
printf("%s\n", sb.buf + 11);
exit(0);
}
+ if (argc == 3 && !strcmp(argv[1], "--print")) {
+ char *refname = xmalloc(strlen(argv[2]) + 1);
+
+ if (check_ref_format(argv[2]))
+ exit(1);
+ if (normalize_path_copy(refname, argv[2]))
+ die("Could not normalize ref name '%s'", argv[2]);
+ printf("%s\n", refname);
+ exit(0);
+ }
if (argc != 2)
usage("git check-ref-format refname");
return !!check_ref_format(argv[1]);
index 382bc6e823516adcbc231e3075c731d59dd27b29..eb45afb018f6e3849204b44cce06ae1a4e2e29aa 100644 (file)
refname2=$(git check-ref-format --branch @{-2}) &&
test "$refname2" = master'
+valid_ref_normalized() {
+ test_expect_success "ref name '$1' simplifies to '$2'" "
+ refname=\$(git check-ref-format --print '$1') &&
+ test \"\$refname\" = '$2'"
+}
+invalid_ref_normalized() {
+ test_expect_success "check-ref-format --print rejects '$1'" "
+ test_must_fail git check-ref-format --print '$1'"
+}
+
+valid_ref_normalized 'heads/foo' 'heads/foo'
+valid_ref_normalized 'refs///heads/foo' 'refs/heads/foo'
+invalid_ref_normalized 'foo'
+invalid_ref_normalized 'heads/foo/../bar'
+invalid_ref_normalized 'heads/./foo'
+invalid_ref_normalized 'heads\foo'
+
test_done