tag: make list exclude !<pattern>
Please see the following patch which filters the tag list of "!" prefaced patterns. If this is deemed desirable and correct, I'll resubmit with updated documentation and unit tests.
Thanks,
Tom Grennan (1):
tag: make list exclude !<pattern>
builtin/tag.c | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-)
Signature · 1 line
1.7.8
Use the "!" prefix to ignore tags of the given pattern. This has precedence over other matching patterns. For example,
$ git tag -l \!*-rc? v1.7.8* v1.7.8 v1.7.8.1 v1.7.8.2 v1.7.8.3 v1.7.8.4 $ git tag -l v1.7.8* \!*-rc? v1.7.8 v1.7.8.1 v1.7.8.2 v1.7.8.3 v1.7.8.4
This is equivalent to,
$ git tag -l v1.7.8* | grep -v '\-rc.' v1.7.8 v1.7.8.1 v1.7.8.2 v1.7.8.3 v1.7.8.4
--- builtin/tag.c | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-)
builtin/tag.c +9 -4
@@ -32,13 +32,18 @@ struct tag_filter {static int match_pattern (const char **patterns,const char *ref) { +int ret; +/* no pattern means match everything */ if (!*patterns)return 1 ; -for (; *patterns; patterns++) -if (!fnmatch (*patterns, ref,0 )) -return 1 ; -return 0 ; +for (ret =0 ; *patterns; patterns++) +if (**patterns =='!' ) { +if (!fnmatch (*patterns+1 , ref,0 )) +return 0 ; + }else if (!fnmatch (*patterns, ref,0 )) + ret =1 ; +return ret; }static int in_commit_list (const struct commit_list *want,struct commit *c)
Signature · 1 line
1.7.8
Quoted 3 lines · Tom Grennan
Use the "!" prefix to ignore tags of the given pattern. This has precedence over other matching patterns. For example,
...
Quoted 18 lines
static int
match_pattern(const char **patterns, const char *ref){(quoted diff) +2
-0+ int ret; +/* no pattern means match everything */ if (!*patterns) return 1;(quoted diff) +7
-4- for (; *patterns; patterns++) - if (!fnmatch(*patterns, ref, 0)) - return 1; - return 0; + for (ret = 0; *patterns; patterns++) + if (**patterns == '!') { + if (!fnmatch(*patterns+1, ref, 0)) + return 0; + } else if (!fnmatch(*patterns, ref, 0)) + ret = 1; + return ret;
Quoted 1 line
}
Correction, match_pattern() needs to be as follows to support all these cases,
$ git tag -l $ git tag -l \!*-rc? $ git tag -l \!*-rc? v1.7.8* $ git tag -l v1.7.8* \!*-rc? $ git tag -l v1.7.8*
Signature · 1 line
TomG
builtin/tag.c +9 -6
@@ -32,13 +32,16 @@ struct tag_filter {static int match_pattern (const char **patterns,const char *ref) { -/* no pattern means match everything */ -if (!*patterns) -return 1 ; +int had_match_pattern =0 , had_match =0 ; +for (; *patterns; patterns++) -if (!fnmatch (*patterns, ref,0 )) -return 1 ; -return 0 ; +if (**patterns !='!' ) { + had_match_pattern =1 ; +if (!fnmatch (*patterns, ref,0 )) + had_match =1 ; + }else if (!fnmatch (*patterns+1 , ref,0 )) +return 0 ; +return had_match_pattern ? had_match :1 ; }static int in_commit_list (const struct commit_list *want,struct commit *c)
Quoted 3 lines · Tom Grennan
Please see the following patch which filters the tag list of "!" prefaced patterns. If this is deemed desirable and correct, I'll resubmit with updated documentation and unit tests.
git-branch, git-tag and git-for-each-ref are in the same family. I think it's good to that all three commands share things, like this pattern matching.
About the '!' for exclusion, maybe it's better to move from fnmatch() as matching machinery to pathspec. Then when git learns negative pathspec [1], we have this feature for free.
[1] http://thread.gmane.org/gmane.comp.version-control.git/189645/focus=190072
Signature · 1 line
Duy
Quoted 8 lines · Nguyen Thai Ngoc Duy
Quoted 3 lines · Tom Grennan
Please see the following patch which filters the tag list of "!" prefaced patterns. If this is deemed desirable and correct, I'll resubmit with updated documentation and unit tests.
git-branch, git-tag and git-for-each-ref are in the same family. I think it's good to that all three commands share things, like this pattern matching.
Yes, git-branch and git-tag could now use a common match_patterns() but git-for-each-ref needs some rearranging; as will: git-describe, git-replace, git-ls-remote, git-name-rev, and git-show-branch.
If we pursue this, it may be best to first add match_patterns() to ./refs.[ch] then incrementally modify these builtin commands to use it.
Quoted 5 lines
About the '!' for exclusion, maybe it's better to move from
fnmatch()as matching machinery to pathspec. Then when git learns negative pathspec [1], we have this feature for free.[1] http://thread.gmane.org/gmane.comp.version-control.git/189645/focus=190072
I have to study this more. I'm not sure that --exclude has precedence over matches. It also looks like this would require a lot more change to the above.
Thanks,
TomG
Quoted 10 lines · Tom Grennan
Quoted 8 lines · Nguyen Thai Ngoc Duy
Quoted 3 lines · Tom Grennan
Please see the following patch which filters the tag list of "!" prefaced patterns. If this is deemed desirable and correct, I'll resubmit with updated documentation and unit tests.
git-branch, git-tag and git-for-each-ref are in the same family. I think it's good to that all three commands share things, like this pattern matching.
Quoted 6 lines
Yes, git-branch and git-tag could now use a common
match_patterns()but git-for-each-ref needs some rearranging; as will: git-describe, git-replace, git-ls-remote, git-name-rev, and git-show-branch.If we pursue this, it may be best to first add
match_patterns()to ./refs.[ch] then incrementally modify these builtin commands to use it.
The following series implements !<pattern> with: git-tag, git-branch, and git-for-each-ref.
This still requires Documentation and unit test updates but I think these are close to functionally complete.
Quoted 5 lines
Quoted 5 lines
About the '!' for exclusion, maybe it's better to move from
fnmatch()as matching machinery to pathspec. Then when git learns negative pathspec [1], we have this feature for free.[1] http://thread.gmane.org/gmane.comp.version-control.git/189645/focus=190072
After looking at this some more, I don't understand the value of replacing libc:fnmatch(). Or are you just referring to '--exclude' instead of [!]<pattern> argument parsing?
---
Tom Grennan (4):
refs: add common refname_match_patterns()
tag: use refs.c:refname_match_patterns()
branch: use refs.c:refname_match_patterns()
for-each-ref: use refs.c:refname_match_patterns()
Documentation/git-tag.txt | 10 ++++++---- builtin/branch.c | 16 ++-------------- builtin/for-each-ref.c | 23 +++-------------------- builtin/tag.c | 15 ++------------- refs.c | 14 ++++++++++++++ refs.h | 8 ++++++++ 6 files changed, 35 insertions(+), 51 deletions(-)
Signature · 1 line
1.7.8
PATCH v2 1/4 refs: add common refname_match_patterns()
--- refs.c | 14 ++++++++++++++ refs.h | 8 ++++++++ 2 files changed, 22 insertions(+), 0 deletions(-)
refs.c +14 -0
@@ -1057,6 +1057,20 @@ int refname_match(const char *abbrev_name, const char *full_name, const char **rreturn 0 ; } +int refname_match_patterns (const char **patterns,const char *refname) +{ +int given_match_pattern =0 , had_match =0 ; + +for (; *patterns; patterns++) +if (**patterns !='!' ) { + given_match_pattern =1 ; +if (!fnmatch (*patterns, refname,0 )) + had_match =1 ; + }else if (!fnmatch (*patterns+1 , refname,0 )) +return 0 ; +return given_match_pattern ? had_match :1 ; +} +static struct ref_lock *verify_lock (struct ref_lock *lock,const unsigned char *old_sha1,int mustexist) {
refs.h +8 -0
@@ -152,4 +152,12 @@ int update_ref(const char *action, const char *refname, const unsigned char *sha1, const unsigned char *oldval, int flags, enum action_on_err onerr); +/** +* Returns: +* 1 with NULL patterns +* 0 if refname fnmatch()es any ! prefaced pattern +* 1 if refname fnmatch()es any pattern +*/ +extern int refname_match_patterns (const char **patterns,const char *refname); +#endif /* REFS_H */
Signature · 1 line
1.7.8
Re: [PATCHv2 1/4] refs: add common refname_match_patterns()
Quoted 7 lines · Tom Grennan
refs.h +0
-0@@ -152,4 +152,12 @@ int update_ref(const char *action, const char *refname, const unsigned char *sha1, const unsigned char *oldval, int flags, enum action_on_err onerr);
refs.h int update_ref(const char *action, const char *refname, · line 163
Quoted 10 lines
refs.h +8
-0+/** +* Returns: +* 1 with NULL patterns +* 0 if refname fnmatch()es any ! prefaced pattern +* 1 if refname fnmatch()es any pattern +*/ +extern int refname_match_patterns (const char **patterns,const char *refname); +#endif /* REFS_H */
This comment is unclear and incomplete.
1. What does "NULL patterns" mean? Your code fails if patterns==NULL, so I guess you mean "1 if there are no patterns in the list".
2. Since the three conditions are not mutually exclusive, you should say how they are connected. I believe that you want something like "A otherwise B otherwise C".
3. You haven't specified what happens if refname matches neither a !-prefixed pattern nor a non-!-prefixed pattern. Does this behavior depend on which types of patterns were present in the list?
I see that you have described the behavior more completely in the commit message for patch 2/4, but the commit message is not enough: this behavior should be described precisely in both code comments (when the function is defined) and in the user documentation (when the functionality is added to a command).
Michael
Signature · 3 lines
Michael Haggerty [email protected] http://softwareswirl.blogspot.com/
Re: [PATCHv2 1/4] refs: add common refname_match_patterns()
Quoted 32 lines · Michael Haggerty
Quoted 7 lines · Tom Grennan
refs.h +0
-0@@ -152,4 +152,12 @@ int update_ref(const char *action, const char *refname, const unsigned char *sha1, const unsigned char *oldval, int flags, enum action_on_err onerr);refs.h int update_ref(const char *action, const char *refname, · line 163
Quoted 10 lines
refs.h +8
-0+/** +* Returns: +* 1 with NULL patterns +* 0 if refname fnmatch()es any ! prefaced pattern +* 1 if refname fnmatch()es any pattern +*/ +extern int refname_match_patterns (const char **patterns,const char *refname); +#endif /* REFS_H */ This comment is unclear and incomplete.
1. What does "NULL patterns" mean? Your code fails if patterns==NULL, so I guess you mean "1 if there are no patterns in the list".
2. Since the three conditions are not mutually exclusive, you should say how they are connected. I believe that you want something like "A otherwise B otherwise C".
3. You haven't specified what happens if refname matches neither a !-prefixed pattern nor a non-!-prefixed pattern. Does this behavior depend on which types of patterns were present in the list?
Quoted 5 lines
I see that you have described the behavior more completely in the commit message for patch 2/4, but the commit message is not enough: this behavior should be described precisely in both code comments (when the function is defined) and in the user documentation (when the functionality is added to a command).
Yes, I didn't explicitly state that the precedence is the order written and in correctly described the first case. How about?
/**
* Returns in highest to lowest precedence:
* 1 with an empty patterns list * 0 if refname fnmatch()es any ^ prefaced pattern * 1 if refname fnmatch()es any other pattern * 0 otherwise
*/
Thanks,
TomG
Re: [PATCHv2 1/4] refs: add common refname_match_patterns()
Quoted 10 lines · Tom Grennan
Yes, I didn't explicitly state that the precedence is the order written and in correctly described the first case. How about?
/**
* Returns in highest to lowest precedence:* 1 with an empty patterns list * 0 if refname fnmatch()es any ^ prefaced pattern * 1 if refname fnmatch()es any other pattern * 0 otherwise*/
Much better; thanks.
Please note that this choice of semantics limits its power. For example, if the rule were instead (like with gitattributes(5)) "if more than one pattern matches a refname, a later pattern overrides an earlier pattern", then one could do things like
refs/remotes/*/* !refs/remotes/gitster/* refs/remotes/gitster/master
to include specific references within a hierarchy that is otherwise excluded.
However, since rev-list apparently uses a rule more like the one that you are proposing, it might be better to be consistent than to choose a different convention.
Michael
Signature · 3 lines
Michael Haggerty [email protected] http://softwareswirl.blogspot.com/
Re: [PATCHv2 1/4] refs: add common refname_match_patterns()
Quoted 19 lines · Michael Haggerty
Quoted 10 lines · Tom Grennan
Yes, I didn't explicitly state that the precedence is the order written and in correctly described the first case. How about?
/**
* Returns in highest to lowest precedence:* 1 with an empty patterns list * 0 if refname fnmatch()es any ^ prefaced pattern * 1 if refname fnmatch()es any other pattern * 0 otherwise*/
Much better; thanks.
Please note that this choice of semantics limits its power. For example, if the rule were instead (like with gitattributes(5)) "if more than one pattern matches a refname, a later pattern overrides an earlier pattern", then one could do things like
Quoted 8 lines
refs/remotes/*/* !refs/remotes/gitster/* refs/remotes/gitster/master
to include specific references within a hierarchy that is otherwise excluded.
However, since rev-list apparently uses a rule more like the one that you are proposing, it might be better to be consistent than to choose a different convention.
Hmm, I think it's important to have same respective result in each of these case's,
$ git tag -l | grep v1.7.8.* $ git tag -l v1.7.8*
$ git tag -l | grep -v .*-rc* $ git tag -l ^*-rc*
$ git tag -l v1.7.8* | grep -v .*-rc* $ git tag -l v1.7.8* ^*-rc* $ git tag -l ^*-rc* v1.7.8*
What I propose is somewhat analogous to gitignore's double negative,
* An optional prefix ! which negates the pattern; any matching
file excluded by a previous pattern will become included again. If a negated pattern matches, this will override lower precedence patterns sources.
I still prefer "^" to "!" b/c A) it doesn't cause the noted regressions; and B) doesn't need command quoting. I'd accept the counter proposals of --exclude or --with[out][-TYPE] but frankly, that's more code/documentation churn ("less code is always better"[TM]) and worse, more crap to type on the command line:
$ git --with-tags v1.7.8* --without-tags '*-rc*' tag -l v1.7.8* or $ git tag -l --exclude '*-rc*' v1.7.8* vs. $ git tag -l v1.7.8* ^*-rc*
Signature · 1 line
TomG
Re: [PATCHv2 1/4] refs: add common refname_match_patterns()
In reply to Tom Grennanrefs.c int refname_match(const char *abbrev_name, const char *full_name, const char **r · line 1072
Quoted 13 lines · Tom Grennan
refs.c +13
-0+int refname_match_patterns (const char **patterns,const char *refname) +{ +int given_match_pattern =0 , had_match =0 ; + +for (; *patterns; patterns++) +if (**patterns !='!' ) { + given_match_pattern =1 ; +if (!fnmatch (*patterns, refname,0 )) + had_match =1 ; + }else if (!fnmatch (*patterns+1 , refname,0 )) +return 0 ; +return given_match_pattern ? had_match :1 ; +}
This, while its semantics seem sane, is highly inefficient when you have many patterns, and you will be calling this to filter dozens of refs. And it can trivially improved by first pre-parsing the pattern[] array.
* If you know the patterns do not have any negative entry, you can return true upon seeing the first match. Because you do not pre-parse the pattern[] array, this loop does not know if there is any negative one, and has to scan it always all the way.
* If you arrange the pattern[] array so that it has negative ones early, again, you can return false upon seeing the first hit with a negative one. If your input has negative ones at the end, the loop ends up scanning all the way, noting the positive matches, only to discard upon seeing the negative match at the end.
That is why I said Nguyen's idea of reusing pathspec matching logic somewhat attractive, even though I think it has downsides (the exact matching logic for pathspec is more similar to that of for-each-ref and very different from branch/tag).
Re: [PATCHv2 1/4] refs: add common refname_match_patterns()
Quoted 31 lines · Junio C Hamano
refs.c int refname_match(const char *abbrev_name, const char *full_name, const char **r · line 1072
Quoted 13 lines · Tom Grennan
refs.c +13
-0+int refname_match_patterns (const char **patterns,const char *refname) +{ +int given_match_pattern =0 , had_match =0 ; + +for (; *patterns; patterns++) +if (**patterns !='!' ) { + given_match_pattern =1 ; +if (!fnmatch (*patterns, refname,0 )) + had_match =1 ; + }else if (!fnmatch (*patterns+1 , refname,0 )) +return 0 ; +return given_match_pattern ? had_match :1 ; +}This, while its semantics seem sane, is highly inefficient when you have many patterns, and you will be calling this to filter dozens of refs. And it can trivially improved by first pre-parsing the pattern[] array.
* If you know the patterns do not have any negative entry, you can return true upon seeing the first match. Because you do not pre-parse the pattern[] array, this loop does not know if there is any negative one, and has to scan it always all the way.
* If you arrange the pattern[] array so that it has negative ones early, again, you can return false upon seeing the first hit with a negative one. If your input has negative ones at the end, the loop ends up scanning all the way, noting the positive matches, only to discard upon seeing the negative match at the end.
Quoted 4 lines
That is why I said Nguyen's idea of reusing pathspec matching logic somewhat attractive, even though I think it has downsides (the exact matching logic for pathspec is more similar to that of for-each-ref and very different from branch/tag).
Yes, I should have stated that this emphasized containment over efficiency. If instead we stipulate that the caller must list exclusion patterns before others, this could simply be:
int match_pattern(const char **patterns, const char *refname)
{
if (*patterns)
return 1;
for (; *patterns && **patterns == '!'; patterns++)
if (!fnmatch(*patterns+1, refname, 0))
return 0;
for (; *patterns; patterns++)
if (!fnmatch(*patterns, refname, 0))
return 1;
return 0;
}Of course I'd add a with_exclusions_first() before the respective ref iterator.
Signature · 1 line
TomG
Re: [PATCHv2 1/4] refs: add common refname_match_patterns()
Quoted 3 lines · Tom Grennan
Yes, I should have stated that this emphasized containment over efficiency. If instead we stipulate that the caller must list exclusion patterns before others, this could simply be:
No.
You have to pre-parse and rearrange the pattern[] list *only once* before matching them against dozens of refs, so instead of forcing the callers do anything funky, you give a function that gets a pattern[] list and returns something that can be efficiently used by the match_pattern() function, and have the caller pass that thing, not the original pattern[] list, to the match_pattern() function.
That is how pathspec matching side of the logic is arranged.
I keep saying that it is probably not a good idea to directly reuse the pathspec code, but you would want to study and learn from the overall structure of it.
Re: [PATCHv2 1/4] refs: add common refname_match_patterns()
Quoted 6 lines · Junio C Hamano
Quoted 3 lines · Tom Grennan
Yes, I should have stated that this emphasized containment over efficiency. If instead we stipulate that the caller must list exclusion patterns before others, this could simply be:
Quoted 8 lines
No.
You have to pre-parse and rearrange the pattern[] list *only once* before matching them against dozens of refs, so instead of forcing the callers do anything funky, you give a function that gets a pattern[] list and returns something that can be efficiently used by the
match_pattern()function, and have the caller pass that thing, not the original pattern[] list, to thematch_pattern()function.
Hmm, I'm not communicating very well; this is exactly what I meant by,
Quoted 2 lines
Quoted 2 lines
Of course I'd add a
with_exclusions_first()before the respective ref iterator.
Signature · 1 line
TomG
Quoted 31 lines · Junio C Hamano
refs.c int refname_match(const char *abbrev_name, const char *full_name, const char **r · line 1072
Quoted 13 lines · Tom Grennan
refs.c +13
-0+int refname_match_patterns (const char **patterns,const char *refname) +{ +int given_match_pattern =0 , had_match =0 ; + +for (; *patterns; patterns++) +if (**patterns !='!' ) { + given_match_pattern =1 ; +if (!fnmatch (*patterns, refname,0 )) + had_match =1 ; + }else if (!fnmatch (*patterns+1 , refname,0 )) +return 0 ; +return given_match_pattern ? had_match :1 ; +}This, while its semantics seem sane, is highly inefficient when you have many patterns, and you will be calling this to filter dozens of refs. And it can trivially improved by first pre-parsing the pattern[] array.
* If you know the patterns do not have any negative entry, you can return true upon seeing the first match. Because you do not pre-parse the pattern[] array, this loop does not know if there is any negative one, and has to scan it always all the way.
* If you arrange the pattern[] array so that it has negative ones early, again, you can return false upon seeing the first hit with a negative one. If your input has negative ones at the end, the loop ends up scanning all the way, noting the positive matches, only to discard upon seeing the negative match at the end.
Quoted 4 lines
That is why I said Nguyen's idea of reusing pathspec matching logic somewhat attractive, even though I think it has downsides (the exact matching logic for pathspec is more similar to that of for-each-ref and very different from branch/tag).
Yes, I should have stated that this emphasized containment over efficiency. If instead we stipulate that the caller must list exclusion patterns before others, this could simply be:
int match_pattern(const char **patterns, const char *refname)
{
if (*patterns)
return 1;
for (; *patterns && **patterns == '!'; patterns++)
if (!fnmatch(*patterns+1, refname, 0))
return 0;
for (; *patterns; patterns++)
if (!fnmatch(*patterns, refname, 0))
return 1;
return 0;
}Of course I'd add a with_exclusions_first() before the respective ref iterator.
Signature · 1 line
TomG
PATCH v2 2/4 tag: use refs.c:refname_match_patterns()
In reply to Tom GrennanThis will exclude tags matching patterns prefaced with the '!' character. This has precedence over other matching patterns. For example,
$ git tag -l \!*-rc? v1.7.8* v1.7.8 v1.7.8.1 v1.7.8.2 v1.7.8.3 v1.7.8.4 $ git tag -l v1.7.8* \!*-rc? v1.7.8 v1.7.8.1 v1.7.8.2 v1.7.8.3 v1.7.8.4
This is equivalent to,
$ git tag -l v1.7.8* | grep -v '\-rc.'
Without a matching pattern, filter all tags with the "!" patterns,
$ ./git-tag -l \!*-rc? gitgui-0.10.0 gitgui-0.10.1 gitgui-0.10.2 ... v1.7.8.3 v1.7.8.4 v1.7.9
That is equivalent to,
$ git tag -l | grep -v '\-rc.'
--- Documentation/git-tag.txt | 10 ++++++---- builtin/tag.c | 15 ++------------- 2 files changed, 8 insertions(+), 17 deletions(-)
Documentation/git-tag.txt +6 -4
@@ -12,7 +12,7 @@ SYNOPSIS 'git tag' [-a | -s | -u <key-id>] [-f] [-m <msg> | -F <file>] <tagname> [<commit> | <object>] 'git tag' -d <tagname>... -'git tag' [-n[<num>]] -l [--contains <commit>] [<pattern>...] +'git tag' [-n[<num>]] -l [--contains <commit>] [[!]<pattern>...] 'git tag' -v <tagname>... DESCRIPTION
@@ -75,13 +75,15 @@ OPTIONS If no number is given to `-n`, only the first line is printed. If the tag is not annotated, the commit message is displayed instead. --l <pattern>:: ---list <pattern>:: +-l [!]<pattern>:: +--list [!]<pattern>:: List tags with names that match the given pattern (or all if no pattern is given). Running "git tag" without arguments also lists all tags. The pattern is a shell wildcard (i.e., matched using fnmatch(3)). Multiple patterns may be given; if any of - them matches, the tag is shown. + them matches, the tag is shown. If the pattern is prefaced with + the '!' character, all tags matching the pattern are filtered + from the list. --contains <commit>:: Only list tags which contain the specified commit.
builtin/tag.c +2 -13
@@ -19,7 +19,7 @@static const char *const git_tag_usage[] = {"git tag [-a|-s|-u <key-id>] [-f] [-m <msg>|-F <file>] <tagname> [<head>]" ,"git tag -d <tagname>..." , -"git tag -l [-n[<num>]] [<pattern>...]" , +"git tag -l [-n[<num>]] [[!]<pattern>...]" ,"git tag -v <tagname>..." ,NULL };
@@ -30,17 +30,6 @@ struct tag_filter {struct commit_list *with_commit; }; -static int match_pattern (const char **patterns,const char *ref) -{ -/* no pattern means match everything */ -if (!*patterns) -return 1 ; -for (; *patterns; patterns++) -if (!fnmatch (*patterns, ref,0 )) -return 1 ; -return 0 ; -} -static int in_commit_list (const struct commit_list *want,struct commit *c) {for (; want; want = want->next)
@@ -88,7 +77,7 @@ static int show_reference(const char *refname, const unsigned char *sha1, {struct tag_filter *filter = cb_data; -if (match_pattern (filter->patterns, refname)) { +if (refname_match_patterns (filter->patterns, refname)) {int i;unsigned long size;enum object_type type;
Signature · 1 line
1.7.8
PATCH v2 3/4 branch: use refs.c:refname_match_patterns()
In reply to Tom Grennan--- builtin/branch.c | 16 ++-------------- 1 files changed, 2 insertions(+), 14 deletions(-)
builtin/branch.c +2 -14
@@ -266,18 +266,6 @@ struct append_ref_cb {int ret; }; -static int match_patterns (const char **pattern,const char *refname) -{ -if (!*pattern) -return 1 ;/* no pattern always matches */ -while (*pattern) { -if (!fnmatch (*pattern, refname,0 )) -return 1 ; - pattern++; - } -return 0 ; -} -static int append_ref (const char *refname,const unsigned char *sha1,int flags,void *cb_data) {struct append_ref_cb *cb = (struct append_ref_cb *)(cb_data);
@@ -312,7 +300,7 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,if ((kind & ref_list->kinds) ==0 )return 0 ; -if (!match_patterns (cb->pattern, refname)) +if (!refname_match_patterns (cb->pattern, refname))return 0 ; commit =NULL ;
@@ -542,7 +530,7 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, struqsort (ref_list.list, ref_list.index,sizeof (struct ref_item ), ref_cmp); detached = (detached && (kinds &REF_LOCAL_BRANCH )); -if (detached &&match_patterns (pattern,"HEAD" )) +if (detached &&refname_match_patterns (pattern,"HEAD" ))show_detached (&ref_list);for (i =0 ; i < ref_list.index; i++) {
Signature · 1 line
1.7.8
PATCH v2 4/4 for-each-ref: use refs.c:refname_match_patterns()
In reply to Tom Grennan--- builtin/for-each-ref.c | 23 +++-------------------- 1 files changed, 3 insertions(+), 20 deletions(-)
builtin/for-each-ref.c +3 -20
@@ -781,25 +781,8 @@ static int grab_single_ref(const char *refname, const unsigned char *sha1, int fstruct refinfo *ref;int cnt; -if (*cb->grab_pattern) { -const char **pattern; -int namelen =strlen (refname); -for (pattern = cb->grab_pattern; *pattern; pattern++) { -const char *p = *pattern; -int plen =strlen (p); - -if ((plen <= namelen) && - !strncmp (refname, p, plen) && - (refname[plen] =='\0' || - refname[plen] =='/' || - p[plen-1 ] =='/' )) -break ; -if (!fnmatch (p, refname,FNM_PATHNAME )) -break ; - } -if (!*pattern) -return 0 ; - } +if (!refname_match_patterns (cb->grab_pattern, refname)) +return 0 ;/* * We do not open the object yet; sort may only need refname
@@ -974,7 +957,7 @@ static int opt_parse_sort(const struct option *opt, const char *arg, int unset) }static char const *const for_each_ref_usage[] = { -"git for-each-ref [options] [<pattern>]" , +"git for-each-ref [options] [[!]<pattern>...]" ,NULL };
Signature · 1 line
1.7.8
Quoted 13 lines · Tom Grennan
Quoted 2 lines
If we pursue this, it may be best to first add
match_patterns()to ./refs.[ch] then incrementally modify these builtin commands to use it.The following series implements !<pattern> with: git-tag, git-branch, and git-for-each-ref.
This still requires Documentation and unit test updates but I think these are close to functionally complete.
Quoted 4 lines
Quoted 4 lines
About the '!' for exclusion, maybe it's better to move from
fnmatch()as matching machinery to pathspec. Then when git learns negative pathspec [1], we have this feature for free.
Quoted 5 lines
Quoted 1 line
After looking at this some more, I don't understand the value of replacing libc:fnmatch(). Or are you just referring to '--exclude' instead of [!]<pattern> argument parsing?
I have not formed a firm opinion on Nguyen's idea to reuse pathspec matching infrastructure for this purpose, so I wouldn't comment on that part. It certainly looks attractive, as it allows users to learn one and only one extended matching syntax, but at the same time, it has a risk to mislead people to think that the namespace for refs is similar to that of the filesystem paths, which I see as a mild downside.
In any case, I do not like the structure of this series. If it followed our usual pattern, it would consist of patches in this order:
- Patch 1 would extract match_pattern() from builtin/tag.c and introduce the new helper function refname_match_patterns() to refs.c. It updates the call sites of match_pattern() in builtin/tag.c, match_patterns() in builtin/branch.c, and the implementation of grab_single_ref() in builtin/for-each-ref.c with a call to the new helper function.
This step can and probably should be done as three sub-steps. 1a would move builtin/tag.c::match_pattern() to refs.::refname_match_patterns(), 1b would use the new helper in builtin/branch.c and 1c would do the same for builtin/for-each-ref.c.
It is important that this patch does so without introducing any new functionality to the new function over the old one. When done this way, there is no risk of introducing new bugs at 1a because it is purely a code movement and renaming; 1b could introduce a bug that changes semantics for bulitin/branch.c if its match_patterns() does things differently from match_pattern() lifted from builtin/tag.c, and if it is found out to be buggy, we can discard 1b without discarding 1a. Same for 1c, which I highly suspect will introduce regression without looking at the code (for-each-ref is prefix-match only), that can safely be discarded.
This is to make it easier to ensure that the update does not introduce new bugs.
- Patch 2 would then add the new functionality to the new helper. It would also adjust the documentation of the three end user facing commands to describe the fallout coming from this change, and adds new tests to make sure future changes will not break this new functionality.
That is, first refactor and clean-up without adding anything new, and then build new stuff on solidified ground.
Do we allow a refname whose pathname component begins with '!', by the way? If we do, how does a user look for a tag whose name is "!xyzzy"? "Naming your tag !xyzzy used to be allowed but it is now forbidden after this patch" is not an acceptable answer---it is called a regression. If the negation operator were "^" or something that we explicitly forbid from a refname, we wouldn't have such a problem.
Quoted 56 lines · Junio C Hamano
Quoted 13 lines · Tom Grennan
Quoted 2 lines
If we pursue this, it may be best to first add
match_patterns()to ./refs.[ch] then incrementally modify these builtin commands to use it.The following series implements !<pattern> with: git-tag, git-branch, and git-for-each-ref.
This still requires Documentation and unit test updates but I think these are close to functionally complete.
Quoted 4 lines
Quoted 4 lines
About the '!' for exclusion, maybe it's better to move from
fnmatch()as matching machinery to pathspec. Then when git learns negative pathspec [1], we have this feature for free.Quoted 5 lines
Quoted 1 line
After looking at this some more, I don't understand the value of replacing libc:fnmatch(). Or are you just referring to '--exclude' instead of [!]<pattern> argument parsing?
I have not formed a firm opinion on Nguyen's idea to reuse pathspec matching infrastructure for this purpose, so I wouldn't comment on that part. It certainly looks attractive, as it allows users to learn one and only one extended matching syntax, but at the same time, it has a risk to mislead people to think that the namespace for refs is similar to that of the filesystem paths, which I see as a mild downside.
In any case, I do not like the structure of this series. If it followed our usual pattern, it would consist of patches in this order:
- Patch 1 would extract
match_pattern()frombuiltin/tag.cand introduce the new helper functionrefname_match_patterns()torefs.c. It updates the call sites ofmatch_pattern()inbuiltin/tag.c,match_patterns()inbuiltin/branch.c, and the implementation ofgrab_single_ref()inbuiltin/for-each-ref.cwith a call to the new helper function.This step can and probably should be done as three sub-steps. 1a would move builtin/tag.c::match_pattern() to refs.::refname_match_patterns(), 1b would use the new helper in
builtin/branch.cand 1c would do the same forbuiltin/for-each-ref.c.It is important that this patch does so without introducing any new functionality to the new function over the old one. When done this way, there is no risk of introducing new bugs at 1a because it is purely a code movement and renaming; 1b could introduce a bug that changes semantics for
bulitin/branch.cif itsmatch_patterns()does things differently frommatch_pattern()lifted frombuiltin/tag.c, and if it is found out to be buggy, we can discard 1b without discarding 1a. Same for 1c, which I highly suspect will introduce regression without looking at the code (for-each-ref is prefix-match only), that can safely be discarded.This is to make it easier to ensure that the update does not introduce new bugs.
Quoted 8 lines
- Patch 2 would then add the new functionality to the new helper. It would also adjust the documentation of the three end user facing commands to describe the fallout coming from this change, and adds new tests to make sure future changes will not break this new functionality.
That is, first refactor and clean-up without adding anything new, and then build new stuff on solidified ground.
Nuts! I have the cart before the horse. I'll try to rearrange the series as suggested by tomorrow. Thanks.
Quoted 6 lines
Do we allow a refname whose pathname component begins with '!', by the way? If we do, how does a user look for a tag whose name is "!xyzzy"? "Naming your tag !xyzzy used to be allowed but it is now forbidden after this patch" is not an acceptable answer---it is called a regression. If the negation operator were "^" or something that we explicitly forbid from a refname, we wouldn't have such a problem.
Cool, as I recall, v7 or earlier /bin/sh also used "^" to preface exclusion patterns. Another option is the bash extglob syntax of !(pattern) although I'd prefer "^" b/c one wouldn't have to quote it with bash:
$ git branch --list ^pu
Signature · 1 line
TomG
It has taken me a while to get back to this; the following series rebase and rework my proposed "!<pattern>" feature. The first patch extracts match_pattern() from builtin/tag.c and updates this to replace similar functions in builtin/{branch,for-each-ref,ls-remote}.c
The second patch uses the OPT_CALLBACK wrapper on the recently added "--points-at" option of git-tag. I should have implemented it this way to begin with but I missed Jeff King's suggestion within that thread.
The remaining patches add "--exclude <pattern>" options (vs. "!<pattern>") to: git-tag, git-branch, and git-for-each-ref.
For example,
$ git tag -l --exclude "*-rc?" "v1.7.8*" $ git branch -r --exclude \*HEAD $ git for-each-ref --format="%(refname)" --exclude "*HEAD" refs/remotes/origin
Instead of,
$ git tag -l "!*-rc?" "v1.7.8*" $ git branch -r "!*HEAD" $ git for-each-ref --format="%(refname)" "!*HEAD" refs/remotes/origin
Note that I haven't yet added an "--exclude" feature to git-ls-remote because I think that I should first update its option parsing.
Thanks,
Tom Grennan (5):
refs: add match_pattern()
tag --points-at option wrapper
tag --exclude option
branch --exclude option
for-each-ref --exclude option
Documentation/git-branch.txt | 7 ++++- Documentation/git-for-each-ref.txt | 7 ++++- Documentation/git-tag.txt | 6 +++- builtin/branch.c | 30 ++++++++----------- builtin/for-each-ref.c | 27 +++++------------ builtin/ls-remote.c | 12 ++------ builtin/tag.c | 35 ++++++++++------------ refs.c | 36 +++++++++++++++++++++++ refs.h | 12 ++++++++ t/t3200-branch.sh | 23 +++++++++++++++ t/t6300-for-each-ref.sh | 11 +++++++ t/t7004-tag.sh | 56 ++++++++++++++++++++++++++++++++++++ 12 files changed, 195 insertions(+), 67 deletions(-)
Signature · 1 line
1.7.8
PATCH v3 1/5 refs: add match_pattern()
Used-by: git-branch, git-for-each-ref, git-ls-remote, and git-tag
--- builtin/branch.c | 16 ++-------------- builtin/for-each-ref.c | 21 ++------------------- builtin/ls-remote.c | 12 +++--------- builtin/tag.c | 13 +------------ refs.c | 36 ++++++++++++++++++++++++++++++++++++ refs.h | 12 ++++++++++++ 6 files changed, 56 insertions(+), 54 deletions(-)
builtin/branch.c +2 -14
@@ -266,18 +266,6 @@ struct append_ref_cb {int ret; }; -static int match_patterns (const char **pattern,const char *refname) -{ -if (!*pattern) -return 1 ;/* no pattern always matches */ -while (*pattern) { -if (!fnmatch (*pattern, refname,0 )) -return 1 ; - pattern++; - } -return 0 ; -} -static int append_ref (const char *refname,const unsigned char *sha1,int flags,void *cb_data) {struct append_ref_cb *cb = (struct append_ref_cb *)(cb_data);
@@ -312,7 +300,7 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,if ((kind & ref_list->kinds) ==0 )return 0 ; -if (!match_patterns (cb->pattern, refname)) +if (!match_pattern (refname, cb->pattern,NULL ,0 ))return 0 ; commit =NULL ;
@@ -542,7 +530,7 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, struqsort (ref_list.list, ref_list.index,sizeof (struct ref_item ), ref_cmp); detached = (detached && (kinds &REF_LOCAL_BRANCH )); -if (detached &&match_patterns (pattern,"HEAD" )) +if (detached &&match_pattern ("HEAD" , pattern,NULL ,0 ))show_detached (&ref_list);for (i =0 ; i < ref_list.index; i++) {
builtin/for-each-ref.c +2 -19
@@ -781,25 +781,8 @@ static int grab_single_ref(const char *refname, const unsigned char *sha1, int fstruct refinfo *ref;int cnt; -if (*cb->grab_pattern) { -const char **pattern; -int namelen =strlen (refname); -for (pattern = cb->grab_pattern; *pattern; pattern++) { -const char *p = *pattern; -int plen =strlen (p); - -if ((plen <= namelen) && - !strncmp (refname, p, plen) && - (refname[plen] =='\0' || - refname[plen] =='/' || - p[plen-1 ] =='/' )) -break ; -if (!fnmatch (p, refname,FNM_PATHNAME )) -break ; - } -if (!*pattern) -return 0 ; - } +if (!match_pattern (refname, cb->grab_pattern,NULL ,FNM_PATHNAME )) +return 0 ;/* * We do not open the object yet; sort may only need refname
builtin/ls-remote.c +3 -9
@@ -2,6 +2,7 @@#include "cache.h" #include "transport.h" #include "remote.h" +#include "refs.h" static const char ls_remote_usage[] ="git ls-remote [--heads] [--tags] [-u <exec> | --upload-pack <exec>]\n"
@@ -13,19 +14,12 @@ static const char ls_remote_usage[] =*/ static int tail_match (const char **pattern,const char *path) { -const char *p;char pathbuf[PATH_MAX ]; -if (!pattern) -return 1 ;/* no restriction */ -if (snprintf (pathbuf,sizeof (pathbuf),"/%s" , path) >sizeof (pathbuf))return error ("insanely long ref %.*s..." ,20 , path); -while ((p = *(pattern++)) !=NULL ) { -if (!fnmatch (p, pathbuf,0 )) -return 1 ; - } -return 0 ; + +return match_pattern (pathbuf, pattern,NULL ,0 ); }int cmd_ls_remote (int argc,const char **argv,const char *prefix)
builtin/tag.c +1 -12
@@ -34,17 +34,6 @@ struct tag_filter {static struct sha1_array points_at; -static int match_pattern (const char **patterns,const char *ref) -{ -/* no pattern means match everything */ -if (!*patterns) -return 1 ; -for (; *patterns; patterns++) -if (!fnmatch (*patterns, ref,0 )) -return 1 ; -return 0 ; -} -static const unsigned char *match_points_at (const char *refname,const unsigned char *sha1) {
@@ -149,7 +138,7 @@ static int show_reference(const char *refname, const unsigned char *sha1, {struct tag_filter *filter = cb_data; -if (match_pattern (filter->patterns, refname)) { +if (match_pattern (refname, filter->patterns,NULL ,0 )) {if (filter->with_commit) {struct commit *commit;
refs.c +36 -0
@@ -3,6 +3,7 @@#include "object.h" #include "tag.h" #include "dir.h" +#include "string-list.h" /* ISSYMREF=0x01, ISPACKED=0x02 and ISBROKEN=0x04 are public interfaces */ #define REF_KNOWS_PEELED 0x10
@@ -2127,3 +2128,38 @@ char *shorten_unambiguous_ref(const char *refname, int strict)free (short_name);return xstrdup (refname); } + +static int match_path (const char *name,const char *pattern,int nlen) +{ +int plen =strlen (pattern); + +return ((plen <= nlen) && + !strncmp (name, pattern, plen) && + (name[plen] =='\0' || + name[plen] =='/' || + pattern[plen-1 ] =='/' )); +} + +int match_pattern (const char *name,const char **match, +struct string_list *exclude,int flags) +{ +int nlen =strlen (name); + +if (exclude) { +struct string_list_item *x; +for_each_string_list_item (x, exclude) { +if (!fnmatch (x->string, name,0 )) +return 0 ; + } + } +if (!match || !*match) +return 1 ; +for (; *match; match++) { +if (flags ==FNM_PATHNAME ) +if (match_path (name, *match, nlen)) +return 1 ; +if (!fnmatch (*match, name, flags)) +return 1 ; + } +return 0 ; +}
refs.h +12 -0
@@ -144,4 +144,16 @@ int update_ref(const char *action, const char *refname, const unsigned char *sha1, const unsigned char *oldval, int flags, enum action_on_err onerr); +/* +* match_pattern() - compares a name with pattern match and ignore lists +* This returns in highest to lowest precedence: +* 0 if <name> fnmatch() an <exclude> pattern +* 1 if <match> is NULL or empty +* 1 if <flags> is FNM_PATHNAME and <name> is an exact match of a listed +* pattern upto and including a trailing '/' +* 1 <name> fnmatch() a <match> pattern +* 0 otherwise +*/ +int match_pattern (const char *name,const char **match,struct string_list *exclude,int flags); +#endif /* REFS_H */
Signature · 1 line
1.7.8
Re: [PATCHv3 1/5] refs: add match_pattern()
refs.c char *shorten_unambiguous_ref(const char *refname, int strict) · line 2141
Quoted 10 lines · Tom Grennan
refs.c +10
-0+static int match_path (const char *name,const char *pattern,int nlen) +{ +int plen =strlen (pattern); + +return ((plen <= nlen) && + !strncmp (name, pattern, plen) && + (name[plen] =='\0' || + name[plen] =='/' || + pattern[plen-1 ] =='/' )); +}
This is a counterpart to the tail match found in ls-remote, so we would want to call it with a name that makes it clear this is a leading path match not just "path" match. Perhaps match_leading_path() or something.
Quoted 13 lines
refs.c +13
-0+int match_pattern (const char *name,const char **match, +struct string_list *exclude,int flags) +{ +int nlen =strlen (name); + +if (exclude) { +struct string_list_item *x; +for_each_string_list_item (x, exclude) { +if (!fnmatch (x->string, name,0 )) +return 0 ; + } + } +if (!match || !*match)
refs.c char *shorten_unambiguous_ref(const char *refname, int strict) · line 2165
Quoted 10 lines
refs.c +10
-0+return 1 ; +for (; *match; match++) { +if (flags ==FNM_PATHNAME ) +if (match_path (name, *match, nlen)) +return 1 ; +if (!fnmatch (*match, name, flags)) +return 1 ; + } +return 0 ; +}
As an API for a consolidated and generic function, the design needs a bit more improving, I would think.
- The name match_pattern() was OK for a static function inside a single file, but it is way too vague for a global function. This is to match refnames, so I suspect there should at least be a string "ref_" somewhere in its name.
- You pass "flags" argument, so that later we _could_ enhance the implementation to cover needs for new callers, but alas, it uses its full bits to express only one "do we do FNM_PATHNAME or not?" bit of information, so essentially "flags" does not give us any expandability.
- Is it a sane assumption that a caller that asks FNM_PATHNAME will always want match_path() semantics, too? Aren't these two logically independent?
- Is it a sane assumption that a caller that gives an exclude list will want neither FNM_PATHNAME semantics nor match_path() semantics?
- Positive patterns are passed in "const char **match", and negative ones are in "struct string_list *". Doesn't the inconsistency strike you as strange?
Perhaps like...
#define REF_MATCH_LEADING 01 #define REF_MATCH_TRAILING 02 #define REF_MATCH_FNM_PATH 04
static int match_one(const char *name, size_t namelen, const char *pattern,
unsigned flags)
{
if ((flags & REF_MATCH_LEADING) &&
match_leading_path(name, pattern, namelen))
return 1;
if ((flags & REF_MATCH_TRAILING) &&
match_trailing_path(name, pattern, namelen))
return 1;
if (!fnmatch(pattern, name,
(flags & REF_MATCH_FNM_PATH) ? FNM_PATHNAME : 0))
return 1;
return 0;
}int ref_match_pattern(const char *name,
const char **pattern, const char **exclude, unsigned flags)
{
size_t namelen = strlen(name);
if (exclude) {
while (*exclude) {
if (match_one(name, namelen, *exclude, flags))
return 0;
exclude++;
}
}
if (!pattern || !*pattern)
return 1;
while (*pattern) {
if (match_one(name, namelen, *pattern, flags))
return 1;
pattern++;
}
return 0;
}and then the caller could do something like
ref_match_pattern("refs/heads/master",
["maste?", NULL],
["refs/heads/", NULL],
(REF_MATCH_FNM_PATH|REF_MATCH_LEADING));Note that the above "ref_match_pattern()" gives the same "flags" for the call to match_one() for elements in both positive and negative array and it is very deliberate. See review comment to [3/5] for the reasoning.
Thanks.
Re: [PATCHv3 1/5] refs: add match_pattern()
Quoted 16 lines · Junio C Hamano
refs.c char *shorten_unambiguous_ref(const char *refname, int strict) · line 2141
Quoted 10 lines · Tom Grennan
refs.c +10
-0+static int match_path (const char *name,const char *pattern,int nlen) +{ +int plen =strlen (pattern); + +return ((plen <= nlen) && + !strncmp (name, pattern, plen) && + (name[plen] =='\0' || + name[plen] =='/' || + pattern[plen-1 ] =='/' )); +}This is a counterpart to the tail match found in ls-remote, so we would want to call it with a name that makes it clear this is a leading path match not just "path" match. Perhaps
match_leading_path()or something.
OK
Quoted 27 lines
Quoted 13 lines
refs.c +13
-0+int match_pattern (const char *name,const char **match, +struct string_list *exclude,int flags) +{ +int nlen =strlen (name); + +if (exclude) { +struct string_list_item *x; +for_each_string_list_item (x, exclude) { +if (!fnmatch (x->string, name,0 )) +return 0 ; + } + } +if (!match || !*match)refs.c char *shorten_unambiguous_ref(const char *refname, int strict) · line 2165
Quoted 10 lines
refs.c +10
-0+return 1 ; +for (; *match; match++) { +if (flags ==FNM_PATHNAME ) +if (match_path (name, *match, nlen)) +return 1 ; +if (!fnmatch (*match, name, flags)) +return 1 ; + } +return 0 ; +}As an API for a consolidated and generic function, the design needs a bit more improving, I would think.
Quoted 4 lines
- The name
match_pattern()was OK for a static function inside a single file, but it is way too vague for a global function. This is to match refnames, so I suspect there should at least be a string "ref_" somewhere in its name.
OK
Quoted 4 lines
- You pass "flags" argument, so that later we _could_ enhance the implementation to cover needs for new callers, but alas, it uses its full bits to express only one "do we do
FNM_PATHNAMEor not?" bit of information, so essentially "flags" does not give us any expandability.
I agree.
Quoted 3 lines
- Is it a sane assumption that a caller that asks
FNM_PATHNAMEwill always wantmatch_path()semantics, too? Aren't these two logically independent?
Yes, these should be ligically independent although the current use has combined them.
Quoted 2 lines
- Is it a sane assumption that a caller that gives an exclude list will want neither
FNM_PATHNAMEsemantics normatch_path()semantics?
I'm not sure. I tried using FNM_PATHNAME with both exclusion and match patterns of git-for-each-ref but I couldn't get it to do something like this:
git for-each-ref ... --exclude '*HEAD' refs/remotes/
I don't remember if this worked,
git for-each-ref ... --exclude HEAD refs/remotes/
Now I see how an implicit TRAILING match would be useful,
git for-each-ref ... --exclude /HEAD refs/remotes/
Where git-for-each-ref uses this flag:
REF_MATCH_LEADING | REF_MATCH_TRAILING | REF_MATCH_FNM_PATH
I'll experiment with this more.
Quoted 3 lines
- Positive patterns are passed in "const char **match", and negative ones are in "struct
string_list*". Doesn't the inconsistency strike you as strange?
Yes, I tried to minimize change but the conversion of argv's to string_list's won't add that much.
Quoted 44 lines
Perhaps like...
#define REF_MATCH_LEADING 01 #define REF_MATCH_TRAILING 02 #define REF_MATCH_FNM_PATH 04static int match_one(const char *name,
size_tnamelen, const char *pattern,
unsigned flags){ if ((flags & REF_MATCH_LEADING) && match_leading_path(name, pattern, namelen)) return 1; if ((flags & REF_MATCH_TRAILING) && match_trailing_path(name, pattern, namelen)) return 1; if (!fnmatch(pattern, name, (flags & REF_MATCH_FNM_PATH) ? FNM_PATHNAME : 0)) return 1; return 0; }int ref_match_pattern(const char *name,
const char **pattern, const char **exclude, unsigned flags){ size_t namelen = strlen(name); if (exclude) { while (*exclude) { if (match_one(name, namelen, *exclude, flags)) return 0; exclude++; } } if (!pattern || !*pattern) return 1; while (*pattern) { if (match_one(name, namelen, *pattern, flags)) return 1; pattern++; } return 0; }and then the caller could do something like
Quoted 8 lines
ref_match_pattern("refs/heads/master", ["maste?", NULL], ["refs/heads/", NULL], (REF_MATCH_FNM_PATH|REF_MATCH_LEADING));Note that the above "
ref_match_pattern()" gives the same "flags" for the call tomatch_one()for elements in both positive and negative array and it is very deliberate. See review comment to [3/5] for the reasoning.
OK, I think that I understand, but please confirm, you'd expect no output in the above example, right?
Signature · 1 line
TomG
Re: [PATCHv3 1/5] refs: add match_pattern()
Quoted 2 lines · Tom Grennan
Yes, I tried to minimize change but the conversion of argv's to string_list's won't add that much.
How about _not_ using string_list? After all, string_list is not just a collection of strings, but is a table to hold strings with attributes. I thought argv_array is more appropriate abstraction for the purpose of your patch.
Quoted 11 lines
Quoted 8 lines
ref_match_pattern("refs/heads/master", ["maste?", NULL], ["refs/heads/", NULL], (REF_MATCH_FNM_PATH|REF_MATCH_LEADING));Note that the above "
ref_match_pattern()" gives the same "flags" for the call tomatch_one()for elements in both positive and negative array and it is very deliberate. See review comment to [3/5] for the reasoning.OK, I think that I understand, but please confirm, you'd expect no output in the above example, right?
"maste?" would match with FNM_PATHNAME with "refs/heads/master" but the negative "refs/heads/" matches with it, so yeah, I expect that the function would return false.
Re: [PATCHv3 1/5] refs: add match_pattern()
Quoted 9 lines · Junio C Hamano
Quoted 2 lines · Tom Grennan
Yes, I tried to minimize change but the conversion of argv's to string_list's won't add that much.
How about _not_ using
string_list? After all,string_listis not just a collection of strings, but is a table to hold strings with attributes. I thoughtargv_arrayis more appropriate abstraction for the purpose of your patch.
OK, It looks like I should also add a common parse_opt_argv_array() to parse-options-cb. Of course that would be in a separate, dependent patch.
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
ref_match_pattern("refs/heads/master", ["maste?", NULL], ["refs/heads/", NULL], (REF_MATCH_FNM_PATH|REF_MATCH_LEADING));Note that the above "
ref_match_pattern()" gives the same "flags" for the call tomatch_one()for elements in both positive and negative array and it is very deliberate. See review comment to [3/5] for the reasoning.
Quoted 6 lines
Quoted 2 lines
OK, I think that I understand, but please confirm, you'd expect no output in the above example, right?
"maste?" would match with
FNM_PATHNAMEwith "refs/heads/master" but the negative "refs/heads/" matches with it, so yeah, I expect that the function would return false.
thanks, that's a good test case.
Signature · 1 line
TomG
PATCH v3 2/5 tag --points-at option wrapper
In reply to Tom GrennanUse the OPT_CALLBACK wrapper with "--points-at" instead of an OPTION_CALLBACK block.
--- builtin/tag.c | 7 +++---- 1 files changed, 3 insertions(+), 4 deletions(-)
builtin/tag.c +3 -4
@@ -456,10 +456,9 @@ int cmd_tag(int argc, const char **argv, const char *prefix) PARSE_OPT_LASTARG_DEFAULT, parse_opt_with_commit, (intptr_t)"HEAD", }, - { - OPTION_CALLBACK, 0, "points-at", NULL, "object", - "print only tags of the object", 0, parse_opt_points_at - }, + OPT_CALLBACK(0, "points-at", NULL, "object", + "print only tags of the object", + parse_opt_points_at),OPT_END () };
Signature · 1 line
1.7.8
PATCH v3 3/5 tag --exclude option
In reply to Tom GrennanExample,
$ git tag -l --exclude "*-rc?" "v1.7.8*" v1.7.8 v1.7.8.1 v1.7.8.2 v1.7.8.3 v1.7.8.4
Which is equivalent to,
$ git tag -l "v1.7.8*" | grep -v \\-rc. v1.7.8 v1.7.8.1 v1.7.8.2 v1.7.8.3 v1.7.8.4
--- Documentation/git-tag.txt | 6 ++++- builtin/tag.c | 17 ++++++++++--- t/t7004-tag.sh | 56 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 5 deletions(-)
Documentation/git-tag.txt +5 -1
@@ -13,7 +13,7 @@ SYNOPSIS <tagname> [<commit> | <object>] 'git tag' -d <tagname>... 'git tag' [-n[<num>]] -l [--contains <commit>] [--points-at <object>] - [<pattern>...] + [--exclude <pattern>] [<pattern>...] 'git tag' -v <tagname>... DESCRIPTION
@@ -90,6 +90,10 @@ OPTIONS --points-at <object>:: Only list tags of the given object. +--exclude <pattern>:: + Don't list tags matching the given pattern. This has precedence + over any other match pattern arguments. + -m <msg>:: --message=<msg>:: Use the given tag message (instead of prompting).
builtin/tag.c +13 -4
@@ -21,7 +21,7 @@ static const char * const git_tag_usage[] = {"git tag [-a|-s|-u <key-id>] [-f] [-m <msg>|-F <file>] <tagname> [<head>]" ,"git tag -d <tagname>..." ,"git tag -l [-n[<num>]] [--contains <commit>] [--points-at <object>] " -"\n\t\t[<pattern>...]" , +"\n\t\t[--exclude <pattern>] [<pattern>...]" ,"git tag -v <tagname>..." , NULL };
@@ -30,6 +30,7 @@ struct tag_filter {const char **patterns;int lines;struct commit_list *with_commit; +struct string_list *exclude; };static struct sha1_array points_at;
@@ -138,7 +139,7 @@ static int show_reference(const char *refname, const unsigned char *sha1, {struct tag_filter *filter = cb_data; -if (match_pattern (refname, filter->patterns,NULL ,0 )) { +if (match_pattern (refname, filter->patterns, filter->exclude,0 )) {if (filter->with_commit) {struct commit *commit;
@@ -165,13 +166,15 @@ static int show_reference(const char *refname, const unsigned char *sha1, }static int list_tags (const char **patterns,int lines, -struct commit_list *with_commit) +struct commit_list *with_commit, +struct string_list *exclude) {struct tag_filter filter; filter.patterns = patterns; filter.lines = lines; filter.with_commit = with_commit; + filter.exclude = exclude;for_each_tag_ref (show_reference, (void *) &filter);
@@ -428,6 +431,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)const char *msgfile =NULL , *keyid =NULL ;struct msg_arg msg = {0 ,STRBUF_INIT };struct commit_list *with_commit =NULL ; +struct string_list exclude =STRING_LIST_INIT_NODUP ;struct option options[] = {OPT_BOOLEAN ('l' ,"list" , &list,"list tag names" ), {OPTION_INTEGER ,'n' ,NULL , &lines,"n" ,
@@ -459,6 +463,9 @@ int cmd_tag(int argc, const char **argv, const char *prefix)OPT_CALLBACK (0 ,"points-at" ,NULL ,"object" ,"print only tags of the object" , parse_opt_points_at), +OPT_CALLBACK (0 ,"exclude" , &exclude,"pattern" , +"ignore pattern matching tags" , + parse_opt_string_list), OPT_END() };
@@ -485,13 +492,15 @@ int cmd_tag(int argc, const char **argv, const char *prefix)usage_with_options (git_tag_usage, options);if (list)return list_tags (argv, lines ==-1 ?0 : lines, - with_commit); + with_commit, &exclude);if (lines !=-1 )die (_ ("-n option is only allowed with -l." ));if (with_commit)die (_ ("--contains option is only allowed with -l." ));if (points_at.nr)die (_ ("--points-at option is only allowed with -l." )); +if (exclude.nr) +die (_ ("--exclude option is only allowed with -l." ));if (delete)return for_each_tag_name (argv, delete_tag);if (verify)
t/t7004-tag.sh +56 -0
86 lines not on this page · raw message
Signature · 1 line
1.7.8
Re: [PATCHv3 3/5] tag --exclude option
Quoted 9 lines · Tom Grennan
Example,
$ git tag -l --exclude "*-rc?" "v1.7.8*" v1.7.8 v1.7.8.1 v1.7.8.2 v1.7.8.3 v1.7.8.4Which is equivalent to,
Quoted 8 lines
$ git tag -l "v1.7.8*" | grep -v \\-rc. v1.7.8 v1.7.8.1 v1.7.8.2 v1.7.8.3 v1.7.8.4Signed-off-by Tom Grennan <[email protected]>
Having an example is a good way to illustrate your explanation, but it is not a substitution. Could we have at least one real sentence to describe what the added option *does*?
This comment applies to all the patches in this series except for the second patch.
Quoted 14 lines
Documentation/git-tag.txt +1
-1@@ -13,7 +13,7 @@ SYNOPSIS <tagname> [<commit> | <object>] 'git tag' -d <tagname>... 'git tag' [-n[<num>]] -l [--contains <commit>] [--points-at <object>] - [<pattern>...] + [--exclude <pattern>] [<pattern>...] 'git tag' -v <tagname>... DESCRIPTION
Documentation/git-tag.txt OPTIONS · line 95
Quoted 6 lines
Documentation/git-tag.txt +3
-0@@ -90,6 +90,10 @@ OPTIONS --points-at <object>:: Only list tags of the given object. +--exclude <pattern>:: + Don't list tags matching the given pattern. This has precedence + over any other match pattern arguments.
As you do not specify what kind of pattern matching is done to this exclude pattern, it is important to use the same logic between positive and negative ones to give users a consistent UI. Unfortunately we use fnmatch without FNM_PATHNAME for positive ones, so this exclude pattern needs to follow the same semantics to reduce confusion.
This comment applies to all the patches in this series to add this option to existing commands that take the positive pattern.
Documentation/git-tag.txt test_expect_success \ · line 215
Quoted 11 lines
Documentation/git-tag.txt +7
-0@@ -202,6 +206,15 @@ test_expect_success \ ' cat >expect <<EOF +v0.2.1 +EOF +test_expect_success \ + 'listing tags with a suffix as pattern and prefix exclusion' ' + git tag -l --exclude "v1.*" "*.1" > actual && + test_cmp expect actual +'
I know you are imitating the style of surrounding tests that is an older parts of this script, but it is an eyesore. More modern tests are written like this:
test_expect_success 'label for the test' '
cat >expect <<-EOF &&
v0.2.1
EOF
git tag -l ... >actual &&
test_cmp expect actual
'to avoid unnecessary backslash on the first line, and have the preparation of test vectore _inside_ test_expect_success. We would eventually want to update the older part to the newer style for consistency.
Two possible ways to go about this are (1) have a "pure style" patch at the beginning to update older tests to a new style and then add new code and new test as a follow-up patch written in modern, or (2) add new code and new test in modern, and make a mental note to update the older ones after the dust settles. Adding new tests written in older style to a file that already has mixed styles is the worst thing you can do.
This comment applies to all the patches in this series with tests.
Thanks.
Re: [PATCHv3 3/5] tag --exclude option
Quoted 18 lines · Junio C Hamano
Quoted 16 lines · Tom Grennan
Example,
$ git tag -l --exclude "*-rc?" "v1.7.8*" v1.7.8 v1.7.8.1 v1.7.8.2 v1.7.8.3 v1.7.8.4Which is equivalent to,
$ git tag -l "v1.7.8*" | grep -v \\-rc. v1.7.8 v1.7.8.1 v1.7.8.2 v1.7.8.3 v1.7.8.4
Quoted 9 lines
Quoted 1 line
Signed-off-by Tom Grennan <[email protected]>Having an example is a good way to illustrate your explanation, but it is not a substitution. Could we have at least one real sentence to describe what the added option *does*?
This comment applies to all the patches in this series except for the second patch.
OK, I'll add the "exclude" option description from the respective man pages.
Quoted 27 lines
Quoted 14 lines
Documentation/git-tag.txt +1
-1@@ -13,7 +13,7 @@ SYNOPSIS <tagname> [<commit> | <object>] 'git tag' -d <tagname>... 'git tag' [-n[<num>]] -l [--contains <commit>] [--points-at <object>] - [<pattern>...] + [--exclude <pattern>] [<pattern>...] 'git tag' -v <tagname>... DESCRIPTIONDocumentation/git-tag.txt OPTIONS · line 95
Quoted 6 lines
Documentation/git-tag.txt +3
-0@@ -90,6 +90,10 @@ OPTIONS --points-at <object>:: Only list tags of the given object. +--exclude <pattern>:: + Don't list tags matching the given pattern. This has precedence + over any other match pattern arguments.As you do not specify what kind of pattern matching is done to this exclude pattern, it is important to use the same logic between positive and negative ones to give users a consistent UI. Unfortunately we use fnmatch without
FNM_PATHNAMEfor positive ones, so this exclude pattern needs to follow the same semantics to reduce confusion.
Quoted 2 lines
This comment applies to all the patches in this series to add this option to existing commands that take the positive pattern.
OK, should I also describe the --no-exclude option?
Quoted 28 lines
Documentation/git-tag.txt test_expect_success \ · line 215
Quoted 11 lines
Documentation/git-tag.txt +7
-0@@ -202,6 +206,15 @@ test_expect_success \ ' cat >expect <<EOF +v0.2.1 +EOF +test_expect_success \ + 'listing tags with a suffix as pattern and prefix exclusion' ' + git tag -l --exclude "v1.*" "*.1" > actual && + test_cmp expect actual +'I know you are imitating the style of surrounding tests that is an older parts of this script, but it is an eyesore. More modern tests are written like this:
test_expect_success 'label for the test' ' cat >expect <<-EOF && v0.2.1 EOF git tag -l ... >actual && test_cmp expect actual 'to avoid unnecessary backslash on the first line, and have the preparation of test vectore _inside_
test_expect_success. We would eventually want to update the older part to the newer style for consistency.
Quoted 8 lines
Two possible ways to go about this are (1) have a "pure style" patch at the beginning to update older tests to a new style and then add new code and new test as a follow-up patch written in modern, or (2) add new code and new test in modern, and make a mental note to update the older ones after the dust settles. Adding new tests written in older style to a file that already has mixed styles is the worst thing you can do.
This comment applies to all the patches in this series with tests.
I'd prefer, (1) precede each "--exclude" patch with a "pure style" patch to update the respective tests. However, since this will result in a lot of conflict with concurrent development; I'll separate the test patches from the code and documentation. I'll then cycle on rebasing the style and new test patches until the development of each is quiescent.
Thanks,
TomG
Re: [PATCHv3 3/5] tag --exclude option
Quoted 8 lines · Tom Grennan
Quoted 6 lines · Junio C Hamano
As you do not specify what kind of pattern matching is done to this exclude pattern, it is important to use the same logic between positive and negative ones to give users a consistent UI. Unfortunately we use fnmatch without
FNM_PATHNAMEfor positive ones, so this exclude pattern needs to follow the same semantics to reduce confusion.
Quoted 4 lines
Quoted 2 lines
This comment applies to all the patches in this series to add this option to existing commands that take the positive pattern.
OK, should I also describe the --no-exclude option?
If you support it, yes. What does it do?
--no-exclude::
Cancels all the --exclude options given so far on the command line.
perhaps?
cover modernize test style
In reply to Tom GrennanQuoted 24 lines · Tom Grennan
Quoted 23 lines · Junio C Hamano
I know you are imitating the style of surrounding tests that is an older parts of this script, but it is an eyesore. More modern tests are written like this:
test_expect_success 'label for the test' ' cat >expect <<-EOF && v0.2.1 EOF git tag -l ... >actual && test_cmp expect actual 'to avoid unnecessary backslash on the first line, and have the preparation of test vectore _inside_
test_expect_success. We would eventually want to update the older part to the newer style for consistency.Two possible ways to go about this are (1) have a "pure style" patch at the beginning to update older tests to a new style and then add new code and new test as a follow-up patch written in modern, or (2) add new code and new test in modern, and make a mental note to update the older ones after the dust settles. Adding new tests written in older style to a file that already has mixed styles is the worst thing you can do.
Quoted 8 lines
Quoted 1 line
This comment applies to all the patches in this series with tests.
I'd prefer, (1) precede each "--exclude" patch with a "pure style" patch to update the respective tests. However, since this will result in a lot of conflict with concurrent development; I'll separate the test patches from the code and documentation. I'll then cycle on rebasing the style and new test patches until the development of each is quiescent.
Per request, the following series modernize the style of the respective test scripts. The common themes are:
- Guard setup with test_expect_success
- Single-quoted, tab prefaced test blocks of < 80 cols
- Redirect unwanted output
- Use a "here" filter for some expect generation
I also used pipelines to validate expected results rather than temporary files, i.e.
TEST | test_cmp expect -
vs. TEST >actual && test_cmp expect actual
Since the later three patches have a lot of whitespace change, I've included an alternate, PATCH-w series that filters these for more substantive review. However, even the filtered series is very large causing me to second guess whether such style modernization should be pursued; so, I look forward to your input.
Thanks,
Tom Grennan (5):
t6300 (for-each-ref): modernize style
t5512 (ls-remote): modernize style
t3200 (branch): modernize style
t0040 (parse-options): modernize style
t7004 (tag): modernize style
t/t7004-tag.sh | 1680 ++++++++++++++++++++++++++------------------------------ 1 files changed, 783 insertions(+), 897 deletions(-)
Signature · 1 line
1.7.8
PATCH 101/105 t6300 (for-each-ref): modernize style
- Guard setup with test_expect_success
- Single-quoted, tab prefaced test blocks of < 80 cols
- Redirect unwanted output
--- t/t6300-for-each-ref.sh | 296 +++++++++++++++++++++++++---------------------- 1 files changed, 157 insertions(+), 139 deletions(-)
t/t6300-for-each-ref.sh +157 -139
@@ -5,9 +5,17 @@ test_description='for-each-ref test' +if ! test -r test-lib.sh ; then + (cd ${0%/*} && ./${0##*/} $@) + exit $? +fi + . ./test-lib.sh . "$TEST_DIRECTORY"/lib-gpg.sh +quiet () { "$@" >/dev/null; } +silent () { "$@" >/dev/null 2>&1; } + # Mon Jul 3 15:18:43 2006 +0000 datestamp=1151939923 setdate_and_increment () {
@@ -22,9 +30,9 @@ test_expect_success 'Create sample commit with known timestamp' ' setdate_and_increment && echo "Using $datestamp" > one && git add one && - git commit -m "Initial" && + git commit -q -m "Initial" && setdate_and_increment && - git tag -a -m "Tagging at $datestamp" testtag + quiet git tag -a -m "Tagging at $datestamp" testtag ' test_expect_success 'Create upstream config' '
@@ -115,261 +123,270 @@ test_atom tag contents 'Tagging at 1151939927 ' test_expect_success 'Check invalid atoms names are errors' ' - test_must_fail git for-each-ref --format="%(INVALID)" refs/heads + silent test_must_fail git for-each-ref --format="%(INVALID)" refs/heads ' test_expect_success 'Check format specifiers are ignored in naming date atoms' ' - git for-each-ref --format="%(authordate)" refs/heads && - git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads && - git for-each-ref --format="%(authordate) %(authordate:default)" refs/heads && - git for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads + f1="%(authordate)" && + f2="%(authordate:default) %(authordate)" && + f3="%(authordate) %(authordate:default)" && + f4="%(authordate:default) %(authordate:default)" + quiet git for-each-ref --format="$f1" refs/heads && + quiet git for-each-ref --format="$f2" refs/heads && + quiet git for-each-ref --format="$f3" refs/heads && + quiet git for-each-ref --format="$f4" refs/heads ' test_expect_success 'Check valid format specifiers for date fields' ' - git for-each-ref --format="%(authordate:default)" refs/heads && - git for-each-ref --format="%(authordate:relative)" refs/heads && - git for-each-ref --format="%(authordate:short)" refs/heads && - git for-each-ref --format="%(authordate:local)" refs/heads && - git for-each-ref --format="%(authordate:iso8601)" refs/heads && - git for-each-ref --format="%(authordate:rfc2822)" refs/heads + quiet git for-each-ref --format="%(authordate:default)" refs/heads && + quiet git for-each-ref --format="%(authordate:relative)" refs/heads && + quiet git for-each-ref --format="%(authordate:short)" refs/heads && + quiet git for-each-ref --format="%(authordate:local)" refs/heads && + quiet git for-each-ref --format="%(authordate:iso8601)" refs/heads && + quiet git for-each-ref --format="%(authordate:rfc2822)" refs/heads ' test_expect_success 'Check invalid format specifiers are errors' ' - test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads + h="%(authordate:INVALID)" && + silent test_must_fail git for-each-ref --format="$h" refs/heads ' -cat >expected <<\EOF +test_expect_success 'Check unformatted date fields output' ' + '" + cat >expect <<-EOF && 'refs/heads/master' 'Mon Jul 3 17:18:43 2006 +0200' 'Mon Jul 3 17:18:44 2006 +0200' 'refs/tags/testtag' 'Mon Jul 3 17:18:45 2006 +0200' EOF - -test_expect_success 'Check unformatted date fields output' ' - (git for-each-ref --shell --format="%(refname) %(committerdate) %(authordate)" refs/heads && - git for-each-ref --shell --format="%(refname) %(taggerdate)" refs/tags) >actual && - test_cmp expected actual + "' + h="%(refname) %(committerdate) %(authordate)" && + t="%(refname) %(taggerdate)" && + (git for-each-ref --shell --format="$h" refs/heads && + git for-each-ref --shell --format="$t" refs/tags) | + test_cmp expect - ' test_expect_success 'Check format "default" formatted date fields output' ' - f=default && - (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && - git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual && - test_cmp expected actual + h="%(refname) %(committerdate:default) %(authordate:default)" && + t="%(refname) %(taggerdate:default)" && + (git for-each-ref --shell --format="$h" refs/heads && + git for-each-ref --shell --format="$t" refs/tags) | + test_cmp expect - ' -# Don't know how to do relative check because I can't know when this script -# is going to be run and can't fake the current time to git, and hence can't -# provide expected output. Instead, I'll just make sure that "relative" -# doesn't exit in error -# -#cat >expected <<\EOF -# -#EOF -# test_expect_success 'Check format "relative" date fields output' ' - f=relative && - (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && - git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual + '" + # Don't know how to do relative check because I can't know when this + # script is going to be run and can't fake the current time to git, + # and hence can't provide expected output. Instead, I'll just make + # sure that 'relative' doesn't exit in error + "' + h="%(refname) %(committerdate:relative) %(authordate:relative)" && + t="%(refname) %(taggerdate:relative)" && + quiet git for-each-ref --shell --format="$h" refs/heads && + quiet git for-each-ref --shell --format="$t" refs/tags ' -cat >expected <<\EOF +test_expect_success 'Check format "short" date fields output' ' + '" + cat >expect <<-EOF 'refs/heads/master' '2006-07-03' '2006-07-03' 'refs/tags/testtag' '2006-07-03' EOF - -test_expect_success 'Check format "short" date fields output' ' - f=short && - (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && - git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual && - test_cmp expected actual + "' + h="%(refname) %(committerdate:short) %(authordate:short)" && + t="%(refname) %(taggerdate:short)" && + (git for-each-ref --shell --format="$h" refs/heads && + git for-each-ref --shell --format="$t" refs/tags) | + test_cmp expect - ' -cat >expected <<\EOF +test_expect_success 'Check format "local" date fields output' ' + '" + cat >expect <<-EOF 'refs/heads/master' 'Mon Jul 3 15:18:43 2006' 'Mon Jul 3 15:18:44 2006' 'refs/tags/testtag' 'Mon Jul 3 15:18:45 2006' EOF - -test_expect_success 'Check format "local" date fields output' ' - f=local && - (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && - git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual && - test_cmp expected actual + "' + h="%(refname) %(committerdate:local) %(authordate:local)" && + t="%(refname) %(taggerdate:local)" && + (git for-each-ref --shell --format="$h" refs/heads && + git for-each-ref --shell --format="$t" refs/tags) | + test_cmp expect - ' -cat >expected <<\EOF +test_expect_success 'Check format "iso8601" date fields output' ' + '" + cat >expect <<-EOF 'refs/heads/master' '2006-07-03 17:18:43 +0200' '2006-07-03 17:18:44 +0200' 'refs/tags/testtag' '2006-07-03 17:18:45 +0200' EOF - -test_expect_success 'Check format "iso8601" date fields output' ' - f=iso8601 && - (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && - git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual && - test_cmp expected actual + "' + h="%(refname) %(committerdate:iso8601) %(authordate:iso8601)" && + t="%(refname) %(taggerdate:iso8601)" && + (git for-each-ref --shell --format="$h" refs/heads && + git for-each-ref --shell --format="$t" refs/tags) | + test_cmp expect - ' -cat >expected <<\EOF +test_expect_success 'Check format "rfc2822" date fields output' ' + '" + cat >expect <<-EOF 'refs/heads/master' 'Mon, 3 Jul 2006 17:18:43 +0200' 'Mon, 3 Jul 2006 17:18:44 +0200' 'refs/tags/testtag' 'Mon, 3 Jul 2006 17:18:45 +0200' EOF - -test_expect_success 'Check format "rfc2822" date fields output' ' - f=rfc2822 && - (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && - git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual && - test_cmp expected actual + "' + h="%(refname) %(committerdate:rfc2822) %(authordate:rfc2822)" && + t="%(refname) %(taggerdate:rfc2822)" && + (git for-each-ref --shell --format="$h" refs/heads && + git for-each-ref --shell --format="$t" refs/tags) | + test_cmp expect - ' -cat >expected <<\EOF +test_expect_success 'Verify ascending sort' ' + cat >expect <<-EOF refs/heads/master refs/remotes/origin/master refs/tags/testtag EOF - -test_expect_success 'Verify ascending sort' ' - git for-each-ref --format="%(refname)" --sort=refname >actual && - test_cmp expected actual + git for-each-ref --format="%(refname)" --sort=refname | + test_cmp expect - ' - -cat >expected <<\EOF +test_expect_success 'Verify descending sort' ' + cat >expect <<-EOF refs/tags/testtag refs/remotes/origin/master refs/heads/master EOF - -test_expect_success 'Verify descending sort' ' - git for-each-ref --format="%(refname)" --sort=-refname >actual && - test_cmp expected actual + git for-each-ref --format="%(refname)" --sort=-refname | + test_cmp expect - ' -cat >expected <<\EOF +test_expect_success 'Quoting style: shell' ' + '" + cat >expect <<-EOF 'refs/heads/master' 'refs/remotes/origin/master' 'refs/tags/testtag' EOF - -test_expect_success 'Quoting style: shell' ' - git for-each-ref --shell --format="%(refname)" >actual && - test_cmp expected actual + "' + git for-each-ref --shell --format="%(refname)" | + test_cmp expect - ' test_expect_success 'Quoting style: perl' ' - git for-each-ref --perl --format="%(refname)" >actual && - test_cmp expected actual + git for-each-ref --perl --format="%(refname)" | + test_cmp expect - ' test_expect_success 'Quoting style: python' ' - git for-each-ref --python --format="%(refname)" >actual && - test_cmp expected actual + git for-each-ref --python --format="%(refname)" | + test_cmp expect - ' -cat >expected <<\EOF +test_expect_success 'Quoting style: tcl' ' + cat >expect <<-EOF "refs/heads/master" "refs/remotes/origin/master" "refs/tags/testtag" EOF - -test_expect_success 'Quoting style: tcl' ' - git for-each-ref --tcl --format="%(refname)" >actual && - test_cmp expected actual + git for-each-ref --tcl --format="%(refname)" | + test_cmp expect - ' -for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do - test_expect_success "more than one quoting style: $i" " - git for-each-ref $i 2>&1 | (read line && - case \$line in - \"error: more than one quoting style\"*) : happy;; - *) false - esac) - " -done - -cat >expected <<\EOF +test_expect_success 'more than one quoting styles' ' + cat >expect <<-EOF + error: more than one quoting style? + EOF + git for-each-ref --perl --shell 2>&1 | head -n 1 | + test_cmp expect - && + git for-each-ref -s --python 2>&1 | head -n 1 | + test_cmp expect - && + git for-each-ref --python --tcl 2>&1 | head -n 1 | + test_cmp expect - && + git for-each-ref --tcl --perl 2>&1 | head -n 1 | + test_cmp expect - +' +test_expect_success 'Check short refname format' ' + cat >expect <<-EOF master testtag EOF - -test_expect_success 'Check short refname format' ' - (git for-each-ref --format="%(refname:short)" refs/heads && - git for-each-ref --format="%(refname:short)" refs/tags) >actual && - test_cmp expected actual + git for-each-ref --format="%(refname:short)" refs/heads refs/tags | + test_cmp expect - ' -cat >expected <<EOF +test_expect_success 'Check short upstream format' ' + cat >expect <<-EOF origin/master EOF - -test_expect_success 'Check short upstream format' ' - git for-each-ref --format="%(upstream:short)" refs/heads >actual && - test_cmp expected actual + git for-each-ref --format="%(upstream:short)" refs/heads | + test_cmp expect - ' -cat >expected <<EOF +test_expect_success 'Check short objectname format' ' + cat >expect <<-EOF 67a36f1 EOF - -test_expect_success 'Check short objectname format' ' - git for-each-ref --format="%(objectname:short)" refs/heads >actual && - test_cmp expected actual + git for-each-ref --format="%(objectname:short)" refs/heads | + test_cmp expect - ' test_expect_success 'Check for invalid refname format' ' - test_must_fail git for-each-ref --format="%(refname:INVALID)" + silent test_must_fail git for-each-ref --format="%(refname:INVALID)" ' -cat >expected <<\EOF +test_expect_success 'Check ambiguous head and tag refs (strict)' ' + cat >expect <<-EOF heads/master tags/master EOF - -test_expect_success 'Check ambiguous head and tag refs (strict)' ' git config --bool core.warnambiguousrefs true && - git checkout -b newtag && + git checkout -q -b newtag && echo "Using $datestamp" > one && git add one && - git commit -m "Branch" && + git commit -q -m "Branch" && setdate_and_increment && - git tag -m "Tagging at $datestamp" master && - git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual && - test_cmp expected actual + quiet git tag -m "Tagging at $datestamp" master && + f="%(refname:short)" && + git for-each-ref --format "$f" refs/heads/master refs/tags/master | + test_cmp expect - ' -cat >expected <<\EOF +test_expect_success 'Check ambiguous head and tag refs (loose)' ' + cat >expect <<-EOF heads/master master EOF - -test_expect_success 'Check ambiguous head and tag refs (loose)' ' git config --bool core.warnambiguousrefs false && - git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual && - test_cmp expected actual + f="%(refname:short)" && + git for-each-ref --format "$f" refs/heads/master refs/tags/master | + test_cmp expect - ' -cat >expected <<\EOF +test_expect_success 'Check ambiguous head and tag refs II (loose)' ' + cat >expect <<-EOF heads/ambiguous ambiguous EOF - -test_expect_success 'Check ambiguous head and tag refs II (loose)' ' - git checkout master && + git checkout -q master && git tag ambiguous testtag^0 && git branch ambiguous testtag^0 && - git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual && - test_cmp expected actual + f="%(refname:short)" && + git for-each-ref --format "$f" refs/heads/ambiguous refs/tags/ambiguous | + test_cmp expect - ' test_expect_success 'an unusual tag with an incomplete line' ' - git tag -m "bogo" bogo && bogo=$(git cat-file tag bogo) && bogo=$(printf "%s" "$bogo" | git mktag) && git tag -f bogo "$bogo" && git for-each-ref --format "%(body)" refs/tags/bogo - ' test_expect_success 'create tag with subject and body content' ' - cat >>msg <<-\EOF && + cat >msg <<-\EOF && the subject line first body line
@@ -395,8 +412,9 @@ test_expect_success 'create tag with multiline subject' ' first body line second body line EOF - git tag -F msg multiline + quiet git tag -F msg multiline ' + test_atom refs/tags/multiline subject 'first subject line second subject line' test_atom refs/tags/multiline contents:subject 'first subject line second subject line' test_atom refs/tags/multiline body 'first body line
Signature · 1 line
1.7.8
Re: [PATCH-w 101/105] t6300 (for-each-ref): modernize style
t/t6300-for-each-ref.sh line 11
Quoted 4 lines · Tom Grennan
t/t6300-for-each-ref.sh +4
-0+if ! test -r test-lib.sh ; then + (cd ${0%/*} && ./${0##*/} $@) + exit $? +fi
Not very nice; why is this an improvement?
t/t6300-for-each-ref.sh line 17
Quoted 5 lines
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-gpg.sht/t6300-for-each-ref.sh +2
-0+quiet () { "$@" >/dev/null; } +silent () { "$@" >/dev/null 2>&1; }
Not nice, either.
t/t6300-for-each-ref.sh test_expect_success 'Create sample commit with known timestamp' ' · line 35
Quoted 12 lines
# Mon Jul 3 15:18:43 2006 +0000
datestamp=1151939923
setdate_and_increment() {t/t6300-for-each-ref.sh +2
-2@@ -22,9 +30,9 @@ test_expect_success 'Create sample commit with known timestamp' ' setdate_and_increment && echo "Using $datestamp" > one && git add one && - git commit -m "Initial" && + git commit -q -m "Initial" && setdate_and_increment && - git tag -a -m "Tagging at $datestamp" testtag + quiet git tag -a -m "Tagging at $datestamp" testtag
Why? Why? Why?
cd t && sh ./t1234-frotz.sh
would be silent enough and suppressing the output from the commands like this patch does makes it _harder_ for people to debug their changes to the script with
sh ./t1234-frotz.sh -v
Most of the change in this patch does nothing to do with "modernize style".
Re: [PATCH-w 101/105] t6300 (for-each-ref): modernize style
Quoted 8 lines · Junio C Hamano
t/t6300-for-each-ref.sh line 11
Quoted 4 lines · Tom Grennan
t/t6300-for-each-ref.sh +4
-0+if ! test -r test-lib.sh ; then + (cd ${0%/*} && ./${0##*/} $@) + exit $? +fiNot very nice; why is this an improvement?
I liked being able to,
t/t1234-frotz.sh [-q|-v] in addition to, cd t && sh ./t1234-frotz.sh
Quoted 7 lines
t/t6300-for-each-ref.sh line 17
Quoted 5 lines
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-gpg.sht/t6300-for-each-ref.sh +2
-0+quiet () { "$@" >/dev/null; } +silent () { "$@" >/dev/null 2>&1; }Not nice, either.
"Not nice" b/c they're on one line?
I like simple things compressed so I quickly glance pass them. Sort of forest through the trees.
Quoted 15 lines
t/t6300-for-each-ref.sh test_expect_success 'Create sample commit with known timestamp' ' · line 35
Quoted 12 lines
# Mon Jul 3 15:18:43 2006 +0000
datestamp=1151939923
setdate_and_increment() {t/t6300-for-each-ref.sh +2
-2@@ -22,9 +30,9 @@ test_expect_success 'Create sample commit with known timestamp' ' setdate_and_increment && echo "Using $datestamp" > one && git add one && - git commit -m "Initial" && + git commit -q -m "Initial" && setdate_and_increment && - git tag -a -m "Tagging at $datestamp" testtag + quiet git tag -a -m "Tagging at $datestamp" testtagWhy? Why? Why?
Quoted 7 lines
cd t && sh ./t1234-frotz.shwould be silent enough and suppressing the output from the commands like this patch does makes it _harder_ for people to debug their changes to the script with
sh ./t1234-frotz.sh -v
Hmm, I found the noise distracting. For example, w/o redirecting stderr, most of the test_must_fail puke as expected. If it's expected, why show it? BTW since it's a different stream, to get the error near the exec log one has to:
sh ./t1234-frotz.sh -v |& less
Otherwise it's challenging to separate the expected vs unexpected failures.
Most of the "quiet's" are with git-tag and git-branch. I'd prefer --quiet and --silent options to these commands like git-init, git-commit, etc.
Quoted 1 line
Most of the change in this patch does nothing to do with "modernize style".
It's trivial to remove these "quiet" and "silent", but to me that's the only value added by these patches. More seriously, the remaining modernization still seems much larger than its value.
Signature · 1 line
TomG
Re: [PATCH-w 101/105] t6300 (for-each-ref): modernize style
Quoted 3 lines · Tom Grennan
It's trivial to remove these "quiet" and "silent", but to me that's the only value added by these patches. More seriously, the remaining modernization still seems much larger than its value.
Don't do that, then ;-).
Some older scripts do redirect the output from the commands to /dev/null but that dates back before we made the default reasonably silent, and in "modern" style we tend to keep them sent to their standard output to help debuggability. These quiet/silent takes us to the prehistoric times.
Re: [PATCH-w 101/105] t6300 (for-each-ref): modernize style
Quoted 6 lines · Junio C Hamano
Quoted 3 lines · Tom Grennan
It's trivial to remove these "quiet" and "silent", but to me that's the only value added by these patches. More seriously, the remaining modernization still seems much larger than its value.
Quoted 6 lines
Don't do that, then ;-).
Some older scripts do redirect the output from the commands to
/dev/nullbut that dates back before we made the default reasonably silent, and in "modern" style we tend to keep them sent to their standard output to help debuggability. These quiet/silent takes us to the prehistoric times.
Hey! I am prehistoric:-)
Like I said, I think there is currently a debug distraction with verbose mode. However, rather than hiding expected failures and diverting other output as I had, perhaps we should dup stderr to stdout in verbose mode so error messages show up near the logged invocation when piped through a pager (i.e. mimic "|&"). With this, one can quickly scan past the noise to focus on the broken cases.
exec 5>&1
exec 6<&0
if test "$verbose" = "t"
then
- exec 4>&2 3>&1
+ exec 4>&1 3>&1
else
exec 4>/dev/null 3>/dev/null
fi
For example, try this w/ and w/o the above change.
(cd t && ./t5512-ls-remote.sh) | less
I still think git-branch and git-tag should have a -q option; better yet, the wrapper itself (i.e. git --quiet/--silent XXX).
Signature · 1 line
TomG
Re: [PATCH-w 101/105] t6300 (for-each-ref): modernize style
Quoted 5 lines · Tom Grennan
Quoted 2 lines · Junio C Hamano
Tom Grennan <[email protected]> writes:
For example, try this w/ and w/o the above change.
(cd t && ./t5512-ls-remote.sh) | less
(cd t && ./t5512-ls-remote.sh -v) | less
Signature · 1 line
TomG
Re: [PATCH-w 101/105] t6300 (for-each-ref): modernize style
In reply to Tom GrennanI sent out a reply to the same effect as Junio's longer one in this side-thread. You can disregard that. Sorry for not first reading the whole thread.
Quoted 14 lines · Tom Grennan
Quoted 6 lines · Junio C Hamano
Quoted 3 lines · Tom Grennan
It's trivial to remove these "quiet" and "silent", but to me that's the only value added by these patches. More seriously, the remaining modernization still seems much larger than its value.
Quoted 6 lines
Don't do that, then ;-).
Some older scripts do redirect the output from the commands to
/dev/nullbut that dates back before we made the default reasonably silent, and in "modern" style we tend to keep them sent to their standard output to help debuggability. These quiet/silent takes us to the prehistoric times.
Quoted 8 lines
Hey! I am prehistoric:-)
Like I said, I think there is currently a debug distraction with verbose mode. However, rather than hiding expected failures and diverting other output as I had, perhaps we should dup stderr to stdout in verbose mode so error messages show up near the logged invocation when piped through a pager (i.e. mimic "|&"). With this, one can quickly scan past the noise to focus on the broken cases.
If you have trouble finding the broken case, you can run with -v -i.
I also think you are making an argument for a different feature (which does not rob us of having all the debug output): test-lib.sh could perhaps redirect the test output to a file, and dump the file to stdout only if the test failed. Perhaps --verbose-failing or something like that.
Otherwise, your proposal is restricting us to having only an "easily scannable" amount of output per test, perhaps 5-15 lines. Which I personally think is an insane restriction for something that was intended for debugging in the first place.
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chRe: [PATCH-w 101/105] t6300 (for-each-ref): modernize style
Quoted 19 lines · Thomas Rast
Quoted 9 lines · Tom Grennan
Quoted 2 lines · Junio C Hamano
Tom Grennan <[email protected]> writes:
Like I said, I think there is currently a debug distraction with verbose mode. However, rather than hiding expected failures and diverting other output as I had, perhaps we should dup stderr to stdout in verbose mode so error messages show up near the logged invocation when piped through a pager (i.e. mimic "|&"). With this, one can quickly scan past the noise to focus on the broken cases.
If you have trouble finding the broken case, you can run with -v -i.
I also think you are making an argument for a different feature (which does not rob us of having all the debug output):
test-lib.shcould perhaps redirect the test output to a file, and dump the file to stdout only if the test failed. Perhaps --verbose-failing or something like that.
Quoted 4 lines
Otherwise, your proposal is restricting us to having only an "easily scannable" amount of output per test, perhaps 5-15 lines. Which I personally think is an insane restriction for something that was intended for debugging in the first place.
Oh, I hadn't tried -i with -v. This does mimic "|&".
(cd t && ./t5512-ls-remote.sh -v -i) | less (cd t && ./t5512-ls-remote.sh -v) |& less
So, please ignore my suggestion.
Thanks,
TomG
PATCH 102/105 t5512 (ls-remote): modernize style
In reply to Tom Grennan- Guard setup with test_expect_success
- Single-quoted, tab prefaced test blocks of < 80 cols
- Redirect unwanted output
--- t/t5512-ls-remote.sh | 29 ++++++++++++++++++++--------- 1 files changed, 20 insertions(+), 9 deletions(-)
t/t5512-ls-remote.sh +20 -9
@@ -2,14 +2,22 @@ test_description='git ls-remote' +if ! test -r test-lib.sh ; then + (cd ${0%/*} && ./${0##*/} $@) + exit $? +fi + . ./test-lib.sh +quiet () { "$@" >/dev/null; } +silent () { "$@" >/dev/null 2>&1; } + test_expect_success setup ' >file && git add file && test_tick && - git commit -m initial && + git commit -q -m initial && git tag mark && git show-ref --tags -d | sed -e "s/ / /" >expected.tag && (
@@ -51,7 +59,7 @@ test_expect_success 'ls-remote self' ' test_expect_success 'dies when no remote specified and no default remotes found' ' - test_must_fail git ls-remote + silent test_must_fail git ls-remote '
@@ -70,8 +78,8 @@ test_expect_success 'use "origin" when no remote specified' ' test_expect_success 'suppress "From <url>" with -q' ' - git ls-remote -q 2>actual_err && - test_must_fail test_cmp exp_err actual_err + quiet git ls-remote -q 2>actual_err && + test_must_fail cmp -s exp_err actual_err '
@@ -83,7 +91,7 @@ test_expect_success 'use branch.<name>.remote if possible' ' # # setup a new remote to differentiate from "origin" - git clone . other.git && + git clone -q . other.git && ( cd other.git && echo "$(git rev-parse HEAD) HEAD"
@@ -102,11 +110,13 @@ test_expect_success 'use branch.<name>.remote if possible' ' ' -cat >exp <<EOF +test_expect_success 'confuses pattern as remote when no remote specified' ' + '" + cat >exp <<-EOF fatal: 'refs*master' does not appear to be a git repository fatal: The remote end hung up unexpectedly EOF -test_expect_success 'confuses pattern as remote when no remote specified' ' + "' # # Do not expect "git ls-remote <pattern>" to work; ls-remote, correctly, # confuses <pattern> for <remote>. Although ugly, this behaviour is akin
@@ -124,7 +134,7 @@ test_expect_success 'confuses pattern as remote when no remote specified' ' ' test_expect_success 'die with non-2 for wrong repository even with --exit-code' ' - git ls-remote --exit-code ./no-such-repository ;# not && + silent git ls-remote --exit-code ./no-such-repository ;# not && status=$? && test $status != 2 && test $status != 0 '
@@ -136,7 +146,8 @@ test_expect_success 'Report success even when nothing matches' ' ' test_expect_success 'Report no-match with --exit-code' ' - test_expect_code 2 git ls-remote --exit-code other.git "refs/nsn/*" >actual && + test_expect_code 2 git ls-remote --exit-code other.git "refs/nsn/*" \ + >actual && >expect && test_cmp expect actual '
Signature · 1 line
1.7.8
PATCH 1/5 t6300 (for-each-ref): modernize style
In reply to Tom Grennan- Guard setup with test_expect_success
- Single-quoted, tab prefaced test blocks of < 80 cols
- Redirect unwanted output
--- t/t6300-for-each-ref.sh | 364 +++++++++++++++++++++++++---------------------- 1 files changed, 191 insertions(+), 173 deletions(-)
t/t6300-for-each-ref.sh +191 -173
@@ -5,9 +5,17 @@ test_description='for-each-ref test' +if ! test -r test-lib.sh ; then + (cd ${0%/*} && ./${0##*/} $@) + exit $? +fi + . ./test-lib.sh . "$TEST_DIRECTORY"/lib-gpg.sh +quiet () { "$@" >/dev/null; } +silent () { "$@" >/dev/null 2>&1; } + # Mon Jul 3 15:18:43 2006 +0000 datestamp=1151939923 setdate_and_increment () {
@@ -22,9 +30,9 @@ test_expect_success 'Create sample commit with known timestamp' ' setdate_and_increment && echo "Using $datestamp" > one && git add one && - git commit -m "Initial" && + git commit -q -m "Initial" && setdate_and_increment && - git tag -a -m "Tagging at $datestamp" testtag + quiet git tag -a -m "Tagging at $datestamp" testtag ' test_expect_success 'Create upstream config' '
@@ -115,261 +123,270 @@ test_atom tag contents 'Tagging at 1151939927 ' test_expect_success 'Check invalid atoms names are errors' ' - test_must_fail git for-each-ref --format="%(INVALID)" refs/heads + silent test_must_fail git for-each-ref --format="%(INVALID)" refs/heads ' test_expect_success 'Check format specifiers are ignored in naming date atoms' ' - git for-each-ref --format="%(authordate)" refs/heads && - git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads && - git for-each-ref --format="%(authordate) %(authordate:default)" refs/heads && - git for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads + f1="%(authordate)" && + f2="%(authordate:default) %(authordate)" && + f3="%(authordate) %(authordate:default)" && + f4="%(authordate:default) %(authordate:default)" + quiet git for-each-ref --format="$f1" refs/heads && + quiet git for-each-ref --format="$f2" refs/heads && + quiet git for-each-ref --format="$f3" refs/heads && + quiet git for-each-ref --format="$f4" refs/heads ' test_expect_success 'Check valid format specifiers for date fields' ' - git for-each-ref --format="%(authordate:default)" refs/heads && - git for-each-ref --format="%(authordate:relative)" refs/heads && - git for-each-ref --format="%(authordate:short)" refs/heads && - git for-each-ref --format="%(authordate:local)" refs/heads && - git for-each-ref --format="%(authordate:iso8601)" refs/heads && - git for-each-ref --format="%(authordate:rfc2822)" refs/heads + quiet git for-each-ref --format="%(authordate:default)" refs/heads && + quiet git for-each-ref --format="%(authordate:relative)" refs/heads && + quiet git for-each-ref --format="%(authordate:short)" refs/heads && + quiet git for-each-ref --format="%(authordate:local)" refs/heads && + quiet git for-each-ref --format="%(authordate:iso8601)" refs/heads && + quiet git for-each-ref --format="%(authordate:rfc2822)" refs/heads ' test_expect_success 'Check invalid format specifiers are errors' ' - test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads + h="%(authordate:INVALID)" && + silent test_must_fail git for-each-ref --format="$h" refs/heads ' -cat >expected <<\EOF -'refs/heads/master' 'Mon Jul 3 17:18:43 2006 +0200' 'Mon Jul 3 17:18:44 2006 +0200' -'refs/tags/testtag' 'Mon Jul 3 17:18:45 2006 +0200' -EOF - test_expect_success 'Check unformatted date fields output' ' - (git for-each-ref --shell --format="%(refname) %(committerdate) %(authordate)" refs/heads && - git for-each-ref --shell --format="%(refname) %(taggerdate)" refs/tags) >actual && - test_cmp expected actual + '" + cat >expect <<-EOF && + 'refs/heads/master' 'Mon Jul 3 17:18:43 2006 +0200' 'Mon Jul 3 17:18:44 2006 +0200' + 'refs/tags/testtag' 'Mon Jul 3 17:18:45 2006 +0200' + EOF + "' + h="%(refname) %(committerdate) %(authordate)" && + t="%(refname) %(taggerdate)" && + (git for-each-ref --shell --format="$h" refs/heads && + git for-each-ref --shell --format="$t" refs/tags) | + test_cmp expect - ' test_expect_success 'Check format "default" formatted date fields output' ' - f=default && - (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && - git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual && - test_cmp expected actual + h="%(refname) %(committerdate:default) %(authordate:default)" && + t="%(refname) %(taggerdate:default)" && + (git for-each-ref --shell --format="$h" refs/heads && + git for-each-ref --shell --format="$t" refs/tags) | + test_cmp expect - ' -# Don't know how to do relative check because I can't know when this script -# is going to be run and can't fake the current time to git, and hence can't -# provide expected output. Instead, I'll just make sure that "relative" -# doesn't exit in error -# -#cat >expected <<\EOF -# -#EOF -# test_expect_success 'Check format "relative" date fields output' ' - f=relative && - (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && - git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual + '" + # Don't know how to do relative check because I can't know when this + # script is going to be run and can't fake the current time to git, + # and hence can't provide expected output. Instead, I'll just make + # sure that 'relative' doesn't exit in error + "' + h="%(refname) %(committerdate:relative) %(authordate:relative)" && + t="%(refname) %(taggerdate:relative)" && + quiet git for-each-ref --shell --format="$h" refs/heads && + quiet git for-each-ref --shell --format="$t" refs/tags ' -cat >expected <<\EOF -'refs/heads/master' '2006-07-03' '2006-07-03' -'refs/tags/testtag' '2006-07-03' -EOF - test_expect_success 'Check format "short" date fields output' ' - f=short && - (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && - git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual && - test_cmp expected actual + '" + cat >expect <<-EOF + 'refs/heads/master' '2006-07-03' '2006-07-03' + 'refs/tags/testtag' '2006-07-03' + EOF + "' + h="%(refname) %(committerdate:short) %(authordate:short)" && + t="%(refname) %(taggerdate:short)" && + (git for-each-ref --shell --format="$h" refs/heads && + git for-each-ref --shell --format="$t" refs/tags) | + test_cmp expect - ' -cat >expected <<\EOF -'refs/heads/master' 'Mon Jul 3 15:18:43 2006' 'Mon Jul 3 15:18:44 2006' -'refs/tags/testtag' 'Mon Jul 3 15:18:45 2006' -EOF - test_expect_success 'Check format "local" date fields output' ' - f=local && - (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && - git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual && - test_cmp expected actual + '" + cat >expect <<-EOF + 'refs/heads/master' 'Mon Jul 3 15:18:43 2006' 'Mon Jul 3 15:18:44 2006' + 'refs/tags/testtag' 'Mon Jul 3 15:18:45 2006' + EOF + "' + h="%(refname) %(committerdate:local) %(authordate:local)" && + t="%(refname) %(taggerdate:local)" && + (git for-each-ref --shell --format="$h" refs/heads && + git for-each-ref --shell --format="$t" refs/tags) | + test_cmp expect - ' -cat >expected <<\EOF -'refs/heads/master' '2006-07-03 17:18:43 +0200' '2006-07-03 17:18:44 +0200' -'refs/tags/testtag' '2006-07-03 17:18:45 +0200' -EOF - test_expect_success 'Check format "iso8601" date fields output' ' - f=iso8601 && - (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && - git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual && - test_cmp expected actual + '" + cat >expect <<-EOF + 'refs/heads/master' '2006-07-03 17:18:43 +0200' '2006-07-03 17:18:44 +0200' + 'refs/tags/testtag' '2006-07-03 17:18:45 +0200' + EOF + "' + h="%(refname) %(committerdate:iso8601) %(authordate:iso8601)" && + t="%(refname) %(taggerdate:iso8601)" && + (git for-each-ref --shell --format="$h" refs/heads && + git for-each-ref --shell --format="$t" refs/tags) | + test_cmp expect - ' -cat >expected <<\EOF -'refs/heads/master' 'Mon, 3 Jul 2006 17:18:43 +0200' 'Mon, 3 Jul 2006 17:18:44 +0200' -'refs/tags/testtag' 'Mon, 3 Jul 2006 17:18:45 +0200' -EOF - test_expect_success 'Check format "rfc2822" date fields output' ' - f=rfc2822 && - (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && - git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual && - test_cmp expected actual + '" + cat >expect <<-EOF + 'refs/heads/master' 'Mon, 3 Jul 2006 17:18:43 +0200' 'Mon, 3 Jul 2006 17:18:44 +0200' + 'refs/tags/testtag' 'Mon, 3 Jul 2006 17:18:45 +0200' + EOF + "' + h="%(refname) %(committerdate:rfc2822) %(authordate:rfc2822)" && + t="%(refname) %(taggerdate:rfc2822)" && + (git for-each-ref --shell --format="$h" refs/heads && + git for-each-ref --shell --format="$t" refs/tags) | + test_cmp expect - ' -cat >expected <<\EOF -refs/heads/master -refs/remotes/origin/master -refs/tags/testtag -EOF - test_expect_success 'Verify ascending sort' ' - git for-each-ref --format="%(refname)" --sort=refname >actual && - test_cmp expected actual + cat >expect <<-EOF + refs/heads/master + refs/remotes/origin/master + refs/tags/testtag + EOF + git for-each-ref --format="%(refname)" --sort=refname | + test_cmp expect - ' - -cat >expected <<\EOF -refs/tags/testtag -refs/remotes/origin/master -refs/heads/master -EOF - test_expect_success 'Verify descending sort' ' - git for-each-ref --format="%(refname)" --sort=-refname >actual && - test_cmp expected actual + cat >expect <<-EOF + refs/tags/testtag + refs/remotes/origin/master + refs/heads/master + EOF + git for-each-ref --format="%(refname)" --sort=-refname | + test_cmp expect - ' -cat >expected <<\EOF -'refs/heads/master' -'refs/remotes/origin/master' -'refs/tags/testtag' -EOF - test_expect_success 'Quoting style: shell' ' - git for-each-ref --shell --format="%(refname)" >actual && - test_cmp expected actual + '" + cat >expect <<-EOF + 'refs/heads/master' + 'refs/remotes/origin/master' + 'refs/tags/testtag' + EOF + "' + git for-each-ref --shell --format="%(refname)" | + test_cmp expect - ' test_expect_success 'Quoting style: perl' ' - git for-each-ref --perl --format="%(refname)" >actual && - test_cmp expected actual + git for-each-ref --perl --format="%(refname)" | + test_cmp expect - ' test_expect_success 'Quoting style: python' ' - git for-each-ref --python --format="%(refname)" >actual && - test_cmp expected actual + git for-each-ref --python --format="%(refname)" | + test_cmp expect - ' -cat >expected <<\EOF -"refs/heads/master" -"refs/remotes/origin/master" -"refs/tags/testtag" -EOF - test_expect_success 'Quoting style: tcl' ' - git for-each-ref --tcl --format="%(refname)" >actual && - test_cmp expected actual + cat >expect <<-EOF + "refs/heads/master" + "refs/remotes/origin/master" + "refs/tags/testtag" + EOF + git for-each-ref --tcl --format="%(refname)" | + test_cmp expect - ' -for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do - test_expect_success "more than one quoting style: $i" " - git for-each-ref $i 2>&1 | (read line && - case \$line in - \"error: more than one quoting style\"*) : happy;; - *) false - esac) - " -done - -cat >expected <<\EOF -master -testtag -EOF - +test_expect_success 'more than one quoting styles' ' + cat >expect <<-EOF + error: more than one quoting style? + EOF + git for-each-ref --perl --shell 2>&1 | head -n 1 | + test_cmp expect - && + git for-each-ref -s --python 2>&1 | head -n 1 | + test_cmp expect - && + git for-each-ref --python --tcl 2>&1 | head -n 1 | + test_cmp expect - && + git for-each-ref --tcl --perl 2>&1 | head -n 1 | + test_cmp expect - +' test_expect_success 'Check short refname format' ' - (git for-each-ref --format="%(refname:short)" refs/heads && - git for-each-ref --format="%(refname:short)" refs/tags) >actual && - test_cmp expected actual + cat >expect <<-EOF + master + testtag + EOF + git for-each-ref --format="%(refname:short)" refs/heads refs/tags | + test_cmp expect - ' -cat >expected <<EOF -origin/master -EOF - test_expect_success 'Check short upstream format' ' - git for-each-ref --format="%(upstream:short)" refs/heads >actual && - test_cmp expected actual + cat >expect <<-EOF + origin/master + EOF + git for-each-ref --format="%(upstream:short)" refs/heads | + test_cmp expect - ' -cat >expected <<EOF -67a36f1 -EOF - test_expect_success 'Check short objectname format' ' - git for-each-ref --format="%(objectname:short)" refs/heads >actual && - test_cmp expected actual + cat >expect <<-EOF + 67a36f1 + EOF + git for-each-ref --format="%(objectname:short)" refs/heads | + test_cmp expect - ' test_expect_success 'Check for invalid refname format' ' - test_must_fail git for-each-ref --format="%(refname:INVALID)" + silent test_must_fail git for-each-ref --format="%(refname:INVALID)" ' -cat >expected <<\EOF -heads/master -tags/master -EOF - test_expect_success 'Check ambiguous head and tag refs (strict)' ' + cat >expect <<-EOF + heads/master + tags/master + EOF git config --bool core.warnambiguousrefs true && - git checkout -b newtag && + git checkout -q -b newtag && echo "Using $datestamp" > one && git add one && - git commit -m "Branch" && + git commit -q -m "Branch" && setdate_and_increment && - git tag -m "Tagging at $datestamp" master && - git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual && - test_cmp expected actual + quiet git tag -m "Tagging at $datestamp" master && + f="%(refname:short)" && + git for-each-ref --format "$f" refs/heads/master refs/tags/master | + test_cmp expect - ' -cat >expected <<\EOF -heads/master -master -EOF - test_expect_success 'Check ambiguous head and tag refs (loose)' ' + cat >expect <<-EOF + heads/master + master + EOF git config --bool core.warnambiguousrefs false && - git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual && - test_cmp expected actual + f="%(refname:short)" && + git for-each-ref --format "$f" refs/heads/master refs/tags/master | + test_cmp expect - ' -cat >expected <<\EOF -heads/ambiguous -ambiguous -EOF - test_expect_success 'Check ambiguous head and tag refs II (loose)' ' - git checkout master && + cat >expect <<-EOF + heads/ambiguous + ambiguous + EOF + git checkout -q master && git tag ambiguous testtag^0 && git branch ambiguous testtag^0 && - git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual && - test_cmp expected actual + f="%(refname:short)" && + git for-each-ref --format "$f" refs/heads/ambiguous refs/tags/ambiguous | + test_cmp expect - ' test_expect_success 'an unusual tag with an incomplete line' ' - git tag -m "bogo" bogo && bogo=$(git cat-file tag bogo) && bogo=$(printf "%s" "$bogo" | git mktag) && git tag -f bogo "$bogo" && git for-each-ref --format "%(body)" refs/tags/bogo - ' test_expect_success 'create tag with subject and body content' ' - cat >>msg <<-\EOF && + cat >msg <<-\EOF && the subject line first body line
@@ -395,8 +412,9 @@ test_expect_success 'create tag with multiline subject' ' first body line second body line EOF - git tag -F msg multiline + quiet git tag -F msg multiline ' + test_atom refs/tags/multiline subject 'first subject line second subject line' test_atom refs/tags/multiline contents:subject 'first subject line second subject line' test_atom refs/tags/multiline body 'first body line
@@ -417,9 +435,9 @@ test_expect_success GPG 'create signed tags' ' git tag -s -m "" signed-empty && git tag -s -m "subject line" signed-short && cat >msg <<-\EOF && - subject line + subject line - body contents + body contents EOF git tag -s -F msg signed-long '
Signature · 1 line
1.7.8
Re: [PATCH 1/5] t6300 (for-each-ref): modernize style
Am 3/1/2012 2:45, schrieb Tom Grennan:
Review
Quoted 2 lines
(quoted diff) +2
-0+ git for-each-ref --format="%(refname)" --sort=refname | + test_cmp expect -
DON'T DO THIS. It loses the exit code of the git invocation.
(And it is contrary to my effort to move all test_cmp away from being used in a pipeline because I want to use a comparator tool that does not understand '-' as stdin.)
-- Hannes
Re: [PATCH 1/5] t6300 (for-each-ref): modernize style
Quoted 9 lines · Johannes Sixt
Am 3/1/2012 2:45, schrieb Tom Grennan:
Review
Quoted 2 lines
(quoted diff) +2
-0+ git for-each-ref --format="%(refname)" --sort=refname | + test_cmp expect -DON'T DO THIS. It loses the exit code of the git invocation.
(And it is contrary to my effort to move all
test_cmpaway from being used in a pipeline because I want to use a comparator tool that does not understand '-' as stdin.)
OK, with bash, one could get that from PIPESTATUS, but that doesn't help if you're not using bash or desire a different comparator.
Thanks,
TomG
PATCH 2/5 t5512 (ls-remote): modernize style
In reply to Tom Grennan- Guard setup with test_expect_success
- Single-quoted, tab prefaced test blocks of < 80 cols
- Redirect unwanted output
--- t/t5512-ls-remote.sh | 33 ++++++++++++++++++++++----------- 1 files changed, 22 insertions(+), 11 deletions(-)
t/t5512-ls-remote.sh +22 -11
@@ -2,14 +2,22 @@ test_description='git ls-remote' +if ! test -r test-lib.sh ; then + (cd ${0%/*} && ./${0##*/} $@) + exit $? +fi + . ./test-lib.sh +quiet () { "$@" >/dev/null; } +silent () { "$@" >/dev/null 2>&1; } + test_expect_success setup ' >file && git add file && test_tick && - git commit -m initial && + git commit -q -m initial && git tag mark && git show-ref --tags -d | sed -e "s/ / /" >expected.tag && (
@@ -51,7 +59,7 @@ test_expect_success 'ls-remote self' ' test_expect_success 'dies when no remote specified and no default remotes found' ' - test_must_fail git ls-remote + silent test_must_fail git ls-remote '
@@ -70,8 +78,8 @@ test_expect_success 'use "origin" when no remote specified' ' test_expect_success 'suppress "From <url>" with -q' ' - git ls-remote -q 2>actual_err && - test_must_fail test_cmp exp_err actual_err + quiet git ls-remote -q 2>actual_err && + test_must_fail cmp -s exp_err actual_err '
@@ -83,7 +91,7 @@ test_expect_success 'use branch.<name>.remote if possible' ' # # setup a new remote to differentiate from "origin" - git clone . other.git && + git clone -q . other.git && ( cd other.git && echo "$(git rev-parse HEAD) HEAD"
@@ -102,11 +110,13 @@ test_expect_success 'use branch.<name>.remote if possible' ' ' -cat >exp <<EOF -fatal: 'refs*master' does not appear to be a git repository -fatal: The remote end hung up unexpectedly -EOF test_expect_success 'confuses pattern as remote when no remote specified' ' + '" + cat >exp <<-EOF + fatal: 'refs*master' does not appear to be a git repository + fatal: The remote end hung up unexpectedly + EOF + "' # # Do not expect "git ls-remote <pattern>" to work; ls-remote, correctly, # confuses <pattern> for <remote>. Although ugly, this behaviour is akin
@@ -124,7 +134,7 @@ test_expect_success 'confuses pattern as remote when no remote specified' ' ' test_expect_success 'die with non-2 for wrong repository even with --exit-code' ' - git ls-remote --exit-code ./no-such-repository ;# not && + silent git ls-remote --exit-code ./no-such-repository ;# not && status=$? && test $status != 2 && test $status != 0 '
@@ -136,7 +146,8 @@ test_expect_success 'Report success even when nothing matches' ' ' test_expect_success 'Report no-match with --exit-code' ' - test_expect_code 2 git ls-remote --exit-code other.git "refs/nsn/*" >actual && + test_expect_code 2 git ls-remote --exit-code other.git "refs/nsn/*" \ + >actual && >expect && test_cmp expect actual '
Signature · 1 line
1.7.8
Re: [PATCH 2/5] t5512 (ls-remote): modernize style
Quoted 1 line · Tom Grennan
- Redirect unwanted output
[...]
t/t5512-ls-remote.sh line 20
Quoted 2 lines
t/t5512-ls-remote.sh +1
-1- git commit -m initial && + git commit -q -m initial &&
Why? When are you seeing the output, except with --verbose? In the latter case, isn't it useful to have as much output as possible?
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chPATCH 3/5 t3200 (branch): modernize style
In reply to Tom Grennan- Guard setup with test_expect_success
- Single-quoted, tab prefaced test blocks of < 80 cols
- Redirect unwanted output
- Use a "here" filter for expect generation
--- t/t3200-branch.sh | 593 +++++++++++++++++++++++++++-------------------------- 1 files changed, 304 insertions(+), 289 deletions(-)
t/t3200-branch.sh +304 -289
@@ -5,125 +5,132 @@ test_description='git branch assorted tests' +if ! test -r test-lib.sh ; then + (cd ${0%/*} && ./${0##*/} $@) + exit $? +fi + . ./test-lib.sh -test_expect_success \ - 'prepare a trivial repository' \ - 'echo Hello > A && - git update-index --add A && - git commit -m "Initial commit." && - echo World >> A && - git update-index --add A && - git commit -m "Second commit." && - HEAD=$(git rev-parse --verify HEAD)' +quiet () { "$@" >/dev/null; } +silent () { "$@" >/dev/null 2>&1; } +here () { sed 's/\\s/ /g; s/\\t/\t/g; s/\\n/\n/g' $@; } + +test_expect_success 'prepare a trivial repository' ' + echo Hello >A && + git update-index --add A && + git commit -q -m "Initial commit." && + echo World >>A && + git update-index --add A && + git commit -q -m "Second commit." && + HEAD=$(git rev-parse --verify HEAD) +' -test_expect_success \ - 'git branch --help should not have created a bogus branch' ' - test_might_fail git branch --help </dev/null >/dev/null 2>/dev/null && - test_path_is_missing .git/refs/heads/--help +test_expect_success 'git branch --help should not have created a bogus branch' ' + silent test_might_fail git branch --help </dev/null && + test_path_is_missing .git/refs/heads/--help ' test_expect_success 'branch -h in broken repository' ' - mkdir broken && - ( - cd broken && - git init && - >.git/refs/heads/master && - test_expect_code 129 git branch -h >usage 2>&1 - ) && - grep "[Uu]sage" broken/usage -' - -test_expect_success \ - 'git branch abc should create a branch' \ - 'git branch abc && test_path_is_file .git/refs/heads/abc' - -test_expect_success \ - 'git branch a/b/c should create a branch' \ - 'git branch a/b/c && test_path_is_file .git/refs/heads/a/b/c' - -cat >expect <<EOF -$_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master -EOF -test_expect_success \ - 'git branch -l d/e/f should create a branch and a log' \ - 'GIT_COMMITTER_DATE="2005-05-26 23:30" \ - git branch -l d/e/f && - test_path_is_file .git/refs/heads/d/e/f && - test_path_is_file .git/logs/refs/heads/d/e/f && - test_cmp expect .git/logs/refs/heads/d/e/f' - -test_expect_success \ - 'git branch -d d/e/f should delete a branch and a log' \ - 'git branch -d d/e/f && - test_path_is_missing .git/refs/heads/d/e/f && - test_path_is_missing .git/logs/refs/heads/d/e/f' - -test_expect_success \ - 'git branch j/k should work after branch j has been deleted' \ - 'git branch j && - git branch -d j && - git branch j/k' - -test_expect_success \ - 'git branch l should work after branch l/m has been deleted' \ - 'git branch l/m && - git branch -d l/m && - git branch l' - -test_expect_success \ - 'git branch -m dumps usage' \ - 'test_expect_code 129 git branch -m 2>err && - grep "[Uu]sage: git branch" err' - -test_expect_success \ - 'git branch -m m m/m should work' \ - 'git branch -l m && - git branch -m m m/m && - test_path_is_file .git/logs/refs/heads/m/m' - -test_expect_success \ - 'git branch -m n/n n should work' \ - 'git branch -l n/n && + git init -q broken && + test_when_finished rm -rf broken usage && + >broken/.git/refs/heads/master && + >usage 2>&1 test_expect_code 129 git --git-dir=broken/.git branch -h && + grep -q "[Uu]sage" usage +' + +test_expect_success 'git branch abc should create a branch' ' + git branch abc && test_path_is_file .git/refs/heads/abc +' + +test_expect_success 'git branch a/b/c should create a branch' ' + git branch a/b/c && test_path_is_file .git/refs/heads/a/b/c +' + +test_expect_success 'git branch -l d/e/f should create a branch and a log' ' + id="$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" + date="1117150200 +0000" + msg="branch: Created from master" + here >expect <<-EOF + $_z40 $HEAD $id $date\t$msg + EOF + GIT_COMMITTER_DATE="2005-05-26 23:30" git branch -l d/e/f && + test_path_is_file .git/refs/heads/d/e/f && + test_path_is_file .git/logs/refs/heads/d/e/f && + test_cmp expect .git/logs/refs/heads/d/e/f +' + +test_expect_success 'git branch -d d/e/f should delete a branch and a log' ' + quiet git branch -d d/e/f && + test_path_is_missing .git/refs/heads/d/e/f && + test_path_is_missing .git/logs/refs/heads/d/e/f +' + +test_expect_success 'git branch j/k should work after branch j has been deleted' ' + git branch j && + quiet git branch -d j && + git branch j/k +' + +test_expect_success 'git branch l should work after branch l/m has been deleted' ' + git branch l/m && + quiet git branch -d l/m && + git branch l +' + +test_expect_success 'git branch -m dumps usage' ' + test_expect_code 129 git branch -m 2>err && + grep -q "[Uu]sage: git branch" err +' + +test_expect_success 'git branch -m m m/m should work' ' + git branch -l m && + git branch -m m m/m && + test_path_is_file .git/logs/refs/heads/m/m +' + +test_expect_success 'git branch -m n/n n should work' ' + git branch -l n/n && git branch -m n/n n && - test_path_is_file .git/logs/refs/heads/n' + test_path_is_file .git/logs/refs/heads/n +' test_expect_success 'git branch -m o/o o should fail when o/p exists' ' git branch o/o && - git branch o/p && - test_must_fail git branch -m o/o o + git branch o/p && + silent test_must_fail git branch -m o/o o ' test_expect_success 'git branch -m q r/q should fail when r exists' ' git branch q && git branch r && - test_must_fail git branch -m q r/q + silent test_must_fail git branch -m q r/q ' test_expect_success 'git branch -M foo bar should fail when bar is checked out' ' git branch bar && - git checkout -b foo && - test_must_fail git branch -M bar foo + git checkout -q -b foo && + silent test_must_fail git branch -M bar foo ' test_expect_success 'git branch -M baz bam should succeed when baz is checked out' ' - git checkout -b baz && + git checkout -q -b baz && git branch bam && git branch -M baz bam ' test_expect_success 'git branch -M master should work when master is checked out' ' - git checkout master && + git checkout -q master && git branch -M master ' test_expect_success 'git branch -M master master should work when master is checked out' ' - git checkout master && + git checkout -q master && git branch -M master master ' test_expect_success 'git branch -M master2 master2 should work when master is checked out' ' - git checkout master && + git checkout -q master && git branch master2 && git branch -M master2 master2 '
@@ -131,7 +138,7 @@ test_expect_success 'git branch -M master2 master2 should work when master is ch test_expect_success 'git branch -v -d t should work' ' git branch t && test_path_is_file .git/refs/heads/t && - git branch -v -d t && + quiet git branch -v -d t && test_path_is_missing .git/refs/heads/t '
@@ -141,188 +148,198 @@ test_expect_success 'git branch -v -m t s should work' ' git branch -v -m t s && test_path_is_missing .git/refs/heads/t && test_path_is_file .git/refs/heads/s && - git branch -d s + quiet git branch -d s ' test_expect_success 'git branch -m -d t s should fail' ' git branch t && test_path_is_file .git/refs/heads/t && - test_must_fail git branch -m -d t s && - git branch -d t && + silent test_must_fail git branch -m -d t s && + quiet git branch -d t && test_path_is_missing .git/refs/heads/t ' test_expect_success 'git branch --list -d t should fail' ' git branch t && test_path_is_file .git/refs/heads/t && - test_must_fail git branch --list -d t && - git branch -d t && + silent test_must_fail git branch --list -d t && + quiet git branch -d t && test_path_is_missing .git/refs/heads/t ' -mv .git/config .git/config-saved - test_expect_success 'git branch -m q q2 without config should succeed' ' + mv .git/config .git/config-saved && + test_when_finished mv .git/config-saved .git/config && git branch -m q q2 && git branch -m q2 q ' -mv .git/config-saved .git/config - -git config branch.s/s.dummy Hello - -test_expect_success \ - 'git branch -m s/s s should work when s/t is deleted' \ - 'git branch -l s/s && +test_expect_success 'git branch -m s/s s should work when s/t is deleted' ' + git config branch.s/s.dummy Hello + git branch -l s/s && test_path_is_file .git/logs/refs/heads/s/s && - git branch -l s/t && + git branch -l s/t && test_path_is_file .git/logs/refs/heads/s/t && - git branch -d s/t && - git branch -m s/s s && - test_path_is_file .git/logs/refs/heads/s' - -test_expect_success 'config information was renamed, too' \ - "test $(git config branch.s.dummy) = Hello && - test_must_fail git config branch.s/s/dummy" + quiet git branch -d s/t && + git branch -m s/s s && + test_path_is_file .git/logs/refs/heads/s +' -test_expect_success 'renaming a symref is not allowed' \ +test_expect_success 'config information was renamed, too' ' + test $(git config branch.s.dummy) = Hello && + silent test_must_fail git config branch.s/s/dummy ' + +test_expect_success 'renaming a symref is not allowed' ' git symbolic-ref refs/heads/master2 refs/heads/master && - test_must_fail git branch -m master2 master3 && - git symbolic-ref refs/heads/master2 && + silent test_must_fail git branch -m master2 master3 && + quiet git symbolic-ref refs/heads/master2 && test_path_is_file .git/refs/heads/master && test_path_is_missing .git/refs/heads/master3 ' -test_expect_success SYMLINKS \ - 'git branch -m u v should fail when the reflog for u is a symlink' ' - git branch -l u && - mv .git/logs/refs/heads/u real-u && - ln -s real-u .git/logs/refs/heads/u && - test_must_fail git branch -m u v -' - -test_expect_success 'test tracking setup via --track' \ - 'git config remote.local.url . && - git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --track my1 local/master && - test $(git config branch.my1.remote) = local && - test $(git config branch.my1.merge) = refs/heads/master' - -test_expect_success 'test tracking setup (non-wildcard, matching)' \ - 'git config remote.local.url . && - git config remote.local.fetch refs/heads/master:refs/remotes/local/master && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --track my4 local/master && - test $(git config branch.my4.remote) = local && - test $(git config branch.my4.merge) = refs/heads/master' - -test_expect_success 'test tracking setup (non-wildcard, not matching)' \ - 'git config remote.local.url . && - git config remote.local.fetch refs/heads/s:refs/remotes/local/s && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --track my5 local/master && - ! test "$(git config branch.my5.remote)" = local && - ! test "$(git config branch.my5.merge)" = refs/heads/master' - -test_expect_success 'test tracking setup via config' \ - 'git config branch.autosetupmerge true && - git config remote.local.url . && - git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch my3 local/master && - test $(git config branch.my3.remote) = local && - test $(git config branch.my3.merge) = refs/heads/master' - -test_expect_success 'test overriding tracking setup via --no-track' \ - 'git config branch.autosetupmerge true && - git config remote.local.url . && - git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --no-track my2 local/master && - git config branch.autosetupmerge false && - ! test "$(git config branch.my2.remote)" = local && - ! test "$(git config branch.my2.merge)" = refs/heads/master' - -test_expect_success 'no tracking without .fetch entries' \ - 'git config branch.autosetupmerge true && - git branch my6 s && - git config branch.automsetupmerge false && - test -z "$(git config branch.my6.remote)" && - test -z "$(git config branch.my6.merge)"' - -test_expect_success 'test tracking setup via --track but deeper' \ - 'git config remote.local.url . && - git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/o/o || git fetch local) && - git branch --track my7 local/o/o && - test "$(git config branch.my7.remote)" = local && - test "$(git config branch.my7.merge)" = refs/heads/o/o' - -test_expect_success 'test deleting branch deletes branch config' \ - 'git branch -d my7 && - test -z "$(git config branch.my7.remote)" && - test -z "$(git config branch.my7.merge)"' - -test_expect_success 'test deleting branch without config' \ - 'git branch my7 s && - sha1=$(git rev-parse my7 | cut -c 1-7) && - echo "Deleted branch my7 (was $sha1)." >expect && - git branch -d my7 >actual 2>&1 && - test_i18ncmp expect actual' - -test_expect_success 'test --track without .fetch entries' \ - 'git branch --track my8 && - test "$(git config branch.my8.remote)" && - test "$(git config branch.my8.merge)"' - -test_expect_success \ - 'branch from non-branch HEAD w/autosetupmerge=always' \ - 'git config branch.autosetupmerge always && - git branch my9 HEAD^ && - git config branch.autosetupmerge false' - -test_expect_success \ - 'branch from non-branch HEAD w/--track causes failure' \ - 'test_must_fail git branch --track my10 HEAD^' - -test_expect_success \ - 'branch from tag w/--track causes failure' \ - 'git tag foobar && - test_must_fail git branch --track my11 foobar' +test_expect_success SYMLINKS 'git branch -m u v should fail when the reflog for u is a symlink' ' + git branch -l u && + mv .git/logs/refs/heads/u real-u && + ln -s real-u .git/logs/refs/heads/u && + silent test_must_fail git branch -m u v +' + +test_expect_success 'test tracking setup via --track' ' + git config remote.local.url . && + git config remote.local.fetch refs/heads/*:refs/remotes/local/* && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --track my1 local/master && + test $(git config branch.my1.remote) = local && + test $(git config branch.my1.merge) = refs/heads/master +' + +test_expect_success 'test tracking setup (non-wildcard, matching)' ' + git config remote.local.url . && + git config remote.local.fetch \ + refs/heads/master:refs/remotes/local/master && + (git show-ref -q refs/remotes/local/master || git fetch local) && + quiet git branch --track my4 local/master && + test $(git config branch.my4.remote) = local && + test $(git config branch.my4.merge) = refs/heads/master +' + +test_expect_success 'test tracking setup (non-wildcard, not matching)' ' + git config remote.local.url . && + git config remote.local.fetch refs/heads/s:refs/remotes/local/s && + (git show-ref -q refs/remotes/local/master || git fetch local) && + quiet git branch --track my5 local/master && + ! test "$(git config branch.my5.remote)" = local && + ! test "$(git config branch.my5.merge)" = refs/heads/master +' + +test_expect_success 'test tracking setup via config' ' + git config branch.autosetupmerge true && + git config remote.local.url . && + git config remote.local.fetch refs/heads/*:refs/remotes/local/* && + (git show-ref -q refs/remotes/local/master || git fetch local) && + quiet git branch my3 local/master && + test $(git config branch.my3.remote) = local && + test $(git config branch.my3.merge) = refs/heads/master +' + +test_expect_success 'test overriding tracking setup via --no-track' ' + git config branch.autosetupmerge true && + git config remote.local.url . && + git config remote.local.fetch refs/heads/*:refs/remotes/local/* && + (git show-ref -q refs/remotes/local/master || git fetch local) && + git branch --no-track my2 local/master && + git config branch.autosetupmerge false && + ! test "$(git config branch.my2.remote)" = local && + ! test "$(git config branch.my2.merge)" = refs/heads/master +' + +test_expect_success 'no tracking without .fetch entries' ' + git config branch.autosetupmerge true && + git branch my6 s && + git config branch.automsetupmerge false && + test -z "$(git config branch.my6.remote)" && + test -z "$(git config branch.my6.merge)" +' + +test_expect_success 'test tracking setup via --track but deeper' ' + git config remote.local.url . && + git config remote.local.fetch refs/heads/*:refs/remotes/local/* && + (git show-ref -q refs/remotes/local/o/o || git fetch local) && + quiet git branch --track my7 local/o/o && + test "$(git config branch.my7.remote)" = local && + test "$(git config branch.my7.merge)" = refs/heads/o/o +' + +test_expect_success 'test deleting branch deletes branch config' ' + quiet git branch -d my7 && + test -z "$(git config branch.my7.remote)" && + test -z "$(git config branch.my7.merge)" +' + +test_expect_success 'test deleting branch without config' ' + git branch my7 s && + sha1=$(git rev-parse my7 | cut -c 1-7) && + echo "Deleted branch my7 (was $sha1)." >expect && + git branch -d my7 >actual 2>&1 && + test_i18ncmp expect actual +' + +test_expect_success 'test --track without .fetch entries' ' + quiet git branch --track my8 && + test "$(git config branch.my8.remote)" && + test "$(git config branch.my8.merge)" +' + +test_expect_success 'branch from non-branch HEAD w/autosetupmerge=always' ' + git config branch.autosetupmerge always && + git branch my9 HEAD^ && + git config branch.autosetupmerge false +' + +test_expect_success 'branch from non-branch HEAD w/--track causes failure' ' + silent test_must_fail git branch --track my10 HEAD^ +' + +test_expect_success 'branch from tag w/--track causes failure' ' + git tag foobar && + silent test_must_fail git branch --track my11 foobar +' # Keep this test last, as it changes the current branch -cat >expect <<EOF -$_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master -EOF -test_expect_success \ - 'git checkout -b g/h/i -l should create a branch and a log' \ - 'GIT_COMMITTER_DATE="2005-05-26 23:30" \ - git checkout -b g/h/i -l master && - test_path_is_file .git/refs/heads/g/h/i && - test_path_is_file .git/logs/refs/heads/g/h/i && - test_cmp expect .git/logs/refs/heads/g/h/i' +test_expect_success 'git checkout -b g/h/i -l should create a branch and a log' ' + id="$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" + date="1117150200 +0000" + msg="branch: Created from master" + here >expect <<-EOF + $_z40 $HEAD $id $date\t$msg + EOF + GIT_COMMITTER_DATE="2005-05-26 23:30" \ + git checkout -q -b g/h/i -l master && + test_path_is_file .git/refs/heads/g/h/i && + test_path_is_file .git/logs/refs/heads/g/h/i && + test_cmp expect .git/logs/refs/heads/g/h/i +' test_expect_success 'checkout -b makes reflog by default' ' - git checkout master && + git checkout -q master && git config --unset core.logAllRefUpdates && - git checkout -b alpha && - git rev-parse --verify alpha@{0} + git checkout -q -b alpha && + quiet git rev-parse --verify alpha@{0} ' test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' ' - git checkout master && + git checkout -q master && git config core.logAllRefUpdates false && - git checkout -b beta && - test_must_fail git rev-parse --verify beta@{0} + git checkout -q -b beta && + silent test_must_fail git rev-parse --verify beta@{0} ' test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' ' - git checkout master && - git checkout -lb gamma && + git checkout -q master && + git checkout -q -lb gamma && git config --unset core.logAllRefUpdates && - git rev-parse --verify gamma@{0} + quiet git rev-parse --verify gamma@{0} ' test_expect_success 'avoid ambiguous track' '
@@ -331,7 +348,7 @@ test_expect_success 'avoid ambiguous track' ' git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master && git config remote.ambi2.url lilili && git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master && - git branch all1 master && + silent git branch all1 master && test -z "$(git config branch.all1.merge)" '
@@ -339,9 +356,9 @@ test_expect_success 'autosetuprebase local on a tracked local branch' ' git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && git config branch.autosetuprebase local && - (git show-ref -q refs/remotes/local/o || git fetch local) && + (git show-ref -q refs/remotes/local/o || git fetch -q local) && git branch mybase && - git branch --track myr1 mybase && + quiet git branch --track myr1 mybase && test "$(git config branch.myr1.remote)" = . && test "$(git config branch.myr1.merge)" = refs/heads/mybase && test "$(git config branch.myr1.rebase)" = true
@@ -351,9 +368,9 @@ test_expect_success 'autosetuprebase always on a tracked local branch' ' git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && git config branch.autosetuprebase always && - (git show-ref -q refs/remotes/local/o || git fetch local) && + (git show-ref -q refs/remotes/local/o || git fetch -q local) && git branch mybase2 && - git branch --track myr2 mybase && + quiet git branch --track myr2 mybase && test "$(git config branch.myr2.remote)" = . && test "$(git config branch.myr2.merge)" = refs/heads/mybase && test "$(git config branch.myr2.rebase)" = true
@@ -363,9 +380,9 @@ test_expect_success 'autosetuprebase remote on a tracked local branch' ' git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && git config branch.autosetuprebase remote && - (git show-ref -q refs/remotes/local/o || git fetch local) && + (git show-ref -q refs/remotes/local/o || git fetch -q local) && git branch mybase3 && - git branch --track myr3 mybase2 && + quiet git branch --track myr3 mybase2 && test "$(git config branch.myr3.remote)" = . && test "$(git config branch.myr3.merge)" = refs/heads/mybase2 && ! test "$(git config branch.myr3.rebase)" = true
@@ -375,9 +392,9 @@ test_expect_success 'autosetuprebase never on a tracked local branch' ' git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && git config branch.autosetuprebase never && - (git show-ref -q refs/remotes/local/o || git fetch local) && + (git show-ref -q refs/remotes/local/o || git fetch -q local) && git branch mybase4 && - git branch --track myr4 mybase2 && + quiet git branch --track myr4 mybase2 && test "$(git config branch.myr4.remote)" = . && test "$(git config branch.myr4.merge)" = refs/heads/mybase2 && ! test "$(git config branch.myr4.rebase)" = true
@@ -387,8 +404,8 @@ test_expect_success 'autosetuprebase local on a tracked remote branch' ' git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && git config branch.autosetuprebase local && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --track myr5 local/master && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --track myr5 local/master && test "$(git config branch.myr5.remote)" = local && test "$(git config branch.myr5.merge)" = refs/heads/master && ! test "$(git config branch.myr5.rebase)" = true
@@ -398,8 +415,8 @@ test_expect_success 'autosetuprebase never on a tracked remote branch' ' git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && git config branch.autosetuprebase never && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --track myr6 local/master && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --track myr6 local/master && test "$(git config branch.myr6.remote)" = local && test "$(git config branch.myr6.merge)" = refs/heads/master && ! test "$(git config branch.myr6.rebase)" = true
@@ -409,8 +426,8 @@ test_expect_success 'autosetuprebase remote on a tracked remote branch' ' git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && git config branch.autosetuprebase remote && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --track myr7 local/master && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --track myr7 local/master && test "$(git config branch.myr7.remote)" = local && test "$(git config branch.myr7.merge)" = refs/heads/master && test "$(git config branch.myr7.rebase)" = true
@@ -420,8 +437,8 @@ test_expect_success 'autosetuprebase always on a tracked remote branch' ' git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && git config branch.autosetuprebase remote && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --track myr8 local/master && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --track myr8 local/master && test "$(git config branch.myr8.remote)" = local && test "$(git config branch.myr8.merge)" = refs/heads/master && test "$(git config branch.myr8.rebase)" = true
@@ -431,8 +448,8 @@ test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' ' git config --unset branch.autosetuprebase && git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --track myr9 local/master && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --track myr9 local/master && test "$(git config branch.myr9.remote)" = local && test "$(git config branch.myr9.merge)" = refs/heads/master && test "z$(git config branch.myr9.rebase)" = z
@@ -441,9 +458,9 @@ test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' ' test_expect_success 'autosetuprebase unconfigured on a tracked local branch' ' git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/o || git fetch local) && + (git show-ref -q refs/remotes/local/o || git fetch -q local) && git branch mybase10 && - git branch --track myr10 mybase2 && + quiet git branch --track myr10 mybase2 && test "$(git config branch.myr10.remote)" = . && test "$(git config branch.myr10.merge)" = refs/heads/mybase2 && test "z$(git config branch.myr10.rebase)" = z
@@ -452,8 +469,8 @@ test_expect_success 'autosetuprebase unconfigured on a tracked local branch' ' test_expect_success 'autosetuprebase unconfigured on untracked local branch' ' git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --no-track myr11 mybase2 && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --no-track myr11 mybase2 && test "z$(git config branch.myr11.remote)" = z && test "z$(git config branch.myr11.merge)" = z && test "z$(git config branch.myr11.rebase)" = z
@@ -462,8 +479,8 @@ test_expect_success 'autosetuprebase unconfigured on untracked local branch' ' test_expect_success 'autosetuprebase unconfigured on untracked remote branch' ' git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --no-track myr12 local/master && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --no-track myr12 local/master && test "z$(git config branch.myr12.remote)" = z && test "z$(git config branch.myr12.merge)" = z && test "z$(git config branch.myr12.rebase)" = z
@@ -473,8 +490,8 @@ test_expect_success 'autosetuprebase never on an untracked local branch' ' git config branch.autosetuprebase never && git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --no-track myr13 mybase2 && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --no-track myr13 mybase2 && test "z$(git config branch.myr13.remote)" = z && test "z$(git config branch.myr13.merge)" = z && test "z$(git config branch.myr13.rebase)" = z
@@ -484,8 +501,8 @@ test_expect_success 'autosetuprebase local on an untracked local branch' ' git config branch.autosetuprebase local && git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --no-track myr14 mybase2 && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --no-track myr14 mybase2 && test "z$(git config branch.myr14.remote)" = z && test "z$(git config branch.myr14.merge)" = z && test "z$(git config branch.myr14.rebase)" = z
@@ -495,8 +512,8 @@ test_expect_success 'autosetuprebase remote on an untracked local branch' ' git config branch.autosetuprebase remote && git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --no-track myr15 mybase2 && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --no-track myr15 mybase2 && test "z$(git config branch.myr15.remote)" = z && test "z$(git config branch.myr15.merge)" = z && test "z$(git config branch.myr15.rebase)" = z
@@ -506,8 +523,8 @@ test_expect_success 'autosetuprebase always on an untracked local branch' ' git config branch.autosetuprebase always && git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --no-track myr16 mybase2 && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --no-track myr16 mybase2 && test "z$(git config branch.myr16.remote)" = z && test "z$(git config branch.myr16.merge)" = z && test "z$(git config branch.myr16.rebase)" = z
@@ -517,8 +534,8 @@ test_expect_success 'autosetuprebase never on an untracked remote branch' ' git config branch.autosetuprebase never && git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --no-track myr17 local/master && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --no-track myr17 local/master && test "z$(git config branch.myr17.remote)" = z && test "z$(git config branch.myr17.merge)" = z && test "z$(git config branch.myr17.rebase)" = z
@@ -528,8 +545,8 @@ test_expect_success 'autosetuprebase local on an untracked remote branch' ' git config branch.autosetuprebase local && git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --no-track myr18 local/master && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --no-track myr18 local/master && test "z$(git config branch.myr18.remote)" = z && test "z$(git config branch.myr18.merge)" = z && test "z$(git config branch.myr18.rebase)" = z
@@ -539,8 +556,8 @@ test_expect_success 'autosetuprebase remote on an untracked remote branch' ' git config branch.autosetuprebase remote && git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --no-track myr19 local/master && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --no-track myr19 local/master && test "z$(git config branch.myr19.remote)" = z && test "z$(git config branch.myr19.merge)" = z && test "z$(git config branch.myr19.rebase)" = z
@@ -550,8 +567,8 @@ test_expect_success 'autosetuprebase always on an untracked remote branch' ' git config branch.autosetuprebase always && git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --no-track myr20 local/master && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --no-track myr20 local/master && test "z$(git config branch.myr20.remote)" = z && test "z$(git config branch.myr20.merge)" = z && test "z$(git config branch.myr20.rebase)" = z
@@ -559,8 +576,8 @@ test_expect_success 'autosetuprebase always on an untracked remote branch' ' test_expect_success 'autosetuprebase always on detached HEAD' ' git config branch.autosetupmerge always && - test_when_finished git checkout master && - git checkout HEAD^0 && + test_when_finished git checkout -q master && + git checkout -q HEAD^0 && git branch my11 && test -z "$(git config branch.my11.remote)" && test -z "$(git config branch.my11.merge)"
@@ -568,20 +585,20 @@ test_expect_success 'autosetuprebase always on detached HEAD' ' test_expect_success 'detect misconfigured autosetuprebase (bad value)' ' git config branch.autosetuprebase garbage && - test_must_fail git branch + silent test_must_fail git branch ' test_expect_success 'detect misconfigured autosetuprebase (no value)' ' git config --unset branch.autosetuprebase && echo "[branch] autosetuprebase" >> .git/config && - test_must_fail git branch && + silent test_must_fail git branch && git config --unset branch.autosetuprebase ' test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' ' - git checkout my9 && + git checkout -q my9 && git config --unset branch.my8.merge && - test_must_fail git branch -d my8 + silent test_must_fail git branch -d my8 ' test_expect_success 'attempt to delete a branch merged to its base' '
@@ -589,32 +606,30 @@ test_expect_success 'attempt to delete a branch merged to its base' ' # we would not have allowed deleting my8 that is not merged # to my9, but it is set to track master that already has my8 git config branch.my8.merge refs/heads/master && - git branch -d my8 + silent git branch -d my8 ' test_expect_success 'attempt to delete a branch merged to its base' ' - git checkout master && + git checkout -q master && echo Third >>A && - git commit -m "Third commit" A && - git branch -t my10 my9 && - git branch -f my10 HEAD^ && + git commit -q -m "Third commit" A && + quiet git branch -t my10 my9 && + quiet git branch -f my10 HEAD^ && # we are on master which is at the third commit, and my10 # is behind us, so traditionally we would have allowed deleting # it; but my10 is set to track my9 that is further behind. - test_must_fail git branch -d my10 + silent test_must_fail git branch -d my10 ' test_expect_success 'use set-upstream on the current branch' ' - git checkout master && - git --bare init myupstream.git && - git push myupstream.git master:refs/heads/frotz && + git checkout -q master && + git --bare init -q myupstream.git && + git push -q myupstream.git master:refs/heads/frotz && git remote add origin myupstream.git && - git fetch && - git branch --set-upstream master origin/frotz && - + git fetch -q && + quiet git branch --set-upstream master origin/frotz && test "z$(git config branch.master.remote)" = "zorigin" && test "z$(git config branch.master.merge)" = "zrefs/heads/frotz" - ' test_expect_success 'use --edit-description' '
@@ -637,7 +652,7 @@ test_expect_success 'detect typo in branch name when using --edit-description' ' ( EDITOR=./editor && export EDITOR && - test_must_fail git branch --edit-description no-such-branch + silent test_must_fail git branch --edit-description no-such-branch ) '
@@ -645,11 +660,11 @@ test_expect_success 'refuse --edit-description on unborn branch for now' ' write_script editor <<-\EOF && echo "New contents" >"$1" EOF - git checkout --orphan unborn && + git checkout -q --orphan unborn && ( EDITOR=./editor && export EDITOR && - test_must_fail git branch --edit-description + silent test_must_fail git branch --edit-description ) '
Signature · 1 line
1.7.8
PATCH 4/5 t0040 (parse-options): modernize style
In reply to Tom Grennan- Guard setup with test_expect_success
- Single-quoted, tab prefaced test blocks of < 80 cols
- Redirect unwanted output
--- t/t0040-parse-options.sh | 519 ++++++++++++++++++++++------------------------ 1 files changed, 245 insertions(+), 274 deletions(-)
t/t0040-parse-options.sh +245 -274
@@ -5,353 +5,324 @@ test_description='our own option parser' +if ! test -r test-lib.sh ; then + (cd ${0%/*} && ./${0##*/} $@) + exit $? +fi + . ./test-lib.sh -cat > expect << EOF -usage: test-parse-options <options> - - -b, --boolean get a boolean - -4, --or4 bitwise-or boolean with ...0100 - --neg-or4 same as --no-or4 - - -i, --integer <n> get a integer - -j <n> get a integer, too - --set23 set integer to 23 - -t <time> get timestamp of <time> - -L, --length <str> get length of <str> - -F, --file <file> set file to <file> - -String options - -s, --string <string> - get a string - --string2 <str> get another string - --st <st> get another string (pervert ordering) - -o <str> get another string - --default-string set string to default - --list <str> add str to list - -Magic arguments - --quux means --quux - -NUM set integer to NUM - + same as -b - --ambiguous positive ambiguity - --no-ambiguous negative ambiguity - -Standard options - --abbrev[=<n>] use <n> digits to display SHA-1s - -v, --verbose be verbose - -n, --dry-run dry run - -q, --quiet be quiet - -EOF +silent () { "$@" >/dev/null 2>&1; } test_expect_success 'test help' ' - test_must_fail test-parse-options -h > output 2> output.err && - test ! -s output.err && - test_cmp expect output + sed -e "s/^|//" >expect <<-\EOF && + |usage: test-parse-options <options> + + | -b, --boolean get a boolean + | -4, --or4 bitwise-or boolean with ...0100 + | --neg-or4 same as --no-or4 + + | -i, --integer <n> get a integer + | -j <n> get a integer, too + | --set23 set integer to 23 + | -t <time> get timestamp of <time> + | -L, --length <str> get length of <str> + | -F, --file <file> set file to <file> + + |String options + | -s, --string <string> + | get a string + | --string2 <str> get another string + | --st <st> get another string (pervert ordering) + | -o <str> get another string + | --default-string set string to default + | --list <str> add str to list + + |Magic arguments + | --quux means --quux + | -NUM set integer to NUM + | + same as -b + | --ambiguous positive ambiguity + | --no-ambiguous negative ambiguity + + |Standard options + | --abbrev[=<n>] use <n> digits to display SHA-1s + | -v, --verbose be verbose + | -n, --dry-run dry run + | -q, --quiet be quiet + + EOF + cp expect expect.err + test_must_fail test-parse-options -h 2>err | test_cmp expect - && + test ! -s err ' -mv expect expect.err - -cat > expect << EOF -boolean: 2 -integer: 1729 -timestamp: 0 -string: 123 -abbrev: 7 -verbose: 2 -quiet: no -dry run: yes -file: prefix/my.file -EOF - test_expect_success 'short options' ' - test-parse-options -s123 -b -i 1729 -b -vv -n -F my.file \ - > output 2> output.err && - test_cmp expect output && - test ! -s output.err + cat >expect <<-\EOF && + boolean: 2 + integer: 1729 + timestamp: 0 + string: 123 + abbrev: 7 + verbose: 2 + quiet: no + dry run: yes + file: prefix/my.file + EOF + test-parse-options -s123 -b -i 1729 -b -vv -n -F my.file 2>err | + test_cmp expect - && + test ! -s err ' -cat > expect << EOF -boolean: 2 -integer: 1729 -timestamp: 0 -string: 321 -abbrev: 10 -verbose: 2 -quiet: no -dry run: no -file: prefix/fi.le -EOF - test_expect_success 'long options' ' + cat >expect <<-\EOF && + boolean: 2 + integer: 1729 + timestamp: 0 + string: 321 + abbrev: 10 + verbose: 2 + quiet: no + dry run: no + file: prefix/fi.le + EOF test-parse-options --boolean --integer 1729 --boolean --string2=321 \ - --verbose --verbose --no-dry-run --abbrev=10 --file fi.le\ - --obsolete > output 2> output.err && - test ! -s output.err && - test_cmp expect output + --verbose --verbose --no-dry-run --abbrev=10 --file fi.le \ + --obsolete 2>err | test_cmp expect - && + test ! -s err ' test_expect_success 'missing required value' ' - test-parse-options -s; - test $? = 129 && - test-parse-options --string; - test $? = 129 && - test-parse-options --file; - test $? = 129 + silent test_expect_code 129 test-parse-options -s && + silent test_expect_code 129 test-parse-options --string && + silent test_expect_code 129 test-parse-options --file ' -cat > expect << EOF -boolean: 1 -integer: 13 -timestamp: 0 -string: 123 -abbrev: 7 -verbose: 0 -quiet: no -dry run: no -file: (not set) -arg 00: a1 -arg 01: b1 -arg 02: --boolean -EOF - test_expect_success 'intermingled arguments' ' + cat >expect <<-\EOF && + boolean: 1 + integer: 13 + timestamp: 0 + string: 123 + abbrev: 7 + verbose: 0 + quiet: no + dry run: no + file: (not set) + arg 00: a1 + arg 01: b1 + arg 02: --boolean + EOF test-parse-options a1 --string 123 b1 --boolean -j 13 -- --boolean \ - > output 2> output.err && - test ! -s output.err && - test_cmp expect output + 2>err | test_cmp expect - && + test ! -s err ' -cat > expect << EOF -boolean: 0 -integer: 2 -timestamp: 0 -string: (not set) -abbrev: 7 -verbose: 0 -quiet: no -dry run: no -file: (not set) -EOF - test_expect_success 'unambiguously abbreviated option' ' - test-parse-options --int 2 --boolean --no-bo > output 2> output.err && - test ! -s output.err && - test_cmp expect output + cat >expect <<-\EOF && + boolean: 0 + integer: 2 + timestamp: 0 + string: (not set) + abbrev: 7 + verbose: 0 + quiet: no + dry run: no + file: (not set) + EOF + test-parse-options --int 2 --boolean --no-bo 2>err | + test_cmp expect - && + test ! -s err ' test_expect_success 'unambiguously abbreviated option with "="' ' - test-parse-options --int=2 > output 2> output.err && - test ! -s output.err && - test_cmp expect output + test-parse-options --int=2 2>err | test_cmp expect -&& + test ! -s err ' test_expect_success 'ambiguously abbreviated option' ' - test-parse-options --strin 123; - test $? = 129 + silent test_expect_code 129 test-parse-options --strin 123 ' -cat > expect << EOF -boolean: 0 -integer: 0 -timestamp: 0 -string: 123 -abbrev: 7 -verbose: 0 -quiet: no -dry run: no -file: (not set) -EOF - test_expect_success 'non ambiguous option (after two options it abbreviates)' ' - test-parse-options --st 123 > output 2> output.err && - test ! -s output.err && - test_cmp expect output + cat >expect <<-\EOF && + boolean: 0 + integer: 0 + timestamp: 0 + string: 123 + abbrev: 7 + verbose: 0 + quiet: no + dry run: no + file: (not set) + EOF + test-parse-options --st 123 2>err | test_cmp expect - && + test ! -s err ' -cat > typo.err << EOF -error: did you mean \`--boolean\` (with two dashes ?) -EOF - test_expect_success 'detect possible typos' ' - test_must_fail test-parse-options -boolean > output 2> output.err && - test ! -s output && - test_cmp typo.err output.err + cat >typo.err <<-\EOF && + error: did you mean `--boolean` (with two dashes ?) + EOF + >expect + test_must_fail test-parse-options -boolean 2>err | test_cmp expect - && + test_cmp typo.err err ' -cat > expect <<EOF -boolean: 0 -integer: 0 -timestamp: 0 -string: (not set) -abbrev: 7 -verbose: 0 -quiet: no -dry run: no -file: (not set) -arg 00: --quux -EOF - test_expect_success 'keep some options as arguments' ' - test-parse-options --quux > output 2> output.err && - test ! -s output.err && - test_cmp expect output + cat >expect <<-\EOF && + boolean: 0 + integer: 0 + timestamp: 0 + string: (not set) + abbrev: 7 + verbose: 0 + quiet: no + dry run: no + file: (not set) + arg 00: --quux + EOF + test-parse-options --quux 2>err | test_cmp expect - && + test ! -s err ' -cat > expect <<EOF -boolean: 0 -integer: 0 -timestamp: 1 -string: default -abbrev: 7 -verbose: 0 -quiet: yes -dry run: no -file: (not set) -arg 00: foo -EOF - test_expect_success 'OPT_DATE() and OPT_SET_PTR() work' ' - test-parse-options -t "1970-01-01 00:00:01 +0000" --default-string \ - foo -q > output 2> output.err && - test ! -s output.err && - test_cmp expect output + cat >expect <<-\EOF && + boolean: 0 + integer: 0 + timestamp: 1 + string: default + abbrev: 7 + verbose: 0 + quiet: yes + dry run: no + file: (not set) + arg 00: foo + EOF + test-parse-options -t "1970-01-01 00:00:01 +0000" \ + --default-string foo -q 2>err | test_cmp expect - && + test ! -s err ' -cat > expect <<EOF -Callback: "four", 0 -boolean: 5 -integer: 4 -timestamp: 0 -string: (not set) -abbrev: 7 -verbose: 0 -quiet: no -dry run: no -file: (not set) -EOF - test_expect_success 'OPT_CALLBACK() and OPT_BIT() work' ' - test-parse-options --length=four -b -4 > output 2> output.err && - test ! -s output.err && - test_cmp expect output + cat >expect <<-\EOF && + Callback: "four", 0 + boolean: 5 + integer: 4 + timestamp: 0 + string: (not set) + abbrev: 7 + verbose: 0 + quiet: no + dry run: no + file: (not set) + EOF + test-parse-options --length=four -b -4 2>err | test_cmp expect - && + test ! -s err ' -cat > expect <<EOF -Callback: "not set", 1 -EOF - test_expect_success 'OPT_CALLBACK() and callback errors work' ' - test_must_fail test-parse-options --no-length > output 2> output.err && - test_cmp expect output && - test_cmp expect.err output.err + cat >expect <<-\EOF && + Callback: "not set", 1 + EOF + test_must_fail test-parse-options --no-length 2>err | + test_cmp expect - && + test_cmp expect.err err ' -cat > expect <<EOF -boolean: 1 -integer: 23 -timestamp: 0 -string: (not set) -abbrev: 7 -verbose: 0 -quiet: no -dry run: no -file: (not set) -EOF - test_expect_success 'OPT_BIT() and OPT_SET_INT() work' ' - test-parse-options --set23 -bbbbb --no-or4 > output 2> output.err && - test ! -s output.err && - test_cmp expect output + cat >expect <<-\EOF && + boolean: 1 + integer: 23 + timestamp: 0 + string: (not set) + abbrev: 7 + verbose: 0 + quiet: no + dry run: no + file: (not set) + EOF + test-parse-options --set23 -bbbbb --no-or4 2>err | test_cmp expect - && + test ! -s err ' test_expect_success 'OPT_NEGBIT() and OPT_SET_INT() work' ' - test-parse-options --set23 -bbbbb --neg-or4 > output 2> output.err && - test ! -s output.err && - test_cmp expect output + test-parse-options --set23 -bbbbb --neg-or4 2>err | test_cmp expect - && + test ! -s err ' -cat > expect <<EOF -boolean: 6 -integer: 0 -timestamp: 0 -string: (not set) -abbrev: 7 -verbose: 0 -quiet: no -dry run: no -file: (not set) -EOF - test_expect_success 'OPT_BIT() works' ' - test-parse-options -bb --or4 > output 2> output.err && - test ! -s output.err && - test_cmp expect output + cat >expect <<-\EOF && + boolean: 6 + integer: 0 + timestamp: 0 + string: (not set) + abbrev: 7 + verbose: 0 + quiet: no + dry run: no + file: (not set) + EOF + test-parse-options -bb --or4 2>err | test_cmp expect - && + test ! -s err ' test_expect_success 'OPT_NEGBIT() works' ' - test-parse-options -bb --no-neg-or4 > output 2> output.err && - test ! -s output.err && - test_cmp expect output + test-parse-options -bb --no-neg-or4 2>err | test_cmp expect - && + test ! -s err ' test_expect_success 'OPT_BOOLEAN() with PARSE_OPT_NODASH works' ' - test-parse-options + + + + + + > output 2> output.err && - test ! -s output.err && - test_cmp expect output + test-parse-options + + + + + + 2>err | test_cmp expect - && + test ! -s err ' -cat > expect <<EOF -boolean: 0 -integer: 12345 -timestamp: 0 -string: (not set) -abbrev: 7 -verbose: 0 -quiet: no -dry run: no -file: (not set) -EOF test_expect_success 'OPT_NUMBER_CALLBACK() works' ' - test-parse-options -12345 > output 2> output.err && - test ! -s output.err && - test_cmp expect output + cat >expect <<-\EOF && + boolean: 0 + integer: 12345 + timestamp: 0 + string: (not set) + abbrev: 7 + verbose: 0 + quiet: no + dry run: no + file: (not set) + EOF + test-parse-options -12345 2>err | test_cmp expect - && + test ! -s err ' -cat >expect <<EOF -boolean: 0 -integer: 0 -timestamp: 0 -string: (not set) -abbrev: 7 -verbose: 0 -quiet: no -dry run: no -file: (not set) -EOF - test_expect_success 'negation of OPT_NONEG flags is not ambiguous' ' - test-parse-options --no-ambig >output 2>output.err && - test ! -s output.err && - test_cmp expect output + cat >expect <<-\EOF && + boolean: 0 + integer: 0 + timestamp: 0 + string: (not set) + abbrev: 7 + verbose: 0 + quiet: no + dry run: no + file: (not set) + EOF + test-parse-options --no-ambig 2>err | test_cmp expect - && + test ! -s err ' -cat >>expect <<'EOF' -list: foo -list: bar -list: baz -EOF test_expect_success '--list keeps list of strings' ' - test-parse-options --list foo --list=bar --list=baz >output && - test_cmp expect output + cat >>expect <<-\EOF && + list: foo + list: bar + list: baz + EOF + test-parse-options --list foo --list=bar --list=baz | test_cmp expect - ' test_expect_success '--no-list resets list' ' - test-parse-options --list=other --list=irrelevant --list=options \ - --no-list --list=foo --list=bar --list=baz >output && - test_cmp expect output + test-parse-options --list=other --list=irrelevant \ + --list=options --no-list --list=foo --list=bar --list=baz | + test_cmp expect - ' test_done
Signature · 1 line
1.7.8
PATCH 5/5 t7004 (tag): modernize style
In reply to Tom Grennan- Guard setup with test_expect_success
- Single-quoted, tab prefaced test blocks of < 80 cols
- Redirect unwanted output
- Use a "here" filter for expect generation
--- t/t7004-tag.sh | 1680 ++++++++++++++++++++++++++------------------------------ 1 files changed, 783 insertions(+), 897 deletions(-)
t/t7004-tag.sh +783 -897
@@ -7,15 +7,37 @@ test_description='git tag Tests for operations with tags.' +if ! test -r test-lib.sh ; then + (cd ${0%/*} && ./${0##*/} $@) + exit $? +fi + . ./test-lib.sh . "$TEST_DIRECTORY"/lib-gpg.sh -# creating and listing lightweight tags: +quiet () { "$@" >/dev/null; } +silent () { "$@" >/dev/null 2>&1; } +here () { sed 's/\\s/ /g; s/\\t/\t/g; s/\\n/\n/g' $@; } tag_exists () { git show-ref --quiet --verify refs/tags/"$1" } +gen_header () { # name, object, type, time + cat <<-EOF && + object $2 + type $3 + tag $1 + tagger C O Mitter <[email protected]> $4 -0700 + + EOF + here +} + +get_header () { + git cat-file tag "$1" | sed -e "/BEGIN PGP/q" +} + # todo: git tag -l now returns always zero, when fixed, change this test test_expect_success 'listing all tags in an empty tree should succeed' ' git tag -l &&
@@ -27,36 +49,38 @@ test_expect_success 'listing all tags in an empty tree should output nothing' ' test `git tag | wc -l` -eq 0 ' -test_expect_success 'looking for a tag in an empty tree should fail' \ - '! (tag_exists mytag)' +test_expect_success 'looking for a tag in an empty tree should fail' ' + ! tag_exists mytag +' test_expect_success 'creating a tag in an empty tree should fail' ' - test_must_fail git tag mynotag && + silent test_must_fail git tag mynotag && ! tag_exists mynotag ' test_expect_success 'creating a tag for HEAD in an empty tree should fail' ' - test_must_fail git tag mytaghead HEAD && + silent test_must_fail git tag mytaghead HEAD && ! tag_exists mytaghead ' test_expect_success 'creating a tag for an unknown revision should fail' ' - test_must_fail git tag mytagnorev aaaaaaaaaaa && + silent test_must_fail git tag mytagnorev aaaaaaaaaaa && ! tag_exists mytagnorev ' -# commit used in the tests, test_tick is also called here to freeze the date: test_expect_success 'creating a tag using default HEAD should succeed' ' + # commit used in the tests + # test_tick is also called here to freeze the date: test_tick && - echo foo >foo && + echo >foo foo && git add foo && - git commit -m Foo && + git commit -q -m Foo && git tag mytag ' test_expect_success 'listing all tags if one exists should succeed' ' - git tag -l && - git tag + quiet git tag -l && + quiet git tag ' test_expect_success 'listing all tags if one exists should output that tag' '
@@ -66,36 +90,36 @@ test_expect_success 'listing all tags if one exists should output that tag' ' # pattern matching: -test_expect_success 'listing a tag using a matching pattern should succeed' \ - 'git tag -l mytag' +test_expect_success 'listing a tag using a matching pattern should succeed' ' + quiet git tag -l mytag +' -test_expect_success \ - 'listing a tag using a matching pattern should output that tag' \ - 'test `git tag -l mytag` = mytag' +test_expect_success 'listing a tag using a matching pattern should output that tag' ' + test `git tag -l mytag` = mytag +' # todo: git tag -l now returns always zero, when fixed, change this test -test_expect_success \ - 'listing tags using a non-matching pattern should suceed' \ - 'git tag -l xxx' +test_expect_success 'listing tags using a non-matching pattern should suceed' ' + git tag -l xxx +' -test_expect_success \ - 'listing tags using a non-matching pattern should output nothing' \ - 'test `git tag -l xxx | wc -l` -eq 0' +test_expect_success 'listing tags using a non-matching pattern should output nothing' ' + test `git tag -l xxx | wc -l` -eq 0 +' # special cases for creating tags: -test_expect_success \ - 'trying to create a tag with the name of one existing should fail' \ - 'test_must_fail git tag mytag' +test_expect_success 'trying to create a tag with the name of one existing should fail' ' + silent test_must_fail git tag mytag +' -test_expect_success \ - 'trying to create a tag with a non-valid name should fail' ' +test_expect_success 'trying to create a tag with a non-valid name should fail' ' test `git tag -l | wc -l` -eq 1 && - test_must_fail git tag "" && - test_must_fail git tag .othertag && - test_must_fail git tag "other tag" && - test_must_fail git tag "othertag^" && - test_must_fail git tag "other~tag" && + silent test_must_fail git tag "" && + silent test_must_fail git tag .othertag && + silent test_must_fail git tag "other tag" && + silent test_must_fail git tag "othertag^" && + silent test_must_fail git tag "other~tag" && test `git tag -l | wc -l` -eq 1 '
@@ -108,62 +132,59 @@ test_expect_success 'creating a tag using HEAD directly should succeed' ' test_expect_success 'trying to delete an unknown tag should fail' ' ! tag_exists unknown-tag && - test_must_fail git tag -d unknown-tag + silent test_must_fail git tag -d unknown-tag ' -cat >expect <<EOF -myhead -mytag -EOF -test_expect_success \ - 'trying to delete tags without params should succeed and do nothing' ' - git tag -l > actual && test_cmp expect actual && +test_expect_success 'trying to delete tags without params should succeed and do nothing' ' + cat >expect <<-EOF && + myhead + mytag + EOF + git tag -l | test_cmp expect - && git tag -d && - git tag -l > actual && test_cmp expect actual + git tag -l | test_cmp expect - ' -test_expect_success \ - 'deleting two existing tags in one command should succeed' ' +test_expect_success 'deleting two existing tags in one command should succeed' ' tag_exists mytag && tag_exists myhead && - git tag -d mytag myhead && + quiet git tag -d mytag myhead && ! tag_exists mytag && ! tag_exists myhead ' -test_expect_success \ - 'creating a tag with the name of another deleted one should succeed' ' +test_expect_success 'creating a tag with the name of another deleted one should succeed' ' ! tag_exists mytag && git tag mytag && tag_exists mytag ' -test_expect_success \ - 'trying to delete two tags, existing and not, should fail in the 2nd' ' +test_expect_success 'trying to delete two tags, existing and not, should fail in the 2nd' ' tag_exists mytag && ! tag_exists myhead && - test_must_fail git tag -d mytag anothertag && + silent test_must_fail git tag -d mytag anothertag && ! tag_exists mytag && ! tag_exists myhead ' -test_expect_success 'trying to delete an already deleted tag should fail' \ - 'test_must_fail git tag -d mytag' +test_expect_success 'trying to delete an already deleted tag should fail' ' + silent test_must_fail git tag -d mytag +' # listing various tags with pattern matching: -cat >expect <<EOF -a1 -aa1 -cba -t210 -t211 -v0.2.1 -v1.0 -v1.0.1 -v1.1.3 -EOF test_expect_success 'listing all tags should print them ordered' ' + cat >expect <<-EOF && + a1 + aa1 + cba + t210 + t211 + v0.2.1 + v1.0 + v1.0.1 + v1.1.3 + EOF git tag v1.0.1 && git tag t211 && git tag aa1 &&
@@ -173,561 +194,486 @@ test_expect_success 'listing all tags should print them ordered' ' git tag a1 && git tag v1.0 && git tag t210 && - git tag -l > actual && - test_cmp expect actual && - git tag > actual && - test_cmp expect actual + git tag -l | test_cmp expect - && + git tag | test_cmp expect - ' -cat >expect <<EOF -a1 -aa1 -cba -EOF -test_expect_success \ - 'listing tags with substring as pattern must print those matching' ' - rm *a* && - git tag -l "*a*" > current && - test_cmp expect current -' - -cat >expect <<EOF -v0.2.1 -v1.0.1 -EOF -test_expect_success \ - 'listing tags with a suffix as pattern must print those matching' ' - git tag -l "*.1" > actual && - test_cmp expect actual +test_expect_success 'listing tags with substring as pattern must print those matching' ' + cat >expect <<-EOF && + a1 + aa1 + cba + EOF + git tag -l "*a*" | test_cmp expect - ' -cat >expect <<EOF -t210 -t211 -EOF -test_expect_success \ - 'listing tags with a prefix as pattern must print those matching' ' - git tag -l "t21*" > actual && - test_cmp expect actual +test_expect_success 'listing tags with a suffix as pattern must print those matching' ' + cat >expect <<-EOF && + v0.2.1 + v1.0.1 + EOF + git tag -l "*.1" | test_cmp expect - ' -cat >expect <<EOF -a1 -EOF -test_expect_success \ - 'listing tags using a name as pattern must print that one matching' ' - git tag -l a1 > actual && - test_cmp expect actual +test_expect_success 'listing tags with a prefix as pattern must print those matching' ' + cat >expect <<-EOF && + t210 + t211 + EOF + git tag -l "t21*" | test_cmp expect - ' -cat >expect <<EOF -v1.0 -EOF -test_expect_success \ - 'listing tags using a name as pattern must print that one matching' ' - git tag -l v1.0 > actual && - test_cmp expect actual +test_expect_success 'listing tags using a name as pattern must print that one matching' ' + cat >expect <<-EOF && + a1 + EOF + git tag -l a1 | test_cmp expect - ' -cat >expect <<EOF -v1.0.1 -v1.1.3 -EOF -test_expect_success \ - 'listing tags with ? in the pattern should print those matching' ' - git tag -l "v1.?.?" > actual && - test_cmp expect actual +test_expect_success 'listing tags using a name as pattern must print that one matching' ' + cat >expect <<-EOF && + v1.0 + EOF + git tag -l v1.0 | test_cmp expect - ' ->expect -test_expect_success \ - 'listing tags using v.* should print nothing because none have v.' ' - git tag -l "v.*" > actual && - test_cmp expect actual +test_expect_success 'listing tags with ? in the pattern should print those matching' ' + cat >expect <<-EOF && + v1.0.1 + v1.1.3 + EOF + git tag -l "v1.?.?" | test_cmp expect - ' -cat >expect <<EOF -v0.2.1 -v1.0 -v1.0.1 -v1.1.3 -EOF -test_expect_success \ - 'listing tags using v* should print only those having v' ' - git tag -l "v*" > actual && - test_cmp expect actual +test_expect_success 'listing tags using v.* should print nothing because none have v.' ' + >expect && + git tag -l "v.*" | test_cmp expect - +' + +test_expect_success 'listing tags using v* should print only those having v' ' + cat >expect <<-EOF && + v0.2.1 + v1.0 + v1.0.1 + v1.1.3 + EOF + git tag -l "v*" | test_cmp expect - ' test_expect_success 'tag -l can accept multiple patterns' ' - git tag -l "v1*" "v0*" >actual && - test_cmp expect actual + git tag -l "v1*" "v0*" | test_cmp expect - ' # creating and verifying lightweight tags: -test_expect_success \ - 'a non-annotated tag created without parameters should point to HEAD' ' +test_expect_success 'a non-annotated tag created without parameters should point to HEAD' ' git tag non-annotated-tag && test $(git cat-file -t non-annotated-tag) = commit && test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD) ' -test_expect_success 'trying to verify an unknown tag should fail' \ - 'test_must_fail git tag -v unknown-tag' +test_expect_success 'trying to verify an unknown tag should fail' ' + silent test_must_fail git tag -v unknown-tag +' -test_expect_success \ - 'trying to verify a non-annotated and non-signed tag should fail' \ - 'test_must_fail git tag -v non-annotated-tag' +test_expect_success 'trying to verify a non-annotated and non-signed tag should fail' ' + silent test_must_fail git tag -v non-annotated-tag +' -test_expect_success \ - 'trying to verify many non-annotated or unknown tags, should fail' \ - 'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2' +test_expect_success 'trying to verify many non-annotated or unknown tags, should fail' ' + silent test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2 +' # creating annotated tags: -get_tag_msg () { - git cat-file tag "$1" | sed -e "/BEGIN PGP/q" -} - -# run test_tick before committing always gives the time in that timezone -get_tag_header () { -cat <<EOF -object $2 -type $3 -tag $1 -tagger C O Mitter <[email protected]> $4 -0700 - -EOF -} - -commit=$(git rev-parse HEAD) -time=$test_tick - -get_tag_header annotated-tag $commit commit $time >expect -echo "A message" >>expect -test_expect_success \ - 'creating an annotated tag with -m message should succeed' ' - git tag -m "A message" annotated-tag && - get_tag_msg annotated-tag >actual && - test_cmp expect actual +test_expect_success 'creating an annotated tag with -m message should succeed' ' + commit=$(git rev-parse HEAD) && + time=$test_tick && + name="annotated-tag" && + msg="A message" && + gen_header >expect $name $commit commit $time <<-EOF && + $msg + EOF + git tag -m "$msg" $name && + get_header $name | test_cmp expect - ' -cat >msgfile <<EOF -Another message -in a file. -EOF -get_tag_header file-annotated-tag $commit commit $time >expect -cat msgfile >>expect -test_expect_success \ - 'creating an annotated tag with -F messagefile should succeed' ' - git tag -F msgfile file-annotated-tag && - get_tag_msg file-annotated-tag >actual && - test_cmp expect actual +test_expect_success 'creating an annotated tag with -F messagefile should succeed' ' + name="file-annotated-tag" && + gen_header >expect $name $commit commit $time <<-EOF && + Another message + in a file. + EOF + tail -n 2 expect >msgfile && + git tag -F msgfile $name && + get_header $name | test_cmp expect - ' -cat >inputmsg <<EOF -A message from the -standard input -EOF -get_tag_header stdin-annotated-tag $commit commit $time >expect -cat inputmsg >>expect test_expect_success 'creating an annotated tag with -F - should succeed' ' - git tag -F - stdin-annotated-tag <inputmsg && - get_tag_msg stdin-annotated-tag >actual && - test_cmp expect actual + name="stdin-annotated-tag" && + gen_header >expect $name $commit commit $time <<-EOF && + A message from the + standard input + EOF + tail -n 2 expect | git tag -F - $name && + get_header $name | test_cmp expect - ' -test_expect_success \ - 'trying to create a tag with a non-existing -F file should fail' ' +test_expect_success 'trying to create a tag with a non-existing -F file should fail' ' ! test -f nonexistingfile && ! tag_exists notag && - test_must_fail git tag -F nonexistingfile notag && + silent test_must_fail git tag -F nonexistingfile notag && ! tag_exists notag ' -test_expect_success \ - 'trying to create tags giving both -m or -F options should fail' ' - echo "message file 1" >msgfile1 && - echo "message file 2" >msgfile2 && +test_expect_success 'trying to create tags giving both -m or -F options should fail' ' + echo >msgfile1 "message file 1" && + echo >msgfile2 "message file 2" && ! tag_exists msgtag && - test_must_fail git tag -m "message 1" -F msgfile1 msgtag && + silent test_must_fail git tag -m "message 1" -F msgfile1 msgtag && ! tag_exists msgtag && - test_must_fail git tag -F msgfile1 -m "message 1" msgtag && + silent test_must_fail git tag -F msgfile1 -m "message 1" msgtag && ! tag_exists msgtag && - test_must_fail git tag -m "message 1" -F msgfile1 \ + silent test_must_fail git tag -m "message 1" -F msgfile1 \ -m "message 2" msgtag && ! tag_exists msgtag ' # blank and empty messages: -get_tag_header empty-annotated-tag $commit commit $time >expect -test_expect_success \ - 'creating a tag with an empty -m message should succeed' ' - git tag -m "" empty-annotated-tag && - get_tag_msg empty-annotated-tag >actual && - test_cmp expect actual +test_expect_success 'creating a tag with an empty -m message should succeed' ' + name="empty-annotated-tag" && + gen_header >expect $name $commit commit $time </dev/null && + git tag -m "" $name && + get_header $name | test_cmp expect - ' ->emptyfile -get_tag_header emptyfile-annotated-tag $commit commit $time >expect -test_expect_success \ - 'creating a tag with an empty -F messagefile should succeed' ' - git tag -F emptyfile emptyfile-annotated-tag && - get_tag_msg emptyfile-annotated-tag >actual && - test_cmp expect actual +test_expect_success 'creating a tag with an empty -F messagefile should succeed' ' + >emptyfile && + name="emptyfile-annotated-tag" && + gen_header >expect $name $commit commit $time </dev/null && + git tag -F emptyfile $name && + get_header $name | test_cmp expect - ' -printf '\n\n \n\t\nLeading blank lines\n' >blanksfile -printf '\n\t \t \nRepeated blank lines\n' >>blanksfile -printf '\n\n\nTrailing spaces \t \n' >>blanksfile -printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile -get_tag_header blanks-annotated-tag $commit commit $time >expect -cat >>expect <<EOF -Leading blank lines +test_expect_success 'extra blanks in the message for an annotated tag should be removed' ' + here >blanksfile <<-\EOF && -Repeated blank lines + \s\s + \t + Leading blank lines -Trailing spaces + \t\s\t\s\s + Repeated blank lines -Trailing blank lines -EOF -test_expect_success \ - 'extra blanks in the message for an annotated tag should be removed' ' - git tag -F blanksfile blanks-annotated-tag && - get_tag_msg blanks-annotated-tag >actual && - test_cmp expect actual + + + Trailing spaces\s\s\s\s\s\s\t\s\s + + Trailing blank lines + + \t\s + + EOF + name="blanks-annotated-tag" && + gen_header $name $commit commit $time >expect <<-EOF && + Leading blank lines + + Repeated blank lines + + Trailing spaces + + Trailing blank lines + EOF + git tag -F blanksfile $name && + get_header $name | test_cmp expect - ' -get_tag_header blank-annotated-tag $commit commit $time >expect -test_expect_success \ - 'creating a tag with blank -m message with spaces should succeed' ' - git tag -m " " blank-annotated-tag && - get_tag_msg blank-annotated-tag >actual && - test_cmp expect actual +test_expect_success 'creating a tag with blank -m message with spaces should succeed' ' + name="blank-annotated-tag" && + gen_header $name $commit commit $time </dev/null >expect && + git tag -m " " $name && + get_header $name | test_cmp expect - ' -echo ' ' >blankfile -echo '' >>blankfile -echo ' ' >>blankfile -get_tag_header blankfile-annotated-tag $commit commit $time >expect -test_expect_success \ - 'creating a tag with blank -F messagefile with spaces should succeed' ' - git tag -F blankfile blankfile-annotated-tag && - get_tag_msg blankfile-annotated-tag >actual && - test_cmp expect actual +test_expect_success 'creating a tag with blank -F messagefile with spaces should succeed' ' + here >blankfile <<-\EOF && + \s\s\s\s\s + + \s\s + EOF + name="blankfile-annotated-tag" && + gen_header >expect $name $commit commit $time </dev/null && + git tag -F blankfile $name && + get_header $name | test_cmp expect - ' -printf ' ' >blanknonlfile -get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect -test_expect_success \ - 'creating a tag with -F file of spaces and no newline should succeed' ' - git tag -F blanknonlfile blanknonlfile-annotated-tag && - get_tag_msg blanknonlfile-annotated-tag >actual && - test_cmp expect actual +test_expect_success 'creating a tag with -F file of spaces and no newline should succeed' ' + printf >blanknonlfile " " && + name="blanknonlfile-annotated-tag" && + gen_header >expect $name $commit commit $time </dev/null && + git tag -F blanknonlfile $name && + get_header $name | test_cmp expect - ' # messages with commented lines: -cat >commentsfile <<EOF -# A comment +test_expect_success 'creating a tag using a -F messagefile with #comments should succeed' ' + cat >commentsfile <<-EOF && + # A comment -############ -The message. -############ -One line. + ############ + The message. + ############ + One line. -# commented lines -# commented lines + # commented lines + # commented lines -Another line. -# comments + Another line. + # comments -Last line. -EOF -get_tag_header comments-annotated-tag $commit commit $time >expect -cat >>expect <<EOF -The message. -One line. + Last line. + EOF + name="comments-annotated-tag" && + gen_header $name $commit commit $time >expect <<-EOF && + The message. + One line. -Another line. + Another line. -Last line. -EOF -test_expect_success \ - 'creating a tag using a -F messagefile with #comments should succeed' ' - git tag -F commentsfile comments-annotated-tag && - get_tag_msg comments-annotated-tag >actual && - test_cmp expect actual + Last line. + EOF + git tag -F commentsfile $name && + get_header $name | test_cmp expect - ' -get_tag_header comment-annotated-tag $commit commit $time >expect -test_expect_success \ - 'creating a tag with a #comment in the -m message should succeed' ' - git tag -m "#comment" comment-annotated-tag && - get_tag_msg comment-annotated-tag >actual && - test_cmp expect actual +test_expect_success 'creating a tag with a #comment in the -m message should succeed' ' + name="comment-annotated-tag" && + gen_header $name $commit commit $time >expect </dev/null && + git tag -m "#comment" $name && + get_header $name | test_cmp expect - ' -echo '#comment' >commentfile -echo '' >>commentfile -echo '####' >>commentfile -get_tag_header commentfile-annotated-tag $commit commit $time >expect -test_expect_success \ - 'creating a tag with #comments in the -F messagefile should succeed' ' - git tag -F commentfile commentfile-annotated-tag && - get_tag_msg commentfile-annotated-tag >actual && - test_cmp expect actual +test_expect_success 'creating a tag with #comments in the -F messagefile should succeed' ' + cat >commentfile <<-EOF && + #comment + + #### + EOF + name="commentfile-annotated-tag" && + gen_header $name $commit commit $time >expect </dev/null && + git tag -F commentfile $name && + get_header $name | test_cmp expect - ' -printf '#comment' >commentnonlfile -get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect -test_expect_success \ - 'creating a tag with a file of #comment and no newline should succeed' ' - git tag -F commentnonlfile commentnonlfile-annotated-tag && - get_tag_msg commentnonlfile-annotated-tag >actual && - test_cmp expect actual +test_expect_success 'creating a tag with a file of #comment and no newline should succeed' ' + printf >commentnonlfile "#comment" && + name="commentnonlfile-annotated-tag" && + gen_header >expect $name $commit commit $time </dev/null && + git tag -F commentnonlfile $name && + get_header $name | test_cmp expect - ' # listing messages for annotated non-signed tags: -test_expect_success \ - 'listing the one-line message of a non-signed tag should succeed' ' +test_expect_success 'listing the one-line message of a non-signed tag should succeed' ' git tag -m "A msg" tag-one-line && - echo "tag-one-line" >expect && - git tag -l | grep "^tag-one-line" >actual && - test_cmp expect actual && - git tag -n0 -l | grep "^tag-one-line" >actual && - test_cmp expect actual && - git tag -n0 -l tag-one-line >actual && - test_cmp expect actual && - - echo "tag-one-line A msg" >expect && - git tag -n1 -l | grep "^tag-one-line" >actual && - test_cmp expect actual && - git tag -n -l | grep "^tag-one-line" >actual && - test_cmp expect actual && - git tag -n1 -l tag-one-line >actual && - test_cmp expect actual && - git tag -n2 -l tag-one-line >actual && - test_cmp expect actual && - git tag -n999 -l tag-one-line >actual && - test_cmp expect actual + echo >expect "tag-one-line" && + git tag -l | grep "^tag-one-line" | test_cmp expect - && + git tag -n0 -l | grep "^tag-one-line" | test_cmp expect - && + git tag -n0 -l tag-one-line | test_cmp expect - && + + echo >expect "tag-one-line A msg" && + git tag -n1 -l | grep "^tag-one-line" | test_cmp expect - && + git tag -n -l | grep "^tag-one-line" | test_cmp expect - && + git tag -n1 -l tag-one-line | test_cmp expect - && + git tag -n2 -l tag-one-line | test_cmp expect - && + git tag -n999 -l tag-one-line | test_cmp expect - ' -test_expect_success \ - 'listing the zero-lines message of a non-signed tag should succeed' ' +test_expect_success 'listing the zero-lines message of a non-signed tag should succeed' ' git tag -m "" tag-zero-lines && - echo "tag-zero-lines" >expect && - git tag -l | grep "^tag-zero-lines" >actual && - test_cmp expect actual && - git tag -n0 -l | grep "^tag-zero-lines" >actual && - test_cmp expect actual && - git tag -n0 -l tag-zero-lines >actual && - test_cmp expect actual && - - echo "tag-zero-lines " >expect && - git tag -n1 -l | grep "^tag-zero-lines" >actual && - test_cmp expect actual && - git tag -n -l | grep "^tag-zero-lines" >actual && - test_cmp expect actual && - git tag -n1 -l tag-zero-lines >actual && - test_cmp expect actual && - git tag -n2 -l tag-zero-lines >actual && - test_cmp expect actual && - git tag -n999 -l tag-zero-lines >actual && - test_cmp expect actual + echo >expect "tag-zero-lines" && + git tag -l | grep "^tag-zero-lines" | test_cmp expect - && + git tag -n0 -l | grep "^tag-zero-lines" | test_cmp expect - && + git tag -n0 -l tag-zero-lines | test_cmp expect - && + + echo >expect "tag-zero-lines " && + git tag -n1 -l | grep "^tag-zero-lines" | test_cmp expect - && + git tag -n -l | grep "^tag-zero-lines" | test_cmp expect - && + git tag -n1 -l tag-zero-lines | test_cmp expect - && + git tag -n2 -l tag-zero-lines | test_cmp expect - && + git tag -n999 -l tag-zero-lines | test_cmp expect - ' -echo 'tag line one' >annotagmsg -echo 'tag line two' >>annotagmsg -echo 'tag line three' >>annotagmsg -test_expect_success \ - 'listing many message lines of a non-signed tag should succeed' ' +test_expect_success 'listing many message lines of a non-signed tag should succeed' ' + cat >annotagmsg <<-EOF && + tag line one + tag line two + tag line three + EOF git tag -F annotagmsg tag-lines && - echo "tag-lines" >expect && - git tag -l | grep "^tag-lines" >actual && - test_cmp expect actual && - git tag -n0 -l | grep "^tag-lines" >actual && - test_cmp expect actual && - git tag -n0 -l tag-lines >actual && - test_cmp expect actual && + git tag -l | grep "^tag-lines" | test_cmp expect - && + git tag -n0 -l | grep "^tag-lines" | test_cmp expect - && + git tag -n0 -l tag-lines | test_cmp expect - && echo "tag-lines tag line one" >expect && - git tag -n1 -l | grep "^tag-lines" >actual && - test_cmp expect actual && - git tag -n -l | grep "^tag-lines" >actual && - test_cmp expect actual && - git tag -n1 -l tag-lines >actual && - test_cmp expect actual && + git tag -n1 -l | grep "^tag-lines" | test_cmp expect - && + git tag -n -l | grep "^tag-lines" | test_cmp expect - && + git tag -n1 -l tag-lines | test_cmp expect - && echo " tag line two" >>expect && - git tag -n2 -l | grep "^ *tag.line" >actual && - test_cmp expect actual && - git tag -n2 -l tag-lines >actual && - test_cmp expect actual && + git tag -n2 -l | grep "^.*tag.line" | test_cmp expect - && + git tag -n2 -l tag-lines | test_cmp expect - && echo " tag line three" >>expect && - git tag -n3 -l | grep "^ *tag.line" >actual && - test_cmp expect actual && - git tag -n3 -l tag-lines >actual && - test_cmp expect actual && - git tag -n4 -l | grep "^ *tag.line" >actual && - test_cmp expect actual && - git tag -n4 -l tag-lines >actual && - test_cmp expect actual && - git tag -n99 -l | grep "^ *tag.line" >actual && - test_cmp expect actual && - git tag -n99 -l tag-lines >actual && - test_cmp expect actual + git tag -n3 -l | grep "^.*tag.line" | test_cmp expect - && + git tag -n3 -l tag-lines | test_cmp expect - && + git tag -n4 -l | grep "^.*tag.line" | test_cmp expect - && + git tag -n4 -l tag-lines | test_cmp expect - && + git tag -n99 -l | grep "^.*tag.line" | test_cmp expect - && + git tag -n99 -l tag-lines | test_cmp expect - ' test_expect_success 'annotations for blobs are empty' ' - blob=$(git hash-object -w --stdin <<-\EOF - Blob paragraph 1. + blob=$(git hash-object -w --stdin <<-EOF + Blob paragraph 1. - Blob paragraph 2. + Blob paragraph 2. EOF ) && git tag tag-blob $blob && - echo "tag-blob " >expect && - git tag -n1 -l tag-blob >actual && - test_cmp expect actual + echo >expect "tag-blob " && + git tag -n1 -l tag-blob | test_cmp expect - ' # trying to verify annotated non-signed tags: -test_expect_success GPG \ - 'trying to verify an annotated non-signed tag should fail' ' +test_expect_success GPG 'trying to verify an annotated non-signed tag should fail' ' tag_exists annotated-tag && - test_must_fail git tag -v annotated-tag + silent test_must_fail git tag -v annotated-tag ' -test_expect_success GPG \ - 'trying to verify a file-annotated non-signed tag should fail' ' +test_expect_success GPG 'trying to verify a file-annotated non-signed tag should fail' ' tag_exists file-annotated-tag && - test_must_fail git tag -v file-annotated-tag + silent test_must_fail git tag -v file-annotated-tag ' -test_expect_success GPG \ - 'trying to verify two annotated non-signed tags should fail' ' +test_expect_success GPG 'trying to verify two annotated non-signed tags should fail' ' tag_exists annotated-tag file-annotated-tag && - test_must_fail git tag -v annotated-tag file-annotated-tag + silent test_must_fail git tag -v annotated-tag file-annotated-tag ' # creating and verifying signed tags: -get_tag_header signed-tag $commit commit $time >expect -echo 'A signed tag message' >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG 'creating a signed tag with -m message should succeed' ' - git tag -s -m "A signed tag message" signed-tag && - get_tag_msg signed-tag >actual && - test_cmp expect actual + name="signed-tag" && + msg="A signed tag message" && + gen_header >expect $name $commit commit $time <<-EOF && + $msg + -----BEGIN PGP SIGNATURE----- + EOF + git tag -s -m "$msg" $name && + get_header $name | test_cmp expect - ' -get_tag_header u-signed-tag $commit commit $time >expect -echo 'Another message' >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG 'sign with a given key id' ' - - git tag -u [email protected] -m "Another message" u-signed-tag && - get_tag_msg u-signed-tag >actual && - test_cmp expect actual - + name="u-signed-tag" && + msg="Another message" && + gen_header >expect $name $commit commit $time <<-EOF && + $msg + -----BEGIN PGP SIGNATURE----- + EOF + git tag -u [email protected] -m "$msg" $name && + get_header $name | test_cmp expect - ' test_expect_success GPG 'sign with an unknown id (1)' ' - - test_must_fail git tag -u [email protected] \ + silent test_must_fail git tag -u [email protected] \ -m "Another message" o-signed-tag - ' test_expect_success GPG 'sign with an unknown id (2)' ' - - test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag - + silent test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag ' -cat >fakeeditor <<'EOF' -#!/bin/sh -test -n "$1" && exec >"$1" -echo A signed tag message -echo from a fake editor. -EOF -chmod +x fakeeditor - -get_tag_header implied-sign $commit commit $time >expect -./fakeeditor >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG '-u implies signed tag' ' - GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign && - get_tag_msg implied-sign >actual && - test_cmp expect actual + cat <<-\EOF | write_script fakeeditor && + test -n "$1" && exec >"$1" + echo A signed tag message + echo from a fake editor. + EOF + name="implied-signed" && + gen_header >expect $name $commit commit $time <<-EOF && + A signed tag message + from a fake editor. + -----BEGIN PGP SIGNATURE----- + EOF + GIT_EDITOR=./fakeeditor git tag -u CDDE430D $name && + get_header $name | test_cmp expect - ' -cat >sigmsgfile <<EOF -Another signed tag -message in a file. -EOF -get_tag_header file-signed-tag $commit commit $time >expect -cat sigmsgfile >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag with -F messagefile should succeed' ' - git tag -s -F sigmsgfile file-signed-tag && - get_tag_msg file-signed-tag >actual && - test_cmp expect actual +test_expect_success GPG 'creating a signed tag with -F messagefile should succeed' ' + name="file-signed-tag" && + gen_header >expect $name $commit commit $time <<-EOF && + Another signed tag + message in a file. + -----BEGIN PGP SIGNATURE----- + EOF + tail -n 3 expect | head -n 2 >sigmsgfile + git tag -s -F sigmsgfile $name && + get_header $name | test_cmp expect - ' -cat >siginputmsg <<EOF -A signed tag message from -the standard input -EOF -get_tag_header stdin-signed-tag $commit commit $time >expect -cat siginputmsg >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG 'creating a signed tag with -F - should succeed' ' - git tag -s -F - stdin-signed-tag <siginputmsg && - get_tag_msg stdin-signed-tag >actual && - test_cmp expect actual + name="stdin-signed-tag" && + gen_header >expect $name $commit commit $time <<-EOF && + A signed tag message from + the standard input + -----BEGIN PGP SIGNATURE----- + EOF + tail -n 3 expect | head -n 2 | git tag -s -F - $name && + get_header $name | test_cmp expect - ' -get_tag_header implied-annotate $commit commit $time >expect -./fakeeditor >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG '-s implies annotated tag' ' - GIT_EDITOR=./fakeeditor git tag -s implied-annotate && - get_tag_msg implied-annotate >actual && - test_cmp expect actual + name="implied-signed-tag" && + gen_header >expect $name $commit commit $time <<-EOF && + A signed tag message + from a fake editor. + -----BEGIN PGP SIGNATURE----- + EOF + GIT_EDITOR=./fakeeditor git tag -s $name && + get_header $name | test_cmp expect - ' -test_expect_success GPG \ - 'trying to create a signed tag with non-existing -F file should fail' ' +test_expect_success GPG 'trying to create a signed tag with non-existing -F file should fail' ' ! test -f nonexistingfile && ! tag_exists nosigtag && - test_must_fail git tag -s -F nonexistingfile nosigtag && + silent test_must_fail git tag -s -F nonexistingfile nosigtag && ! tag_exists nosigtag ' -test_expect_success GPG 'verifying a signed tag should succeed' \ - 'git tag -v signed-tag' +test_expect_success GPG 'verifying a signed tag should succeed' ' + silent git tag -v signed-tag +' -test_expect_success GPG 'verifying two signed tags in one command should succeed' \ - 'git tag -v signed-tag file-signed-tag' +test_expect_success GPG 'verifying two signed tags in one command should succeed' ' + silent git tag -v signed-tag file-signed-tag +' -test_expect_success GPG \ - 'verifying many signed and non-signed tags should fail' ' - test_must_fail git tag -v signed-tag annotated-tag && - test_must_fail git tag -v file-annotated-tag file-signed-tag && - test_must_fail git tag -v annotated-tag \ +test_expect_success GPG 'verifying many signed and non-signed tags should fail' ' + silent test_must_fail git tag -v signed-tag annotated-tag && + silent test_must_fail git tag -v file-annotated-tag file-signed-tag && + silent test_must_fail git tag -v annotated-tag \ file-signed-tag file-annotated-tag && - test_must_fail git tag -v signed-tag annotated-tag file-signed-tag + silent test_must_fail git tag -v signed-tag \ + annotated-tag file-signed-tag ' test_expect_success GPG 'verifying a forged tag should fail' '
@@ -735,405 +681,374 @@ test_expect_success GPG 'verifying a forged tag should fail' ' sed -e "s/signed-tag/forged-tag/" | git mktag) && git tag forged-tag $forged && - test_must_fail git tag -v forged-tag + silent test_must_fail git tag -v forged-tag ' # blank and empty messages for signed tags: -get_tag_header empty-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag with an empty -m message should succeed' ' - git tag -s -m "" empty-signed-tag && - get_tag_msg empty-signed-tag >actual && - test_cmp expect actual && - git tag -v empty-signed-tag -' - ->sigemptyfile -get_tag_header emptyfile-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag with an empty -F messagefile should succeed' ' - git tag -s -F sigemptyfile emptyfile-signed-tag && - get_tag_msg emptyfile-signed-tag >actual && - test_cmp expect actual && - git tag -v emptyfile-signed-tag -' - -printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile -printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile -printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile -printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile -get_tag_header blanks-signed-tag $commit commit $time >expect -cat >>expect <<EOF -Leading blank lines - -Repeated blank lines - -Trailing spaces - -Trailing blank lines -EOF -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'extra blanks in the message for a signed tag should be removed' ' - git tag -s -F sigblanksfile blanks-signed-tag && - get_tag_msg blanks-signed-tag >actual && - test_cmp expect actual && - git tag -v blanks-signed-tag -' - -get_tag_header blank-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag with a blank -m message should succeed' ' - git tag -s -m " " blank-signed-tag && - get_tag_msg blank-signed-tag >actual && - test_cmp expect actual && - git tag -v blank-signed-tag -' - -echo ' ' >sigblankfile -echo '' >>sigblankfile -echo ' ' >>sigblankfile -get_tag_header blankfile-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag with blank -F file with spaces should succeed' ' - git tag -s -F sigblankfile blankfile-signed-tag && - get_tag_msg blankfile-signed-tag >actual && - test_cmp expect actual && - git tag -v blankfile-signed-tag -' - -printf ' ' >sigblanknonlfile -get_tag_header blanknonlfile-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag with spaces and no newline should succeed' ' - git tag -s -F sigblanknonlfile blanknonlfile-signed-tag && - get_tag_msg blanknonlfile-signed-tag >actual && - test_cmp expect actual && - git tag -v signed-tag +test_expect_success GPG 'creating a signed tag with an empty -m message should succeed' ' + name="empty-signed-tag" && + gen_header $name $commit commit $time >expect <<-EOF && + -----BEGIN PGP SIGNATURE----- + EOF + git tag -s -m "" $name && + get_header $name | test_cmp expect - && + silent git tag -v $name +' + +test_expect_success GPG 'creating a signed tag with an empty -F messagefile should succeed' ' + >sigemptyfile && + name="emptyfile-signed-tag" && + gen_header $name $commit commit $time >expect <<-EOF && + -----BEGIN PGP SIGNATURE----- + EOF + git tag -s -F sigemptyfile $name && + get_header $name | test_cmp expect - && + silent git tag -v $name +' + +test_expect_success GPG 'extra blanks in the message for a signed tag should be removed' ' + here >sigblanksfile <<-\EOF && + + \s\s + \t + Leading blank lines + + \t\s\t\s\s + Repeated blank lines + + + + Trailing spaces\s\s\s\s\s\s\t\s\s + + Trailing blank lines + + \t\s + + EOF + name="blanks-signed-tag" && + gen_header $name $commit commit $time >expect <<-EOF && + Leading blank lines + + Repeated blank lines + + Trailing spaces + + Trailing blank lines + -----BEGIN PGP SIGNATURE----- + EOF + git tag -s -F sigblanksfile $name && + get_header $name | test_cmp expect - && + silent git tag -v $name +' + +test_expect_success GPG 'creating a signed tag with a blank -m message should succeed' ' + name="blank-signed-tag" && + gen_header >expect $name $commit commit $time <<-EOF && + -----BEGIN PGP SIGNATURE----- + EOF + git tag -s -m " " $name && + get_header $name | test_cmp expect - && + silent git tag -v $name +' + +test_expect_success GPG 'creating a signed tag with blank -F file with spaces should succeed' ' + here >sigblankfile <<-\EOF && + \s\s\s\s\s + + \s\s + EOF + name="blankfile-signed-tag" && + gen_header >expect $name $commit commit $time <<-EOF && + -----BEGIN PGP SIGNATURE----- + EOF + git tag -s -F sigblankfile $name && + get_header $name | test_cmp expect - && + silent git tag -v $name +' + +test_expect_success GPG 'creating a signed tag with spaces and no newline should succeed' ' + printf >sigblanknonlfile " " && + name="blanknonlfile-signed-tag" && + gen_header $name $commit commit $time >expect <<-EOF && + -----BEGIN PGP SIGNATURE----- + EOF + git tag -s -F sigblanknonlfile $name && + get_header $name | test_cmp expect - && + silent git tag -v $name ' # messages with commented lines for signed tags: -cat >sigcommentsfile <<EOF -# A comment - -############ -The message. -############ -One line. - - -# commented lines -# commented lines - -Another line. -# comments - -Last line. -EOF -get_tag_header comments-signed-tag $commit commit $time >expect -cat >>expect <<EOF -The message. -One line. - -Another line. - -Last line. -EOF -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag with a -F file with #comments should succeed' ' - git tag -s -F sigcommentsfile comments-signed-tag && - get_tag_msg comments-signed-tag >actual && - test_cmp expect actual && - git tag -v comments-signed-tag -' - -get_tag_header comment-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag with #commented -m message should succeed' ' - git tag -s -m "#comment" comment-signed-tag && - get_tag_msg comment-signed-tag >actual && - test_cmp expect actual && - git tag -v comment-signed-tag -' - -echo '#comment' >sigcommentfile -echo '' >>sigcommentfile -echo '####' >>sigcommentfile -get_tag_header commentfile-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag with #commented -F messagefile should succeed' ' - git tag -s -F sigcommentfile commentfile-signed-tag && - get_tag_msg commentfile-signed-tag >actual && - test_cmp expect actual && - git tag -v commentfile-signed-tag -' - -printf '#comment' >sigcommentnonlfile -get_tag_header commentnonlfile-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag with a #comment and no newline should succeed' ' - git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag && - get_tag_msg commentnonlfile-signed-tag >actual && - test_cmp expect actual && - git tag -v commentnonlfile-signed-tag +test_expect_success GPG 'creating a signed tag with a -F file with #comments should succeed' ' + cat >sigcommentsfile <<-EOF && + # A comment + + ############ + The message. + ############ + One line. + + + # commented lines + # commented lines + + Another line. + # comments + + Last line. + EOF + name="comments-signed-tag" && + gen_header >expect $name $commit commit $time <<-EOF && + The message. + One line. + + Another line. + + Last line. + -----BEGIN PGP SIGNATURE----- + EOF + git tag -s -F sigcommentsfile $name && + get_header $name | test_cmp expect - && + silent git tag -v $name +' + +test_expect_success GPG 'creating a signed tag with #commented -m message should succeed' ' + name="comment-signed-tag" && + gen_header $name $commit commit $time >expect <<-EOF && + -----BEGIN PGP SIGNATURE----- + EOF + git tag -s -m "#comment" $name && + get_header $name | test_cmp expect - && + silent git tag -v $name +' + +test_expect_success GPG 'creating a signed tag with #commented -F messagefile should succeed' ' + cat >sigcommentfile <<-EOF && + #comment + + #### + EOF + name="commentfile-signed-tag" && + gen_header $name $commit commit $time >expect <<-EOF && + -----BEGIN PGP SIGNATURE----- + EOF + git tag -s -F sigcommentfile $name && + get_header $name | test_cmp expect - && + silent git tag -v $name +' + +test_expect_success GPG 'creating a signed tag with a #comment and no newline should succeed' ' + printf "#comment" >sigcommentnonlfile && + name="commentnonlfile-signed-tag" && + gen_header $name $commit commit $time >expect <<-EOF && + -----BEGIN PGP SIGNATURE----- + EOF + git tag -s -F sigcommentnonlfile $name && + get_header $name | test_cmp expect - && + silent git tag -v $name ' # listing messages for signed tags: -test_expect_success GPG \ - 'listing the one-line message of a signed tag should succeed' ' +test_expect_success GPG 'listing the one-line message of a signed tag should succeed' ' git tag -s -m "A message line signed" stag-one-line && echo "stag-one-line" >expect && - git tag -l | grep "^stag-one-line" >actual && - test_cmp expect actual && - git tag -n0 -l | grep "^stag-one-line" >actual && - test_cmp expect actual && - git tag -n0 -l stag-one-line >actual && - test_cmp expect actual && + git tag -l | grep "^stag-one-line" | test_cmp expect - && + git tag -n0 -l | grep "^stag-one-line" | test_cmp expect - && + git tag -n0 -l stag-one-line | test_cmp expect - && echo "stag-one-line A message line signed" >expect && - git tag -n1 -l | grep "^stag-one-line" >actual && - test_cmp expect actual && - git tag -n -l | grep "^stag-one-line" >actual && - test_cmp expect actual && - git tag -n1 -l stag-one-line >actual && - test_cmp expect actual && - git tag -n2 -l stag-one-line >actual && - test_cmp expect actual && - git tag -n999 -l stag-one-line >actual && - test_cmp expect actual + git tag -n1 -l | grep "^stag-one-line" | test_cmp expect - && + git tag -n -l | grep "^stag-one-line" | test_cmp expect - && + git tag -n1 -l stag-one-line | test_cmp expect - && + git tag -n2 -l stag-one-line | test_cmp expect - && + git tag -n999 -l stag-one-line | test_cmp expect - ' -test_expect_success GPG \ - 'listing the zero-lines message of a signed tag should succeed' ' +test_expect_success GPG 'listing the zero-lines message of a signed tag should succeed' ' git tag -s -m "" stag-zero-lines && echo "stag-zero-lines" >expect && - git tag -l | grep "^stag-zero-lines" >actual && - test_cmp expect actual && - git tag -n0 -l | grep "^stag-zero-lines" >actual && - test_cmp expect actual && - git tag -n0 -l stag-zero-lines >actual && - test_cmp expect actual && + git tag -l | grep "^stag-zero-lines" | test_cmp expect - && + git tag -n0 -l | grep "^stag-zero-lines" | test_cmp expect - && + git tag -n0 -l stag-zero-lines | test_cmp expect - && echo "stag-zero-lines " >expect && - git tag -n1 -l | grep "^stag-zero-lines" >actual && - test_cmp expect actual && - git tag -n -l | grep "^stag-zero-lines" >actual && - test_cmp expect actual && - git tag -n1 -l stag-zero-lines >actual && - test_cmp expect actual && - git tag -n2 -l stag-zero-lines >actual && - test_cmp expect actual && - git tag -n999 -l stag-zero-lines >actual && - test_cmp expect actual -' - -echo 'stag line one' >sigtagmsg -echo 'stag line two' >>sigtagmsg -echo 'stag line three' >>sigtagmsg -test_expect_success GPG \ - 'listing many message lines of a signed tag should succeed' ' + git tag -n1 -l | grep "^stag-zero-lines" | test_cmp expect - && + git tag -n -l | grep "^stag-zero-lines" | test_cmp expect - && + git tag -n1 -l stag-zero-lines | test_cmp expect - && + git tag -n2 -l stag-zero-lines | test_cmp expect - && + git tag -n999 -l stag-zero-lines | test_cmp expect - +' + +test_expect_success GPG 'listing many message lines of a signed tag should succeed' ' + cat >sigtagmsg <<-EOF && + stag line one + stag line two + stag line three + EOF git tag -s -F sigtagmsg stag-lines && echo "stag-lines" >expect && - git tag -l | grep "^stag-lines" >actual && - test_cmp expect actual && - git tag -n0 -l | grep "^stag-lines" >actual && - test_cmp expect actual && - git tag -n0 -l stag-lines >actual && - test_cmp expect actual && + git tag -l | grep "^stag-lines" | test_cmp expect - && + git tag -n0 -l | grep "^stag-lines" | test_cmp expect - && + git tag -n0 -l stag-lines | test_cmp expect - && echo "stag-lines stag line one" >expect && - git tag -n1 -l | grep "^stag-lines" >actual && - test_cmp expect actual && - git tag -n -l | grep "^stag-lines" >actual && - test_cmp expect actual && - git tag -n1 -l stag-lines >actual && - test_cmp expect actual && + git tag -n1 -l | grep "^stag-lines" | test_cmp expect - && + git tag -n -l | grep "^stag-lines" | test_cmp expect - && + git tag -n1 -l stag-lines | test_cmp expect - && echo " stag line two" >>expect && - git tag -n2 -l | grep "^ *stag.line" >actual && - test_cmp expect actual && - git tag -n2 -l stag-lines >actual && - test_cmp expect actual && + git tag -n2 -l | grep "^.*stag.line" | test_cmp expect - && + git tag -n2 -l stag-lines | test_cmp expect - && echo " stag line three" >>expect && - git tag -n3 -l | grep "^ *stag.line" >actual && - test_cmp expect actual && - git tag -n3 -l stag-lines >actual && - test_cmp expect actual && - git tag -n4 -l | grep "^ *stag.line" >actual && - test_cmp expect actual && - git tag -n4 -l stag-lines >actual && - test_cmp expect actual && - git tag -n99 -l | grep "^ *stag.line" >actual && - test_cmp expect actual && - git tag -n99 -l stag-lines >actual && - test_cmp expect actual -' - -# tags pointing to objects different from commits: - -tree=$(git rev-parse HEAD^{tree}) -blob=$(git rev-parse HEAD:foo) -tag=$(git rev-parse signed-tag 2>/dev/null) - -get_tag_header tree-signed-tag $tree tree $time >expect -echo "A message for a tree" >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag pointing to a tree should succeed' ' - git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} && - get_tag_msg tree-signed-tag >actual && - test_cmp expect actual + git tag -n3 -l | grep "^.*stag.line" | test_cmp expect - && + git tag -n3 -l stag-lines | test_cmp expect - && + git tag -n4 -l | grep "^.*stag.line" | test_cmp expect - && + git tag -n4 -l stag-lines | test_cmp expect - && + git tag -n99 -l | grep "^.*stag.line" | test_cmp expect - && + git tag -n99 -l stag-lines | test_cmp expect - +' + + +test_expect_success GPG 'creating a signed tag pointing to a tree should succeed' ' + # tags pointing to objects different from commits: + tree=$(git rev-parse HEAD^{tree}) && + blob=$(git rev-parse HEAD:foo) && + tag=$(git rev-parse signed-tag) && + name="tree-signed-tag" && + msg="A message for a tree" && + gen_header $name $tree tree $time >expect <<-EOF && + $msg + -----BEGIN PGP SIGNATURE----- + EOF + git tag -s -m "$msg" $name HEAD^{tree} && + get_header $name | test_cmp expect - ' -get_tag_header blob-signed-tag $blob blob $time >expect -echo "A message for a blob" >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag pointing to a blob should succeed' ' - git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo && - get_tag_msg blob-signed-tag >actual && - test_cmp expect actual +test_expect_success GPG 'creating a signed tag pointing to a blob should succeed' ' + msg="A message for a blob" && + name="blob-signed-tag" && + gen_header $name $blob blob $time >expect <<-EOF && + $msg + -----BEGIN PGP SIGNATURE----- + EOF + git tag -s -m "$msg" $name HEAD:foo && + get_header $name | test_cmp expect - ' -get_tag_header tag-signed-tag $tag tag $time >expect -echo "A message for another tag" >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag pointing to another tag should succeed' ' - git tag -s -m "A message for another tag" tag-signed-tag signed-tag && - get_tag_msg tag-signed-tag >actual && - test_cmp expect actual +test_expect_success GPG 'creating a signed tag pointing to another tag should succeed' ' + msg="A message for another tag" && + name="tag-signed-tag" && + gen_header $name $tag tag $time >expect <<-EOF && + $msg + -----BEGIN PGP SIGNATURE----- + EOF + git tag -s -m "$msg" $name signed-tag && + get_header $name | test_cmp expect - ' # usage with rfc1991 signatures -echo "rfc1991" > gpghome/gpg.conf -get_tag_header rfc1991-signed-tag $commit commit $time >expect -echo "RFC1991 signed tag" >>expect -echo '-----BEGIN PGP MESSAGE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag with rfc1991' ' - git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit && - get_tag_msg rfc1991-signed-tag >actual && - test_cmp expect actual +test_expect_success GPG 'creating a signed tag with rfc1991' ' + echo "rfc1991" >gpghome/gpg.conf && + msg="RFC1991 signed tag" && + name="rfc1991-signed-tag" + gen_header $name $commit commit $time >expect <<-EOF && + $msg + -----BEGIN PGP MESSAGE----- + EOF + git tag -s -m "$msg" $name $commit && + get_header $name | test_cmp expect - ' -cat >fakeeditor <<'EOF' -#!/bin/sh -cp "$1" actual -EOF -chmod +x fakeeditor - -test_expect_success GPG \ - 'reediting a signed tag body omits signature' ' +test_expect_success GPG 'reediting a signed tag body omits signature' ' + cat <<-\EOF | write_script fakeeditor && + cp "$1" actual + EOF echo "RFC1991 signed tag" >expect && - GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit && + GIT_EDITOR=./fakeeditor \ + quiet git tag -f -s rfc1991-signed-tag $commit && test_cmp expect actual ' -test_expect_success GPG \ - 'verifying rfc1991 signature' ' - git tag -v rfc1991-signed-tag +test_expect_success GPG 'verifying rfc1991 signature' ' + silent git tag -v rfc1991-signed-tag ' -test_expect_success GPG \ - 'list tag with rfc1991 signature' ' +test_expect_success GPG 'list tag with rfc1991 signature' ' echo "rfc1991-signed-tag RFC1991 signed tag" >expect && - git tag -l -n1 rfc1991-signed-tag >actual && - test_cmp expect actual && - git tag -l -n2 rfc1991-signed-tag >actual && - test_cmp expect actual && - git tag -l -n999 rfc1991-signed-tag >actual && - test_cmp expect actual + git tag -l -n1 rfc1991-signed-tag | test_cmp expect - && + git tag -l -n2 rfc1991-signed-tag | test_cmp expect - && + git tag -l -n999 rfc1991-signed-tag | test_cmp expect - ' -rm -f gpghome/gpg.conf - -test_expect_success GPG \ - 'verifying rfc1991 signature without --rfc1991' ' - git tag -v rfc1991-signed-tag +test_expect_success GPG 'verifying rfc1991 signature without --rfc1991' ' + rm -f gpghome/gpg.conf && + silent git tag -v rfc1991-signed-tag ' -test_expect_success GPG \ - 'list tag with rfc1991 signature without --rfc1991' ' - echo "rfc1991-signed-tag RFC1991 signed tag" >expect && - git tag -l -n1 rfc1991-signed-tag >actual && - test_cmp expect actual && - git tag -l -n2 rfc1991-signed-tag >actual && - test_cmp expect actual && - git tag -l -n999 rfc1991-signed-tag >actual && - test_cmp expect actual +test_expect_success GPG 'list tag with rfc1991 signature without --rfc1991' ' + echo >expect "rfc1991-signed-tag RFC1991 signed tag" && + git tag -l -n1 rfc1991-signed-tag | test_cmp expect - && + git tag -l -n2 rfc1991-signed-tag | test_cmp expect - && + git tag -l -n999 rfc1991-signed-tag | test_cmp expect - ' -test_expect_success GPG \ - 'reediting a signed tag body omits signature' ' +test_expect_success GPG 'reediting a signed tag body omits signature' ' echo "RFC1991 signed tag" >expect && - GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit && + GIT_EDITOR=./fakeeditor \ + quiet git tag -f -s rfc1991-signed-tag $commit && test_cmp expect actual ' -# try to sign with bad user.signingkey -git config user.signingkey BobTheMouse -test_expect_success GPG \ - 'git tag -s fails if gpg is misconfigured' \ - 'test_must_fail git tag -s -m tail tag-gpg-failure' -git config --unset user.signingkey - -# try to verify without gpg: +test_expect_success GPG 'git tag -s fails if gpg is misconfigured' ' + # try to sign with bad user.signingkey + git config user.signingkey BobTheMouse && + silent test_must_fail git tag -s -m tail tag-gpg-failure && + git config --unset user.signingkey +' -rm -rf gpghome -test_expect_success GPG \ - 'verify signed tag fails when public key is not present' \ - 'test_must_fail git tag -v signed-tag' +test_expect_success GPG 'verify signed tag fails when public key is not present' ' + # try to verify without gpg: + rm -rf gpghome && + silent test_must_fail git tag -v signed-tag +' -test_expect_success \ - 'git tag -a fails if tag annotation is empty' ' - ! (GIT_EDITOR=cat git tag -a initial-comment) +test_expect_success 'git tag -a fails if tag annotation is empty' ' + ! (GIT_EDITOR=cat silent git tag -a initial-comment) ' -test_expect_success \ - 'message in editor has initial comment' ' - ! (GIT_EDITOR=cat git tag -a initial-comment > actual) +test_expect_success 'message in editor has initial comment' ' + ! (GIT_EDITOR=cat git tag -a initial-comment >actual 2>/dev/null) ' test_expect_success 'message in editor has initial comment: first line' ' # check the first line --- should be empty echo >first.expect && - sed -e 1q <actual >first.actual && + sed -e 1q actual >first.actual && test_i18ncmp first.expect first.actual ' -test_expect_success \ - 'message in editor has initial comment: remainder' ' +test_expect_success 'message in editor has initial comment: remainder' ' # remove commented lines from the remainder -- should be empty >rest.expect sed -e 1d -e '/^#/d' <actual >rest.actual && test_cmp rest.expect rest.actual ' -get_tag_header reuse $commit commit $time >expect -echo "An annotation to be reused" >> expect -test_expect_success \ - 'overwriting an annoted tag should use its previous body' ' - git tag -a -m "An annotation to be reused" reuse && - GIT_EDITOR=true git tag -f -a reuse && - get_tag_msg reuse >actual && - test_cmp expect actual +test_expect_success 'overwriting an annoted tag should use its previous body' ' + name="reuse" && + msg="An annotation to be reused" && + gen_header $name $commit commit $time >expect <<-EOF && + reuse + EOF + git tag -a -m "$msg" $name && + GIT_EDITOR=true git tag -f -a -m "reuse" $name && + get_header $name | test_cmp expect - ' test_expect_success 'filename for the message is relative to cwd' '
@@ -1144,7 +1059,7 @@ test_expect_success 'filename for the message is relative to cwd' ' cd subdir && git tag -a -F msgfile-5 tag-from-subdir ) && - git cat-file tag tag-from-subdir | grep "in sub directory" + git cat-file tag tag-from-subdir | grep -q "in sub directory" ' test_expect_success 'filename for the message is relative to cwd' '
@@ -1153,172 +1068,143 @@ test_expect_success 'filename for the message is relative to cwd' ' cd subdir && git tag -a -F msgfile-6 tag-from-subdir-2 ) && - git cat-file tag tag-from-subdir-2 | grep "in sub directory" + git cat-file tag tag-from-subdir-2 | grep -q "in sub directory" ' -# create a few more commits to test --contains - -hash1=$(git rev-parse HEAD) - test_expect_success 'creating second commit and tag' ' + # create a few more commits to test --contains + hash1=$(git rev-parse HEAD) && echo foo-2.0 >foo && git add foo && - git commit -m second && + git commit -q -m second && + hash2=$(git rev-parse HEAD) && git tag v2.0 ' -hash2=$(git rev-parse HEAD) - test_expect_success 'creating third commit without tag' ' echo foo-dev >foo && git add foo && - git commit -m third + git commit -q -m third && + hash3=$(git rev-parse HEAD) +' + +test_expect_success 'checking that first commit is in all tags (hash)' ' + # simple linear checks of --contains + cat >expect <<-EOF && + v0.2.1 + v1.0 + v1.0.1 + v1.1.3 + v2.0 + EOF + git tag -l --contains $hash1 v* | test_cmp expect - ' -hash3=$(git rev-parse HEAD) - -# simple linear checks of --continue - -cat > expected <<EOF -v0.2.1 -v1.0 -v1.0.1 -v1.1.3 -v2.0 -EOF - -test_expect_success 'checking that first commit is in all tags (hash)' " - git tag -l --contains $hash1 v* >actual && - test_cmp expected actual -" - -# other ways of specifying the commit -test_expect_success 'checking that first commit is in all tags (tag)' " - git tag -l --contains v1.0 v* >actual && - test_cmp expected actual -" - -test_expect_success 'checking that first commit is in all tags (relative)' " - git tag -l --contains HEAD~2 v* >actual && - test_cmp expected actual -" - -cat > expected <<EOF -v2.0 -EOF - -test_expect_success 'checking that second commit only has one tag' " - git tag -l --contains $hash2 v* >actual && - test_cmp expected actual -" +test_expect_success 'checking that first commit is in all tags (tag)' ' + # other ways of specifying the commit + git tag -l --contains v1.0 v* | test_cmp expect - +' +test_expect_success 'checking that first commit is in all tags (relative)' ' + git tag -l --contains HEAD~2 v* | test_cmp expect - +' -cat > expected <<EOF -EOF +test_expect_success 'checking that second commit only has one tag' ' + cat >expect <<-EOF && + v2.0 + EOF + git tag -l --contains $hash2 v* | test_cmp expect - +' -test_expect_success 'checking that third commit has no tags' " - git tag -l --contains $hash3 v* >actual && - test_cmp expected actual -" +test_expect_success 'checking that third commit has no tags' ' + >expect + git tag -l --contains $hash3 v* | test_cmp expect - +' # how about a simple merge? test_expect_success 'creating simple branch' ' git branch stable v2.0 && - git checkout stable && - echo foo-3.0 > foo && - git commit foo -m fourth && + git checkout -q stable && + echo foo-3.0 >foo && + git commit -q foo -m fourth && + hash4=$(git rev-parse HEAD) && git tag v3.0 ' -hash4=$(git rev-parse HEAD) - -cat > expected <<EOF -v3.0 -EOF - -test_expect_success 'checking that branch head only has one tag' " - git tag -l --contains $hash4 v* >actual && - test_cmp expected actual -" +test_expect_success 'checking that branch head only has one tag' ' + cat >expect <<-EOF && + v3.0 + EOF + git tag -l --contains $hash4 v* | test_cmp expect - +' test_expect_success 'merging original branch into this branch' ' - git merge --strategy=ours master && + git merge -q --strategy=ours master && git tag v4.0 ' -cat > expected <<EOF -v4.0 -EOF - -test_expect_success 'checking that original branch head has one tag now' " - git tag -l --contains $hash3 v* >actual && - test_cmp expected actual -" - -cat > expected <<EOF -v0.2.1 -v1.0 -v1.0.1 -v1.1.3 -v2.0 -v3.0 -v4.0 -EOF - -test_expect_success 'checking that initial commit is in all tags' " - git tag -l --contains $hash1 v* >actual && - test_cmp expected actual -" +test_expect_success 'checking that original branch head has one tag now' ' + cat >expect <<-EOF && + v4.0 + EOF + git tag -l --contains $hash3 v* | test_cmp expect - +' + +test_expect_success 'checking that initial commit is in all tags' ' + cat >expect <<-EOF && + v0.2.1 + v1.0 + v1.0.1 + v1.1.3 + v2.0 + v3.0 + v4.0 + EOF + git tag -l --contains $hash1 v* | test_cmp expect - +' -# mixing modes and options: test_expect_success 'mixing incompatibles modes and options is forbidden' ' - test_must_fail git tag -a && - test_must_fail git tag -l -v && - test_must_fail git tag -n 100 && - test_must_fail git tag -l -m msg && - test_must_fail git tag -l -F some file && - test_must_fail git tag -v -s + # mixing modes and options: + silent test_must_fail git tag -a && + silent test_must_fail git tag -l -v && + silent test_must_fail git tag -n 100 && + silent test_must_fail git tag -l -m msg && + silent test_must_fail git tag -l -F some file && + silent test_must_fail git tag -v -s && + silent test_must_fail git tag --points-at=v4.0 foo ' # check points-at -test_expect_success '--points-at cannot be used in non-list mode' ' - test_must_fail git tag --points-at=v4.0 foo -' - test_expect_success '--points-at finds lightweight tags' ' echo v4.0 >expect && - git tag --points-at v4.0 >actual && - test_cmp expect actual + git tag --points-at v4.0 | test_cmp expect - ' test_expect_success '--points-at finds annotated tags of commits' ' git tag -m "v4.0, annotated" annotated-v4.0 v4.0 && echo annotated-v4.0 >expect && - git tag -l --points-at v4.0 "annotated*" >actual && - test_cmp expect actual + git tag -l --points-at v4.0 "annotated*" | test_cmp expect - ' test_expect_success '--points-at finds annotated tags of tags' ' git tag -m "describing the v4.0 tag object" \ annotated-again-v4.0 annotated-v4.0 && - cat >expect <<-\EOF && - annotated-again-v4.0 - annotated-v4.0 + cat >expect <<-EOF && + annotated-again-v4.0 + annotated-v4.0 EOF - git tag --points-at=annotated-v4.0 >actual && - test_cmp expect actual + git tag --points-at=annotated-v4.0 | test_cmp expect - ' test_expect_success 'multiple --points-at are OR-ed together' ' - cat >expect <<-\EOF && - v2.0 - v3.0 + cat >expect <<-EOF && + v2.0 + v3.0 EOF - git tag --points-at=v2.0 --points-at=v3.0 >actual && - test_cmp expect actual + git tag --points-at=v2.0 --points-at=v3.0 | test_cmp expect - ' test_done
Signature · 1 line
1.7.8
PATCH 103/105 t3200 (branch): modernize style
In reply to Tom Grennan- Guard setup with test_expect_success
- Single-quoted, tab prefaced test blocks of < 80 cols
- Redirect unwanted output
- Use a "here" filter for expect generation
--- t/t3200-branch.sh | 457 +++++++++++++++++++++++++++-------------------------- 1 files changed, 236 insertions(+), 221 deletions(-)
t/t3200-branch.sh +236 -221
@@ -5,125 +5,132 @@ test_description='git branch assorted tests' +if ! test -r test-lib.sh ; then + (cd ${0%/*} && ./${0##*/} $@) + exit $? +fi + . ./test-lib.sh -test_expect_success \ - 'prepare a trivial repository' \ - 'echo Hello > A && +quiet () { "$@" >/dev/null; } +silent () { "$@" >/dev/null 2>&1; } +here () { sed 's/\\s/ /g; s/\\t/\t/g; s/\\n/\n/g' $@; } + +test_expect_success 'prepare a trivial repository' ' + echo Hello >A && git update-index --add A && - git commit -m "Initial commit." && + git commit -q -m "Initial commit." && echo World >> A && git update-index --add A && - git commit -m "Second commit." && - HEAD=$(git rev-parse --verify HEAD)' + git commit -q -m "Second commit." && + HEAD=$(git rev-parse --verify HEAD) +' -test_expect_success \ - 'git branch --help should not have created a bogus branch' ' - test_might_fail git branch --help </dev/null >/dev/null 2>/dev/null && +test_expect_success 'git branch --help should not have created a bogus branch' ' + silent test_might_fail git branch --help </dev/null && test_path_is_missing .git/refs/heads/--help ' test_expect_success 'branch -h in broken repository' ' - mkdir broken && - ( - cd broken && - git init && - >.git/refs/heads/master && - test_expect_code 129 git branch -h >usage 2>&1 - ) && - grep "[Uu]sage" broken/usage + git init -q broken && + test_when_finished rm -rf broken usage && + >broken/.git/refs/heads/master && + >usage 2>&1 test_expect_code 129 git --git-dir=broken/.git branch -h && + grep -q "[Uu]sage" usage ' -test_expect_success \ - 'git branch abc should create a branch' \ - 'git branch abc && test_path_is_file .git/refs/heads/abc' +test_expect_success 'git branch abc should create a branch' ' + git branch abc && test_path_is_file .git/refs/heads/abc +' -test_expect_success \ - 'git branch a/b/c should create a branch' \ - 'git branch a/b/c && test_path_is_file .git/refs/heads/a/b/c' +test_expect_success 'git branch a/b/c should create a branch' ' + git branch a/b/c && test_path_is_file .git/refs/heads/a/b/c +' -cat >expect <<EOF -$_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master +test_expect_success 'git branch -l d/e/f should create a branch and a log' ' + id="$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" + date="1117150200 +0000" + msg="branch: Created from master" + here >expect <<-EOF + $_z40 $HEAD $id $date\t$msg EOF -test_expect_success \ - 'git branch -l d/e/f should create a branch and a log' \ - 'GIT_COMMITTER_DATE="2005-05-26 23:30" \ - git branch -l d/e/f && + GIT_COMMITTER_DATE="2005-05-26 23:30" git branch -l d/e/f && test_path_is_file .git/refs/heads/d/e/f && test_path_is_file .git/logs/refs/heads/d/e/f && - test_cmp expect .git/logs/refs/heads/d/e/f' + test_cmp expect .git/logs/refs/heads/d/e/f +' -test_expect_success \ - 'git branch -d d/e/f should delete a branch and a log' \ - 'git branch -d d/e/f && +test_expect_success 'git branch -d d/e/f should delete a branch and a log' ' + quiet git branch -d d/e/f && test_path_is_missing .git/refs/heads/d/e/f && - test_path_is_missing .git/logs/refs/heads/d/e/f' - -test_expect_success \ - 'git branch j/k should work after branch j has been deleted' \ - 'git branch j && - git branch -d j && - git branch j/k' - -test_expect_success \ - 'git branch l should work after branch l/m has been deleted' \ - 'git branch l/m && - git branch -d l/m && - git branch l' - -test_expect_success \ - 'git branch -m dumps usage' \ - 'test_expect_code 129 git branch -m 2>err && - grep "[Uu]sage: git branch" err' - -test_expect_success \ - 'git branch -m m m/m should work' \ - 'git branch -l m && + test_path_is_missing .git/logs/refs/heads/d/e/f +' + +test_expect_success 'git branch j/k should work after branch j has been deleted' ' + git branch j && + quiet git branch -d j && + git branch j/k +' + +test_expect_success 'git branch l should work after branch l/m has been deleted' ' + git branch l/m && + quiet git branch -d l/m && + git branch l +' + +test_expect_success 'git branch -m dumps usage' ' + test_expect_code 129 git branch -m 2>err && + grep -q "[Uu]sage: git branch" err +' + +test_expect_success 'git branch -m m m/m should work' ' + git branch -l m && git branch -m m m/m && - test_path_is_file .git/logs/refs/heads/m/m' + test_path_is_file .git/logs/refs/heads/m/m +' -test_expect_success \ - 'git branch -m n/n n should work' \ - 'git branch -l n/n && +test_expect_success 'git branch -m n/n n should work' ' + git branch -l n/n && git branch -m n/n n && - test_path_is_file .git/logs/refs/heads/n' + test_path_is_file .git/logs/refs/heads/n +' test_expect_success 'git branch -m o/o o should fail when o/p exists' ' git branch o/o && git branch o/p && - test_must_fail git branch -m o/o o + silent test_must_fail git branch -m o/o o ' test_expect_success 'git branch -m q r/q should fail when r exists' ' git branch q && git branch r && - test_must_fail git branch -m q r/q + silent test_must_fail git branch -m q r/q ' test_expect_success 'git branch -M foo bar should fail when bar is checked out' ' git branch bar && - git checkout -b foo && - test_must_fail git branch -M bar foo + git checkout -q -b foo && + silent test_must_fail git branch -M bar foo ' test_expect_success 'git branch -M baz bam should succeed when baz is checked out' ' - git checkout -b baz && + git checkout -q -b baz && git branch bam && git branch -M baz bam ' test_expect_success 'git branch -M master should work when master is checked out' ' - git checkout master && + git checkout -q master && git branch -M master ' test_expect_success 'git branch -M master master should work when master is checked out' ' - git checkout master && + git checkout -q master && git branch -M master master ' test_expect_success 'git branch -M master2 master2 should work when master is checked out' ' - git checkout master && + git checkout -q master && git branch master2 && git branch -M master2 master2 '
@@ -131,7 +138,7 @@ test_expect_success 'git branch -M master2 master2 should work when master is ch test_expect_success 'git branch -v -d t should work' ' git branch t && test_path_is_file .git/refs/heads/t && - git branch -v -d t && + quiet git branch -v -d t && test_path_is_missing .git/refs/heads/t '
@@ -141,188 +148,198 @@ test_expect_success 'git branch -v -m t s should work' ' git branch -v -m t s && test_path_is_missing .git/refs/heads/t && test_path_is_file .git/refs/heads/s && - git branch -d s + quiet git branch -d s ' test_expect_success 'git branch -m -d t s should fail' ' git branch t && test_path_is_file .git/refs/heads/t && - test_must_fail git branch -m -d t s && - git branch -d t && + silent test_must_fail git branch -m -d t s && + quiet git branch -d t && test_path_is_missing .git/refs/heads/t ' test_expect_success 'git branch --list -d t should fail' ' git branch t && test_path_is_file .git/refs/heads/t && - test_must_fail git branch --list -d t && - git branch -d t && + silent test_must_fail git branch --list -d t && + quiet git branch -d t && test_path_is_missing .git/refs/heads/t ' -mv .git/config .git/config-saved - test_expect_success 'git branch -m q q2 without config should succeed' ' + mv .git/config .git/config-saved && + test_when_finished mv .git/config-saved .git/config && git branch -m q q2 && git branch -m q2 q ' -mv .git/config-saved .git/config - +test_expect_success 'git branch -m s/s s should work when s/t is deleted' ' git config branch.s/s.dummy Hello - -test_expect_success \ - 'git branch -m s/s s should work when s/t is deleted' \ - 'git branch -l s/s && + git branch -l s/s && test_path_is_file .git/logs/refs/heads/s/s && git branch -l s/t && test_path_is_file .git/logs/refs/heads/s/t && - git branch -d s/t && + quiet git branch -d s/t && git branch -m s/s s && - test_path_is_file .git/logs/refs/heads/s' - -test_expect_success 'config information was renamed, too' \ - "test $(git config branch.s.dummy) = Hello && - test_must_fail git config branch.s/s/dummy" + test_path_is_file .git/logs/refs/heads/s +' -test_expect_success 'renaming a symref is not allowed' \ +test_expect_success 'config information was renamed, too' ' + test $(git config branch.s.dummy) = Hello && + silent test_must_fail git config branch.s/s/dummy ' + +test_expect_success 'renaming a symref is not allowed' ' git symbolic-ref refs/heads/master2 refs/heads/master && - test_must_fail git branch -m master2 master3 && - git symbolic-ref refs/heads/master2 && + silent test_must_fail git branch -m master2 master3 && + quiet git symbolic-ref refs/heads/master2 && test_path_is_file .git/refs/heads/master && test_path_is_missing .git/refs/heads/master3 ' -test_expect_success SYMLINKS \ - 'git branch -m u v should fail when the reflog for u is a symlink' ' +test_expect_success SYMLINKS 'git branch -m u v should fail when the reflog for u is a symlink' ' git branch -l u && mv .git/logs/refs/heads/u real-u && ln -s real-u .git/logs/refs/heads/u && - test_must_fail git branch -m u v + silent test_must_fail git branch -m u v ' -test_expect_success 'test tracking setup via --track' \ - 'git config remote.local.url . && +test_expect_success 'test tracking setup via --track' ' + git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --track my1 local/master && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --track my1 local/master && test $(git config branch.my1.remote) = local && - test $(git config branch.my1.merge) = refs/heads/master' + test $(git config branch.my1.merge) = refs/heads/master +' -test_expect_success 'test tracking setup (non-wildcard, matching)' \ - 'git config remote.local.url . && - git config remote.local.fetch refs/heads/master:refs/remotes/local/master && +test_expect_success 'test tracking setup (non-wildcard, matching)' ' + git config remote.local.url . && + git config remote.local.fetch \ + refs/heads/master:refs/remotes/local/master && (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --track my4 local/master && + quiet git branch --track my4 local/master && test $(git config branch.my4.remote) = local && - test $(git config branch.my4.merge) = refs/heads/master' + test $(git config branch.my4.merge) = refs/heads/master +' -test_expect_success 'test tracking setup (non-wildcard, not matching)' \ - 'git config remote.local.url . && +test_expect_success 'test tracking setup (non-wildcard, not matching)' ' + git config remote.local.url . && git config remote.local.fetch refs/heads/s:refs/remotes/local/s && (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --track my5 local/master && + quiet git branch --track my5 local/master && ! test "$(git config branch.my5.remote)" = local && - ! test "$(git config branch.my5.merge)" = refs/heads/master' + ! test "$(git config branch.my5.merge)" = refs/heads/master +' -test_expect_success 'test tracking setup via config' \ - 'git config branch.autosetupmerge true && +test_expect_success 'test tracking setup via config' ' + git config branch.autosetupmerge true && git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch my3 local/master && + quiet git branch my3 local/master && test $(git config branch.my3.remote) = local && - test $(git config branch.my3.merge) = refs/heads/master' + test $(git config branch.my3.merge) = refs/heads/master +' -test_expect_success 'test overriding tracking setup via --no-track' \ - 'git config branch.autosetupmerge true && +test_expect_success 'test overriding tracking setup via --no-track' ' + git config branch.autosetupmerge true && git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && (git show-ref -q refs/remotes/local/master || git fetch local) && git branch --no-track my2 local/master && git config branch.autosetupmerge false && ! test "$(git config branch.my2.remote)" = local && - ! test "$(git config branch.my2.merge)" = refs/heads/master' + ! test "$(git config branch.my2.merge)" = refs/heads/master +' -test_expect_success 'no tracking without .fetch entries' \ - 'git config branch.autosetupmerge true && +test_expect_success 'no tracking without .fetch entries' ' + git config branch.autosetupmerge true && git branch my6 s && git config branch.automsetupmerge false && test -z "$(git config branch.my6.remote)" && - test -z "$(git config branch.my6.merge)"' + test -z "$(git config branch.my6.merge)" +' -test_expect_success 'test tracking setup via --track but deeper' \ - 'git config remote.local.url . && +test_expect_success 'test tracking setup via --track but deeper' ' + git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && (git show-ref -q refs/remotes/local/o/o || git fetch local) && - git branch --track my7 local/o/o && + quiet git branch --track my7 local/o/o && test "$(git config branch.my7.remote)" = local && - test "$(git config branch.my7.merge)" = refs/heads/o/o' + test "$(git config branch.my7.merge)" = refs/heads/o/o +' -test_expect_success 'test deleting branch deletes branch config' \ - 'git branch -d my7 && +test_expect_success 'test deleting branch deletes branch config' ' + quiet git branch -d my7 && test -z "$(git config branch.my7.remote)" && - test -z "$(git config branch.my7.merge)"' + test -z "$(git config branch.my7.merge)" +' -test_expect_success 'test deleting branch without config' \ - 'git branch my7 s && +test_expect_success 'test deleting branch without config' ' + git branch my7 s && sha1=$(git rev-parse my7 | cut -c 1-7) && echo "Deleted branch my7 (was $sha1)." >expect && git branch -d my7 >actual 2>&1 && - test_i18ncmp expect actual' + test_i18ncmp expect actual +' -test_expect_success 'test --track without .fetch entries' \ - 'git branch --track my8 && +test_expect_success 'test --track without .fetch entries' ' + quiet git branch --track my8 && test "$(git config branch.my8.remote)" && - test "$(git config branch.my8.merge)"' + test "$(git config branch.my8.merge)" +' -test_expect_success \ - 'branch from non-branch HEAD w/autosetupmerge=always' \ - 'git config branch.autosetupmerge always && +test_expect_success 'branch from non-branch HEAD w/autosetupmerge=always' ' + git config branch.autosetupmerge always && git branch my9 HEAD^ && - git config branch.autosetupmerge false' + git config branch.autosetupmerge false +' -test_expect_success \ - 'branch from non-branch HEAD w/--track causes failure' \ - 'test_must_fail git branch --track my10 HEAD^' +test_expect_success 'branch from non-branch HEAD w/--track causes failure' ' + silent test_must_fail git branch --track my10 HEAD^ +' -test_expect_success \ - 'branch from tag w/--track causes failure' \ - 'git tag foobar && - test_must_fail git branch --track my11 foobar' +test_expect_success 'branch from tag w/--track causes failure' ' + git tag foobar && + silent test_must_fail git branch --track my11 foobar +' # Keep this test last, as it changes the current branch -cat >expect <<EOF -$_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master +test_expect_success 'git checkout -b g/h/i -l should create a branch and a log' ' + id="$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" + date="1117150200 +0000" + msg="branch: Created from master" + here >expect <<-EOF + $_z40 $HEAD $id $date\t$msg EOF -test_expect_success \ - 'git checkout -b g/h/i -l should create a branch and a log' \ - 'GIT_COMMITTER_DATE="2005-05-26 23:30" \ - git checkout -b g/h/i -l master && + GIT_COMMITTER_DATE="2005-05-26 23:30" \ + git checkout -q -b g/h/i -l master && test_path_is_file .git/refs/heads/g/h/i && test_path_is_file .git/logs/refs/heads/g/h/i && - test_cmp expect .git/logs/refs/heads/g/h/i' + test_cmp expect .git/logs/refs/heads/g/h/i +' test_expect_success 'checkout -b makes reflog by default' ' - git checkout master && + git checkout -q master && git config --unset core.logAllRefUpdates && - git checkout -b alpha && - git rev-parse --verify alpha@{0} + git checkout -q -b alpha && + quiet git rev-parse --verify alpha@{0} ' test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' ' - git checkout master && + git checkout -q master && git config core.logAllRefUpdates false && - git checkout -b beta && - test_must_fail git rev-parse --verify beta@{0} + git checkout -q -b beta && + silent test_must_fail git rev-parse --verify beta@{0} ' test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' ' - git checkout master && - git checkout -lb gamma && + git checkout -q master && + git checkout -q -lb gamma && git config --unset core.logAllRefUpdates && - git rev-parse --verify gamma@{0} + quiet git rev-parse --verify gamma@{0} ' test_expect_success 'avoid ambiguous track' '
@@ -331,7 +348,7 @@ test_expect_success 'avoid ambiguous track' ' git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master && git config remote.ambi2.url lilili && git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master && - git branch all1 master && + silent git branch all1 master && test -z "$(git config branch.all1.merge)" '
@@ -339,9 +356,9 @@ test_expect_success 'autosetuprebase local on a tracked local branch' ' git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && git config branch.autosetuprebase local && - (git show-ref -q refs/remotes/local/o || git fetch local) && + (git show-ref -q refs/remotes/local/o || git fetch -q local) && git branch mybase && - git branch --track myr1 mybase && + quiet git branch --track myr1 mybase && test "$(git config branch.myr1.remote)" = . && test "$(git config branch.myr1.merge)" = refs/heads/mybase && test "$(git config branch.myr1.rebase)" = true
@@ -351,9 +368,9 @@ test_expect_success 'autosetuprebase always on a tracked local branch' ' git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && git config branch.autosetuprebase always && - (git show-ref -q refs/remotes/local/o || git fetch local) && + (git show-ref -q refs/remotes/local/o || git fetch -q local) && git branch mybase2 && - git branch --track myr2 mybase && + quiet git branch --track myr2 mybase && test "$(git config branch.myr2.remote)" = . && test "$(git config branch.myr2.merge)" = refs/heads/mybase && test "$(git config branch.myr2.rebase)" = true
@@ -363,9 +380,9 @@ test_expect_success 'autosetuprebase remote on a tracked local branch' ' git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && git config branch.autosetuprebase remote && - (git show-ref -q refs/remotes/local/o || git fetch local) && + (git show-ref -q refs/remotes/local/o || git fetch -q local) && git branch mybase3 && - git branch --track myr3 mybase2 && + quiet git branch --track myr3 mybase2 && test "$(git config branch.myr3.remote)" = . && test "$(git config branch.myr3.merge)" = refs/heads/mybase2 && ! test "$(git config branch.myr3.rebase)" = true
@@ -375,9 +392,9 @@ test_expect_success 'autosetuprebase never on a tracked local branch' ' git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && git config branch.autosetuprebase never && - (git show-ref -q refs/remotes/local/o || git fetch local) && + (git show-ref -q refs/remotes/local/o || git fetch -q local) && git branch mybase4 && - git branch --track myr4 mybase2 && + quiet git branch --track myr4 mybase2 && test "$(git config branch.myr4.remote)" = . && test "$(git config branch.myr4.merge)" = refs/heads/mybase2 && ! test "$(git config branch.myr4.rebase)" = true
@@ -387,8 +404,8 @@ test_expect_success 'autosetuprebase local on a tracked remote branch' ' git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && git config branch.autosetuprebase local && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --track myr5 local/master && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --track myr5 local/master && test "$(git config branch.myr5.remote)" = local && test "$(git config branch.myr5.merge)" = refs/heads/master && ! test "$(git config branch.myr5.rebase)" = true
@@ -398,8 +415,8 @@ test_expect_success 'autosetuprebase never on a tracked remote branch' ' git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && git config branch.autosetuprebase never && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --track myr6 local/master && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --track myr6 local/master && test "$(git config branch.myr6.remote)" = local && test "$(git config branch.myr6.merge)" = refs/heads/master && ! test "$(git config branch.myr6.rebase)" = true
@@ -409,8 +426,8 @@ test_expect_success 'autosetuprebase remote on a tracked remote branch' ' git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && git config branch.autosetuprebase remote && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --track myr7 local/master && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --track myr7 local/master && test "$(git config branch.myr7.remote)" = local && test "$(git config branch.myr7.merge)" = refs/heads/master && test "$(git config branch.myr7.rebase)" = true
@@ -420,8 +437,8 @@ test_expect_success 'autosetuprebase always on a tracked remote branch' ' git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && git config branch.autosetuprebase remote && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --track myr8 local/master && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --track myr8 local/master && test "$(git config branch.myr8.remote)" = local && test "$(git config branch.myr8.merge)" = refs/heads/master && test "$(git config branch.myr8.rebase)" = true
@@ -431,8 +448,8 @@ test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' ' git config --unset branch.autosetuprebase && git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --track myr9 local/master && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --track myr9 local/master && test "$(git config branch.myr9.remote)" = local && test "$(git config branch.myr9.merge)" = refs/heads/master && test "z$(git config branch.myr9.rebase)" = z
@@ -441,9 +458,9 @@ test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' ' test_expect_success 'autosetuprebase unconfigured on a tracked local branch' ' git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/o || git fetch local) && + (git show-ref -q refs/remotes/local/o || git fetch -q local) && git branch mybase10 && - git branch --track myr10 mybase2 && + quiet git branch --track myr10 mybase2 && test "$(git config branch.myr10.remote)" = . && test "$(git config branch.myr10.merge)" = refs/heads/mybase2 && test "z$(git config branch.myr10.rebase)" = z
@@ -452,8 +469,8 @@ test_expect_success 'autosetuprebase unconfigured on a tracked local branch' ' test_expect_success 'autosetuprebase unconfigured on untracked local branch' ' git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --no-track myr11 mybase2 && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --no-track myr11 mybase2 && test "z$(git config branch.myr11.remote)" = z && test "z$(git config branch.myr11.merge)" = z && test "z$(git config branch.myr11.rebase)" = z
@@ -462,8 +479,8 @@ test_expect_success 'autosetuprebase unconfigured on untracked local branch' ' test_expect_success 'autosetuprebase unconfigured on untracked remote branch' ' git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --no-track myr12 local/master && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --no-track myr12 local/master && test "z$(git config branch.myr12.remote)" = z && test "z$(git config branch.myr12.merge)" = z && test "z$(git config branch.myr12.rebase)" = z
@@ -473,8 +490,8 @@ test_expect_success 'autosetuprebase never on an untracked local branch' ' git config branch.autosetuprebase never && git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --no-track myr13 mybase2 && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --no-track myr13 mybase2 && test "z$(git config branch.myr13.remote)" = z && test "z$(git config branch.myr13.merge)" = z && test "z$(git config branch.myr13.rebase)" = z
@@ -484,8 +501,8 @@ test_expect_success 'autosetuprebase local on an untracked local branch' ' git config branch.autosetuprebase local && git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --no-track myr14 mybase2 && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --no-track myr14 mybase2 && test "z$(git config branch.myr14.remote)" = z && test "z$(git config branch.myr14.merge)" = z && test "z$(git config branch.myr14.rebase)" = z
@@ -495,8 +512,8 @@ test_expect_success 'autosetuprebase remote on an untracked local branch' ' git config branch.autosetuprebase remote && git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --no-track myr15 mybase2 && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --no-track myr15 mybase2 && test "z$(git config branch.myr15.remote)" = z && test "z$(git config branch.myr15.merge)" = z && test "z$(git config branch.myr15.rebase)" = z
@@ -506,8 +523,8 @@ test_expect_success 'autosetuprebase always on an untracked local branch' ' git config branch.autosetuprebase always && git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --no-track myr16 mybase2 && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --no-track myr16 mybase2 && test "z$(git config branch.myr16.remote)" = z && test "z$(git config branch.myr16.merge)" = z && test "z$(git config branch.myr16.rebase)" = z
@@ -517,8 +534,8 @@ test_expect_success 'autosetuprebase never on an untracked remote branch' ' git config branch.autosetuprebase never && git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --no-track myr17 local/master && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --no-track myr17 local/master && test "z$(git config branch.myr17.remote)" = z && test "z$(git config branch.myr17.merge)" = z && test "z$(git config branch.myr17.rebase)" = z
@@ -528,8 +545,8 @@ test_expect_success 'autosetuprebase local on an untracked remote branch' ' git config branch.autosetuprebase local && git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --no-track myr18 local/master && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --no-track myr18 local/master && test "z$(git config branch.myr18.remote)" = z && test "z$(git config branch.myr18.merge)" = z && test "z$(git config branch.myr18.rebase)" = z
@@ -539,8 +556,8 @@ test_expect_success 'autosetuprebase remote on an untracked remote branch' ' git config branch.autosetuprebase remote && git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --no-track myr19 local/master && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --no-track myr19 local/master && test "z$(git config branch.myr19.remote)" = z && test "z$(git config branch.myr19.merge)" = z && test "z$(git config branch.myr19.rebase)" = z
@@ -550,8 +567,8 @@ test_expect_success 'autosetuprebase always on an untracked remote branch' ' git config branch.autosetuprebase always && git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --no-track myr20 local/master && + (git show-ref -q refs/remotes/local/master || git fetch -q local) && + quiet git branch --no-track myr20 local/master && test "z$(git config branch.myr20.remote)" = z && test "z$(git config branch.myr20.merge)" = z && test "z$(git config branch.myr20.rebase)" = z
@@ -559,8 +576,8 @@ test_expect_success 'autosetuprebase always on an untracked remote branch' ' test_expect_success 'autosetuprebase always on detached HEAD' ' git config branch.autosetupmerge always && - test_when_finished git checkout master && - git checkout HEAD^0 && + test_when_finished git checkout -q master && + git checkout -q HEAD^0 && git branch my11 && test -z "$(git config branch.my11.remote)" && test -z "$(git config branch.my11.merge)"
@@ -568,20 +585,20 @@ test_expect_success 'autosetuprebase always on detached HEAD' ' test_expect_success 'detect misconfigured autosetuprebase (bad value)' ' git config branch.autosetuprebase garbage && - test_must_fail git branch + silent test_must_fail git branch ' test_expect_success 'detect misconfigured autosetuprebase (no value)' ' git config --unset branch.autosetuprebase && echo "[branch] autosetuprebase" >> .git/config && - test_must_fail git branch && + silent test_must_fail git branch && git config --unset branch.autosetuprebase ' test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' ' - git checkout my9 && + git checkout -q my9 && git config --unset branch.my8.merge && - test_must_fail git branch -d my8 + silent test_must_fail git branch -d my8 ' test_expect_success 'attempt to delete a branch merged to its base' '
@@ -589,32 +606,30 @@ test_expect_success 'attempt to delete a branch merged to its base' ' # we would not have allowed deleting my8 that is not merged # to my9, but it is set to track master that already has my8 git config branch.my8.merge refs/heads/master && - git branch -d my8 + silent git branch -d my8 ' test_expect_success 'attempt to delete a branch merged to its base' ' - git checkout master && + git checkout -q master && echo Third >>A && - git commit -m "Third commit" A && - git branch -t my10 my9 && - git branch -f my10 HEAD^ && + git commit -q -m "Third commit" A && + quiet git branch -t my10 my9 && + quiet git branch -f my10 HEAD^ && # we are on master which is at the third commit, and my10 # is behind us, so traditionally we would have allowed deleting # it; but my10 is set to track my9 that is further behind. - test_must_fail git branch -d my10 + silent test_must_fail git branch -d my10 ' test_expect_success 'use set-upstream on the current branch' ' - git checkout master && - git --bare init myupstream.git && - git push myupstream.git master:refs/heads/frotz && + git checkout -q master && + git --bare init -q myupstream.git && + git push -q myupstream.git master:refs/heads/frotz && git remote add origin myupstream.git && - git fetch && - git branch --set-upstream master origin/frotz && - + git fetch -q && + quiet git branch --set-upstream master origin/frotz && test "z$(git config branch.master.remote)" = "zorigin" && test "z$(git config branch.master.merge)" = "zrefs/heads/frotz" - ' test_expect_success 'use --edit-description' '
@@ -637,7 +652,7 @@ test_expect_success 'detect typo in branch name when using --edit-description' ' ( EDITOR=./editor && export EDITOR && - test_must_fail git branch --edit-description no-such-branch + silent test_must_fail git branch --edit-description no-such-branch ) '
@@ -645,11 +660,11 @@ test_expect_success 'refuse --edit-description on unborn branch for now' ' write_script editor <<-\EOF && echo "New contents" >"$1" EOF - git checkout --orphan unborn && + git checkout -q --orphan unborn && ( EDITOR=./editor && export EDITOR && - test_must_fail git branch --edit-description + silent test_must_fail git branch --edit-description ) '
Signature · 1 line
1.7.8
PATCH 104/105 t0040 (parse-options): modernize style
In reply to Tom Grennan- Guard setup with test_expect_success
- Single-quoted, tab prefaced test blocks of < 80 cols
- Redirect unwanted output
--- t/t0040-parse-options.sh | 283 +++++++++++++++++++++------------------------- 1 files changed, 127 insertions(+), 156 deletions(-)
t/t0040-parse-options.sh +127 -156
@@ -5,55 +5,60 @@ test_description='our own option parser' -. ./test-lib.sh +if ! test -r test-lib.sh ; then + (cd ${0%/*} && ./${0##*/} $@) + exit $? +fi -cat > expect << EOF -usage: test-parse-options <options> - - -b, --boolean get a boolean - -4, --or4 bitwise-or boolean with ...0100 - --neg-or4 same as --no-or4 - - -i, --integer <n> get a integer - -j <n> get a integer, too - --set23 set integer to 23 - -t <time> get timestamp of <time> - -L, --length <str> get length of <str> - -F, --file <file> set file to <file> - -String options - -s, --string <string> - get a string - --string2 <str> get another string - --st <st> get another string (pervert ordering) - -o <str> get another string - --default-string set string to default - --list <str> add str to list - -Magic arguments - --quux means --quux - -NUM set integer to NUM - + same as -b - --ambiguous positive ambiguity - --no-ambiguous negative ambiguity - -Standard options - --abbrev[=<n>] use <n> digits to display SHA-1s - -v, --verbose be verbose - -n, --dry-run dry run - -q, --quiet be quiet +. ./test-lib.sh -EOF +silent () { "$@" >/dev/null 2>&1; } test_expect_success 'test help' ' - test_must_fail test-parse-options -h > output 2> output.err && - test ! -s output.err && - test_cmp expect output -' + sed -e "s/^|//" >expect <<-\EOF && + |usage: test-parse-options <options> + + | -b, --boolean get a boolean + | -4, --or4 bitwise-or boolean with ...0100 + | --neg-or4 same as --no-or4 + + | -i, --integer <n> get a integer + | -j <n> get a integer, too + | --set23 set integer to 23 + | -t <time> get timestamp of <time> + | -L, --length <str> get length of <str> + | -F, --file <file> set file to <file> + + |String options + | -s, --string <string> + | get a string + | --string2 <str> get another string + | --st <st> get another string (pervert ordering) + | -o <str> get another string + | --default-string set string to default + | --list <str> add str to list + + |Magic arguments + | --quux means --quux + | -NUM set integer to NUM + | + same as -b + | --ambiguous positive ambiguity + | --no-ambiguous negative ambiguity + + |Standard options + | --abbrev[=<n>] use <n> digits to display SHA-1s + | -v, --verbose be verbose + | -n, --dry-run dry run + | -q, --quiet be quiet -mv expect expect.err + EOF + cp expect expect.err + test_must_fail test-parse-options -h 2>err | test_cmp expect - && + test ! -s err +' -cat > expect << EOF +test_expect_success 'short options' ' + cat >expect <<-\EOF && boolean: 2 integer: 1729 timestamp: 0
@@ -64,15 +69,13 @@ quiet: no dry run: yes file: prefix/my.file EOF - -test_expect_success 'short options' ' - test-parse-options -s123 -b -i 1729 -b -vv -n -F my.file \ - > output 2> output.err && - test_cmp expect output && - test ! -s output.err + test-parse-options -s123 -b -i 1729 -b -vv -n -F my.file 2>err | + test_cmp expect - && + test ! -s err ' -cat > expect << EOF +test_expect_success 'long options' ' + cat >expect <<-\EOF && boolean: 2 integer: 1729 timestamp: 0
@@ -83,25 +86,20 @@ quiet: no dry run: no file: prefix/fi.le EOF - -test_expect_success 'long options' ' test-parse-options --boolean --integer 1729 --boolean --string2=321 \ --verbose --verbose --no-dry-run --abbrev=10 --file fi.le\ - --obsolete > output 2> output.err && - test ! -s output.err && - test_cmp expect output + --obsolete 2>err | test_cmp expect - && + test ! -s err ' test_expect_success 'missing required value' ' - test-parse-options -s; - test $? = 129 && - test-parse-options --string; - test $? = 129 && - test-parse-options --file; - test $? = 129 + silent test_expect_code 129 test-parse-options -s && + silent test_expect_code 129 test-parse-options --string && + silent test_expect_code 129 test-parse-options --file ' -cat > expect << EOF +test_expect_success 'intermingled arguments' ' + cat >expect <<-\EOF && boolean: 1 integer: 13 timestamp: 0
@@ -115,15 +113,13 @@ arg 00: a1 arg 01: b1 arg 02: --boolean EOF - -test_expect_success 'intermingled arguments' ' test-parse-options a1 --string 123 b1 --boolean -j 13 -- --boolean \ - > output 2> output.err && - test ! -s output.err && - test_cmp expect output + 2>err | test_cmp expect - && + test ! -s err ' -cat > expect << EOF +test_expect_success 'unambiguously abbreviated option' ' + cat >expect <<-\EOF && boolean: 0 integer: 2 timestamp: 0
@@ -134,25 +130,22 @@ quiet: no dry run: no file: (not set) EOF - -test_expect_success 'unambiguously abbreviated option' ' - test-parse-options --int 2 --boolean --no-bo > output 2> output.err && - test ! -s output.err && - test_cmp expect output + test-parse-options --int 2 --boolean --no-bo 2>err | + test_cmp expect - && + test ! -s err ' test_expect_success 'unambiguously abbreviated option with "="' ' - test-parse-options --int=2 > output 2> output.err && - test ! -s output.err && - test_cmp expect output + test-parse-options --int=2 2>err | test_cmp expect -&& + test ! -s err ' test_expect_success 'ambiguously abbreviated option' ' - test-parse-options --strin 123; - test $? = 129 + silent test_expect_code 129 test-parse-options --strin 123 ' -cat > expect << EOF +test_expect_success 'non ambiguous option (after two options it abbreviates)' ' + cat >expect <<-\EOF && boolean: 0 integer: 0 timestamp: 0
@@ -163,24 +156,21 @@ quiet: no dry run: no file: (not set) EOF - -test_expect_success 'non ambiguous option (after two options it abbreviates)' ' - test-parse-options --st 123 > output 2> output.err && - test ! -s output.err && - test_cmp expect output + test-parse-options --st 123 2>err | test_cmp expect - && + test ! -s err ' -cat > typo.err << EOF -error: did you mean \`--boolean\` (with two dashes ?) -EOF - test_expect_success 'detect possible typos' ' - test_must_fail test-parse-options -boolean > output 2> output.err && - test ! -s output && - test_cmp typo.err output.err + cat >typo.err <<-\EOF && + error: did you mean `--boolean` (with two dashes ?) + EOF + >expect + test_must_fail test-parse-options -boolean 2>err | test_cmp expect - && + test_cmp typo.err err ' -cat > expect <<EOF +test_expect_success 'keep some options as arguments' ' + cat >expect <<-\EOF && boolean: 0 integer: 0 timestamp: 0
@@ -192,14 +182,12 @@ dry run: no file: (not set) arg 00: --quux EOF - -test_expect_success 'keep some options as arguments' ' - test-parse-options --quux > output 2> output.err && - test ! -s output.err && - test_cmp expect output + test-parse-options --quux 2>err | test_cmp expect - && + test ! -s err ' -cat > expect <<EOF +test_expect_success 'OPT_DATE() and OPT_SET_PTR() work' ' + cat >expect <<-\EOF && boolean: 0 integer: 0 timestamp: 1
@@ -211,15 +199,13 @@ dry run: no file: (not set) arg 00: foo EOF - -test_expect_success 'OPT_DATE() and OPT_SET_PTR() work' ' - test-parse-options -t "1970-01-01 00:00:01 +0000" --default-string \ - foo -q > output 2> output.err && - test ! -s output.err && - test_cmp expect output + test-parse-options -t "1970-01-01 00:00:01 +0000" \ + --default-string foo -q 2>err | test_cmp expect - && + test ! -s err ' -cat > expect <<EOF +test_expect_success 'OPT_CALLBACK() and OPT_BIT() work' ' + cat >expect <<-\EOF && Callback: "four", 0 boolean: 5 integer: 4
@@ -231,24 +217,21 @@ quiet: no dry run: no file: (not set) EOF - -test_expect_success 'OPT_CALLBACK() and OPT_BIT() work' ' - test-parse-options --length=four -b -4 > output 2> output.err && - test ! -s output.err && - test_cmp expect output + test-parse-options --length=four -b -4 2>err | test_cmp expect - && + test ! -s err ' -cat > expect <<EOF +test_expect_success 'OPT_CALLBACK() and callback errors work' ' + cat >expect <<-\EOF && Callback: "not set", 1 EOF - -test_expect_success 'OPT_CALLBACK() and callback errors work' ' - test_must_fail test-parse-options --no-length > output 2> output.err && - test_cmp expect output && - test_cmp expect.err output.err + test_must_fail test-parse-options --no-length 2>err | + test_cmp expect - && + test_cmp expect.err err ' -cat > expect <<EOF +test_expect_success 'OPT_BIT() and OPT_SET_INT() work' ' + cat >expect <<-\EOF && boolean: 1 integer: 23 timestamp: 0
@@ -259,20 +242,17 @@ quiet: no dry run: no file: (not set) EOF - -test_expect_success 'OPT_BIT() and OPT_SET_INT() work' ' - test-parse-options --set23 -bbbbb --no-or4 > output 2> output.err && - test ! -s output.err && - test_cmp expect output + test-parse-options --set23 -bbbbb --no-or4 2>err | test_cmp expect - && + test ! -s err ' test_expect_success 'OPT_NEGBIT() and OPT_SET_INT() work' ' - test-parse-options --set23 -bbbbb --neg-or4 > output 2> output.err && - test ! -s output.err && - test_cmp expect output + test-parse-options --set23 -bbbbb --neg-or4 2>err | test_cmp expect - && + test ! -s err ' -cat > expect <<EOF +test_expect_success 'OPT_BIT() works' ' + cat >expect <<-\EOF && boolean: 6 integer: 0 timestamp: 0
@@ -283,26 +263,23 @@ quiet: no dry run: no file: (not set) EOF - -test_expect_success 'OPT_BIT() works' ' - test-parse-options -bb --or4 > output 2> output.err && - test ! -s output.err && - test_cmp expect output + test-parse-options -bb --or4 2>err | test_cmp expect - && + test ! -s err ' test_expect_success 'OPT_NEGBIT() works' ' - test-parse-options -bb --no-neg-or4 > output 2> output.err && - test ! -s output.err && - test_cmp expect output + test-parse-options -bb --no-neg-or4 2>err | test_cmp expect - && + test ! -s err ' test_expect_success 'OPT_BOOLEAN() with PARSE_OPT_NODASH works' ' - test-parse-options + + + + + + > output 2> output.err && - test ! -s output.err && - test_cmp expect output + test-parse-options + + + + + + 2>err | test_cmp expect - && + test ! -s err ' -cat > expect <<EOF + +test_expect_success 'OPT_NUMBER_CALLBACK() works' ' + cat >expect <<-\EOF && boolean: 0 integer: 12345 timestamp: 0
@@ -313,14 +290,12 @@ quiet: no dry run: no file: (not set) EOF - -test_expect_success 'OPT_NUMBER_CALLBACK() works' ' - test-parse-options -12345 > output 2> output.err && - test ! -s output.err && - test_cmp expect output + test-parse-options -12345 2>err | test_cmp expect - && + test ! -s err ' -cat >expect <<EOF +test_expect_success 'negation of OPT_NONEG flags is not ambiguous' ' + cat >expect <<-\EOF && boolean: 0 integer: 0 timestamp: 0
@@ -331,27 +306,23 @@ quiet: no dry run: no file: (not set) EOF - -test_expect_success 'negation of OPT_NONEG flags is not ambiguous' ' - test-parse-options --no-ambig >output 2>output.err && - test ! -s output.err && - test_cmp expect output + test-parse-options --no-ambig 2>err | test_cmp expect - && + test ! -s err ' -cat >>expect <<'EOF' +test_expect_success '--list keeps list of strings' ' + cat >>expect <<-\EOF && list: foo list: bar list: baz EOF -test_expect_success '--list keeps list of strings' ' - test-parse-options --list foo --list=bar --list=baz >output && - test_cmp expect output + test-parse-options --list foo --list=bar --list=baz | test_cmp expect - ' test_expect_success '--no-list resets list' ' - test-parse-options --list=other --list=irrelevant --list=options \ - --no-list --list=foo --list=bar --list=baz >output && - test_cmp expect output + test-parse-options --list=other --list=irrelevant \ + --list=options --no-list --list=foo --list=bar --list=baz | + test_cmp expect - ' test_done
Signature · 1 line
1.7.8
PATCH 105/105 t7004 (tag): modernize style
In reply to Tom Grennan- Guard setup with test_expect_success
- Single-quoted, tab prefaced test blocks of < 80 cols
- Redirect unwanted output
- Use a "here" filter for expect generation
--- t/t7004-tag.sh | 1400 ++++++++++++++++++++++++++------------------------------ 1 files changed, 643 insertions(+), 757 deletions(-)
t/t7004-tag.sh +643 -757
@@ -7,15 +7,37 @@ test_description='git tag Tests for operations with tags.' +if ! test -r test-lib.sh ; then + (cd ${0%/*} && ./${0##*/} $@) + exit $? +fi + . ./test-lib.sh . "$TEST_DIRECTORY"/lib-gpg.sh -# creating and listing lightweight tags: +quiet () { "$@" >/dev/null; } +silent () { "$@" >/dev/null 2>&1; } +here () { sed 's/\\s/ /g; s/\\t/\t/g; s/\\n/\n/g' $@; } tag_exists () { git show-ref --quiet --verify refs/tags/"$1" } +gen_header () { # name, object, type, time + cat <<-EOF && + object $2 + type $3 + tag $1 + tagger C O Mitter <[email protected]> $4 -0700 + + EOF + here +} + +get_header () { + git cat-file tag "$1" | sed -e "/BEGIN PGP/q" +} + # todo: git tag -l now returns always zero, when fixed, change this test test_expect_success 'listing all tags in an empty tree should succeed' ' git tag -l &&
@@ -27,36 +49,38 @@ test_expect_success 'listing all tags in an empty tree should output nothing' ' test `git tag | wc -l` -eq 0 ' -test_expect_success 'looking for a tag in an empty tree should fail' \ - '! (tag_exists mytag)' +test_expect_success 'looking for a tag in an empty tree should fail' ' + ! tag_exists mytag +' test_expect_success 'creating a tag in an empty tree should fail' ' - test_must_fail git tag mynotag && + silent test_must_fail git tag mynotag && ! tag_exists mynotag ' test_expect_success 'creating a tag for HEAD in an empty tree should fail' ' - test_must_fail git tag mytaghead HEAD && + silent test_must_fail git tag mytaghead HEAD && ! tag_exists mytaghead ' test_expect_success 'creating a tag for an unknown revision should fail' ' - test_must_fail git tag mytagnorev aaaaaaaaaaa && + silent test_must_fail git tag mytagnorev aaaaaaaaaaa && ! tag_exists mytagnorev ' -# commit used in the tests, test_tick is also called here to freeze the date: test_expect_success 'creating a tag using default HEAD should succeed' ' + # commit used in the tests + # test_tick is also called here to freeze the date: test_tick && - echo foo >foo && + echo >foo foo && git add foo && - git commit -m Foo && + git commit -q -m Foo && git tag mytag ' test_expect_success 'listing all tags if one exists should succeed' ' - git tag -l && - git tag + quiet git tag -l && + quiet git tag ' test_expect_success 'listing all tags if one exists should output that tag' '
@@ -66,36 +90,36 @@ test_expect_success 'listing all tags if one exists should output that tag' ' # pattern matching: -test_expect_success 'listing a tag using a matching pattern should succeed' \ - 'git tag -l mytag' +test_expect_success 'listing a tag using a matching pattern should succeed' ' + quiet git tag -l mytag +' -test_expect_success \ - 'listing a tag using a matching pattern should output that tag' \ - 'test `git tag -l mytag` = mytag' +test_expect_success 'listing a tag using a matching pattern should output that tag' ' + test `git tag -l mytag` = mytag +' # todo: git tag -l now returns always zero, when fixed, change this test -test_expect_success \ - 'listing tags using a non-matching pattern should suceed' \ - 'git tag -l xxx' +test_expect_success 'listing tags using a non-matching pattern should suceed' ' + git tag -l xxx +' -test_expect_success \ - 'listing tags using a non-matching pattern should output nothing' \ - 'test `git tag -l xxx | wc -l` -eq 0' +test_expect_success 'listing tags using a non-matching pattern should output nothing' ' + test `git tag -l xxx | wc -l` -eq 0 +' # special cases for creating tags: -test_expect_success \ - 'trying to create a tag with the name of one existing should fail' \ - 'test_must_fail git tag mytag' +test_expect_success 'trying to create a tag with the name of one existing should fail' ' + silent test_must_fail git tag mytag +' -test_expect_success \ - 'trying to create a tag with a non-valid name should fail' ' +test_expect_success 'trying to create a tag with a non-valid name should fail' ' test `git tag -l | wc -l` -eq 1 && - test_must_fail git tag "" && - test_must_fail git tag .othertag && - test_must_fail git tag "other tag" && - test_must_fail git tag "othertag^" && - test_must_fail git tag "other~tag" && + silent test_must_fail git tag "" && + silent test_must_fail git tag .othertag && + silent test_must_fail git tag "other tag" && + silent test_must_fail git tag "othertag^" && + silent test_must_fail git tag "other~tag" && test `git tag -l | wc -l` -eq 1 '
@@ -108,51 +132,49 @@ test_expect_success 'creating a tag using HEAD directly should succeed' ' test_expect_success 'trying to delete an unknown tag should fail' ' ! tag_exists unknown-tag && - test_must_fail git tag -d unknown-tag + silent test_must_fail git tag -d unknown-tag ' -cat >expect <<EOF +test_expect_success 'trying to delete tags without params should succeed and do nothing' ' + cat >expect <<-EOF && myhead mytag EOF -test_expect_success \ - 'trying to delete tags without params should succeed and do nothing' ' - git tag -l > actual && test_cmp expect actual && + git tag -l | test_cmp expect - && git tag -d && - git tag -l > actual && test_cmp expect actual + git tag -l | test_cmp expect - ' -test_expect_success \ - 'deleting two existing tags in one command should succeed' ' +test_expect_success 'deleting two existing tags in one command should succeed' ' tag_exists mytag && tag_exists myhead && - git tag -d mytag myhead && + quiet git tag -d mytag myhead && ! tag_exists mytag && ! tag_exists myhead ' -test_expect_success \ - 'creating a tag with the name of another deleted one should succeed' ' +test_expect_success 'creating a tag with the name of another deleted one should succeed' ' ! tag_exists mytag && git tag mytag && tag_exists mytag ' -test_expect_success \ - 'trying to delete two tags, existing and not, should fail in the 2nd' ' +test_expect_success 'trying to delete two tags, existing and not, should fail in the 2nd' ' tag_exists mytag && ! tag_exists myhead && - test_must_fail git tag -d mytag anothertag && + silent test_must_fail git tag -d mytag anothertag && ! tag_exists mytag && ! tag_exists myhead ' -test_expect_success 'trying to delete an already deleted tag should fail' \ - 'test_must_fail git tag -d mytag' +test_expect_success 'trying to delete an already deleted tag should fail' ' + silent test_must_fail git tag -d mytag +' # listing various tags with pattern matching: -cat >expect <<EOF +test_expect_success 'listing all tags should print them ordered' ' + cat >expect <<-EOF && a1 aa1 cba
@@ -163,7 +185,6 @@ v1.0 v1.0.1 v1.1.3 EOF -test_expect_success 'listing all tags should print them ordered' ' git tag v1.0.1 && git tag t211 && git tag aa1 &&
@@ -173,217 +194,189 @@ test_expect_success 'listing all tags should print them ordered' ' git tag a1 && git tag v1.0 && git tag t210 && - git tag -l > actual && - test_cmp expect actual && - git tag > actual && - test_cmp expect actual + git tag -l | test_cmp expect - && + git tag | test_cmp expect - ' -cat >expect <<EOF +test_expect_success 'listing tags with substring as pattern must print those matching' ' + cat >expect <<-EOF && a1 aa1 cba EOF -test_expect_success \ - 'listing tags with substring as pattern must print those matching' ' - rm *a* && - git tag -l "*a*" > current && - test_cmp expect current + git tag -l "*a*" | test_cmp expect - ' -cat >expect <<EOF +test_expect_success 'listing tags with a suffix as pattern must print those matching' ' + cat >expect <<-EOF && v0.2.1 v1.0.1 EOF -test_expect_success \ - 'listing tags with a suffix as pattern must print those matching' ' - git tag -l "*.1" > actual && - test_cmp expect actual + git tag -l "*.1" | test_cmp expect - ' -cat >expect <<EOF +test_expect_success 'listing tags with a prefix as pattern must print those matching' ' + cat >expect <<-EOF && t210 t211 EOF -test_expect_success \ - 'listing tags with a prefix as pattern must print those matching' ' - git tag -l "t21*" > actual && - test_cmp expect actual + git tag -l "t21*" | test_cmp expect - ' -cat >expect <<EOF +test_expect_success 'listing tags using a name as pattern must print that one matching' ' + cat >expect <<-EOF && a1 EOF -test_expect_success \ - 'listing tags using a name as pattern must print that one matching' ' - git tag -l a1 > actual && - test_cmp expect actual + git tag -l a1 | test_cmp expect - ' -cat >expect <<EOF +test_expect_success 'listing tags using a name as pattern must print that one matching' ' + cat >expect <<-EOF && v1.0 EOF -test_expect_success \ - 'listing tags using a name as pattern must print that one matching' ' - git tag -l v1.0 > actual && - test_cmp expect actual + git tag -l v1.0 | test_cmp expect - ' -cat >expect <<EOF +test_expect_success 'listing tags with ? in the pattern should print those matching' ' + cat >expect <<-EOF && v1.0.1 v1.1.3 EOF -test_expect_success \ - 'listing tags with ? in the pattern should print those matching' ' - git tag -l "v1.?.?" > actual && - test_cmp expect actual + git tag -l "v1.?.?" | test_cmp expect - ' ->expect -test_expect_success \ - 'listing tags using v.* should print nothing because none have v.' ' - git tag -l "v.*" > actual && - test_cmp expect actual +test_expect_success 'listing tags using v.* should print nothing because none have v.' ' + >expect && + git tag -l "v.*" | test_cmp expect - ' -cat >expect <<EOF +test_expect_success 'listing tags using v* should print only those having v' ' + cat >expect <<-EOF && v0.2.1 v1.0 v1.0.1 v1.1.3 EOF -test_expect_success \ - 'listing tags using v* should print only those having v' ' - git tag -l "v*" > actual && - test_cmp expect actual + git tag -l "v*" | test_cmp expect - ' test_expect_success 'tag -l can accept multiple patterns' ' - git tag -l "v1*" "v0*" >actual && - test_cmp expect actual + git tag -l "v1*" "v0*" | test_cmp expect - ' # creating and verifying lightweight tags: -test_expect_success \ - 'a non-annotated tag created without parameters should point to HEAD' ' +test_expect_success 'a non-annotated tag created without parameters should point to HEAD' ' git tag non-annotated-tag && test $(git cat-file -t non-annotated-tag) = commit && test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD) ' -test_expect_success 'trying to verify an unknown tag should fail' \ - 'test_must_fail git tag -v unknown-tag' +test_expect_success 'trying to verify an unknown tag should fail' ' + silent test_must_fail git tag -v unknown-tag +' -test_expect_success \ - 'trying to verify a non-annotated and non-signed tag should fail' \ - 'test_must_fail git tag -v non-annotated-tag' +test_expect_success 'trying to verify a non-annotated and non-signed tag should fail' ' + silent test_must_fail git tag -v non-annotated-tag +' -test_expect_success \ - 'trying to verify many non-annotated or unknown tags, should fail' \ - 'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2' +test_expect_success 'trying to verify many non-annotated or unknown tags, should fail' ' + silent test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2 +' # creating annotated tags: -get_tag_msg () { - git cat-file tag "$1" | sed -e "/BEGIN PGP/q" -} - -# run test_tick before committing always gives the time in that timezone -get_tag_header () { -cat <<EOF -object $2 -type $3 -tag $1 -tagger C O Mitter <[email protected]> $4 -0700 - +test_expect_success 'creating an annotated tag with -m message should succeed' ' + commit=$(git rev-parse HEAD) && + time=$test_tick && + name="annotated-tag" && + msg="A message" && + gen_header >expect $name $commit commit $time <<-EOF && + $msg EOF -} - -commit=$(git rev-parse HEAD) -time=$test_tick - -get_tag_header annotated-tag $commit commit $time >expect -echo "A message" >>expect -test_expect_success \ - 'creating an annotated tag with -m message should succeed' ' - git tag -m "A message" annotated-tag && - get_tag_msg annotated-tag >actual && - test_cmp expect actual + git tag -m "$msg" $name && + get_header $name | test_cmp expect - ' -cat >msgfile <<EOF +test_expect_success 'creating an annotated tag with -F messagefile should succeed' ' + name="file-annotated-tag" && + gen_header >expect $name $commit commit $time <<-EOF && Another message in a file. EOF -get_tag_header file-annotated-tag $commit commit $time >expect -cat msgfile >>expect -test_expect_success \ - 'creating an annotated tag with -F messagefile should succeed' ' - git tag -F msgfile file-annotated-tag && - get_tag_msg file-annotated-tag >actual && - test_cmp expect actual + tail -n 2 expect >msgfile && + git tag -F msgfile $name && + get_header $name | test_cmp expect - ' -cat >inputmsg <<EOF +test_expect_success 'creating an annotated tag with -F - should succeed' ' + name="stdin-annotated-tag" && + gen_header >expect $name $commit commit $time <<-EOF && A message from the standard input EOF -get_tag_header stdin-annotated-tag $commit commit $time >expect -cat inputmsg >>expect -test_expect_success 'creating an annotated tag with -F - should succeed' ' - git tag -F - stdin-annotated-tag <inputmsg && - get_tag_msg stdin-annotated-tag >actual && - test_cmp expect actual + tail -n 2 expect | git tag -F - $name && + get_header $name | test_cmp expect - ' -test_expect_success \ - 'trying to create a tag with a non-existing -F file should fail' ' +test_expect_success 'trying to create a tag with a non-existing -F file should fail' ' ! test -f nonexistingfile && ! tag_exists notag && - test_must_fail git tag -F nonexistingfile notag && + silent test_must_fail git tag -F nonexistingfile notag && ! tag_exists notag ' -test_expect_success \ - 'trying to create tags giving both -m or -F options should fail' ' - echo "message file 1" >msgfile1 && - echo "message file 2" >msgfile2 && +test_expect_success 'trying to create tags giving both -m or -F options should fail' ' + echo >msgfile1 "message file 1" && + echo >msgfile2 "message file 2" && ! tag_exists msgtag && - test_must_fail git tag -m "message 1" -F msgfile1 msgtag && + silent test_must_fail git tag -m "message 1" -F msgfile1 msgtag && ! tag_exists msgtag && - test_must_fail git tag -F msgfile1 -m "message 1" msgtag && + silent test_must_fail git tag -F msgfile1 -m "message 1" msgtag && ! tag_exists msgtag && - test_must_fail git tag -m "message 1" -F msgfile1 \ + silent test_must_fail git tag -m "message 1" -F msgfile1 \ -m "message 2" msgtag && ! tag_exists msgtag ' # blank and empty messages: -get_tag_header empty-annotated-tag $commit commit $time >expect -test_expect_success \ - 'creating a tag with an empty -m message should succeed' ' - git tag -m "" empty-annotated-tag && - get_tag_msg empty-annotated-tag >actual && - test_cmp expect actual +test_expect_success 'creating a tag with an empty -m message should succeed' ' + name="empty-annotated-tag" && + gen_header >expect $name $commit commit $time </dev/null && + git tag -m "" $name && + get_header $name | test_cmp expect - ' ->emptyfile -get_tag_header emptyfile-annotated-tag $commit commit $time >expect -test_expect_success \ - 'creating a tag with an empty -F messagefile should succeed' ' - git tag -F emptyfile emptyfile-annotated-tag && - get_tag_msg emptyfile-annotated-tag >actual && - test_cmp expect actual +test_expect_success 'creating a tag with an empty -F messagefile should succeed' ' + >emptyfile && + name="emptyfile-annotated-tag" && + gen_header >expect $name $commit commit $time </dev/null && + git tag -F emptyfile $name && + get_header $name | test_cmp expect - ' -printf '\n\n \n\t\nLeading blank lines\n' >blanksfile -printf '\n\t \t \nRepeated blank lines\n' >>blanksfile -printf '\n\n\nTrailing spaces \t \n' >>blanksfile -printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile -get_tag_header blanks-annotated-tag $commit commit $time >expect -cat >>expect <<EOF +test_expect_success 'extra blanks in the message for an annotated tag should be removed' ' + here >blanksfile <<-\EOF && + + \s\s + \t + Leading blank lines + + \t\s\t\s\s + Repeated blank lines + + + + Trailing spaces\s\s\s\s\s\s\t\s\s + + Trailing blank lines + + \t\s + + EOF + name="blanks-annotated-tag" && + gen_header $name $commit commit $time >expect <<-EOF && Leading blank lines Repeated blank lines
@@ -392,44 +385,41 @@ Trailing spaces Trailing blank lines EOF -test_expect_success \ - 'extra blanks in the message for an annotated tag should be removed' ' - git tag -F blanksfile blanks-annotated-tag && - get_tag_msg blanks-annotated-tag >actual && - test_cmp expect actual + git tag -F blanksfile $name && + get_header $name | test_cmp expect - ' -get_tag_header blank-annotated-tag $commit commit $time >expect -test_expect_success \ - 'creating a tag with blank -m message with spaces should succeed' ' - git tag -m " " blank-annotated-tag && - get_tag_msg blank-annotated-tag >actual && - test_cmp expect actual +test_expect_success 'creating a tag with blank -m message with spaces should succeed' ' + name="blank-annotated-tag" && + gen_header $name $commit commit $time </dev/null >expect && + git tag -m " " $name && + get_header $name | test_cmp expect - ' -echo ' ' >blankfile -echo '' >>blankfile -echo ' ' >>blankfile -get_tag_header blankfile-annotated-tag $commit commit $time >expect -test_expect_success \ - 'creating a tag with blank -F messagefile with spaces should succeed' ' - git tag -F blankfile blankfile-annotated-tag && - get_tag_msg blankfile-annotated-tag >actual && - test_cmp expect actual +test_expect_success 'creating a tag with blank -F messagefile with spaces should succeed' ' + here >blankfile <<-\EOF && + \s\s\s\s\s + + \s\s + EOF + name="blankfile-annotated-tag" && + gen_header >expect $name $commit commit $time </dev/null && + git tag -F blankfile $name && + get_header $name | test_cmp expect - ' -printf ' ' >blanknonlfile -get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect -test_expect_success \ - 'creating a tag with -F file of spaces and no newline should succeed' ' - git tag -F blanknonlfile blanknonlfile-annotated-tag && - get_tag_msg blanknonlfile-annotated-tag >actual && - test_cmp expect actual +test_expect_success 'creating a tag with -F file of spaces and no newline should succeed' ' + printf >blanknonlfile " " && + name="blanknonlfile-annotated-tag" && + gen_header >expect $name $commit commit $time </dev/null && + git tag -F blanknonlfile $name && + get_header $name | test_cmp expect - ' # messages with commented lines: -cat >commentsfile <<EOF +test_expect_success 'creating a tag using a -F messagefile with #comments should succeed' ' + cat >commentsfile <<-EOF && # A comment ############
@@ -446,8 +436,8 @@ Another line. Last line. EOF -get_tag_header comments-annotated-tag $commit commit $time >expect -cat >>expect <<EOF + name="comments-annotated-tag" && + gen_header $name $commit commit $time >expect <<-EOF && The message. One line.
@@ -455,279 +445,235 @@ Another line. Last line. EOF -test_expect_success \ - 'creating a tag using a -F messagefile with #comments should succeed' ' - git tag -F commentsfile comments-annotated-tag && - get_tag_msg comments-annotated-tag >actual && - test_cmp expect actual + git tag -F commentsfile $name && + get_header $name | test_cmp expect - ' -get_tag_header comment-annotated-tag $commit commit $time >expect -test_expect_success \ - 'creating a tag with a #comment in the -m message should succeed' ' - git tag -m "#comment" comment-annotated-tag && - get_tag_msg comment-annotated-tag >actual && - test_cmp expect actual +test_expect_success 'creating a tag with a #comment in the -m message should succeed' ' + name="comment-annotated-tag" && + gen_header $name $commit commit $time >expect </dev/null && + git tag -m "#comment" $name && + get_header $name | test_cmp expect - ' -echo '#comment' >commentfile -echo '' >>commentfile -echo '####' >>commentfile -get_tag_header commentfile-annotated-tag $commit commit $time >expect -test_expect_success \ - 'creating a tag with #comments in the -F messagefile should succeed' ' - git tag -F commentfile commentfile-annotated-tag && - get_tag_msg commentfile-annotated-tag >actual && - test_cmp expect actual +test_expect_success 'creating a tag with #comments in the -F messagefile should succeed' ' + cat >commentfile <<-EOF && + #comment + + #### + EOF + name="commentfile-annotated-tag" && + gen_header $name $commit commit $time >expect </dev/null && + git tag -F commentfile $name && + get_header $name | test_cmp expect - ' -printf '#comment' >commentnonlfile -get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect -test_expect_success \ - 'creating a tag with a file of #comment and no newline should succeed' ' - git tag -F commentnonlfile commentnonlfile-annotated-tag && - get_tag_msg commentnonlfile-annotated-tag >actual && - test_cmp expect actual +test_expect_success 'creating a tag with a file of #comment and no newline should succeed' ' + printf >commentnonlfile "#comment" && + name="commentnonlfile-annotated-tag" && + gen_header >expect $name $commit commit $time </dev/null && + git tag -F commentnonlfile $name && + get_header $name | test_cmp expect - ' # listing messages for annotated non-signed tags: -test_expect_success \ - 'listing the one-line message of a non-signed tag should succeed' ' +test_expect_success 'listing the one-line message of a non-signed tag should succeed' ' git tag -m "A msg" tag-one-line && - echo "tag-one-line" >expect && - git tag -l | grep "^tag-one-line" >actual && - test_cmp expect actual && - git tag -n0 -l | grep "^tag-one-line" >actual && - test_cmp expect actual && - git tag -n0 -l tag-one-line >actual && - test_cmp expect actual && - - echo "tag-one-line A msg" >expect && - git tag -n1 -l | grep "^tag-one-line" >actual && - test_cmp expect actual && - git tag -n -l | grep "^tag-one-line" >actual && - test_cmp expect actual && - git tag -n1 -l tag-one-line >actual && - test_cmp expect actual && - git tag -n2 -l tag-one-line >actual && - test_cmp expect actual && - git tag -n999 -l tag-one-line >actual && - test_cmp expect actual + echo >expect "tag-one-line" && + git tag -l | grep "^tag-one-line" | test_cmp expect - && + git tag -n0 -l | grep "^tag-one-line" | test_cmp expect - && + git tag -n0 -l tag-one-line | test_cmp expect - && + + echo >expect "tag-one-line A msg" && + git tag -n1 -l | grep "^tag-one-line" | test_cmp expect - && + git tag -n -l | grep "^tag-one-line" | test_cmp expect - && + git tag -n1 -l tag-one-line | test_cmp expect - && + git tag -n2 -l tag-one-line | test_cmp expect - && + git tag -n999 -l tag-one-line | test_cmp expect - ' -test_expect_success \ - 'listing the zero-lines message of a non-signed tag should succeed' ' +test_expect_success 'listing the zero-lines message of a non-signed tag should succeed' ' git tag -m "" tag-zero-lines && - echo "tag-zero-lines" >expect && - git tag -l | grep "^tag-zero-lines" >actual && - test_cmp expect actual && - git tag -n0 -l | grep "^tag-zero-lines" >actual && - test_cmp expect actual && - git tag -n0 -l tag-zero-lines >actual && - test_cmp expect actual && - - echo "tag-zero-lines " >expect && - git tag -n1 -l | grep "^tag-zero-lines" >actual && - test_cmp expect actual && - git tag -n -l | grep "^tag-zero-lines" >actual && - test_cmp expect actual && - git tag -n1 -l tag-zero-lines >actual && - test_cmp expect actual && - git tag -n2 -l tag-zero-lines >actual && - test_cmp expect actual && - git tag -n999 -l tag-zero-lines >actual && - test_cmp expect actual + echo >expect "tag-zero-lines" && + git tag -l | grep "^tag-zero-lines" | test_cmp expect - && + git tag -n0 -l | grep "^tag-zero-lines" | test_cmp expect - && + git tag -n0 -l tag-zero-lines | test_cmp expect - && + + echo >expect "tag-zero-lines " && + git tag -n1 -l | grep "^tag-zero-lines" | test_cmp expect - && + git tag -n -l | grep "^tag-zero-lines" | test_cmp expect - && + git tag -n1 -l tag-zero-lines | test_cmp expect - && + git tag -n2 -l tag-zero-lines | test_cmp expect - && + git tag -n999 -l tag-zero-lines | test_cmp expect - ' -echo 'tag line one' >annotagmsg -echo 'tag line two' >>annotagmsg -echo 'tag line three' >>annotagmsg -test_expect_success \ - 'listing many message lines of a non-signed tag should succeed' ' +test_expect_success 'listing many message lines of a non-signed tag should succeed' ' + cat >annotagmsg <<-EOF && + tag line one + tag line two + tag line three + EOF git tag -F annotagmsg tag-lines && - echo "tag-lines" >expect && - git tag -l | grep "^tag-lines" >actual && - test_cmp expect actual && - git tag -n0 -l | grep "^tag-lines" >actual && - test_cmp expect actual && - git tag -n0 -l tag-lines >actual && - test_cmp expect actual && + git tag -l | grep "^tag-lines" | test_cmp expect - && + git tag -n0 -l | grep "^tag-lines" | test_cmp expect - && + git tag -n0 -l tag-lines | test_cmp expect - && echo "tag-lines tag line one" >expect && - git tag -n1 -l | grep "^tag-lines" >actual && - test_cmp expect actual && - git tag -n -l | grep "^tag-lines" >actual && - test_cmp expect actual && - git tag -n1 -l tag-lines >actual && - test_cmp expect actual && + git tag -n1 -l | grep "^tag-lines" | test_cmp expect - && + git tag -n -l | grep "^tag-lines" | test_cmp expect - && + git tag -n1 -l tag-lines | test_cmp expect - && echo " tag line two" >>expect && - git tag -n2 -l | grep "^ *tag.line" >actual && - test_cmp expect actual && - git tag -n2 -l tag-lines >actual && - test_cmp expect actual && + git tag -n2 -l | grep "^.*tag.line" | test_cmp expect - && + git tag -n2 -l tag-lines | test_cmp expect - && echo " tag line three" >>expect && - git tag -n3 -l | grep "^ *tag.line" >actual && - test_cmp expect actual && - git tag -n3 -l tag-lines >actual && - test_cmp expect actual && - git tag -n4 -l | grep "^ *tag.line" >actual && - test_cmp expect actual && - git tag -n4 -l tag-lines >actual && - test_cmp expect actual && - git tag -n99 -l | grep "^ *tag.line" >actual && - test_cmp expect actual && - git tag -n99 -l tag-lines >actual && - test_cmp expect actual + git tag -n3 -l | grep "^.*tag.line" | test_cmp expect - && + git tag -n3 -l tag-lines | test_cmp expect - && + git tag -n4 -l | grep "^.*tag.line" | test_cmp expect - && + git tag -n4 -l tag-lines | test_cmp expect - && + git tag -n99 -l | grep "^.*tag.line" | test_cmp expect - && + git tag -n99 -l tag-lines | test_cmp expect - ' test_expect_success 'annotations for blobs are empty' ' - blob=$(git hash-object -w --stdin <<-\EOF + blob=$(git hash-object -w --stdin <<-EOF Blob paragraph 1. Blob paragraph 2. EOF ) && git tag tag-blob $blob && - echo "tag-blob " >expect && - git tag -n1 -l tag-blob >actual && - test_cmp expect actual + echo >expect "tag-blob " && + git tag -n1 -l tag-blob | test_cmp expect - ' # trying to verify annotated non-signed tags: -test_expect_success GPG \ - 'trying to verify an annotated non-signed tag should fail' ' +test_expect_success GPG 'trying to verify an annotated non-signed tag should fail' ' tag_exists annotated-tag && - test_must_fail git tag -v annotated-tag + silent test_must_fail git tag -v annotated-tag ' -test_expect_success GPG \ - 'trying to verify a file-annotated non-signed tag should fail' ' +test_expect_success GPG 'trying to verify a file-annotated non-signed tag should fail' ' tag_exists file-annotated-tag && - test_must_fail git tag -v file-annotated-tag + silent test_must_fail git tag -v file-annotated-tag ' -test_expect_success GPG \ - 'trying to verify two annotated non-signed tags should fail' ' +test_expect_success GPG 'trying to verify two annotated non-signed tags should fail' ' tag_exists annotated-tag file-annotated-tag && - test_must_fail git tag -v annotated-tag file-annotated-tag + silent test_must_fail git tag -v annotated-tag file-annotated-tag ' # creating and verifying signed tags: -get_tag_header signed-tag $commit commit $time >expect -echo 'A signed tag message' >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG 'creating a signed tag with -m message should succeed' ' - git tag -s -m "A signed tag message" signed-tag && - get_tag_msg signed-tag >actual && - test_cmp expect actual + name="signed-tag" && + msg="A signed tag message" && + gen_header >expect $name $commit commit $time <<-EOF && + $msg + -----BEGIN PGP SIGNATURE----- + EOF + git tag -s -m "$msg" $name && + get_header $name | test_cmp expect - ' -get_tag_header u-signed-tag $commit commit $time >expect -echo 'Another message' >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG 'sign with a given key id' ' - - git tag -u [email protected] -m "Another message" u-signed-tag && - get_tag_msg u-signed-tag >actual && - test_cmp expect actual - + name="u-signed-tag" && + msg="Another message" && + gen_header >expect $name $commit commit $time <<-EOF && + $msg + -----BEGIN PGP SIGNATURE----- + EOF + git tag -u [email protected] -m "$msg" $name && + get_header $name | test_cmp expect - ' test_expect_success GPG 'sign with an unknown id (1)' ' - - test_must_fail git tag -u [email protected] \ + silent test_must_fail git tag -u [email protected] \ -m "Another message" o-signed-tag - ' test_expect_success GPG 'sign with an unknown id (2)' ' - - test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag - + silent test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag ' -cat >fakeeditor <<'EOF' -#!/bin/sh +test_expect_success GPG '-u implies signed tag' ' + cat <<-\EOF | write_script fakeeditor && test -n "$1" && exec >"$1" echo A signed tag message echo from a fake editor. EOF -chmod +x fakeeditor - -get_tag_header implied-sign $commit commit $time >expect -./fakeeditor >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG '-u implies signed tag' ' - GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign && - get_tag_msg implied-sign >actual && - test_cmp expect actual + name="implied-signed" && + gen_header >expect $name $commit commit $time <<-EOF && + A signed tag message + from a fake editor. + -----BEGIN PGP SIGNATURE----- + EOF + GIT_EDITOR=./fakeeditor git tag -u CDDE430D $name && + get_header $name | test_cmp expect - ' -cat >sigmsgfile <<EOF +test_expect_success GPG 'creating a signed tag with -F messagefile should succeed' ' + name="file-signed-tag" && + gen_header >expect $name $commit commit $time <<-EOF && Another signed tag message in a file. + -----BEGIN PGP SIGNATURE----- EOF -get_tag_header file-signed-tag $commit commit $time >expect -cat sigmsgfile >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag with -F messagefile should succeed' ' - git tag -s -F sigmsgfile file-signed-tag && - get_tag_msg file-signed-tag >actual && - test_cmp expect actual + tail -n 3 expect | head -n 2 >sigmsgfile + git tag -s -F sigmsgfile $name && + get_header $name | test_cmp expect - ' -cat >siginputmsg <<EOF +test_expect_success GPG 'creating a signed tag with -F - should succeed' ' + name="stdin-signed-tag" && + gen_header >expect $name $commit commit $time <<-EOF && A signed tag message from the standard input + -----BEGIN PGP SIGNATURE----- EOF -get_tag_header stdin-signed-tag $commit commit $time >expect -cat siginputmsg >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG 'creating a signed tag with -F - should succeed' ' - git tag -s -F - stdin-signed-tag <siginputmsg && - get_tag_msg stdin-signed-tag >actual && - test_cmp expect actual + tail -n 3 expect | head -n 2 | git tag -s -F - $name && + get_header $name | test_cmp expect - ' -get_tag_header implied-annotate $commit commit $time >expect -./fakeeditor >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG '-s implies annotated tag' ' - GIT_EDITOR=./fakeeditor git tag -s implied-annotate && - get_tag_msg implied-annotate >actual && - test_cmp expect actual + name="implied-signed-tag" && + gen_header >expect $name $commit commit $time <<-EOF && + A signed tag message + from a fake editor. + -----BEGIN PGP SIGNATURE----- + EOF + GIT_EDITOR=./fakeeditor git tag -s $name && + get_header $name | test_cmp expect - ' -test_expect_success GPG \ - 'trying to create a signed tag with non-existing -F file should fail' ' +test_expect_success GPG 'trying to create a signed tag with non-existing -F file should fail' ' ! test -f nonexistingfile && ! tag_exists nosigtag && - test_must_fail git tag -s -F nonexistingfile nosigtag && + silent test_must_fail git tag -s -F nonexistingfile nosigtag && ! tag_exists nosigtag ' -test_expect_success GPG 'verifying a signed tag should succeed' \ - 'git tag -v signed-tag' +test_expect_success GPG 'verifying a signed tag should succeed' ' + silent git tag -v signed-tag +' -test_expect_success GPG 'verifying two signed tags in one command should succeed' \ - 'git tag -v signed-tag file-signed-tag' +test_expect_success GPG 'verifying two signed tags in one command should succeed' ' + silent git tag -v signed-tag file-signed-tag +' -test_expect_success GPG \ - 'verifying many signed and non-signed tags should fail' ' - test_must_fail git tag -v signed-tag annotated-tag && - test_must_fail git tag -v file-annotated-tag file-signed-tag && - test_must_fail git tag -v annotated-tag \ +test_expect_success GPG 'verifying many signed and non-signed tags should fail' ' + silent test_must_fail git tag -v signed-tag annotated-tag && + silent test_must_fail git tag -v file-annotated-tag file-signed-tag && + silent test_must_fail git tag -v annotated-tag \ file-signed-tag file-annotated-tag && - test_must_fail git tag -v signed-tag annotated-tag file-signed-tag + silent test_must_fail git tag -v signed-tag \ + annotated-tag file-signed-tag ' test_expect_success GPG 'verifying a forged tag should fail' '
@@ -735,38 +681,53 @@ test_expect_success GPG 'verifying a forged tag should fail' ' sed -e "s/signed-tag/forged-tag/" | git mktag) && git tag forged-tag $forged && - test_must_fail git tag -v forged-tag + silent test_must_fail git tag -v forged-tag ' # blank and empty messages for signed tags: -get_tag_header empty-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag with an empty -m message should succeed' ' - git tag -s -m "" empty-signed-tag && - get_tag_msg empty-signed-tag >actual && - test_cmp expect actual && - git tag -v empty-signed-tag -' - ->sigemptyfile -get_tag_header emptyfile-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag with an empty -F messagefile should succeed' ' - git tag -s -F sigemptyfile emptyfile-signed-tag && - get_tag_msg emptyfile-signed-tag >actual && - test_cmp expect actual && - git tag -v emptyfile-signed-tag -' - -printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile -printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile -printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile -printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile -get_tag_header blanks-signed-tag $commit commit $time >expect -cat >>expect <<EOF +test_expect_success GPG 'creating a signed tag with an empty -m message should succeed' ' + name="empty-signed-tag" && + gen_header $name $commit commit $time >expect <<-EOF && + -----BEGIN PGP SIGNATURE----- + EOF + git tag -s -m "" $name && + get_header $name | test_cmp expect - && + silent git tag -v $name +' + +test_expect_success GPG 'creating a signed tag with an empty -F messagefile should succeed' ' + >sigemptyfile && + name="emptyfile-signed-tag" && + gen_header $name $commit commit $time >expect <<-EOF && + -----BEGIN PGP SIGNATURE----- + EOF + git tag -s -F sigemptyfile $name && + get_header $name | test_cmp expect - && + silent git tag -v $name +' + +test_expect_success GPG 'extra blanks in the message for a signed tag should be removed' ' + here >sigblanksfile <<-\EOF && + + \s\s + \t + Leading blank lines + + \t\s\t\s\s + Repeated blank lines + + + + Trailing spaces\s\s\s\s\s\s\t\s\s + + Trailing blank lines + + \t\s + + EOF + name="blanks-signed-tag" && + gen_header $name $commit commit $time >expect <<-EOF && Leading blank lines Repeated blank lines
@@ -774,53 +735,53 @@ Repeated blank lines Trailing spaces Trailing blank lines + -----BEGIN PGP SIGNATURE----- + EOF + git tag -s -F sigblanksfile $name && + get_header $name | test_cmp expect - && + silent git tag -v $name +' + +test_expect_success GPG 'creating a signed tag with a blank -m message should succeed' ' + name="blank-signed-tag" && + gen_header >expect $name $commit commit $time <<-EOF && + -----BEGIN PGP SIGNATURE----- EOF -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'extra blanks in the message for a signed tag should be removed' ' - git tag -s -F sigblanksfile blanks-signed-tag && - get_tag_msg blanks-signed-tag >actual && - test_cmp expect actual && - git tag -v blanks-signed-tag -' - -get_tag_header blank-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag with a blank -m message should succeed' ' - git tag -s -m " " blank-signed-tag && - get_tag_msg blank-signed-tag >actual && - test_cmp expect actual && - git tag -v blank-signed-tag -' - -echo ' ' >sigblankfile -echo '' >>sigblankfile -echo ' ' >>sigblankfile -get_tag_header blankfile-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag with blank -F file with spaces should succeed' ' - git tag -s -F sigblankfile blankfile-signed-tag && - get_tag_msg blankfile-signed-tag >actual && - test_cmp expect actual && - git tag -v blankfile-signed-tag -' - -printf ' ' >sigblanknonlfile -get_tag_header blanknonlfile-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag with spaces and no newline should succeed' ' - git tag -s -F sigblanknonlfile blanknonlfile-signed-tag && - get_tag_msg blanknonlfile-signed-tag >actual && - test_cmp expect actual && - git tag -v signed-tag + git tag -s -m " " $name && + get_header $name | test_cmp expect - && + silent git tag -v $name +' + +test_expect_success GPG 'creating a signed tag with blank -F file with spaces should succeed' ' + here >sigblankfile <<-\EOF && + \s\s\s\s\s + + \s\s + EOF + name="blankfile-signed-tag" && + gen_header >expect $name $commit commit $time <<-EOF && + -----BEGIN PGP SIGNATURE----- + EOF + git tag -s -F sigblankfile $name && + get_header $name | test_cmp expect - && + silent git tag -v $name +' + +test_expect_success GPG 'creating a signed tag with spaces and no newline should succeed' ' + printf >sigblanknonlfile " " && + name="blanknonlfile-signed-tag" && + gen_header $name $commit commit $time >expect <<-EOF && + -----BEGIN PGP SIGNATURE----- + EOF + git tag -s -F sigblanknonlfile $name && + get_header $name | test_cmp expect - && + silent git tag -v $name ' # messages with commented lines for signed tags: -cat >sigcommentsfile <<EOF +test_expect_success GPG 'creating a signed tag with a -F file with #comments should succeed' ' + cat >sigcommentsfile <<-EOF && # A comment ############
@@ -837,303 +798,257 @@ Another line. Last line. EOF -get_tag_header comments-signed-tag $commit commit $time >expect -cat >>expect <<EOF + name="comments-signed-tag" && + gen_header >expect $name $commit commit $time <<-EOF && The message. One line. Another line. Last line. + -----BEGIN PGP SIGNATURE----- + EOF + git tag -s -F sigcommentsfile $name && + get_header $name | test_cmp expect - && + silent git tag -v $name +' + +test_expect_success GPG 'creating a signed tag with #commented -m message should succeed' ' + name="comment-signed-tag" && + gen_header $name $commit commit $time >expect <<-EOF && + -----BEGIN PGP SIGNATURE----- + EOF + git tag -s -m "#comment" $name && + get_header $name | test_cmp expect - && + silent git tag -v $name +' + +test_expect_success GPG 'creating a signed tag with #commented -F messagefile should succeed' ' + cat >sigcommentfile <<-EOF && + #comment + + #### EOF -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag with a -F file with #comments should succeed' ' - git tag -s -F sigcommentsfile comments-signed-tag && - get_tag_msg comments-signed-tag >actual && - test_cmp expect actual && - git tag -v comments-signed-tag -' - -get_tag_header comment-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag with #commented -m message should succeed' ' - git tag -s -m "#comment" comment-signed-tag && - get_tag_msg comment-signed-tag >actual && - test_cmp expect actual && - git tag -v comment-signed-tag -' - -echo '#comment' >sigcommentfile -echo '' >>sigcommentfile -echo '####' >>sigcommentfile -get_tag_header commentfile-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag with #commented -F messagefile should succeed' ' - git tag -s -F sigcommentfile commentfile-signed-tag && - get_tag_msg commentfile-signed-tag >actual && - test_cmp expect actual && - git tag -v commentfile-signed-tag -' - -printf '#comment' >sigcommentnonlfile -get_tag_header commentnonlfile-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag with a #comment and no newline should succeed' ' - git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag && - get_tag_msg commentnonlfile-signed-tag >actual && - test_cmp expect actual && - git tag -v commentnonlfile-signed-tag + name="commentfile-signed-tag" && + gen_header $name $commit commit $time >expect <<-EOF && + -----BEGIN PGP SIGNATURE----- + EOF + git tag -s -F sigcommentfile $name && + get_header $name | test_cmp expect - && + silent git tag -v $name +' + +test_expect_success GPG 'creating a signed tag with a #comment and no newline should succeed' ' + printf "#comment" >sigcommentnonlfile && + name="commentnonlfile-signed-tag" && + gen_header $name $commit commit $time >expect <<-EOF && + -----BEGIN PGP SIGNATURE----- + EOF + git tag -s -F sigcommentnonlfile $name && + get_header $name | test_cmp expect - && + silent git tag -v $name ' # listing messages for signed tags: -test_expect_success GPG \ - 'listing the one-line message of a signed tag should succeed' ' +test_expect_success GPG 'listing the one-line message of a signed tag should succeed' ' git tag -s -m "A message line signed" stag-one-line && echo "stag-one-line" >expect && - git tag -l | grep "^stag-one-line" >actual && - test_cmp expect actual && - git tag -n0 -l | grep "^stag-one-line" >actual && - test_cmp expect actual && - git tag -n0 -l stag-one-line >actual && - test_cmp expect actual && + git tag -l | grep "^stag-one-line" | test_cmp expect - && + git tag -n0 -l | grep "^stag-one-line" | test_cmp expect - && + git tag -n0 -l stag-one-line | test_cmp expect - && echo "stag-one-line A message line signed" >expect && - git tag -n1 -l | grep "^stag-one-line" >actual && - test_cmp expect actual && - git tag -n -l | grep "^stag-one-line" >actual && - test_cmp expect actual && - git tag -n1 -l stag-one-line >actual && - test_cmp expect actual && - git tag -n2 -l stag-one-line >actual && - test_cmp expect actual && - git tag -n999 -l stag-one-line >actual && - test_cmp expect actual + git tag -n1 -l | grep "^stag-one-line" | test_cmp expect - && + git tag -n -l | grep "^stag-one-line" | test_cmp expect - && + git tag -n1 -l stag-one-line | test_cmp expect - && + git tag -n2 -l stag-one-line | test_cmp expect - && + git tag -n999 -l stag-one-line | test_cmp expect - ' -test_expect_success GPG \ - 'listing the zero-lines message of a signed tag should succeed' ' +test_expect_success GPG 'listing the zero-lines message of a signed tag should succeed' ' git tag -s -m "" stag-zero-lines && echo "stag-zero-lines" >expect && - git tag -l | grep "^stag-zero-lines" >actual && - test_cmp expect actual && - git tag -n0 -l | grep "^stag-zero-lines" >actual && - test_cmp expect actual && - git tag -n0 -l stag-zero-lines >actual && - test_cmp expect actual && + git tag -l | grep "^stag-zero-lines" | test_cmp expect - && + git tag -n0 -l | grep "^stag-zero-lines" | test_cmp expect - && + git tag -n0 -l stag-zero-lines | test_cmp expect - && echo "stag-zero-lines " >expect && - git tag -n1 -l | grep "^stag-zero-lines" >actual && - test_cmp expect actual && - git tag -n -l | grep "^stag-zero-lines" >actual && - test_cmp expect actual && - git tag -n1 -l stag-zero-lines >actual && - test_cmp expect actual && - git tag -n2 -l stag-zero-lines >actual && - test_cmp expect actual && - git tag -n999 -l stag-zero-lines >actual && - test_cmp expect actual -' - -echo 'stag line one' >sigtagmsg -echo 'stag line two' >>sigtagmsg -echo 'stag line three' >>sigtagmsg -test_expect_success GPG \ - 'listing many message lines of a signed tag should succeed' ' + git tag -n1 -l | grep "^stag-zero-lines" | test_cmp expect - && + git tag -n -l | grep "^stag-zero-lines" | test_cmp expect - && + git tag -n1 -l stag-zero-lines | test_cmp expect - && + git tag -n2 -l stag-zero-lines | test_cmp expect - && + git tag -n999 -l stag-zero-lines | test_cmp expect - +' + +test_expect_success GPG 'listing many message lines of a signed tag should succeed' ' + cat >sigtagmsg <<-EOF && + stag line one + stag line two + stag line three + EOF git tag -s -F sigtagmsg stag-lines && echo "stag-lines" >expect && - git tag -l | grep "^stag-lines" >actual && - test_cmp expect actual && - git tag -n0 -l | grep "^stag-lines" >actual && - test_cmp expect actual && - git tag -n0 -l stag-lines >actual && - test_cmp expect actual && + git tag -l | grep "^stag-lines" | test_cmp expect - && + git tag -n0 -l | grep "^stag-lines" | test_cmp expect - && + git tag -n0 -l stag-lines | test_cmp expect - && echo "stag-lines stag line one" >expect && - git tag -n1 -l | grep "^stag-lines" >actual && - test_cmp expect actual && - git tag -n -l | grep "^stag-lines" >actual && - test_cmp expect actual && - git tag -n1 -l stag-lines >actual && - test_cmp expect actual && + git tag -n1 -l | grep "^stag-lines" | test_cmp expect - && + git tag -n -l | grep "^stag-lines" | test_cmp expect - && + git tag -n1 -l stag-lines | test_cmp expect - && echo " stag line two" >>expect && - git tag -n2 -l | grep "^ *stag.line" >actual && - test_cmp expect actual && - git tag -n2 -l stag-lines >actual && - test_cmp expect actual && + git tag -n2 -l | grep "^.*stag.line" | test_cmp expect - && + git tag -n2 -l stag-lines | test_cmp expect - && echo " stag line three" >>expect && - git tag -n3 -l | grep "^ *stag.line" >actual && - test_cmp expect actual && - git tag -n3 -l stag-lines >actual && - test_cmp expect actual && - git tag -n4 -l | grep "^ *stag.line" >actual && - test_cmp expect actual && - git tag -n4 -l stag-lines >actual && - test_cmp expect actual && - git tag -n99 -l | grep "^ *stag.line" >actual && - test_cmp expect actual && - git tag -n99 -l stag-lines >actual && - test_cmp expect actual + git tag -n3 -l | grep "^.*stag.line" | test_cmp expect - && + git tag -n3 -l stag-lines | test_cmp expect - && + git tag -n4 -l | grep "^.*stag.line" | test_cmp expect - && + git tag -n4 -l stag-lines | test_cmp expect - && + git tag -n99 -l | grep "^.*stag.line" | test_cmp expect - && + git tag -n99 -l stag-lines | test_cmp expect - ' -# tags pointing to objects different from commits: -tree=$(git rev-parse HEAD^{tree}) -blob=$(git rev-parse HEAD:foo) -tag=$(git rev-parse signed-tag 2>/dev/null) - -get_tag_header tree-signed-tag $tree tree $time >expect -echo "A message for a tree" >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag pointing to a tree should succeed' ' - git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} && - get_tag_msg tree-signed-tag >actual && - test_cmp expect actual +test_expect_success GPG 'creating a signed tag pointing to a tree should succeed' ' + # tags pointing to objects different from commits: + tree=$(git rev-parse HEAD^{tree}) && + blob=$(git rev-parse HEAD:foo) && + tag=$(git rev-parse signed-tag) && + name="tree-signed-tag" && + msg="A message for a tree" && + gen_header $name $tree tree $time >expect <<-EOF && + $msg + -----BEGIN PGP SIGNATURE----- + EOF + git tag -s -m "$msg" $name HEAD^{tree} && + get_header $name | test_cmp expect - ' -get_tag_header blob-signed-tag $blob blob $time >expect -echo "A message for a blob" >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag pointing to a blob should succeed' ' - git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo && - get_tag_msg blob-signed-tag >actual && - test_cmp expect actual +test_expect_success GPG 'creating a signed tag pointing to a blob should succeed' ' + msg="A message for a blob" && + name="blob-signed-tag" && + gen_header $name $blob blob $time >expect <<-EOF && + $msg + -----BEGIN PGP SIGNATURE----- + EOF + git tag -s -m "$msg" $name HEAD:foo && + get_header $name | test_cmp expect - ' -get_tag_header tag-signed-tag $tag tag $time >expect -echo "A message for another tag" >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag pointing to another tag should succeed' ' - git tag -s -m "A message for another tag" tag-signed-tag signed-tag && - get_tag_msg tag-signed-tag >actual && - test_cmp expect actual +test_expect_success GPG 'creating a signed tag pointing to another tag should succeed' ' + msg="A message for another tag" && + name="tag-signed-tag" && + gen_header $name $tag tag $time >expect <<-EOF && + $msg + -----BEGIN PGP SIGNATURE----- + EOF + git tag -s -m "$msg" $name signed-tag && + get_header $name | test_cmp expect - ' # usage with rfc1991 signatures -echo "rfc1991" > gpghome/gpg.conf -get_tag_header rfc1991-signed-tag $commit commit $time >expect -echo "RFC1991 signed tag" >>expect -echo '-----BEGIN PGP MESSAGE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag with rfc1991' ' - git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit && - get_tag_msg rfc1991-signed-tag >actual && - test_cmp expect actual +test_expect_success GPG 'creating a signed tag with rfc1991' ' + echo "rfc1991" >gpghome/gpg.conf && + msg="RFC1991 signed tag" && + name="rfc1991-signed-tag" + gen_header $name $commit commit $time >expect <<-EOF && + $msg + -----BEGIN PGP MESSAGE----- + EOF + git tag -s -m "$msg" $name $commit && + get_header $name | test_cmp expect - ' -cat >fakeeditor <<'EOF' -#!/bin/sh +test_expect_success GPG 'reediting a signed tag body omits signature' ' + cat <<-\EOF | write_script fakeeditor && cp "$1" actual EOF -chmod +x fakeeditor - -test_expect_success GPG \ - 'reediting a signed tag body omits signature' ' echo "RFC1991 signed tag" >expect && - GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit && + GIT_EDITOR=./fakeeditor \ + quiet git tag -f -s rfc1991-signed-tag $commit && test_cmp expect actual ' -test_expect_success GPG \ - 'verifying rfc1991 signature' ' - git tag -v rfc1991-signed-tag +test_expect_success GPG 'verifying rfc1991 signature' ' + silent git tag -v rfc1991-signed-tag ' -test_expect_success GPG \ - 'list tag with rfc1991 signature' ' +test_expect_success GPG 'list tag with rfc1991 signature' ' echo "rfc1991-signed-tag RFC1991 signed tag" >expect && - git tag -l -n1 rfc1991-signed-tag >actual && - test_cmp expect actual && - git tag -l -n2 rfc1991-signed-tag >actual && - test_cmp expect actual && - git tag -l -n999 rfc1991-signed-tag >actual && - test_cmp expect actual + git tag -l -n1 rfc1991-signed-tag | test_cmp expect - && + git tag -l -n2 rfc1991-signed-tag | test_cmp expect - && + git tag -l -n999 rfc1991-signed-tag | test_cmp expect - ' -rm -f gpghome/gpg.conf - -test_expect_success GPG \ - 'verifying rfc1991 signature without --rfc1991' ' - git tag -v rfc1991-signed-tag +test_expect_success GPG 'verifying rfc1991 signature without --rfc1991' ' + rm -f gpghome/gpg.conf && + silent git tag -v rfc1991-signed-tag ' -test_expect_success GPG \ - 'list tag with rfc1991 signature without --rfc1991' ' - echo "rfc1991-signed-tag RFC1991 signed tag" >expect && - git tag -l -n1 rfc1991-signed-tag >actual && - test_cmp expect actual && - git tag -l -n2 rfc1991-signed-tag >actual && - test_cmp expect actual && - git tag -l -n999 rfc1991-signed-tag >actual && - test_cmp expect actual +test_expect_success GPG 'list tag with rfc1991 signature without --rfc1991' ' + echo >expect "rfc1991-signed-tag RFC1991 signed tag" && + git tag -l -n1 rfc1991-signed-tag | test_cmp expect - && + git tag -l -n2 rfc1991-signed-tag | test_cmp expect - && + git tag -l -n999 rfc1991-signed-tag | test_cmp expect - ' -test_expect_success GPG \ - 'reediting a signed tag body omits signature' ' +test_expect_success GPG 'reediting a signed tag body omits signature' ' echo "RFC1991 signed tag" >expect && - GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit && + GIT_EDITOR=./fakeeditor \ + quiet git tag -f -s rfc1991-signed-tag $commit && test_cmp expect actual ' +test_expect_success GPG 'git tag -s fails if gpg is misconfigured' ' # try to sign with bad user.signingkey -git config user.signingkey BobTheMouse -test_expect_success GPG \ - 'git tag -s fails if gpg is misconfigured' \ - 'test_must_fail git tag -s -m tail tag-gpg-failure' + git config user.signingkey BobTheMouse && + silent test_must_fail git tag -s -m tail tag-gpg-failure && git config --unset user.signingkey +' +test_expect_success GPG 'verify signed tag fails when public key is not present' ' # try to verify without gpg: + rm -rf gpghome && + silent test_must_fail git tag -v signed-tag +' -rm -rf gpghome -test_expect_success GPG \ - 'verify signed tag fails when public key is not present' \ - 'test_must_fail git tag -v signed-tag' - -test_expect_success \ - 'git tag -a fails if tag annotation is empty' ' - ! (GIT_EDITOR=cat git tag -a initial-comment) +test_expect_success 'git tag -a fails if tag annotation is empty' ' + ! (GIT_EDITOR=cat silent git tag -a initial-comment) ' -test_expect_success \ - 'message in editor has initial comment' ' - ! (GIT_EDITOR=cat git tag -a initial-comment > actual) +test_expect_success 'message in editor has initial comment' ' + ! (GIT_EDITOR=cat git tag -a initial-comment >actual 2>/dev/null) ' test_expect_success 'message in editor has initial comment: first line' ' # check the first line --- should be empty echo >first.expect && - sed -e 1q <actual >first.actual && + sed -e 1q actual >first.actual && test_i18ncmp first.expect first.actual ' -test_expect_success \ - 'message in editor has initial comment: remainder' ' +test_expect_success 'message in editor has initial comment: remainder' ' # remove commented lines from the remainder -- should be empty >rest.expect sed -e 1d -e '/^#/d' <actual >rest.actual && test_cmp rest.expect rest.actual ' -get_tag_header reuse $commit commit $time >expect -echo "An annotation to be reused" >> expect -test_expect_success \ - 'overwriting an annoted tag should use its previous body' ' - git tag -a -m "An annotation to be reused" reuse && - GIT_EDITOR=true git tag -f -a reuse && - get_tag_msg reuse >actual && - test_cmp expect actual +test_expect_success 'overwriting an annoted tag should use its previous body' ' + name="reuse" && + msg="An annotation to be reused" && + gen_header $name $commit commit $time >expect <<-EOF && + reuse + EOF + git tag -a -m "$msg" $name && + GIT_EDITOR=true git tag -f -a -m "reuse" $name && + get_header $name | test_cmp expect - ' test_expect_success 'filename for the message is relative to cwd' '
@@ -1144,7 +1059,7 @@ test_expect_success 'filename for the message is relative to cwd' ' cd subdir && git tag -a -F msgfile-5 tag-from-subdir ) && - git cat-file tag tag-from-subdir | grep "in sub directory" + git cat-file tag tag-from-subdir | grep -q "in sub directory" ' test_expect_success 'filename for the message is relative to cwd' '
@@ -1153,110 +1068,91 @@ test_expect_success 'filename for the message is relative to cwd' ' cd subdir && git tag -a -F msgfile-6 tag-from-subdir-2 ) && - git cat-file tag tag-from-subdir-2 | grep "in sub directory" + git cat-file tag tag-from-subdir-2 | grep -q "in sub directory" ' -# create a few more commits to test --contains - -hash1=$(git rev-parse HEAD) - test_expect_success 'creating second commit and tag' ' + # create a few more commits to test --contains + hash1=$(git rev-parse HEAD) && echo foo-2.0 >foo && git add foo && - git commit -m second && + git commit -q -m second && + hash2=$(git rev-parse HEAD) && git tag v2.0 ' -hash2=$(git rev-parse HEAD) - test_expect_success 'creating third commit without tag' ' echo foo-dev >foo && git add foo && - git commit -m third -' - + git commit -q -m third && hash3=$(git rev-parse HEAD) +' -# simple linear checks of --continue - -cat > expected <<EOF +test_expect_success 'checking that first commit is in all tags (hash)' ' + # simple linear checks of --contains + cat >expect <<-EOF && v0.2.1 v1.0 v1.0.1 v1.1.3 v2.0 EOF + git tag -l --contains $hash1 v* | test_cmp expect - +' -test_expect_success 'checking that first commit is in all tags (hash)' " - git tag -l --contains $hash1 v* >actual && - test_cmp expected actual -" - +test_expect_success 'checking that first commit is in all tags (tag)' ' # other ways of specifying the commit -test_expect_success 'checking that first commit is in all tags (tag)' " - git tag -l --contains v1.0 v* >actual && - test_cmp expected actual -" + git tag -l --contains v1.0 v* | test_cmp expect - +' -test_expect_success 'checking that first commit is in all tags (relative)' " - git tag -l --contains HEAD~2 v* >actual && - test_cmp expected actual -" +test_expect_success 'checking that first commit is in all tags (relative)' ' + git tag -l --contains HEAD~2 v* | test_cmp expect - +' -cat > expected <<EOF +test_expect_success 'checking that second commit only has one tag' ' + cat >expect <<-EOF && v2.0 EOF + git tag -l --contains $hash2 v* | test_cmp expect - +' -test_expect_success 'checking that second commit only has one tag' " - git tag -l --contains $hash2 v* >actual && - test_cmp expected actual -" - - -cat > expected <<EOF -EOF - -test_expect_success 'checking that third commit has no tags' " - git tag -l --contains $hash3 v* >actual && - test_cmp expected actual -" +test_expect_success 'checking that third commit has no tags' ' + >expect + git tag -l --contains $hash3 v* | test_cmp expect - +' # how about a simple merge? test_expect_success 'creating simple branch' ' git branch stable v2.0 && - git checkout stable && + git checkout -q stable && echo foo-3.0 > foo && - git commit foo -m fourth && + git commit -q foo -m fourth && + hash4=$(git rev-parse HEAD) && git tag v3.0 ' -hash4=$(git rev-parse HEAD) - -cat > expected <<EOF +test_expect_success 'checking that branch head only has one tag' ' + cat >expect <<-EOF && v3.0 EOF - -test_expect_success 'checking that branch head only has one tag' " - git tag -l --contains $hash4 v* >actual && - test_cmp expected actual -" + git tag -l --contains $hash4 v* | test_cmp expect - +' test_expect_success 'merging original branch into this branch' ' - git merge --strategy=ours master && + git merge -q --strategy=ours master && git tag v4.0 ' -cat > expected <<EOF +test_expect_success 'checking that original branch head has one tag now' ' + cat >expect <<-EOF && v4.0 EOF + git tag -l --contains $hash3 v* | test_cmp expect - +' -test_expect_success 'checking that original branch head has one tag now' " - git tag -l --contains $hash3 v* >actual && - test_cmp expected actual -" - -cat > expected <<EOF +test_expect_success 'checking that initial commit is in all tags' ' + cat >expect <<-EOF && v0.2.1 v1.0 v1.0.1
@@ -1265,60 +1161,50 @@ v2.0 v3.0 v4.0 EOF + git tag -l --contains $hash1 v* | test_cmp expect - +' -test_expect_success 'checking that initial commit is in all tags' " - git tag -l --contains $hash1 v* >actual && - test_cmp expected actual -" - -# mixing modes and options: test_expect_success 'mixing incompatibles modes and options is forbidden' ' - test_must_fail git tag -a && - test_must_fail git tag -l -v && - test_must_fail git tag -n 100 && - test_must_fail git tag -l -m msg && - test_must_fail git tag -l -F some file && - test_must_fail git tag -v -s + # mixing modes and options: + silent test_must_fail git tag -a && + silent test_must_fail git tag -l -v && + silent test_must_fail git tag -n 100 && + silent test_must_fail git tag -l -m msg && + silent test_must_fail git tag -l -F some file && + silent test_must_fail git tag -v -s && + silent test_must_fail git tag --points-at=v4.0 foo ' # check points-at -test_expect_success '--points-at cannot be used in non-list mode' ' - test_must_fail git tag --points-at=v4.0 foo -' - test_expect_success '--points-at finds lightweight tags' ' echo v4.0 >expect && - git tag --points-at v4.0 >actual && - test_cmp expect actual + git tag --points-at v4.0 | test_cmp expect - ' test_expect_success '--points-at finds annotated tags of commits' ' git tag -m "v4.0, annotated" annotated-v4.0 v4.0 && echo annotated-v4.0 >expect && - git tag -l --points-at v4.0 "annotated*" >actual && - test_cmp expect actual + git tag -l --points-at v4.0 "annotated*" | test_cmp expect - ' test_expect_success '--points-at finds annotated tags of tags' ' git tag -m "describing the v4.0 tag object" \ annotated-again-v4.0 annotated-v4.0 && - cat >expect <<-\EOF && + cat >expect <<-EOF && annotated-again-v4.0 annotated-v4.0 EOF - git tag --points-at=annotated-v4.0 >actual && - test_cmp expect actual + git tag --points-at=annotated-v4.0 | test_cmp expect - ' test_expect_success 'multiple --points-at are OR-ed together' ' - cat >expect <<-\EOF && + cat >expect <<-EOF && v2.0 v3.0 EOF - git tag --points-at=v2.0 --points-at=v3.0 >actual && - test_cmp expect actual + git tag --points-at=v2.0 --points-at=v3.0 | test_cmp expect - ' test_done
Signature · 1 line
1.7.8
v2 cover modernize test style
In reply to Tom GrennanQuoted 12 lines · I <[email protected]> wrote:
Per request, the following series modernize the style of the respective test scripts. The common themes are:
- Guard setup withtest_expect_success
- Single-quoted, tab prefaced test blocks of < 80 cols
- Redirect unwanted output
- Use a "here" filter for some expect generationI also used pipelines to validate expected results rather than temporary files, i.e.
TEST |test_cmpexpect -
vs. TEST >actual &&test_cmpexpect actual
Quoted 5 lines
Since the later three patches have a lot of whitespace change, I've included an alternate, PATCH-w series that filters these for more substantive review. However, even the filtered series is very large causing me to second guess whether such style modernization should be pursued; so, I look forward to your input.
The following series is a much less ambitious modernization of these tests. This version does NOT:
- Support running with t/TEST.sh vs. (cd t && ./TEST.sh)
- Redirect unwanted output
- Pipeline test_cmp
- Rewrite blocks to be less than 80 columns
This version DOES:
- Guard setup with test_expect_success
(in one case, a shell loop was unwound to facilitate this)
- Single-quoted, tab prefaced test blocks
- >FILE instead of > FILE redirection style
- Use a sed filter to process formatted whitespace test cases
I've also included PATCHv2-w for review alternatives.
Thanks,
Tom Grennan (5):
t7004 (tag): modernize style
t5512 (ls-remote): modernize style
t3200 (branch): modernize style
t0040 (parse-options): modernize style
t6300 (for-each-ref): modernize style
t/t7004-tag.sh | 828 ++++++++++++++++++++++++++++++-------------------------- 1 files changed, 447 insertions(+), 381 deletions(-)
Signature · 1 line
1.7.8
PATCH 101/105 t7004 (tag): modernize style
- Guard setup with test_expect_success
- Single-quoted, tab prefaced test blocks
- Use >FILE instead of > FILE
- Use a "here" filter for generation of expect files with mixed tabs and spaces
--- t/t7004-tag.sh | 590 +++++++++++++++++++++++++++++++------------------------- 1 files changed, 328 insertions(+), 262 deletions(-)
t/t7004-tag.sh +328 -262
@@ -27,8 +27,9 @@ test_expect_success 'listing all tags in an empty tree should output nothing' ' test `git tag | wc -l` -eq 0 ' -test_expect_success 'looking for a tag in an empty tree should fail' \ - '! (tag_exists mytag)' +test_expect_success 'looking for a tag in an empty tree should fail' ' + ! tag_exists mytag +' test_expect_success 'creating a tag in an empty tree should fail' ' test_must_fail git tag mynotag &&
@@ -66,27 +67,32 @@ test_expect_success 'listing all tags if one exists should output that tag' ' # pattern matching: -test_expect_success 'listing a tag using a matching pattern should succeed' \ - 'git tag -l mytag' +test_expect_success 'listing a tag using a matching pattern should succeed' ' + git tag -l mytag +' test_expect_success \ - 'listing a tag using a matching pattern should output that tag' \ - 'test `git tag -l mytag` = mytag' + 'listing a tag using a matching pattern should output that tag' ' + test `git tag -l mytag` = mytag +' # todo: git tag -l now returns always zero, when fixed, change this test test_expect_success \ - 'listing tags using a non-matching pattern should suceed' \ - 'git tag -l xxx' + 'listing tags using a non-matching pattern should suceed' ' + git tag -l xxx +' test_expect_success \ - 'listing tags using a non-matching pattern should output nothing' \ - 'test `git tag -l xxx | wc -l` -eq 0' + 'listing tags using a non-matching pattern should output nothing' ' + test `git tag -l xxx | wc -l` -eq 0 +' # special cases for creating tags: test_expect_success \ - 'trying to create a tag with the name of one existing should fail' \ - 'test_must_fail git tag mytag' + 'trying to create a tag with the name of one existing should fail' ' + test_must_fail git tag mytag +' test_expect_success \ 'trying to create a tag with a non-valid name should fail' '
@@ -111,15 +117,17 @@ test_expect_success 'trying to delete an unknown tag should fail' ' test_must_fail git tag -d unknown-tag ' -cat >expect <<EOF +test_expect_success \ + 'trying to delete tags without params should succeed and do nothing' ' + cat >expect <<-EOF && myhead mytag EOF -test_expect_success \ - 'trying to delete tags without params should succeed and do nothing' ' - git tag -l > actual && test_cmp expect actual && + git tag -l >actual && + test_cmp expect actual && git tag -d && - git tag -l > actual && test_cmp expect actual + git tag -l >actual && + test_cmp expect actual ' test_expect_success \
@@ -147,12 +155,15 @@ test_expect_success \ ! tag_exists myhead ' -test_expect_success 'trying to delete an already deleted tag should fail' \ - 'test_must_fail git tag -d mytag' +test_expect_success \ + 'trying to delete an already deleted tag should fail' ' + test_must_fail git tag -d mytag +' # listing various tags with pattern matching: -cat >expect <<EOF +test_expect_success 'listing all tags should print them ordered' ' + cat >expect <<-EOF && a1 aa1 cba
@@ -163,7 +174,6 @@ v1.0 v1.0.1 v1.1.3 EOF -test_expect_success 'listing all tags should print them ordered' ' git tag v1.0.1 && git tag t211 && git tag aa1 &&
@@ -179,81 +189,81 @@ test_expect_success 'listing all tags should print them ordered' ' test_cmp expect actual ' -cat >expect <<EOF +test_expect_success \ + 'listing tags with substring as pattern must print those matching' ' + cat >expect <<-EOF && a1 aa1 cba EOF -test_expect_success \ - 'listing tags with substring as pattern must print those matching' ' rm *a* && git tag -l "*a*" > current && test_cmp expect current ' -cat >expect <<EOF +test_expect_success \ + 'listing tags with a suffix as pattern must print those matching' ' + cat >expect <<-EOF && v0.2.1 v1.0.1 EOF -test_expect_success \ - 'listing tags with a suffix as pattern must print those matching' ' git tag -l "*.1" > actual && test_cmp expect actual ' -cat >expect <<EOF +test_expect_success \ + 'listing tags with a prefix as pattern must print those matching' ' + cat >expect <<-EOF && t210 t211 EOF -test_expect_success \ - 'listing tags with a prefix as pattern must print those matching' ' git tag -l "t21*" > actual && test_cmp expect actual ' -cat >expect <<EOF -a1 -EOF test_expect_success \ 'listing tags using a name as pattern must print that one matching' ' + cat >expect <<-EOF && + a1 + EOF git tag -l a1 > actual && test_cmp expect actual ' -cat >expect <<EOF -v1.0 -EOF test_expect_success \ 'listing tags using a name as pattern must print that one matching' ' + cat >expect <<-EOF && + v1.0 + EOF git tag -l v1.0 > actual && test_cmp expect actual ' -cat >expect <<EOF +test_expect_success \ + 'listing tags with ? in the pattern should print those matching' ' + cat >expect <<-EOF && v1.0.1 v1.1.3 EOF -test_expect_success \ - 'listing tags with ? in the pattern should print those matching' ' git tag -l "v1.?.?" > actual && test_cmp expect actual ' ->expect test_expect_success \ 'listing tags using v.* should print nothing because none have v.' ' + >expect && git tag -l "v.*" > actual && test_cmp expect actual ' -cat >expect <<EOF +test_expect_success \ + 'listing tags using v* should print only those having v' ' + cat >expect <<-EOF && v0.2.1 v1.0 v1.0.1 v1.1.3 EOF -test_expect_success \ - 'listing tags using v* should print only those having v' ' git tag -l "v*" > actual && test_cmp expect actual '
@@ -272,66 +282,73 @@ test_expect_success \ test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD) ' -test_expect_success 'trying to verify an unknown tag should fail' \ - 'test_must_fail git tag -v unknown-tag' +test_expect_success 'trying to verify an unknown tag should fail' ' + test_must_fail git tag -v unknown-tag +' test_expect_success \ - 'trying to verify a non-annotated and non-signed tag should fail' \ - 'test_must_fail git tag -v non-annotated-tag' + 'trying to verify a non-annotated and non-signed tag should fail' ' + test_must_fail git tag -v non-annotated-tag +' test_expect_success \ - 'trying to verify many non-annotated or unknown tags, should fail' \ - 'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2' + 'trying to verify many non-annotated or unknown tags, should fail' ' + test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2 +' # creating annotated tags: +here='s/\\s/ /g; s/\\t/\t/g; s/\\n/\n/g' + get_tag_msg () { git cat-file tag "$1" | sed -e "/BEGIN PGP/q" } # run test_tick before committing always gives the time in that timezone get_tag_header () { -cat <<EOF + # name, object, type, time + cat <<-EOF && object $2 type $3 tag $1 tagger C O Mitter <[email protected]> $4 -0700 EOF + sed -e "$here" } -commit=$(git rev-parse HEAD) -time=$test_tick - -get_tag_header annotated-tag $commit commit $time >expect -echo "A message" >>expect test_expect_success \ 'creating an annotated tag with -m message should succeed' ' + commit=$(git rev-parse HEAD) && + time=$test_tick && + get_tag_header annotated-tag $commit commit $time \ + >expect <<-EOF && + A message + EOF git tag -m "A message" annotated-tag && get_tag_msg annotated-tag >actual && test_cmp expect actual ' -cat >msgfile <<EOF -Another message -in a file. -EOF -get_tag_header file-annotated-tag $commit commit $time >expect -cat msgfile >>expect test_expect_success \ 'creating an annotated tag with -F messagefile should succeed' ' + cat >msgfile <<-EOF && + A message from the + standard input + EOF + get_tag_header file-annotated-tag $commit commit $time >expect <msgfile git tag -F msgfile file-annotated-tag && get_tag_msg file-annotated-tag >actual && test_cmp expect actual ' -cat >inputmsg <<EOF +test_expect_success 'creating an annotated tag with -F - should succeed' ' + cat >inputmsg <<-EOF && A message from the standard input EOF -get_tag_header stdin-annotated-tag $commit commit $time >expect -cat inputmsg >>expect -test_expect_success 'creating an annotated tag with -F - should succeed' ' + get_tag_header stdin-annotated-tag $commit commit $time \ + >expect <inputmsg git tag -F - stdin-annotated-tag <inputmsg && get_tag_msg stdin-annotated-tag >actual && test_cmp expect actual
@@ -361,29 +378,47 @@ test_expect_success \ # blank and empty messages: -get_tag_header empty-annotated-tag $commit commit $time >expect test_expect_success \ 'creating a tag with an empty -m message should succeed' ' + >emptyfile && + get_tag_header empty-annotated-tag $commit commit $time \ + >expect <emptyfile && git tag -m "" empty-annotated-tag && get_tag_msg empty-annotated-tag >actual && test_cmp expect actual ' ->emptyfile -get_tag_header emptyfile-annotated-tag $commit commit $time >expect test_expect_success \ 'creating a tag with an empty -F messagefile should succeed' ' + get_tag_header emptyfile-annotated-tag $commit commit $time \ + >expect <emptyfile && git tag -F emptyfile emptyfile-annotated-tag && get_tag_msg emptyfile-annotated-tag >actual && test_cmp expect actual ' -printf '\n\n \n\t\nLeading blank lines\n' >blanksfile -printf '\n\t \t \nRepeated blank lines\n' >>blanksfile -printf '\n\n\nTrailing spaces \t \n' >>blanksfile -printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile -get_tag_header blanks-annotated-tag $commit commit $time >expect -cat >>expect <<EOF +test_expect_success \ + 'extra blanks in the message for an annotated tag should be removed' ' + sed -e "$here" >blanksfile <<-\EOF && + + \s\s + \t + Leading blank lines + + \t\s\t\s\s + Repeated blank lines + + + + Trailing spaces\s\s\s\s\s\s\t\s\s + + Trailing blank lines + + \t\s + + EOF + get_tag_header blanks-annotated-tag $commit commit $time \ + >expect <<-EOF && Leading blank lines Repeated blank lines
@@ -392,36 +427,38 @@ Trailing spaces Trailing blank lines EOF -test_expect_success \ - 'extra blanks in the message for an annotated tag should be removed' ' git tag -F blanksfile blanks-annotated-tag && get_tag_msg blanks-annotated-tag >actual && test_cmp expect actual ' -get_tag_header blank-annotated-tag $commit commit $time >expect test_expect_success \ 'creating a tag with blank -m message with spaces should succeed' ' + get_tag_header blank-annotated-tag $commit commit $time >expect <emptyfile && git tag -m " " blank-annotated-tag && get_tag_msg blank-annotated-tag >actual && test_cmp expect actual ' -echo ' ' >blankfile -echo '' >>blankfile -echo ' ' >>blankfile -get_tag_header blankfile-annotated-tag $commit commit $time >expect test_expect_success \ 'creating a tag with blank -F messagefile with spaces should succeed' ' + sed -e "$here" >blankfile <<-\EOF && + \s\s\s\s\s + + \s\s + EOF + get_tag_header blankfile-annotated-tag $commit commit $time \ + >expect <emptyfile && git tag -F blankfile blankfile-annotated-tag && get_tag_msg blankfile-annotated-tag >actual && test_cmp expect actual ' -printf ' ' >blanknonlfile -get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect test_expect_success \ 'creating a tag with -F file of spaces and no newline should succeed' ' + printf " " >blanknonlfile && + get_tag_header blanknonlfile-annotated-tag $commit commit $time \ + >expect <emptyfile && git tag -F blanknonlfile blanknonlfile-annotated-tag && get_tag_msg blanknonlfile-annotated-tag >actual && test_cmp expect actual
@@ -429,7 +466,9 @@ test_expect_success \ # messages with commented lines: -cat >commentsfile <<EOF +test_expect_success \ + 'creating a tag using a -F messagefile with #comments should succeed' ' + cat >commentsfile <<-EOF && # A comment ############
@@ -446,8 +485,8 @@ Another line. Last line. EOF -get_tag_header comments-annotated-tag $commit commit $time >expect -cat >>expect <<EOF + get_tag_header comments-annotated-tag $commit commit $time \ + >expect <<-EOF && The message. One line.
@@ -455,36 +494,39 @@ Another line. Last line. EOF -test_expect_success \ - 'creating a tag using a -F messagefile with #comments should succeed' ' git tag -F commentsfile comments-annotated-tag && get_tag_msg comments-annotated-tag >actual && test_cmp expect actual ' -get_tag_header comment-annotated-tag $commit commit $time >expect test_expect_success \ 'creating a tag with a #comment in the -m message should succeed' ' + get_tag_header comment-annotated-tag $commit commit $time \ + >expect <emptyfile && git tag -m "#comment" comment-annotated-tag && get_tag_msg comment-annotated-tag >actual && test_cmp expect actual ' -echo '#comment' >commentfile -echo '' >>commentfile -echo '####' >>commentfile -get_tag_header commentfile-annotated-tag $commit commit $time >expect test_expect_success \ 'creating a tag with #comments in the -F messagefile should succeed' ' + cat >commentfile <<-EOF && + #comment + + #### + EOF + get_tag_header commentfile-annotated-tag $commit commit $time \ + >expect <emptyfile && git tag -F commentfile commentfile-annotated-tag && get_tag_msg commentfile-annotated-tag >actual && test_cmp expect actual ' -printf '#comment' >commentnonlfile -get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect test_expect_success \ 'creating a tag with a file of #comment and no newline should succeed' ' + printf "#comment" >commentnonlfile && + get_tag_header commentnonlfile-annotated-tag $commit commit $time \ + >expect <emptyfile && git tag -F commentnonlfile commentnonlfile-annotated-tag && get_tag_msg commentnonlfile-annotated-tag >actual && test_cmp expect actual
@@ -542,11 +584,13 @@ test_expect_success \ test_cmp expect actual ' -echo 'tag line one' >annotagmsg -echo 'tag line two' >>annotagmsg -echo 'tag line three' >>annotagmsg test_expect_success \ 'listing many message lines of a non-signed tag should succeed' ' + cat >annotagmsg <<-EOF && + tag line one + tag line two + tag line three + EOF git tag -F annotagmsg tag-lines && echo "tag-lines" >expect &&
@@ -621,20 +665,22 @@ test_expect_success GPG \ # creating and verifying signed tags: -get_tag_header signed-tag $commit commit $time >expect -echo 'A signed tag message' >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG 'creating a signed tag with -m message should succeed' ' +test_expect_success GPG \ + 'creating a signed tag with -m message should succeed' ' + get_tag_header signed-tag $commit commit $time >expect <<-EOF && + A signed tag message + -----BEGIN PGP SIGNATURE----- + EOF git tag -s -m "A signed tag message" signed-tag && get_tag_msg signed-tag >actual && test_cmp expect actual ' -get_tag_header u-signed-tag $commit commit $time >expect -echo 'Another message' >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG 'sign with a given key id' ' - + get_tag_header u-signed-tag $commit commit $time >expect <<-EOF && + Another message + -----BEGIN PGP SIGNATURE----- + EOF git tag -u [email protected] -m "Another message" u-signed-tag && get_tag_msg u-signed-tag >actual && test_cmp expect actual
@@ -654,54 +700,54 @@ test_expect_success GPG 'sign with an unknown id (2)' ' ' -cat >fakeeditor <<'EOF' -#!/bin/sh +test_expect_success GPG '-u implies signed tag' ' + write_script fakeeditor <<-\EOF && test -n "$1" && exec >"$1" echo A signed tag message echo from a fake editor. EOF -chmod +x fakeeditor - -get_tag_header implied-sign $commit commit $time >expect -./fakeeditor >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG '-u implies signed tag' ' + get_tag_header implied-sign $commit commit $time >expect <<-EOF && + A signed tag message + from a fake editor. + -----BEGIN PGP SIGNATURE----- + EOF GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign && get_tag_msg implied-sign >actual && test_cmp expect actual ' -cat >sigmsgfile <<EOF +test_expect_success GPG \ + 'creating a signed tag with -F messagefile should succeed' ' + cat >sigmsgfile <<-EOF Another signed tag message in a file. EOF -get_tag_header file-signed-tag $commit commit $time >expect -cat sigmsgfile >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag with -F messagefile should succeed' ' + get_tag_header file-signed-tag $commit commit $time >expect <sigmsgfile + echo "-----BEGIN PGP SIGNATURE-----" >>expect git tag -s -F sigmsgfile file-signed-tag && get_tag_msg file-signed-tag >actual && test_cmp expect actual ' -cat >siginputmsg <<EOF +test_expect_success GPG 'creating a signed tag with -F - should succeed' ' + cat >siginputmsg <<-EOF A signed tag message from the standard input EOF -get_tag_header stdin-signed-tag $commit commit $time >expect -cat siginputmsg >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG 'creating a signed tag with -F - should succeed' ' + get_tag_header stdin-signed-tag $commit commit $time \ + >expect <siginputmsg && + echo "-----BEGIN PGP SIGNATURE-----" >>expect git tag -s -F - stdin-signed-tag <siginputmsg && get_tag_msg stdin-signed-tag >actual && test_cmp expect actual ' -get_tag_header implied-annotate $commit commit $time >expect -./fakeeditor >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG '-s implies annotated tag' ' + get_tag_header implied-annotate $commit commit $time >expect <<-EOF && + A signed tag message + from a fake editor. + -----BEGIN PGP SIGNATURE----- + EOF GIT_EDITOR=./fakeeditor git tag -s implied-annotate && get_tag_msg implied-annotate >actual && test_cmp expect actual
@@ -715,11 +761,14 @@ test_expect_success GPG \ ! tag_exists nosigtag ' -test_expect_success GPG 'verifying a signed tag should succeed' \ - 'git tag -v signed-tag' +test_expect_success GPG 'verifying a signed tag should succeed' ' + git tag -v signed-tag +' -test_expect_success GPG 'verifying two signed tags in one command should succeed' \ - 'git tag -v signed-tag file-signed-tag' +test_expect_success GPG \ + 'verifying two signed tags in one command should succeed' ' + git tag -v signed-tag file-signed-tag +' test_expect_success GPG \ 'verifying many signed and non-signed tags should fail' '
@@ -740,33 +789,52 @@ test_expect_success GPG 'verifying a forged tag should fail' ' # blank and empty messages for signed tags: -get_tag_header empty-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG \ 'creating a signed tag with an empty -m message should succeed' ' + get_tag_header empty-signed-tag $commit commit $time >expect <<-EOF && + -----BEGIN PGP SIGNATURE----- + EOF git tag -s -m "" empty-signed-tag && get_tag_msg empty-signed-tag >actual && test_cmp expect actual && git tag -v empty-signed-tag ' ->sigemptyfile -get_tag_header emptyfile-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG \ 'creating a signed tag with an empty -F messagefile should succeed' ' + >sigemptyfile && + get_tag_header emptyfile-signed-tag $commit commit $time \ + >expect <<-EOF && + -----BEGIN PGP SIGNATURE----- + EOF git tag -s -F sigemptyfile emptyfile-signed-tag && get_tag_msg emptyfile-signed-tag >actual && test_cmp expect actual && git tag -v emptyfile-signed-tag ' -printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile -printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile -printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile -printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile -get_tag_header blanks-signed-tag $commit commit $time >expect -cat >>expect <<EOF +test_expect_success GPG \ + 'extra blanks in the message for a signed tag should be removed' ' + sed -e "$here" >sigblanksfile <<-\EOF && + + \s\s + \t + Leading blank lines + + \t\s\t\s\s + Repeated blank lines + + + + Trailing spaces\s\s\s\s\s\s\t\s\s + + Trailing blank lines + + \t\s + + EOF + get_tag_header blanks-signed-tag $commit commit $time \ + >expect <<-EOF && Leading blank lines Repeated blank lines
@@ -774,53 +842,61 @@ Repeated blank lines Trailing spaces Trailing blank lines + -----BEGIN PGP SIGNATURE----- EOF -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'extra blanks in the message for a signed tag should be removed' ' git tag -s -F sigblanksfile blanks-signed-tag && get_tag_msg blanks-signed-tag >actual && test_cmp expect actual && git tag -v blanks-signed-tag ' -get_tag_header blank-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG \ 'creating a signed tag with a blank -m message should succeed' ' + get_tag_header blank-signed-tag $commit commit $time \ + >expect <<-EOF && + -----BEGIN PGP SIGNATURE----- + EOF git tag -s -m " " blank-signed-tag && get_tag_msg blank-signed-tag >actual && test_cmp expect actual && git tag -v blank-signed-tag ' -echo ' ' >sigblankfile -echo '' >>sigblankfile -echo ' ' >>sigblankfile -get_tag_header blankfile-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG \ 'creating a signed tag with blank -F file with spaces should succeed' ' + sed -e "$here" >sigblankfile <<-\EOF && + \s\s\s\s\s + + \s\s + EOF + get_tag_header blankfile-signed-tag $commit commit $time \ + >expect <<-EOF && + -----BEGIN PGP SIGNATURE----- + EOF git tag -s -F sigblankfile blankfile-signed-tag && get_tag_msg blankfile-signed-tag >actual && test_cmp expect actual && git tag -v blankfile-signed-tag ' -printf ' ' >sigblanknonlfile -get_tag_header blanknonlfile-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG \ 'creating a signed tag with spaces and no newline should succeed' ' + printf >sigblanknonlfile " " && + get_tag_header blanknonlfile-signed-tag $commit commit $time \ + >expect <<-EOF && + -----BEGIN PGP SIGNATURE----- + EOF git tag -s -F sigblanknonlfile blanknonlfile-signed-tag && get_tag_msg blanknonlfile-signed-tag >actual && test_cmp expect actual && - git tag -v signed-tag + git tag -v blanknonlfile-signed-tag ' # messages with commented lines for signed tags: -cat >sigcommentsfile <<EOF +test_expect_success GPG \ + 'creating a signed tag with a -F file with #comments should succeed' ' + cat >sigcommentsfile <<-EOF && # A comment ############
@@ -837,52 +913,57 @@ Another line. Last line. EOF -get_tag_header comments-signed-tag $commit commit $time >expect -cat >>expect <<EOF + get_tag_header comments-signed-tag $commit commit $time \ + >expect <<-EOF && The message. One line. Another line. Last line. + -----BEGIN PGP SIGNATURE----- EOF -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag with a -F file with #comments should succeed' ' git tag -s -F sigcommentsfile comments-signed-tag && get_tag_msg comments-signed-tag >actual && test_cmp expect actual && git tag -v comments-signed-tag ' -get_tag_header comment-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG \ 'creating a signed tag with #commented -m message should succeed' ' + get_tag_header comment-signed-tag $commit commit $time >expect <<-EOF && + -----BEGIN PGP SIGNATURE----- + EOF git tag -s -m "#comment" comment-signed-tag && get_tag_msg comment-signed-tag >actual && test_cmp expect actual && git tag -v comment-signed-tag ' -echo '#comment' >sigcommentfile -echo '' >>sigcommentfile -echo '####' >>sigcommentfile -get_tag_header commentfile-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG \ 'creating a signed tag with #commented -F messagefile should succeed' ' + cat >sigcommentfile <<-EOF && + #comment + + #### + EOF + get_tag_header commentfile-signed-tag $commit commit $time \ + >expect <<-EOF && + -----BEGIN PGP SIGNATURE----- + EOF git tag -s -F sigcommentfile commentfile-signed-tag && get_tag_msg commentfile-signed-tag >actual && test_cmp expect actual && git tag -v commentfile-signed-tag ' -printf '#comment' >sigcommentnonlfile -get_tag_header commentnonlfile-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG \ 'creating a signed tag with a #comment and no newline should succeed' ' + printf "#comment" >sigcommentnonlfile && + get_tag_header commentnonlfile-signed-tag $commit commit $time \ + >expect <<-EOF && + -----BEGIN PGP SIGNATURE----- + EOF git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag && get_tag_msg commentnonlfile-signed-tag >actual && test_cmp expect actual &&
@@ -941,11 +1022,13 @@ test_expect_success GPG \ test_cmp expect actual ' -echo 'stag line one' >sigtagmsg -echo 'stag line two' >>sigtagmsg -echo 'stag line three' >>sigtagmsg test_expect_success GPG \ 'listing many message lines of a signed tag should succeed' ' + cat >sigtagmsg <<-EOF && + stag line one + stag line two + stag line three + EOF git tag -s -F sigtagmsg stag-lines && echo "stag-lines" >expect &&
@@ -987,72 +1070,68 @@ test_expect_success GPG \ # tags pointing to objects different from commits: -tree=$(git rev-parse HEAD^{tree}) -blob=$(git rev-parse HEAD:foo) -tag=$(git rev-parse signed-tag 2>/dev/null) - -get_tag_header tree-signed-tag $tree tree $time >expect -echo "A message for a tree" >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG \ 'creating a signed tag pointing to a tree should succeed' ' + tree=$(git rev-parse HEAD^{tree}) && + blob=$(git rev-parse HEAD:foo) && + tag=$(git rev-parse signed-tag) && + get_tag_header tree-signed-tag $tree tree $time >expect <<-EOF && + A message for a tree + -----BEGIN PGP SIGNATURE----- + EOF git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} && get_tag_msg tree-signed-tag >actual && test_cmp expect actual ' -get_tag_header blob-signed-tag $blob blob $time >expect -echo "A message for a blob" >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG \ 'creating a signed tag pointing to a blob should succeed' ' + get_tag_header blob-signed-tag $blob blob $time >expect <<-EOF && + A message for a blob + -----BEGIN PGP SIGNATURE----- + EOF git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo && get_tag_msg blob-signed-tag >actual && test_cmp expect actual ' -get_tag_header tag-signed-tag $tag tag $time >expect -echo "A message for another tag" >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG \ 'creating a signed tag pointing to another tag should succeed' ' + get_tag_header tag-signed-tag $tag tag $time >expect <<-EOF && + A message for another tag + -----BEGIN PGP SIGNATURE----- + EOF git tag -s -m "A message for another tag" tag-signed-tag signed-tag && get_tag_msg tag-signed-tag >actual && test_cmp expect actual ' # usage with rfc1991 signatures -echo "rfc1991" > gpghome/gpg.conf -get_tag_header rfc1991-signed-tag $commit commit $time >expect -echo "RFC1991 signed tag" >>expect -echo '-----BEGIN PGP MESSAGE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag with rfc1991' ' +test_expect_success GPG 'creating a signed tag with rfc1991' ' + echo "rfc1991" >gpghome/gpg.conf && + get_tag_header rfc1991-signed-tag $commit commit $time >expect <<-EOF && + RFC1991 signed tag + -----BEGIN PGP MESSAGE----- + EOF git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit && get_tag_msg rfc1991-signed-tag >actual && test_cmp expect actual ' -cat >fakeeditor <<'EOF' -#!/bin/sh +test_expect_success GPG 'reediting a signed tag body omits signature' ' + write_script fakeeditor <<-\EOF && cp "$1" actual EOF -chmod +x fakeeditor - -test_expect_success GPG \ - 'reediting a signed tag body omits signature' ' echo "RFC1991 signed tag" >expect && GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit && test_cmp expect actual ' -test_expect_success GPG \ - 'verifying rfc1991 signature' ' +test_expect_success GPG 'verifying rfc1991 signature' ' git tag -v rfc1991-signed-tag ' -test_expect_success GPG \ - 'list tag with rfc1991 signature' ' +test_expect_success GPG 'list tag with rfc1991 signature' ' echo "rfc1991-signed-tag RFC1991 signed tag" >expect && git tag -l -n1 rfc1991-signed-tag >actual && test_cmp expect actual &&
@@ -1062,15 +1141,12 @@ test_expect_success GPG \ test_cmp expect actual ' -rm -f gpghome/gpg.conf - -test_expect_success GPG \ - 'verifying rfc1991 signature without --rfc1991' ' +test_expect_success GPG 'verifying rfc1991 signature without --rfc1991' ' + rm -f gpghome/gpg.conf && git tag -v rfc1991-signed-tag ' -test_expect_success GPG \ - 'list tag with rfc1991 signature without --rfc1991' ' +test_expect_success GPG 'list tag with rfc1991 signature without --rfc1991' ' echo "rfc1991-signed-tag RFC1991 signed tag" >expect && git tag -l -n1 rfc1991-signed-tag >actual && test_cmp expect actual &&
@@ -1080,26 +1156,26 @@ test_expect_success GPG \ test_cmp expect actual ' -test_expect_success GPG \ - 'reediting a signed tag body omits signature' ' +test_expect_success GPG 'reediting a signed tag body omits signature' ' echo "RFC1991 signed tag" >expect && GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit && test_cmp expect actual ' +test_expect_success GPG 'git tag -s fails if gpg is misconfigured' ' # try to sign with bad user.signingkey -git config user.signingkey BobTheMouse -test_expect_success GPG \ - 'git tag -s fails if gpg is misconfigured' \ - 'test_must_fail git tag -s -m tail tag-gpg-failure' + git config user.signingkey BobTheMouse && + test_must_fail git tag -s -m tail tag-gpg-failure && git config --unset user.signingkey +' # try to verify without gpg: -rm -rf gpghome test_expect_success GPG \ - 'verify signed tag fails when public key is not present' \ - 'test_must_fail git tag -v signed-tag' + 'verify signed tag fails when public key is not present' ' + rm -rf gpghome && + test_must_fail git tag -v signed-tag +' test_expect_success \ 'git tag -a fails if tag annotation is empty' '
@@ -1126,12 +1202,13 @@ test_expect_success \ test_cmp rest.expect rest.actual ' -get_tag_header reuse $commit commit $time >expect -echo "An annotation to be reused" >> expect test_expect_success \ 'overwriting an annoted tag should use its previous body' ' + get_tag_header reuse $commit commit $time >expect <<-EOF && + reuse + EOF git tag -a -m "An annotation to be reused" reuse && - GIT_EDITOR=true git tag -f -a reuse && + GIT_EDITOR=true git tag -f -a -m "reuse" reuse && get_tag_msg reuse >actual && test_cmp expect actual '
@@ -1158,68 +1235,61 @@ test_expect_success 'filename for the message is relative to cwd' ' # create a few more commits to test --contains -hash1=$(git rev-parse HEAD) - test_expect_success 'creating second commit and tag' ' + hash1=$(git rev-parse HEAD) && echo foo-2.0 >foo && git add foo && git commit -m second && + hash2=$(git rev-parse HEAD) && git tag v2.0 ' -hash2=$(git rev-parse HEAD) - test_expect_success 'creating third commit without tag' ' echo foo-dev >foo && git add foo && - git commit -m third -' - + git commit -m third && hash3=$(git rev-parse HEAD) +' -# simple linear checks of --continue +# simple linear checks of --contains -cat > expected <<EOF +test_expect_success 'checking that first commit is in all tags (hash)' ' + cat >expected <<-EOF && v0.2.1 v1.0 v1.0.1 v1.1.3 v2.0 EOF - -test_expect_success 'checking that first commit is in all tags (hash)' " git tag -l --contains $hash1 v* >actual && test_cmp expected actual -" +' # other ways of specifying the commit -test_expect_success 'checking that first commit is in all tags (tag)' " +test_expect_success 'checking that first commit is in all tags (tag)' ' git tag -l --contains v1.0 v* >actual && test_cmp expected actual -" +' -test_expect_success 'checking that first commit is in all tags (relative)' " +test_expect_success 'checking that first commit is in all tags (relative)' ' git tag -l --contains HEAD~2 v* >actual && test_cmp expected actual -" +' -cat > expected <<EOF +test_expect_success 'checking that second commit only has one tag' ' + cat >expected <<-EOF && v2.0 EOF - -test_expect_success 'checking that second commit only has one tag' " git tag -l --contains $hash2 v* >actual && test_cmp expected actual -" - +' -cat > expected <<EOF +test_expect_success 'checking that third commit has no tags' ' + cat >expected <<-EOF && EOF - -test_expect_success 'checking that third commit has no tags' " git tag -l --contains $hash3 v* >actual && test_cmp expected actual -" +' # how about a simple merge?
@@ -1228,35 +1298,33 @@ test_expect_success 'creating simple branch' ' git checkout stable && echo foo-3.0 > foo && git commit foo -m fourth && + hash4=$(git rev-parse HEAD) && git tag v3.0 ' -hash4=$(git rev-parse HEAD) - -cat > expected <<EOF +test_expect_success 'checking that branch head only has one tag' ' + cat >expected <<-EOF && v3.0 EOF - -test_expect_success 'checking that branch head only has one tag' " git tag -l --contains $hash4 v* >actual && test_cmp expected actual -" +' test_expect_success 'merging original branch into this branch' ' git merge --strategy=ours master && git tag v4.0 ' -cat > expected <<EOF +test_expect_success 'checking that original branch head has one tag now' ' + cat >expected <<-EOF && v4.0 EOF - -test_expect_success 'checking that original branch head has one tag now' " git tag -l --contains $hash3 v* >actual && test_cmp expected actual -" +' -cat > expected <<EOF +test_expect_success 'checking that initial commit is in all tags' ' + cat >expected <<-EOF && v0.2.1 v1.0 v1.0.1
@@ -1265,11 +1333,9 @@ v2.0 v3.0 v4.0 EOF - -test_expect_success 'checking that initial commit is in all tags' " git tag -l --contains $hash1 v* >actual && test_cmp expected actual -" +' # mixing modes and options:
Signature · 1 line
1.7.8
PATCH 102/105 t5512 (ls-remote): modernize style
In reply to Tom GrennanGuard setup with test_expect_success
--- t/t5512-ls-remote.sh | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
t/t5512-ls-remote.sh +4 -2
@@ -102,11 +102,13 @@ test_expect_success 'use branch.<name>.remote if possible' ' ' -cat >exp <<EOF +test_expect_success 'confuses pattern as remote when no remote specified' ' + '" + cat >exp <<-EOF fatal: 'refs*master' does not appear to be a git repository fatal: The remote end hung up unexpectedly EOF -test_expect_success 'confuses pattern as remote when no remote specified' ' + "' # # Do not expect "git ls-remote <pattern>" to work; ls-remote, correctly, # confuses <pattern> for <remote>. Although ugly, this behaviour is akin
Signature · 1 line
1.7.8
PATCH v2 1/5 t7004 (tag): modernize style
In reply to Tom Grennan- Guard setup with test_expect_success
- Single-quoted, tab prefaced test blocks
- Use >FILE instead of > FILE
- Use a "here" filter for generation of expect files with mixed tabs and spaces
--- t/t7004-tag.sh | 828 ++++++++++++++++++++++++++++++-------------------------- 1 files changed, 447 insertions(+), 381 deletions(-)
t/t7004-tag.sh +447 -381
@@ -27,8 +27,9 @@ test_expect_success 'listing all tags in an empty tree should output nothing' ' test `git tag | wc -l` -eq 0 ' -test_expect_success 'looking for a tag in an empty tree should fail' \ - '! (tag_exists mytag)' +test_expect_success 'looking for a tag in an empty tree should fail' ' + ! tag_exists mytag +' test_expect_success 'creating a tag in an empty tree should fail' ' test_must_fail git tag mynotag &&
@@ -66,27 +67,32 @@ test_expect_success 'listing all tags if one exists should output that tag' ' # pattern matching: -test_expect_success 'listing a tag using a matching pattern should succeed' \ - 'git tag -l mytag' +test_expect_success 'listing a tag using a matching pattern should succeed' ' + git tag -l mytag +' test_expect_success \ - 'listing a tag using a matching pattern should output that tag' \ - 'test `git tag -l mytag` = mytag' + 'listing a tag using a matching pattern should output that tag' ' + test `git tag -l mytag` = mytag +' # todo: git tag -l now returns always zero, when fixed, change this test test_expect_success \ - 'listing tags using a non-matching pattern should suceed' \ - 'git tag -l xxx' + 'listing tags using a non-matching pattern should suceed' ' + git tag -l xxx +' test_expect_success \ - 'listing tags using a non-matching pattern should output nothing' \ - 'test `git tag -l xxx | wc -l` -eq 0' + 'listing tags using a non-matching pattern should output nothing' ' + test `git tag -l xxx | wc -l` -eq 0 +' # special cases for creating tags: test_expect_success \ - 'trying to create a tag with the name of one existing should fail' \ - 'test_must_fail git tag mytag' + 'trying to create a tag with the name of one existing should fail' ' + test_must_fail git tag mytag +' test_expect_success \ 'trying to create a tag with a non-valid name should fail' '
@@ -111,15 +117,17 @@ test_expect_success 'trying to delete an unknown tag should fail' ' test_must_fail git tag -d unknown-tag ' -cat >expect <<EOF -myhead -mytag -EOF test_expect_success \ 'trying to delete tags without params should succeed and do nothing' ' - git tag -l > actual && test_cmp expect actual && + cat >expect <<-EOF && + myhead + mytag + EOF + git tag -l >actual && + test_cmp expect actual && git tag -d && - git tag -l > actual && test_cmp expect actual + git tag -l >actual && + test_cmp expect actual ' test_expect_success \
@@ -147,23 +155,25 @@ test_expect_success \ ! tag_exists myhead ' -test_expect_success 'trying to delete an already deleted tag should fail' \ - 'test_must_fail git tag -d mytag' +test_expect_success \ + 'trying to delete an already deleted tag should fail' ' + test_must_fail git tag -d mytag +' # listing various tags with pattern matching: -cat >expect <<EOF -a1 -aa1 -cba -t210 -t211 -v0.2.1 -v1.0 -v1.0.1 -v1.1.3 -EOF test_expect_success 'listing all tags should print them ordered' ' + cat >expect <<-EOF && + a1 + aa1 + cba + t210 + t211 + v0.2.1 + v1.0 + v1.0.1 + v1.1.3 + EOF git tag v1.0.1 && git tag t211 && git tag aa1 &&
@@ -173,88 +183,88 @@ test_expect_success 'listing all tags should print them ordered' ' git tag a1 && git tag v1.0 && git tag t210 && - git tag -l > actual && + git tag -l >actual && test_cmp expect actual && - git tag > actual && + git tag >actual && test_cmp expect actual ' -cat >expect <<EOF -a1 -aa1 -cba -EOF test_expect_success \ 'listing tags with substring as pattern must print those matching' ' + cat >expect <<-EOF && + a1 + aa1 + cba + EOF rm *a* && - git tag -l "*a*" > current && + git tag -l "*a*" >current && test_cmp expect current ' -cat >expect <<EOF -v0.2.1 -v1.0.1 -EOF test_expect_success \ 'listing tags with a suffix as pattern must print those matching' ' - git tag -l "*.1" > actual && + cat >expect <<-EOF && + v0.2.1 + v1.0.1 + EOF + git tag -l "*.1" >actual && test_cmp expect actual ' -cat >expect <<EOF -t210 -t211 -EOF test_expect_success \ 'listing tags with a prefix as pattern must print those matching' ' - git tag -l "t21*" > actual && + cat >expect <<-EOF && + t210 + t211 + EOF + git tag -l "t21*" >actual && test_cmp expect actual ' -cat >expect <<EOF -a1 -EOF test_expect_success \ 'listing tags using a name as pattern must print that one matching' ' - git tag -l a1 > actual && + cat >expect <<-EOF && + a1 + EOF + git tag -l a1 >actual && test_cmp expect actual ' -cat >expect <<EOF -v1.0 -EOF test_expect_success \ 'listing tags using a name as pattern must print that one matching' ' - git tag -l v1.0 > actual && + cat >expect <<-EOF && + v1.0 + EOF + git tag -l v1.0 >actual && test_cmp expect actual ' -cat >expect <<EOF -v1.0.1 -v1.1.3 -EOF test_expect_success \ 'listing tags with ? in the pattern should print those matching' ' - git tag -l "v1.?.?" > actual && + cat >expect <<-EOF && + v1.0.1 + v1.1.3 + EOF + git tag -l "v1.?.?" >actual && test_cmp expect actual ' ->expect test_expect_success \ 'listing tags using v.* should print nothing because none have v.' ' - git tag -l "v.*" > actual && + >expect && + git tag -l "v.*" >actual && test_cmp expect actual ' -cat >expect <<EOF -v0.2.1 -v1.0 -v1.0.1 -v1.1.3 -EOF test_expect_success \ 'listing tags using v* should print only those having v' ' - git tag -l "v*" > actual && + cat >expect <<-EOF && + v0.2.1 + v1.0 + v1.0.1 + v1.1.3 + EOF + git tag -l "v*" >actual && test_cmp expect actual '
@@ -272,66 +282,73 @@ test_expect_success \ test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD) ' -test_expect_success 'trying to verify an unknown tag should fail' \ - 'test_must_fail git tag -v unknown-tag' +test_expect_success 'trying to verify an unknown tag should fail' ' + test_must_fail git tag -v unknown-tag +' test_expect_success \ - 'trying to verify a non-annotated and non-signed tag should fail' \ - 'test_must_fail git tag -v non-annotated-tag' + 'trying to verify a non-annotated and non-signed tag should fail' ' + test_must_fail git tag -v non-annotated-tag +' test_expect_success \ - 'trying to verify many non-annotated or unknown tags, should fail' \ - 'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2' + 'trying to verify many non-annotated or unknown tags, should fail' ' + test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2 +' # creating annotated tags: +here='s/\\s/ /g; s/\\t/\t/g; s/\\n/\n/g' + get_tag_msg () { git cat-file tag "$1" | sed -e "/BEGIN PGP/q" } # run test_tick before committing always gives the time in that timezone get_tag_header () { -cat <<EOF -object $2 -type $3 -tag $1 -tagger C O Mitter <[email protected]> $4 -0700 + # name, object, type, time + cat <<-EOF && + object $2 + type $3 + tag $1 + tagger C O Mitter <[email protected]> $4 -0700 -EOF + EOF + sed -e "$here" } -commit=$(git rev-parse HEAD) -time=$test_tick - -get_tag_header annotated-tag $commit commit $time >expect -echo "A message" >>expect test_expect_success \ 'creating an annotated tag with -m message should succeed' ' + commit=$(git rev-parse HEAD) && + time=$test_tick && + get_tag_header annotated-tag $commit commit $time \ + >expect <<-EOF && + A message + EOF git tag -m "A message" annotated-tag && get_tag_msg annotated-tag >actual && test_cmp expect actual ' -cat >msgfile <<EOF -Another message -in a file. -EOF -get_tag_header file-annotated-tag $commit commit $time >expect -cat msgfile >>expect test_expect_success \ 'creating an annotated tag with -F messagefile should succeed' ' + cat >msgfile <<-EOF && + A message from the + standard input + EOF + get_tag_header file-annotated-tag $commit commit $time >expect <msgfile git tag -F msgfile file-annotated-tag && get_tag_msg file-annotated-tag >actual && test_cmp expect actual ' -cat >inputmsg <<EOF -A message from the -standard input -EOF -get_tag_header stdin-annotated-tag $commit commit $time >expect -cat inputmsg >>expect test_expect_success 'creating an annotated tag with -F - should succeed' ' + cat >inputmsg <<-EOF && + A message from the + standard input + EOF + get_tag_header stdin-annotated-tag $commit commit $time \ + >expect <inputmsg git tag -F - stdin-annotated-tag <inputmsg && get_tag_msg stdin-annotated-tag >actual && test_cmp expect actual
@@ -361,67 +378,87 @@ test_expect_success \ # blank and empty messages: -get_tag_header empty-annotated-tag $commit commit $time >expect test_expect_success \ 'creating a tag with an empty -m message should succeed' ' + >emptyfile && + get_tag_header empty-annotated-tag $commit commit $time \ + >expect <emptyfile && git tag -m "" empty-annotated-tag && get_tag_msg empty-annotated-tag >actual && test_cmp expect actual ' ->emptyfile -get_tag_header emptyfile-annotated-tag $commit commit $time >expect test_expect_success \ 'creating a tag with an empty -F messagefile should succeed' ' + get_tag_header emptyfile-annotated-tag $commit commit $time \ + >expect <emptyfile && git tag -F emptyfile emptyfile-annotated-tag && get_tag_msg emptyfile-annotated-tag >actual && test_cmp expect actual ' -printf '\n\n \n\t\nLeading blank lines\n' >blanksfile -printf '\n\t \t \nRepeated blank lines\n' >>blanksfile -printf '\n\n\nTrailing spaces \t \n' >>blanksfile -printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile -get_tag_header blanks-annotated-tag $commit commit $time >expect -cat >>expect <<EOF -Leading blank lines +test_expect_success \ + 'extra blanks in the message for an annotated tag should be removed' ' + sed -e "$here" >blanksfile <<-\EOF && -Repeated blank lines + \s\s + \t + Leading blank lines -Trailing spaces + \t\s\t\s\s + Repeated blank lines -Trailing blank lines -EOF -test_expect_success \ - 'extra blanks in the message for an annotated tag should be removed' ' + + + Trailing spaces\s\s\s\s\s\s\t\s\s + + Trailing blank lines + + \t\s + + EOF + get_tag_header blanks-annotated-tag $commit commit $time \ + >expect <<-EOF && + Leading blank lines + + Repeated blank lines + + Trailing spaces + + Trailing blank lines + EOF git tag -F blanksfile blanks-annotated-tag && get_tag_msg blanks-annotated-tag >actual && test_cmp expect actual ' -get_tag_header blank-annotated-tag $commit commit $time >expect test_expect_success \ 'creating a tag with blank -m message with spaces should succeed' ' + get_tag_header blank-annotated-tag $commit commit $time >expect <emptyfile && git tag -m " " blank-annotated-tag && get_tag_msg blank-annotated-tag >actual && test_cmp expect actual ' -echo ' ' >blankfile -echo '' >>blankfile -echo ' ' >>blankfile -get_tag_header blankfile-annotated-tag $commit commit $time >expect test_expect_success \ 'creating a tag with blank -F messagefile with spaces should succeed' ' + sed -e "$here" >blankfile <<-\EOF && + \s\s\s\s\s + + \s\s + EOF + get_tag_header blankfile-annotated-tag $commit commit $time \ + >expect <emptyfile && git tag -F blankfile blankfile-annotated-tag && get_tag_msg blankfile-annotated-tag >actual && test_cmp expect actual ' -printf ' ' >blanknonlfile -get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect test_expect_success \ 'creating a tag with -F file of spaces and no newline should succeed' ' + printf " " >blanknonlfile && + get_tag_header blanknonlfile-annotated-tag $commit commit $time \ + >expect <emptyfile && git tag -F blanknonlfile blanknonlfile-annotated-tag && get_tag_msg blanknonlfile-annotated-tag >actual && test_cmp expect actual
@@ -429,62 +466,67 @@ test_expect_success \ # messages with commented lines: -cat >commentsfile <<EOF -# A comment +test_expect_success \ + 'creating a tag using a -F messagefile with #comments should succeed' ' + cat >commentsfile <<-EOF && + # A comment -############ -The message. -############ -One line. + ############ + The message. + ############ + One line. -# commented lines -# commented lines + # commented lines + # commented lines -Another line. -# comments + Another line. + # comments -Last line. -EOF -get_tag_header comments-annotated-tag $commit commit $time >expect -cat >>expect <<EOF -The message. -One line. + Last line. + EOF + get_tag_header comments-annotated-tag $commit commit $time \ + >expect <<-EOF && + The message. + One line. -Another line. + Another line. -Last line. -EOF -test_expect_success \ - 'creating a tag using a -F messagefile with #comments should succeed' ' + Last line. + EOF git tag -F commentsfile comments-annotated-tag && get_tag_msg comments-annotated-tag >actual && test_cmp expect actual ' -get_tag_header comment-annotated-tag $commit commit $time >expect test_expect_success \ 'creating a tag with a #comment in the -m message should succeed' ' + get_tag_header comment-annotated-tag $commit commit $time \ + >expect <emptyfile && git tag -m "#comment" comment-annotated-tag && get_tag_msg comment-annotated-tag >actual && test_cmp expect actual ' -echo '#comment' >commentfile -echo '' >>commentfile -echo '####' >>commentfile -get_tag_header commentfile-annotated-tag $commit commit $time >expect test_expect_success \ 'creating a tag with #comments in the -F messagefile should succeed' ' + cat >commentfile <<-EOF && + #comment + + #### + EOF + get_tag_header commentfile-annotated-tag $commit commit $time \ + >expect <emptyfile && git tag -F commentfile commentfile-annotated-tag && get_tag_msg commentfile-annotated-tag >actual && test_cmp expect actual ' -printf '#comment' >commentnonlfile -get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect test_expect_success \ 'creating a tag with a file of #comment and no newline should succeed' ' + printf "#comment" >commentnonlfile && + get_tag_header commentnonlfile-annotated-tag $commit commit $time \ + >expect <emptyfile && git tag -F commentnonlfile commentnonlfile-annotated-tag && get_tag_msg commentnonlfile-annotated-tag >actual && test_cmp expect actual
@@ -542,11 +584,13 @@ test_expect_success \ test_cmp expect actual ' -echo 'tag line one' >annotagmsg -echo 'tag line two' >>annotagmsg -echo 'tag line three' >>annotagmsg test_expect_success \ 'listing many message lines of a non-signed tag should succeed' ' + cat >annotagmsg <<-EOF && + tag line one + tag line two + tag line three + EOF git tag -F annotagmsg tag-lines && echo "tag-lines" >expect &&
@@ -588,9 +632,9 @@ test_expect_success \ test_expect_success 'annotations for blobs are empty' ' blob=$(git hash-object -w --stdin <<-\EOF - Blob paragraph 1. + Blob paragraph 1. - Blob paragraph 2. + Blob paragraph 2. EOF ) && git tag tag-blob $blob &&
@@ -621,20 +665,22 @@ test_expect_success GPG \ # creating and verifying signed tags: -get_tag_header signed-tag $commit commit $time >expect -echo 'A signed tag message' >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG 'creating a signed tag with -m message should succeed' ' +test_expect_success GPG \ + 'creating a signed tag with -m message should succeed' ' + get_tag_header signed-tag $commit commit $time >expect <<-EOF && + A signed tag message + -----BEGIN PGP SIGNATURE----- + EOF git tag -s -m "A signed tag message" signed-tag && get_tag_msg signed-tag >actual && test_cmp expect actual ' -get_tag_header u-signed-tag $commit commit $time >expect -echo 'Another message' >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG 'sign with a given key id' ' - + get_tag_header u-signed-tag $commit commit $time >expect <<-EOF && + Another message + -----BEGIN PGP SIGNATURE----- + EOF git tag -u [email protected] -m "Another message" u-signed-tag && get_tag_msg u-signed-tag >actual && test_cmp expect actual
@@ -654,54 +700,54 @@ test_expect_success GPG 'sign with an unknown id (2)' ' ' -cat >fakeeditor <<'EOF' -#!/bin/sh -test -n "$1" && exec >"$1" -echo A signed tag message -echo from a fake editor. -EOF -chmod +x fakeeditor - -get_tag_header implied-sign $commit commit $time >expect -./fakeeditor >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG '-u implies signed tag' ' + write_script fakeeditor <<-\EOF && + test -n "$1" && exec >"$1" + echo A signed tag message + echo from a fake editor. + EOF + get_tag_header implied-sign $commit commit $time >expect <<-EOF && + A signed tag message + from a fake editor. + -----BEGIN PGP SIGNATURE----- + EOF GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign && get_tag_msg implied-sign >actual && test_cmp expect actual ' -cat >sigmsgfile <<EOF -Another signed tag -message in a file. -EOF -get_tag_header file-signed-tag $commit commit $time >expect -cat sigmsgfile >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG \ 'creating a signed tag with -F messagefile should succeed' ' + cat >sigmsgfile <<-EOF + Another signed tag + message in a file. + EOF + get_tag_header file-signed-tag $commit commit $time >expect <sigmsgfile + echo "-----BEGIN PGP SIGNATURE-----" >>expect git tag -s -F sigmsgfile file-signed-tag && get_tag_msg file-signed-tag >actual && test_cmp expect actual ' -cat >siginputmsg <<EOF -A signed tag message from -the standard input -EOF -get_tag_header stdin-signed-tag $commit commit $time >expect -cat siginputmsg >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG 'creating a signed tag with -F - should succeed' ' + cat >siginputmsg <<-EOF + A signed tag message from + the standard input + EOF + get_tag_header stdin-signed-tag $commit commit $time \ + >expect <siginputmsg && + echo "-----BEGIN PGP SIGNATURE-----" >>expect git tag -s -F - stdin-signed-tag <siginputmsg && get_tag_msg stdin-signed-tag >actual && test_cmp expect actual ' -get_tag_header implied-annotate $commit commit $time >expect -./fakeeditor >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG '-s implies annotated tag' ' + get_tag_header implied-annotate $commit commit $time >expect <<-EOF && + A signed tag message + from a fake editor. + -----BEGIN PGP SIGNATURE----- + EOF GIT_EDITOR=./fakeeditor git tag -s implied-annotate && get_tag_msg implied-annotate >actual && test_cmp expect actual
@@ -715,11 +761,14 @@ test_expect_success GPG \ ! tag_exists nosigtag ' -test_expect_success GPG 'verifying a signed tag should succeed' \ - 'git tag -v signed-tag' +test_expect_success GPG 'verifying a signed tag should succeed' ' + git tag -v signed-tag +' -test_expect_success GPG 'verifying two signed tags in one command should succeed' \ - 'git tag -v signed-tag file-signed-tag' +test_expect_success GPG \ + 'verifying two signed tags in one command should succeed' ' + git tag -v signed-tag file-signed-tag +' test_expect_success GPG \ 'verifying many signed and non-signed tags should fail' '
@@ -740,149 +789,181 @@ test_expect_success GPG 'verifying a forged tag should fail' ' # blank and empty messages for signed tags: -get_tag_header empty-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG \ 'creating a signed tag with an empty -m message should succeed' ' + get_tag_header empty-signed-tag $commit commit $time >expect <<-EOF && + -----BEGIN PGP SIGNATURE----- + EOF git tag -s -m "" empty-signed-tag && get_tag_msg empty-signed-tag >actual && test_cmp expect actual && git tag -v empty-signed-tag ' ->sigemptyfile -get_tag_header emptyfile-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG \ 'creating a signed tag with an empty -F messagefile should succeed' ' + >sigemptyfile && + get_tag_header emptyfile-signed-tag $commit commit $time \ + >expect <<-EOF && + -----BEGIN PGP SIGNATURE----- + EOF git tag -s -F sigemptyfile emptyfile-signed-tag && get_tag_msg emptyfile-signed-tag >actual && test_cmp expect actual && git tag -v emptyfile-signed-tag ' -printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile -printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile -printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile -printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile -get_tag_header blanks-signed-tag $commit commit $time >expect -cat >>expect <<EOF -Leading blank lines +test_expect_success GPG \ + 'extra blanks in the message for a signed tag should be removed' ' + sed -e "$here" >sigblanksfile <<-\EOF && -Repeated blank lines + \s\s + \t + Leading blank lines -Trailing spaces + \t\s\t\s\s + Repeated blank lines -Trailing blank lines -EOF -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'extra blanks in the message for a signed tag should be removed' ' + + + Trailing spaces\s\s\s\s\s\s\t\s\s + + Trailing blank lines + + \t\s + + EOF + get_tag_header blanks-signed-tag $commit commit $time \ + >expect <<-EOF && + Leading blank lines + + Repeated blank lines + + Trailing spaces + + Trailing blank lines + -----BEGIN PGP SIGNATURE----- + EOF git tag -s -F sigblanksfile blanks-signed-tag && get_tag_msg blanks-signed-tag >actual && test_cmp expect actual && git tag -v blanks-signed-tag ' -get_tag_header blank-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG \ 'creating a signed tag with a blank -m message should succeed' ' + get_tag_header blank-signed-tag $commit commit $time \ + >expect <<-EOF && + -----BEGIN PGP SIGNATURE----- + EOF git tag -s -m " " blank-signed-tag && get_tag_msg blank-signed-tag >actual && test_cmp expect actual && git tag -v blank-signed-tag ' -echo ' ' >sigblankfile -echo '' >>sigblankfile -echo ' ' >>sigblankfile -get_tag_header blankfile-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG \ 'creating a signed tag with blank -F file with spaces should succeed' ' + sed -e "$here" >sigblankfile <<-\EOF && + \s\s\s\s\s + + \s\s + EOF + get_tag_header blankfile-signed-tag $commit commit $time \ + >expect <<-EOF && + -----BEGIN PGP SIGNATURE----- + EOF git tag -s -F sigblankfile blankfile-signed-tag && get_tag_msg blankfile-signed-tag >actual && test_cmp expect actual && git tag -v blankfile-signed-tag ' -printf ' ' >sigblanknonlfile -get_tag_header blanknonlfile-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG \ 'creating a signed tag with spaces and no newline should succeed' ' + printf >sigblanknonlfile " " && + get_tag_header blanknonlfile-signed-tag $commit commit $time \ + >expect <<-EOF && + -----BEGIN PGP SIGNATURE----- + EOF git tag -s -F sigblanknonlfile blanknonlfile-signed-tag && get_tag_msg blanknonlfile-signed-tag >actual && test_cmp expect actual && - git tag -v signed-tag + git tag -v blanknonlfile-signed-tag ' # messages with commented lines for signed tags: -cat >sigcommentsfile <<EOF -# A comment +test_expect_success GPG \ + 'creating a signed tag with a -F file with #comments should succeed' ' + cat >sigcommentsfile <<-EOF && + # A comment -############ -The message. -############ -One line. + ############ + The message. + ############ + One line. -# commented lines -# commented lines + # commented lines + # commented lines -Another line. -# comments + Another line. + # comments -Last line. -EOF -get_tag_header comments-signed-tag $commit commit $time >expect -cat >>expect <<EOF -The message. -One line. + Last line. + EOF + get_tag_header comments-signed-tag $commit commit $time \ + >expect <<-EOF && + The message. + One line. -Another line. + Another line. -Last line. -EOF -echo '-----BEGIN PGP SIGNATURE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag with a -F file with #comments should succeed' ' + Last line. + -----BEGIN PGP SIGNATURE----- + EOF git tag -s -F sigcommentsfile comments-signed-tag && get_tag_msg comments-signed-tag >actual && test_cmp expect actual && git tag -v comments-signed-tag ' -get_tag_header comment-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG \ 'creating a signed tag with #commented -m message should succeed' ' + get_tag_header comment-signed-tag $commit commit $time >expect <<-EOF && + -----BEGIN PGP SIGNATURE----- + EOF git tag -s -m "#comment" comment-signed-tag && get_tag_msg comment-signed-tag >actual && test_cmp expect actual && git tag -v comment-signed-tag ' -echo '#comment' >sigcommentfile -echo '' >>sigcommentfile -echo '####' >>sigcommentfile -get_tag_header commentfile-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG \ 'creating a signed tag with #commented -F messagefile should succeed' ' + cat >sigcommentfile <<-EOF && + #comment + + #### + EOF + get_tag_header commentfile-signed-tag $commit commit $time \ + >expect <<-EOF && + -----BEGIN PGP SIGNATURE----- + EOF git tag -s -F sigcommentfile commentfile-signed-tag && get_tag_msg commentfile-signed-tag >actual && test_cmp expect actual && git tag -v commentfile-signed-tag ' -printf '#comment' >sigcommentnonlfile -get_tag_header commentnonlfile-signed-tag $commit commit $time >expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG \ 'creating a signed tag with a #comment and no newline should succeed' ' + printf "#comment" >sigcommentnonlfile && + get_tag_header commentnonlfile-signed-tag $commit commit $time \ + >expect <<-EOF && + -----BEGIN PGP SIGNATURE----- + EOF git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag && get_tag_msg commentnonlfile-signed-tag >actual && test_cmp expect actual &&
@@ -941,11 +1022,13 @@ test_expect_success GPG \ test_cmp expect actual ' -echo 'stag line one' >sigtagmsg -echo 'stag line two' >>sigtagmsg -echo 'stag line three' >>sigtagmsg test_expect_success GPG \ 'listing many message lines of a signed tag should succeed' ' + cat >sigtagmsg <<-EOF && + stag line one + stag line two + stag line three + EOF git tag -s -F sigtagmsg stag-lines && echo "stag-lines" >expect &&
@@ -987,72 +1070,68 @@ test_expect_success GPG \ # tags pointing to objects different from commits: -tree=$(git rev-parse HEAD^{tree}) -blob=$(git rev-parse HEAD:foo) -tag=$(git rev-parse signed-tag 2>/dev/null) - -get_tag_header tree-signed-tag $tree tree $time >expect -echo "A message for a tree" >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG \ 'creating a signed tag pointing to a tree should succeed' ' + tree=$(git rev-parse HEAD^{tree}) && + blob=$(git rev-parse HEAD:foo) && + tag=$(git rev-parse signed-tag) && + get_tag_header tree-signed-tag $tree tree $time >expect <<-EOF && + A message for a tree + -----BEGIN PGP SIGNATURE----- + EOF git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} && get_tag_msg tree-signed-tag >actual && test_cmp expect actual ' -get_tag_header blob-signed-tag $blob blob $time >expect -echo "A message for a blob" >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG \ 'creating a signed tag pointing to a blob should succeed' ' + get_tag_header blob-signed-tag $blob blob $time >expect <<-EOF && + A message for a blob + -----BEGIN PGP SIGNATURE----- + EOF git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo && get_tag_msg blob-signed-tag >actual && test_cmp expect actual ' -get_tag_header tag-signed-tag $tag tag $time >expect -echo "A message for another tag" >>expect -echo '-----BEGIN PGP SIGNATURE-----' >>expect test_expect_success GPG \ 'creating a signed tag pointing to another tag should succeed' ' + get_tag_header tag-signed-tag $tag tag $time >expect <<-EOF && + A message for another tag + -----BEGIN PGP SIGNATURE----- + EOF git tag -s -m "A message for another tag" tag-signed-tag signed-tag && get_tag_msg tag-signed-tag >actual && test_cmp expect actual ' # usage with rfc1991 signatures -echo "rfc1991" > gpghome/gpg.conf -get_tag_header rfc1991-signed-tag $commit commit $time >expect -echo "RFC1991 signed tag" >>expect -echo '-----BEGIN PGP MESSAGE-----' >>expect -test_expect_success GPG \ - 'creating a signed tag with rfc1991' ' +test_expect_success GPG 'creating a signed tag with rfc1991' ' + echo "rfc1991" >gpghome/gpg.conf && + get_tag_header rfc1991-signed-tag $commit commit $time >expect <<-EOF && + RFC1991 signed tag + -----BEGIN PGP MESSAGE----- + EOF git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit && get_tag_msg rfc1991-signed-tag >actual && test_cmp expect actual ' -cat >fakeeditor <<'EOF' -#!/bin/sh -cp "$1" actual -EOF -chmod +x fakeeditor - -test_expect_success GPG \ - 'reediting a signed tag body omits signature' ' +test_expect_success GPG 'reediting a signed tag body omits signature' ' + write_script fakeeditor <<-\EOF && + cp "$1" actual + EOF echo "RFC1991 signed tag" >expect && GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit && test_cmp expect actual ' -test_expect_success GPG \ - 'verifying rfc1991 signature' ' +test_expect_success GPG 'verifying rfc1991 signature' ' git tag -v rfc1991-signed-tag ' -test_expect_success GPG \ - 'list tag with rfc1991 signature' ' +test_expect_success GPG 'list tag with rfc1991 signature' ' echo "rfc1991-signed-tag RFC1991 signed tag" >expect && git tag -l -n1 rfc1991-signed-tag >actual && test_cmp expect actual &&
@@ -1062,15 +1141,12 @@ test_expect_success GPG \ test_cmp expect actual ' -rm -f gpghome/gpg.conf - -test_expect_success GPG \ - 'verifying rfc1991 signature without --rfc1991' ' +test_expect_success GPG 'verifying rfc1991 signature without --rfc1991' ' + rm -f gpghome/gpg.conf && git tag -v rfc1991-signed-tag ' -test_expect_success GPG \ - 'list tag with rfc1991 signature without --rfc1991' ' +test_expect_success GPG 'list tag with rfc1991 signature without --rfc1991' ' echo "rfc1991-signed-tag RFC1991 signed tag" >expect && git tag -l -n1 rfc1991-signed-tag >actual && test_cmp expect actual &&
@@ -1080,26 +1156,26 @@ test_expect_success GPG \ test_cmp expect actual ' -test_expect_success GPG \ - 'reediting a signed tag body omits signature' ' +test_expect_success GPG 'reediting a signed tag body omits signature' ' echo "RFC1991 signed tag" >expect && GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit && test_cmp expect actual ' -# try to sign with bad user.signingkey -git config user.signingkey BobTheMouse -test_expect_success GPG \ - 'git tag -s fails if gpg is misconfigured' \ - 'test_must_fail git tag -s -m tail tag-gpg-failure' -git config --unset user.signingkey +test_expect_success GPG 'git tag -s fails if gpg is misconfigured' ' + # try to sign with bad user.signingkey + git config user.signingkey BobTheMouse && + test_must_fail git tag -s -m tail tag-gpg-failure && + git config --unset user.signingkey +' # try to verify without gpg: -rm -rf gpghome test_expect_success GPG \ - 'verify signed tag fails when public key is not present' \ - 'test_must_fail git tag -v signed-tag' + 'verify signed tag fails when public key is not present' ' + rm -rf gpghome && + test_must_fail git tag -v signed-tag +' test_expect_success \ 'git tag -a fails if tag annotation is empty' '
@@ -1108,7 +1184,7 @@ test_expect_success \ test_expect_success \ 'message in editor has initial comment' ' - ! (GIT_EDITOR=cat git tag -a initial-comment > actual) + ! (GIT_EDITOR=cat git tag -a initial-comment >actual) ' test_expect_success 'message in editor has initial comment: first line' '
@@ -1126,12 +1202,13 @@ test_expect_success \ test_cmp rest.expect rest.actual ' -get_tag_header reuse $commit commit $time >expect -echo "An annotation to be reused" >> expect test_expect_success \ 'overwriting an annoted tag should use its previous body' ' + get_tag_header reuse $commit commit $time >expect <<-EOF && + reuse + EOF git tag -a -m "An annotation to be reused" reuse && - GIT_EDITOR=true git tag -f -a reuse && + GIT_EDITOR=true git tag -f -a -m "reuse" reuse && get_tag_msg reuse >actual && test_cmp expect actual '
@@ -1158,118 +1235,107 @@ test_expect_success 'filename for the message is relative to cwd' ' # create a few more commits to test --contains -hash1=$(git rev-parse HEAD) - test_expect_success 'creating second commit and tag' ' + hash1=$(git rev-parse HEAD) && echo foo-2.0 >foo && git add foo && git commit -m second && + hash2=$(git rev-parse HEAD) && git tag v2.0 ' -hash2=$(git rev-parse HEAD) - test_expect_success 'creating third commit without tag' ' echo foo-dev >foo && git add foo && - git commit -m third + git commit -m third && + hash3=$(git rev-parse HEAD) ' -hash3=$(git rev-parse HEAD) - -# simple linear checks of --continue +# simple linear checks of --contains -cat > expected <<EOF -v0.2.1 -v1.0 -v1.0.1 -v1.1.3 -v2.0 -EOF - -test_expect_success 'checking that first commit is in all tags (hash)' " +test_expect_success 'checking that first commit is in all tags (hash)' ' + cat >expected <<-EOF && + v0.2.1 + v1.0 + v1.0.1 + v1.1.3 + v2.0 + EOF git tag -l --contains $hash1 v* >actual && test_cmp expected actual -" +' # other ways of specifying the commit -test_expect_success 'checking that first commit is in all tags (tag)' " +test_expect_success 'checking that first commit is in all tags (tag)' ' git tag -l --contains v1.0 v* >actual && test_cmp expected actual -" +' -test_expect_success 'checking that first commit is in all tags (relative)' " +test_expect_success 'checking that first commit is in all tags (relative)' ' git tag -l --contains HEAD~2 v* >actual && test_cmp expected actual -" - -cat > expected <<EOF -v2.0 -EOF +' -test_expect_success 'checking that second commit only has one tag' " +test_expect_success 'checking that second commit only has one tag' ' + cat >expected <<-EOF && + v2.0 + EOF git tag -l --contains $hash2 v* >actual && test_cmp expected actual -" - - -cat > expected <<EOF -EOF +' -test_expect_success 'checking that third commit has no tags' " +test_expect_success 'checking that third commit has no tags' ' + cat >expected <<-EOF && + EOF git tag -l --contains $hash3 v* >actual && test_cmp expected actual -" +' # how about a simple merge? test_expect_success 'creating simple branch' ' git branch stable v2.0 && - git checkout stable && - echo foo-3.0 > foo && + git checkout stable && + echo foo-3.0 >foo && git commit foo -m fourth && + hash4=$(git rev-parse HEAD) && git tag v3.0 ' -hash4=$(git rev-parse HEAD) - -cat > expected <<EOF -v3.0 -EOF - -test_expect_success 'checking that branch head only has one tag' " +test_expect_success 'checking that branch head only has one tag' ' + cat >expected <<-EOF && + v3.0 + EOF git tag -l --contains $hash4 v* >actual && test_cmp expected actual -" +' test_expect_success 'merging original branch into this branch' ' git merge --strategy=ours master && - git tag v4.0 + git tag v4.0 ' -cat > expected <<EOF -v4.0 -EOF - -test_expect_success 'checking that original branch head has one tag now' " +test_expect_success 'checking that original branch head has one tag now' ' + cat >expected <<-EOF && + v4.0 + EOF git tag -l --contains $hash3 v* >actual && test_cmp expected actual -" - -cat > expected <<EOF -v0.2.1 -v1.0 -v1.0.1 -v1.1.3 -v2.0 -v3.0 -v4.0 -EOF - -test_expect_success 'checking that initial commit is in all tags' " +' + +test_expect_success 'checking that initial commit is in all tags' ' + cat >expected <<-EOF && + v0.2.1 + v1.0 + v1.0.1 + v1.1.3 + v2.0 + v3.0 + v4.0 + EOF git tag -l --contains $hash1 v* >actual && test_cmp expected actual -" +' # mixing modes and options:
@@ -1305,8 +1371,8 @@ test_expect_success '--points-at finds annotated tags of tags' ' git tag -m "describing the v4.0 tag object" \ annotated-again-v4.0 annotated-v4.0 && cat >expect <<-\EOF && - annotated-again-v4.0 - annotated-v4.0 + annotated-again-v4.0 + annotated-v4.0 EOF git tag --points-at=annotated-v4.0 >actual && test_cmp expect actual
@@ -1314,8 +1380,8 @@ test_expect_success '--points-at finds annotated tags of tags' ' test_expect_success 'multiple --points-at are OR-ed together' ' cat >expect <<-\EOF && - v2.0 - v3.0 + v2.0 + v3.0 EOF git tag --points-at=v2.0 --points-at=v3.0 >actual && test_cmp expect actual
Signature · 1 line
1.7.8
Re: [PATCHv2 1/5] t7004 (tag): modernize style
Am 03.03.2012 03:15, schrieb Tom Grennan:
t/t7004-tag.sh test_expect_success \ · line 161
Quoted 6 lines
t/t7004-tag.sh +4
-2-test_expect_success 'trying to delete an already deleted tag should fail' \ - 'test_must_fail git tag -d mytag' +test_expect_success \ + 'trying to delete an already deleted tag should fail' ' + test_must_fail git tag -d mytag +'
Personally, I prefer lines with 80+ chars over lines broken with a backslash. So, while I can understand that you do not always remove a backslash to avoid churn, I think it is not warranted to *introduce* one to shorten a line below 80 chars. But that's really just a matter of taste.
t/t7004-tag.sh test_expect_success GPG 'sign with an unknown id (2)' ' · line 726
Quoted 8 lines
test_expect_successGPG \t/t7004-tag.sh +6
-0'creating a signed tag with -F messagefile should succeed' ' + cat >sigmsgfile <<-EOF + Another signed tag + message in a file. + EOF + get_tag_header file-signed-tag $commit commit $time >expect <sigmsgfile + echo "-----BEGIN PGP SIGNATURE-----" >>expect
Several && missing here and later in the file.
I stopped reading here. This is too much to read in one go. This should really be broken into several parts. For example, you changed get_tag_header and added several <emptyfile redirections (which should be /dev/null IMO); that has not a lot to do with "modernize style".
t/t7004-tag.sh test_expect_success GPG 'sign with an unknown id (2)' ' · line 730
Quoted 4 lines
t/t7004-tag.sh +0
-0git tag -s -F sigmsgfile file-signed-tag && get_tag_msg file-signed-tag >actual && test_cmp expect actual '
-- Hannes
PATCH v2 2/5 t5512 (ls-remote): modernize style
In reply to Tom GrennanGuard setup with test_expect_success
--- t/t5512-ls-remote.sh | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)
t/t5512-ls-remote.sh +6 -4
@@ -102,11 +102,13 @@ test_expect_success 'use branch.<name>.remote if possible' ' ' -cat >exp <<EOF -fatal: 'refs*master' does not appear to be a git repository -fatal: The remote end hung up unexpectedly -EOF test_expect_success 'confuses pattern as remote when no remote specified' ' + '" + cat >exp <<-EOF + fatal: 'refs*master' does not appear to be a git repository + fatal: The remote end hung up unexpectedly + EOF + "' # # Do not expect "git ls-remote <pattern>" to work; ls-remote, correctly, # confuses <pattern> for <remote>. Although ugly, this behaviour is akin
Signature · 1 line
1.7.8
Re: [PATCHv2 2/5] t5512 (ls-remote): modernize style
t/t5512-ls-remote.sh test_expect_success 'use branch.<name>.remote if possible' ' · line 111
Quoted 7 lines · Tom Grennan
test_expect_success'confuses pattern as remote when no remote specified' 't/t5512-ls-remote.sh +6
-0+ '" + cat >exp <<-EOF + fatal: 'refs*master' does not appear to be a git repository + fatal: The remote end hung up unexpectedly + EOF + "'
Please make it a habit to make your test script a cascade of &&, i.e.
... remote specified' '
cat >exp <<-\EOF &&
fatal: '\''refs*master'\'' does not ...
...
EOFNo need to resend; I'll fix it up locally.
Thanks.
Re: [PATCHv2 2/5] t5512 (ls-remote): modernize style
Quoted 12 lines · Junio C Hamano
t/t5512-ls-remote.sh test_expect_success 'use branch.<name>.remote if possible' ' · line 111
Quoted 7 lines · Tom Grennan
test_expect_success'confuses pattern as remote when no remote specified' 't/t5512-ls-remote.sh +6
-0+ '" + cat >exp <<-EOF + fatal: 'refs*master' does not appear to be a git repository + fatal: The remote end hung up unexpectedly + EOF + "'Please make it a habit to make your test script a cascade of &&, i.e.
Quoted 8 lines
... remote specified' ' cat >exp <<-\EOF && fatal: '\''refs*master'\'' does not ... ... EOFNo need to resend; I'll fix it up locally.
Oops, I missed the && on that one.
What about the quoting of t6300's,
cat >expected <<\EOF
'refs/heads/master' 'Mon Jul 3 17:18:43 2006 +0200' 'Mon Jul 3 17:18:44 2006 +0200' 'refs/tags/testtag' 'Mon Jul 3 17:18:45 2006 +0200'
EOF
Do you want it like this,
cat >expected <<-EOF && '\''refs/heads/master'\'' '\''Mon Jul 3 17:18:43 2006 +0200'\'' '\''Mon Jul 3 17:18:44 2006 +0200'\'' '\''refs/tags/testtag'\'' '\''Mon Jul 3 17:18:45 2006 +0200'\'' EOF
or,
cat >expected <<-EOF && '"'refs/heads/master' 'Mon Jul 3 17:18:43 2006 +0200' 'Mon Jul 3 17:18:44 2006 +0200'"' '"'refs/tags/testtag' 'Mon Jul 3 17:18:45 2006 +0200'"' EOF
or something else?
Thanks,
TomG
PATCH v2 3/5 t3200 (branch): modernize style
In reply to Tom Grennan- Guard setup with test_expect_success
- Single-quoted, tab prefaced test blocks
--- t/t3200-branch.sh | 365 +++++++++++++++++++++++++++-------------------------- 1 files changed, 186 insertions(+), 179 deletions(-)
t/t3200-branch.sh +186 -179
@@ -7,20 +7,20 @@ test_description='git branch assorted tests' . ./test-lib.sh -test_expect_success \ - 'prepare a trivial repository' \ - 'echo Hello > A && - git update-index --add A && - git commit -m "Initial commit." && - echo World >> A && - git update-index --add A && - git commit -m "Second commit." && - HEAD=$(git rev-parse --verify HEAD)' +test_expect_success 'prepare a trivial repository' ' + echo Hello >A && + git update-index --add A && + git commit -m "Initial commit." && + echo World >>A && + git update-index --add A && + git commit -m "Second commit." && + HEAD=$(git rev-parse --verify HEAD) +' test_expect_success \ - 'git branch --help should not have created a bogus branch' ' - test_might_fail git branch --help </dev/null >/dev/null 2>/dev/null && - test_path_is_missing .git/refs/heads/--help + 'git branch --help should not have created a bogus branch' ' + test_might_fail git branch --help </dev/null >/dev/null 2>/dev/null && + test_path_is_missing .git/refs/heads/--help ' test_expect_success 'branch -h in broken repository' '
@@ -34,63 +34,63 @@ test_expect_success 'branch -h in broken repository' ' grep "[Uu]sage" broken/usage ' -test_expect_success \ - 'git branch abc should create a branch' \ - 'git branch abc && test_path_is_file .git/refs/heads/abc' +test_expect_success 'git branch abc should create a branch' ' + git branch abc && test_path_is_file .git/refs/heads/abc +' -test_expect_success \ - 'git branch a/b/c should create a branch' \ - 'git branch a/b/c && test_path_is_file .git/refs/heads/a/b/c' +test_expect_success 'git branch a/b/c should create a branch' ' + git branch a/b/c && test_path_is_file .git/refs/heads/a/b/c +' -cat >expect <<EOF -$_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master -EOF -test_expect_success \ - 'git branch -l d/e/f should create a branch and a log' \ - 'GIT_COMMITTER_DATE="2005-05-26 23:30" \ - git branch -l d/e/f && - test_path_is_file .git/refs/heads/d/e/f && - test_path_is_file .git/logs/refs/heads/d/e/f && - test_cmp expect .git/logs/refs/heads/d/e/f' +test_expect_success 'git branch -l d/e/f should create a branch and a log' ' + cat >expect <<-EOF + $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master + EOF + GIT_COMMITTER_DATE="2005-05-26 23:30" \ + git branch -l d/e/f && + test_path_is_file .git/refs/heads/d/e/f && + test_path_is_file .git/logs/refs/heads/d/e/f && + test_cmp expect .git/logs/refs/heads/d/e/f +' -test_expect_success \ - 'git branch -d d/e/f should delete a branch and a log' \ - 'git branch -d d/e/f && - test_path_is_missing .git/refs/heads/d/e/f && - test_path_is_missing .git/logs/refs/heads/d/e/f' +test_expect_success 'git branch -d d/e/f should delete a branch and a log' ' + git branch -d d/e/f && + test_path_is_missing .git/refs/heads/d/e/f && + test_path_is_missing .git/logs/refs/heads/d/e/f +' -test_expect_success \ - 'git branch j/k should work after branch j has been deleted' \ - 'git branch j && - git branch -d j && - git branch j/k' +test_expect_success 'git branch j/k should work after branch j has been deleted' ' + git branch j && + git branch -d j && + git branch j/k +' -test_expect_success \ - 'git branch l should work after branch l/m has been deleted' \ - 'git branch l/m && - git branch -d l/m && - git branch l' +test_expect_success 'git branch l should work after branch l/m has been deleted' ' + git branch l/m && + git branch -d l/m && + git branch l +' -test_expect_success \ - 'git branch -m dumps usage' \ - 'test_expect_code 129 git branch -m 2>err && - grep "[Uu]sage: git branch" err' +test_expect_success 'git branch -m dumps usage' ' + test_expect_code 129 git branch -m 2>err && + grep "[Uu]sage: git branch" err +' -test_expect_success \ - 'git branch -m m m/m should work' \ - 'git branch -l m && - git branch -m m m/m && - test_path_is_file .git/logs/refs/heads/m/m' +test_expect_success 'git branch -m m m/m should work' ' + git branch -l m && + git branch -m m m/m && + test_path_is_file .git/logs/refs/heads/m/m +' -test_expect_success \ - 'git branch -m n/n n should work' \ - 'git branch -l n/n && +test_expect_success 'git branch -m n/n n should work' ' + git branch -l n/n && git branch -m n/n n && - test_path_is_file .git/logs/refs/heads/n' + test_path_is_file .git/logs/refs/heads/n +' test_expect_success 'git branch -m o/o o should fail when o/p exists' ' git branch o/o && - git branch o/p && + git branch o/p && test_must_fail git branch -m o/o o '
@@ -160,33 +160,30 @@ test_expect_success 'git branch --list -d t should fail' ' test_path_is_missing .git/refs/heads/t ' -mv .git/config .git/config-saved - test_expect_success 'git branch -m q q2 without config should succeed' ' + mv .git/config .git/config-saved && + test_when_finished mv .git/config-saved .git/config && git branch -m q q2 && git branch -m q2 q ' -mv .git/config-saved .git/config - -git config branch.s/s.dummy Hello - -test_expect_success \ - 'git branch -m s/s s should work when s/t is deleted' \ - 'git branch -l s/s && +test_expect_success 'git branch -m s/s s should work when s/t is deleted' ' + git config branch.s/s.dummy Hello + git branch -l s/s && test_path_is_file .git/logs/refs/heads/s/s && - git branch -l s/t && + git branch -l s/t && test_path_is_file .git/logs/refs/heads/s/t && - git branch -d s/t && - git branch -m s/s s && - test_path_is_file .git/logs/refs/heads/s' - -test_expect_success 'config information was renamed, too' \ - "test $(git config branch.s.dummy) = Hello && - test_must_fail git config branch.s/s/dummy" + git branch -d s/t && + git branch -m s/s s && + test_path_is_file .git/logs/refs/heads/s +' -test_expect_success 'renaming a symref is not allowed' \ +test_expect_success 'config information was renamed, too' ' + test $(git config branch.s.dummy) = Hello && + test_must_fail git config branch.s/s/dummy ' + +test_expect_success 'renaming a symref is not allowed' ' git symbolic-ref refs/heads/master2 refs/heads/master && test_must_fail git branch -m master2 master3 && git symbolic-ref refs/heads/master2 &&
@@ -194,115 +191,125 @@ test_expect_success 'renaming a symref is not allowed' \ test_path_is_missing .git/refs/heads/master3 ' -test_expect_success SYMLINKS \ - 'git branch -m u v should fail when the reflog for u is a symlink' ' - git branch -l u && - mv .git/logs/refs/heads/u real-u && - ln -s real-u .git/logs/refs/heads/u && - test_must_fail git branch -m u v -' - -test_expect_success 'test tracking setup via --track' \ - 'git config remote.local.url . && - git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --track my1 local/master && - test $(git config branch.my1.remote) = local && - test $(git config branch.my1.merge) = refs/heads/master' - -test_expect_success 'test tracking setup (non-wildcard, matching)' \ - 'git config remote.local.url . && - git config remote.local.fetch refs/heads/master:refs/remotes/local/master && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --track my4 local/master && - test $(git config branch.my4.remote) = local && - test $(git config branch.my4.merge) = refs/heads/master' - -test_expect_success 'test tracking setup (non-wildcard, not matching)' \ - 'git config remote.local.url . && - git config remote.local.fetch refs/heads/s:refs/remotes/local/s && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --track my5 local/master && - ! test "$(git config branch.my5.remote)" = local && - ! test "$(git config branch.my5.merge)" = refs/heads/master' - -test_expect_success 'test tracking setup via config' \ - 'git config branch.autosetupmerge true && - git config remote.local.url . && - git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch my3 local/master && - test $(git config branch.my3.remote) = local && - test $(git config branch.my3.merge) = refs/heads/master' - -test_expect_success 'test overriding tracking setup via --no-track' \ - 'git config branch.autosetupmerge true && - git config remote.local.url . && - git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/master || git fetch local) && - git branch --no-track my2 local/master && - git config branch.autosetupmerge false && - ! test "$(git config branch.my2.remote)" = local && - ! test "$(git config branch.my2.merge)" = refs/heads/master' - -test_expect_success 'no tracking without .fetch entries' \ - 'git config branch.autosetupmerge true && - git branch my6 s && - git config branch.automsetupmerge false && - test -z "$(git config branch.my6.remote)" && - test -z "$(git config branch.my6.merge)"' - -test_expect_success 'test tracking setup via --track but deeper' \ - 'git config remote.local.url . && - git config remote.local.fetch refs/heads/*:refs/remotes/local/* && - (git show-ref -q refs/remotes/local/o/o || git fetch local) && - git branch --track my7 local/o/o && - test "$(git config branch.my7.remote)" = local && - test "$(git config branch.my7.merge)" = refs/heads/o/o' - -test_expect_success 'test deleting branch deletes branch config' \ - 'git branch -d my7 && - test -z "$(git config branch.my7.remote)" && - test -z "$(git config branch.my7.merge)"' - -test_expect_success 'test deleting branch without config' \ - 'git branch my7 s && - sha1=$(git rev-parse my7 | cut -c 1-7) && - echo "Deleted branch my7 (was $sha1)." >expect && - git branch -d my7 >actual 2>&1 && - test_i18ncmp expect actual' - -test_expect_success 'test --track without .fetch entries' \ - 'git branch --track my8 && - test "$(git config branch.my8.remote)" && - test "$(git config branch.my8.merge)"' +test_expect_success SYMLINKS 'git branch -m u v should fail when the reflog for u is a symlink' ' + git branch -l u && + mv .git/logs/refs/heads/u real-u && + ln -s real-u .git/logs/refs/heads/u && + test_must_fail git branch -m u v +' -test_expect_success \ - 'branch from non-branch HEAD w/autosetupmerge=always' \ - 'git config branch.autosetupmerge always && - git branch my9 HEAD^ && - git config branch.autosetupmerge false' +test_expect_success 'test tracking setup via --track' ' + git config remote.local.url . && + git config remote.local.fetch refs/heads/*:refs/remotes/local/* && + (git show-ref -q refs/remotes/local/master || git fetch local) && + git branch --track my1 local/master && + test $(git config branch.my1.remote) = local && + test $(git config branch.my1.merge) = refs/heads/master +' -test_expect_success \ - 'branch from non-branch HEAD w/--track causes failure' \ - 'test_must_fail git branch --track my10 HEAD^' +test_expect_success 'test tracking setup (non-wildcard, matching)' ' + git config remote.local.url . && + git config remote.local.fetch \ + refs/heads/master:refs/remotes/local/master && + (git show-ref -q refs/remotes/local/master || git fetch local) && + git branch --track my4 local/master && + test $(git config branch.my4.remote) = local && + test $(git config branch.my4.merge) = refs/heads/master +' -test_expect_success \ - 'branch from tag w/--track causes failure' \ - 'git tag foobar && - test_must_fail git branch --track my11 foobar' +test_expect_success 'test tracking setup (non-wildcard, not matching)' ' + git config remote.local.url . && + git config remote.local.fetch refs/heads/s:refs/remotes/local/s && + (git show-ref -q refs/remotes/local/master || git fetch local) && + git branch --track my5 local/master && + ! test "$(git config branch.my5.remote)" = local && + ! test "$(git config branch.my5.merge)" = refs/heads/master +' + +test_expect_success 'test tracking setup via config' ' + git config branch.autosetupmerge true && + git config remote.local.url . && + git config remote.local.fetch refs/heads/*:refs/remotes/local/* && + (git show-ref -q refs/remotes/local/master || git fetch local) && + git branch my3 local/master && + test $(git config branch.my3.remote) = local && + test $(git config branch.my3.merge) = refs/heads/master +' + +test_expect_success 'test overriding tracking setup via --no-track' ' + git config branch.autosetupmerge true && + git config remote.local.url . && + git config remote.local.fetch refs/heads/*:refs/remotes/local/* && + (git show-ref -q refs/remotes/local/master || git fetch local) && + git branch --no-track my2 local/master && + git config branch.autosetupmerge false && + ! test "$(git config branch.my2.remote)" = local && + ! test "$(git config branch.my2.merge)" = refs/heads/master +' + +test_expect_success 'no tracking without .fetch entries' ' + git config branch.autosetupmerge true && + git branch my6 s && + git config branch.automsetupmerge false && + test -z "$(git config branch.my6.remote)" && + test -z "$(git config branch.my6.merge)" +' + +test_expect_success 'test tracking setup via --track but deeper' ' + git config remote.local.url . && + git config remote.local.fetch refs/heads/*:refs/remotes/local/* && + (git show-ref -q refs/remotes/local/o/o || git fetch local) && + git branch --track my7 local/o/o && + test "$(git config branch.my7.remote)" = local && + test "$(git config branch.my7.merge)" = refs/heads/o/o +' + +test_expect_success 'test deleting branch deletes branch config' ' + git branch -d my7 && + test -z "$(git config branch.my7.remote)" && + test -z "$(git config branch.my7.merge)" +' + +test_expect_success 'test deleting branch without config' ' + git branch my7 s && + sha1=$(git rev-parse my7 | cut -c 1-7) && + echo "Deleted branch my7 (was $sha1)." >expect && + git branch -d my7 >actual 2>&1 && + test_i18ncmp expect actual +' + +test_expect_success 'test --track without .fetch entries' ' + git branch --track my8 && + test "$(git config branch.my8.remote)" && + test "$(git config branch.my8.merge)" +' + +test_expect_success 'branch from non-branch HEAD w/autosetupmerge=always' ' + git config branch.autosetupmerge always && + git branch my9 HEAD^ && + git config branch.autosetupmerge false +' + +test_expect_success 'branch from non-branch HEAD w/--track causes failure' ' + test_must_fail git branch --track my10 HEAD^ +' + +test_expect_success 'branch from tag w/--track causes failure' ' + git tag foobar && + test_must_fail git branch --track my11 foobar +' # Keep this test last, as it changes the current branch -cat >expect <<EOF -$_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master -EOF -test_expect_success \ - 'git checkout -b g/h/i -l should create a branch and a log' \ - 'GIT_COMMITTER_DATE="2005-05-26 23:30" \ - git checkout -b g/h/i -l master && - test_path_is_file .git/refs/heads/g/h/i && - test_path_is_file .git/logs/refs/heads/g/h/i && - test_cmp expect .git/logs/refs/heads/g/h/i' +test_expect_success 'git checkout -b g/h/i -l should create a branch and a log' ' + cat >expect <<-EOF + $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master + EOF + GIT_COMMITTER_DATE="2005-05-26 23:30" \ + git checkout -b g/h/i -l master && + test_path_is_file .git/refs/heads/g/h/i && + test_path_is_file .git/logs/refs/heads/g/h/i && + test_cmp expect .git/logs/refs/heads/g/h/i +' test_expect_success 'checkout -b makes reflog by default' ' git checkout master &&
Signature · 1 line
1.7.8
PATCH v2 4/5 t0040 (parse-options): modernize style
In reply to Tom Grennan- Guard setup with test_expect_success
--- t/t0040-parse-options.sh | 438 ++++++++++++++++++++++------------------------ 1 files changed, 212 insertions(+), 226 deletions(-)
t/t0040-parse-options.sh +212 -226
@@ -7,87 +7,83 @@ test_description='our own option parser' . ./test-lib.sh -cat > expect << EOF -usage: test-parse-options <options> - - -b, --boolean get a boolean - -4, --or4 bitwise-or boolean with ...0100 - --neg-or4 same as --no-or4 - - -i, --integer <n> get a integer - -j <n> get a integer, too - --set23 set integer to 23 - -t <time> get timestamp of <time> - -L, --length <str> get length of <str> - -F, --file <file> set file to <file> - -String options - -s, --string <string> - get a string - --string2 <str> get another string - --st <st> get another string (pervert ordering) - -o <str> get another string - --default-string set string to default - --list <str> add str to list - -Magic arguments - --quux means --quux - -NUM set integer to NUM - + same as -b - --ambiguous positive ambiguity - --no-ambiguous negative ambiguity - -Standard options - --abbrev[=<n>] use <n> digits to display SHA-1s - -v, --verbose be verbose - -n, --dry-run dry run - -q, --quiet be quiet - -EOF - test_expect_success 'test help' ' - test_must_fail test-parse-options -h > output 2> output.err && + cat >expect <<-EOF && + usage: test-parse-options <options> + + -b, --boolean get a boolean + -4, --or4 bitwise-or boolean with ...0100 + --neg-or4 same as --no-or4 + + -i, --integer <n> get a integer + -j <n> get a integer, too + --set23 set integer to 23 + -t <time> get timestamp of <time> + -L, --length <str> get length of <str> + -F, --file <file> set file to <file> + + String options + -s, --string <string> + '' get a string + --string2 <str> get another string + --st <st> get another string (pervert ordering) + -o <str> get another string + --default-string set string to default + --list <str> add str to list + + Magic arguments + --quux means --quux + -NUM set integer to NUM + + same as -b + --ambiguous positive ambiguity + --no-ambiguous negative ambiguity + + Standard options + --abbrev[=<n>] use <n> digits to display SHA-1s + -v, --verbose be verbose + -n, --dry-run dry run + -q, --quiet be quiet + + EOF + cp expect expect.err && + test_must_fail test-parse-options -h >output 2>output.err && test ! -s output.err && test_cmp expect output ' -mv expect expect.err - -cat > expect << EOF -boolean: 2 -integer: 1729 -timestamp: 0 -string: 123 -abbrev: 7 -verbose: 2 -quiet: no -dry run: yes -file: prefix/my.file -EOF - test_expect_success 'short options' ' + cat >expect <<-\EOF && + boolean: 2 + integer: 1729 + timestamp: 0 + string: 123 + abbrev: 7 + verbose: 2 + quiet: no + dry run: yes + file: prefix/my.file + EOF test-parse-options -s123 -b -i 1729 -b -vv -n -F my.file \ - > output 2> output.err && + >output 2>output.err && test_cmp expect output && test ! -s output.err ' -cat > expect << EOF -boolean: 2 -integer: 1729 -timestamp: 0 -string: 321 -abbrev: 10 -verbose: 2 -quiet: no -dry run: no -file: prefix/fi.le -EOF - test_expect_success 'long options' ' + cat >expect <<-\EOF && + boolean: 2 + integer: 1729 + timestamp: 0 + string: 321 + abbrev: 10 + verbose: 2 + quiet: no + dry run: no + file: prefix/fi.le + EOF test-parse-options --boolean --integer 1729 --boolean --string2=321 \ - --verbose --verbose --no-dry-run --abbrev=10 --file fi.le\ - --obsolete > output 2> output.err && + --verbose --verbose --no-dry-run --abbrev=10 --file fi.le \ + --obsolete >output 2>output.err && test ! -s output.err && test_cmp expect output '
@@ -101,48 +97,46 @@ test_expect_success 'missing required value' ' test $? = 129 ' -cat > expect << EOF -boolean: 1 -integer: 13 -timestamp: 0 -string: 123 -abbrev: 7 -verbose: 0 -quiet: no -dry run: no -file: (not set) -arg 00: a1 -arg 01: b1 -arg 02: --boolean -EOF - test_expect_success 'intermingled arguments' ' + cat >expect <<-\EOF && + boolean: 1 + integer: 13 + timestamp: 0 + string: 123 + abbrev: 7 + verbose: 0 + quiet: no + dry run: no + file: (not set) + arg 00: a1 + arg 01: b1 + arg 02: --boolean + EOF test-parse-options a1 --string 123 b1 --boolean -j 13 -- --boolean \ - > output 2> output.err && + >output 2>output.err && test ! -s output.err && test_cmp expect output ' -cat > expect << EOF -boolean: 0 -integer: 2 -timestamp: 0 -string: (not set) -abbrev: 7 -verbose: 0 -quiet: no -dry run: no -file: (not set) -EOF - test_expect_success 'unambiguously abbreviated option' ' - test-parse-options --int 2 --boolean --no-bo > output 2> output.err && + cat >expect <<-\EOF && + boolean: 0 + integer: 2 + timestamp: 0 + string: (not set) + abbrev: 7 + verbose: 0 + quiet: no + dry run: no + file: (not set) + EOF + test-parse-options --int 2 --boolean --no-bo >output 2>output.err && test ! -s output.err && test_cmp expect output ' test_expect_success 'unambiguously abbreviated option with "="' ' - test-parse-options --int=2 > output 2> output.err && + test-parse-options --int=2 >output 2>output.err && test ! -s output.err && test_cmp expect output '
@@ -152,198 +146,190 @@ test_expect_success 'ambiguously abbreviated option' ' test $? = 129 ' -cat > expect << EOF -boolean: 0 -integer: 0 -timestamp: 0 -string: 123 -abbrev: 7 -verbose: 0 -quiet: no -dry run: no -file: (not set) -EOF - test_expect_success 'non ambiguous option (after two options it abbreviates)' ' - test-parse-options --st 123 > output 2> output.err && + cat >expect <<-\EOF && + boolean: 0 + integer: 0 + timestamp: 0 + string: 123 + abbrev: 7 + verbose: 0 + quiet: no + dry run: no + file: (not set) + EOF + test-parse-options --st 123 >output 2>output.err && test ! -s output.err && test_cmp expect output ' -cat > typo.err << EOF -error: did you mean \`--boolean\` (with two dashes ?) -EOF - test_expect_success 'detect possible typos' ' - test_must_fail test-parse-options -boolean > output 2> output.err && - test ! -s output && - test_cmp typo.err output.err + cat >typo.err <<-\EOF && + error: did you mean `--boolean` (with two dashes ?) + EOF + >expect + test_must_fail test-parse-options -boolean >output 2>output.err && + test_cmp typo.err output.err && + test_cmp expect output ' -cat > expect <<EOF -boolean: 0 -integer: 0 -timestamp: 0 -string: (not set) -abbrev: 7 -verbose: 0 -quiet: no -dry run: no -file: (not set) -arg 00: --quux -EOF - test_expect_success 'keep some options as arguments' ' - test-parse-options --quux > output 2> output.err && - test ! -s output.err && - test_cmp expect output + cat >expect <<-\EOF && + boolean: 0 + integer: 0 + timestamp: 0 + string: (not set) + abbrev: 7 + verbose: 0 + quiet: no + dry run: no + file: (not set) + arg 00: --quux + EOF + test-parse-options --quux >output 2>output.err && + test ! -s output.err && + test_cmp expect output ' -cat > expect <<EOF -boolean: 0 -integer: 0 -timestamp: 1 -string: default -abbrev: 7 -verbose: 0 -quiet: yes -dry run: no -file: (not set) -arg 00: foo -EOF - test_expect_success 'OPT_DATE() and OPT_SET_PTR() work' ' - test-parse-options -t "1970-01-01 00:00:01 +0000" --default-string \ - foo -q > output 2> output.err && + cat >expect <<-\EOF && + boolean: 0 + integer: 0 + timestamp: 1 + string: default + abbrev: 7 + verbose: 0 + quiet: yes + dry run: no + file: (not set) + arg 00: foo + EOF + test-parse-options -t "1970-01-01 00:00:01 +0000" \ + --default-string foo -q >output 2>output.err && test ! -s output.err && test_cmp expect output ' -cat > expect <<EOF -Callback: "four", 0 -boolean: 5 -integer: 4 -timestamp: 0 -string: (not set) -abbrev: 7 -verbose: 0 -quiet: no -dry run: no -file: (not set) -EOF - test_expect_success 'OPT_CALLBACK() and OPT_BIT() work' ' - test-parse-options --length=four -b -4 > output 2> output.err && + cat >expect <<-\EOF && + Callback: "four", 0 + boolean: 5 + integer: 4 + timestamp: 0 + string: (not set) + abbrev: 7 + verbose: 0 + quiet: no + dry run: no + file: (not set) + EOF + test-parse-options --length=four -b -4 >output 2>output.err && test ! -s output.err && test_cmp expect output ' -cat > expect <<EOF -Callback: "not set", 1 -EOF - test_expect_success 'OPT_CALLBACK() and callback errors work' ' - test_must_fail test-parse-options --no-length > output 2> output.err && + cat >expect <<-\EOF && + Callback: "not set", 1 + EOF + test_must_fail test-parse-options --no-length >output 2>output.err && test_cmp expect output && test_cmp expect.err output.err ' -cat > expect <<EOF -boolean: 1 -integer: 23 -timestamp: 0 -string: (not set) -abbrev: 7 -verbose: 0 -quiet: no -dry run: no -file: (not set) -EOF - test_expect_success 'OPT_BIT() and OPT_SET_INT() work' ' - test-parse-options --set23 -bbbbb --no-or4 > output 2> output.err && + cat >expect <<-\EOF && + boolean: 1 + integer: 23 + timestamp: 0 + string: (not set) + abbrev: 7 + verbose: 0 + quiet: no + dry run: no + file: (not set) + EOF + test-parse-options --set23 -bbbbb --no-or4 >output 2>output.err && test ! -s output.err && test_cmp expect output ' test_expect_success 'OPT_NEGBIT() and OPT_SET_INT() work' ' - test-parse-options --set23 -bbbbb --neg-or4 > output 2> output.err && + test-parse-options --set23 -bbbbb --neg-or4 >output 2>output.err && test ! -s output.err && test_cmp expect output ' -cat > expect <<EOF -boolean: 6 -integer: 0 -timestamp: 0 -string: (not set) -abbrev: 7 -verbose: 0 -quiet: no -dry run: no -file: (not set) -EOF - test_expect_success 'OPT_BIT() works' ' - test-parse-options -bb --or4 > output 2> output.err && + cat >expect <<-\EOF && + boolean: 6 + integer: 0 + timestamp: 0 + string: (not set) + abbrev: 7 + verbose: 0 + quiet: no + dry run: no + file: (not set) + EOF + test-parse-options -bb --or4 >output 2>output.err && test ! -s output.err && test_cmp expect output ' test_expect_success 'OPT_NEGBIT() works' ' - test-parse-options -bb --no-neg-or4 > output 2> output.err && + test-parse-options -bb --no-neg-or4 >output 2>output.err && test ! -s output.err && test_cmp expect output ' test_expect_success 'OPT_BOOLEAN() with PARSE_OPT_NODASH works' ' - test-parse-options + + + + + + > output 2> output.err && + test-parse-options + + + + + + >output 2>output.err && test ! -s output.err && test_cmp expect output ' -cat > expect <<EOF -boolean: 0 -integer: 12345 -timestamp: 0 -string: (not set) -abbrev: 7 -verbose: 0 -quiet: no -dry run: no -file: (not set) -EOF test_expect_success 'OPT_NUMBER_CALLBACK() works' ' - test-parse-options -12345 > output 2> output.err && + cat >expect <<-\EOF && + boolean: 0 + integer: 12345 + timestamp: 0 + string: (not set) + abbrev: 7 + verbose: 0 + quiet: no + dry run: no + file: (not set) + EOF + test-parse-options -12345 >output 2>output.err && test ! -s output.err && test_cmp expect output ' -cat >expect <<EOF -boolean: 0 -integer: 0 -timestamp: 0 -string: (not set) -abbrev: 7 -verbose: 0 -quiet: no -dry run: no -file: (not set) -EOF - test_expect_success 'negation of OPT_NONEG flags is not ambiguous' ' + cat >expect <<-\EOF && + boolean: 0 + integer: 0 + timestamp: 0 + string: (not set) + abbrev: 7 + verbose: 0 + quiet: no + dry run: no + file: (not set) + EOF test-parse-options --no-ambig >output 2>output.err && test ! -s output.err && test_cmp expect output ' -cat >>expect <<'EOF' -list: foo -list: bar -list: baz -EOF test_expect_success '--list keeps list of strings' ' + cat >>expect <<-\EOF && + list: foo + list: bar + list: baz + EOF test-parse-options --list foo --list=bar --list=baz >output && test_cmp expect output '
Signature · 1 line
1.7.8
PATCH v2 5/5 t6300 (for-each-ref): modernize style
In reply to Tom Grennan- Guard setup with test_expect_success
- Unwound one loop to stay within the test_expect_success guard
--- t/t6300-for-each-ref.sh | 186 +++++++++++++++++++++++------------------------ 1 files changed, 92 insertions(+), 94 deletions(-)
t/t6300-for-each-ref.sh +92 -94
@@ -138,12 +138,13 @@ test_expect_success 'Check invalid format specifiers are errors' ' test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads ' -cat >expected <<\EOF -'refs/heads/master' 'Mon Jul 3 17:18:43 2006 +0200' 'Mon Jul 3 17:18:44 2006 +0200' -'refs/tags/testtag' 'Mon Jul 3 17:18:45 2006 +0200' -EOF - test_expect_success 'Check unformatted date fields output' ' + '" + cat >expected <<-EOF && + 'refs/heads/master' 'Mon Jul 3 17:18:43 2006 +0200' 'Mon Jul 3 17:18:44 2006 +0200' + 'refs/tags/testtag' 'Mon Jul 3 17:18:45 2006 +0200' + EOF + "' (git for-each-ref --shell --format="%(refname) %(committerdate) %(authordate)" refs/heads && git for-each-ref --shell --format="%(refname) %(taggerdate)" refs/tags) >actual && test_cmp expected actual
@@ -171,84 +172,85 @@ test_expect_success 'Check format "relative" date fields output' ' git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual ' -cat >expected <<\EOF -'refs/heads/master' '2006-07-03' '2006-07-03' -'refs/tags/testtag' '2006-07-03' -EOF - test_expect_success 'Check format "short" date fields output' ' + '" + cat >expected <<-EOF + 'refs/heads/master' '2006-07-03' '2006-07-03' + 'refs/tags/testtag' '2006-07-03' + EOF + "' f=short && (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual && test_cmp expected actual ' -cat >expected <<\EOF -'refs/heads/master' 'Mon Jul 3 15:18:43 2006' 'Mon Jul 3 15:18:44 2006' -'refs/tags/testtag' 'Mon Jul 3 15:18:45 2006' -EOF - test_expect_success 'Check format "local" date fields output' ' - f=local && - (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && - git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual && + '" + cat >expected <<-EOF + 'refs/heads/master' 'Mon Jul 3 15:18:43 2006' 'Mon Jul 3 15:18:44 2006' + 'refs/tags/testtag' 'Mon Jul 3 15:18:45 2006' + EOF + "' + (git for-each-ref --shell --format="%(refname) %(committerdate:local) %(authordate:local)" refs/heads && + git for-each-ref --shell --format="%(refname) %(taggerdate:local)" refs/tags) >actual && test_cmp expected actual ' -cat >expected <<\EOF -'refs/heads/master' '2006-07-03 17:18:43 +0200' '2006-07-03 17:18:44 +0200' -'refs/tags/testtag' '2006-07-03 17:18:45 +0200' -EOF - test_expect_success 'Check format "iso8601" date fields output' ' + '" + cat >expected <<-EOF + 'refs/heads/master' '2006-07-03 17:18:43 +0200' '2006-07-03 17:18:44 +0200' + 'refs/tags/testtag' '2006-07-03 17:18:45 +0200' + EOF + "' f=iso8601 && (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual && test_cmp expected actual ' -cat >expected <<\EOF -'refs/heads/master' 'Mon, 3 Jul 2006 17:18:43 +0200' 'Mon, 3 Jul 2006 17:18:44 +0200' -'refs/tags/testtag' 'Mon, 3 Jul 2006 17:18:45 +0200' -EOF - test_expect_success 'Check format "rfc2822" date fields output' ' + '" + cat >expected <<-EOF + 'refs/heads/master' 'Mon, 3 Jul 2006 17:18:43 +0200' 'Mon, 3 Jul 2006 17:18:44 +0200' + 'refs/tags/testtag' 'Mon, 3 Jul 2006 17:18:45 +0200' + EOF + "' f=rfc2822 && (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual && test_cmp expected actual ' -cat >expected <<\EOF -refs/heads/master -refs/remotes/origin/master -refs/tags/testtag -EOF - test_expect_success 'Verify ascending sort' ' + cat >expected <<-EOF + refs/heads/master + refs/remotes/origin/master + refs/tags/testtag + EOF git for-each-ref --format="%(refname)" --sort=refname >actual && test_cmp expected actual ' - -cat >expected <<\EOF -refs/tags/testtag -refs/remotes/origin/master -refs/heads/master -EOF - test_expect_success 'Verify descending sort' ' + cat >expected <<-EOF + refs/tags/testtag + refs/remotes/origin/master + refs/heads/master + EOF git for-each-ref --format="%(refname)" --sort=-refname >actual && test_cmp expected actual ' -cat >expected <<\EOF -'refs/heads/master' -'refs/remotes/origin/master' -'refs/tags/testtag' -EOF - test_expect_success 'Quoting style: shell' ' + '" + cat >expected <<-EOF + 'refs/heads/master' + 'refs/remotes/origin/master' + 'refs/tags/testtag' + EOF + "' git for-each-ref --shell --format="%(refname)" >actual && test_cmp expected actual '
@@ -263,52 +265,51 @@ test_expect_success 'Quoting style: python' ' test_cmp expected actual ' -cat >expected <<\EOF -"refs/heads/master" -"refs/remotes/origin/master" -"refs/tags/testtag" -EOF - test_expect_success 'Quoting style: tcl' ' + cat >expected <<-EOF + "refs/heads/master" + "refs/remotes/origin/master" + "refs/tags/testtag" + EOF git for-each-ref --tcl --format="%(refname)" >actual && test_cmp expected actual ' -for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do - test_expect_success "more than one quoting style: $i" " - git for-each-ref $i 2>&1 | (read line && - case \$line in - \"error: more than one quoting style\"*) : happy;; - *) false - esac) - " -done - -cat >expected <<\EOF -master -testtag -EOF - +test_expect_success 'more than one quoting styles' ' + cat >expected <<-EOF + error: more than one quoting style? + EOF + git for-each-ref --perl --shell 2>&1 | head -n 1 >actual && + test_cmp expected actual && + git for-each-ref -s --python 2>&1 | head -n 1 >actual && + test_cmp expected actual && + git for-each-ref --python --tcl 2>&1 | head -n 1 >actual && + test_cmp expected actual && + git for-each-ref --tcl --perl 2>&1 | head -n 1 >actual && + test_cmp expected actual +' test_expect_success 'Check short refname format' ' + cat >expected <<-EOF + master + testtag + EOF (git for-each-ref --format="%(refname:short)" refs/heads && git for-each-ref --format="%(refname:short)" refs/tags) >actual && test_cmp expected actual ' -cat >expected <<EOF -origin/master -EOF - test_expect_success 'Check short upstream format' ' + cat >expected <<-EOF + origin/master + EOF git for-each-ref --format="%(upstream:short)" refs/heads >actual && test_cmp expected actual ' -cat >expected <<EOF -67a36f1 -EOF - test_expect_success 'Check short objectname format' ' + cat >expected <<-EOF + 67a36f1 + EOF git for-each-ref --format="%(objectname:short)" refs/heads >actual && test_cmp expected actual '
@@ -317,12 +318,11 @@ test_expect_success 'Check for invalid refname format' ' test_must_fail git for-each-ref --format="%(refname:INVALID)" ' -cat >expected <<\EOF -heads/master -tags/master -EOF - test_expect_success 'Check ambiguous head and tag refs (strict)' ' + cat >expected <<-EOF + heads/master + tags/master + EOF git config --bool core.warnambiguousrefs true && git checkout -b newtag && echo "Using $datestamp" > one &&
@@ -334,23 +334,21 @@ test_expect_success 'Check ambiguous head and tag refs (strict)' ' test_cmp expected actual ' -cat >expected <<\EOF -heads/master -master -EOF - test_expect_success 'Check ambiguous head and tag refs (loose)' ' + cat >expected <<-EOF + heads/master + master + EOF git config --bool core.warnambiguousrefs false && git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual && test_cmp expected actual ' -cat >expected <<\EOF -heads/ambiguous -ambiguous -EOF - test_expect_success 'Check ambiguous head and tag refs II (loose)' ' + cat >expected <<-EOF + heads/ambiguous + ambiguous + EOF git checkout master && git tag ambiguous testtag^0 && git branch ambiguous testtag^0 &&
@@ -369,7 +367,7 @@ test_expect_success 'an unusual tag with an incomplete line' ' ' test_expect_success 'create tag with subject and body content' ' - cat >>msg <<-\EOF && + cat >msg <<-\EOF && the subject line first body line
@@ -417,9 +415,9 @@ test_expect_success GPG 'create signed tags' ' git tag -s -m "" signed-empty && git tag -s -m "subject line" signed-short && cat >msg <<-\EOF && - subject line + subject line - body contents + body contents EOF git tag -s -F msg signed-long '
Signature · 1 line
1.7.8