Re: [RFC/PATCH] tag: make list exclude !<pattern>

42 messages, 5 authors, 2016-06-15 · open the first message on its own page

Re: [RFC/PATCH] tag: make list exclude !<pattern>

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:53:02

Tom Grennan [off-list ref] writes:
quoted
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
quoted
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?
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.

Re: [RFC/PATCH] tag: make list exclude !<pattern>

From: Michael Haggerty <hidden>
Date: 2016-06-15 22:53:03

On 02/11/2012 04:06 AM, Junio C Hamano wrote:
Tom Grennan [off-list ref] writes:
quoted
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.
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.
According to git-check-ref-format(1), '!' are allowed in reference
names.  (Whether that was a good idea is another question, but now we
have to support it.)

So using "^" would be an option.  A problem is that the new meaning is
not consistent with the use of "^" in rev-list, and therefore would (1)
be confusing and (2) prevent the addition of a similar syntax in rev-list.

Currently,

    git rev-list A B ^C

means "revisions reachable from A or B but not from C".  (For simplicity
assume that A, B, and C are literal reference names without wildcards.)
 The proposal, amended to use "^" instead of "!", is that

    git for-each-ref A B ^C

should mean "the reference names A and B but not C".  Therefore, the command

    git rev-list $(git for-each-ref A B ^C)

, which consistency suggests should do the same thing as the first
command, would in fact be equivalent to

    git rev-list A B

Moreover, it *would* be nice to have this kind of exclude-branch-name
syntax in rev-parse.  Many times I have wanted to type the equivalent of

    gitk --all --not-branch=remotes/korg/*

That is, "show the commits starting at *all branches except for the
specified branches*".  This is different than "show *the commits
starting at all branches* except for *the commits reachable from the
specified branches*", because I want to see the *complete* history of
the non-excluded branches.  (Is there an easy way to do this now?)  The
proposed functionality is a step forward; I could type

    gitk $(git for-each-ref !remotes/korg/*)

But it would be even nicer if this could be expressed directly in rev-parse.

In summary, I suggest we consider using a more verbose syntax for this
new functionality (probably via one or more new options, for example
--not-branch=PATTERN, --not-tag=PATTERN, and/or --not-ref=PATTERN) that
cannot be confused with the existing syntax for excluding commits.

Michael

-- 
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/

Re: [RFC/PATCH] tag: make list exclude !<pattern>

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:03

On Fri, Feb 10, 2012 at 07:06:57PM -0800, Junio C Hamano wrote:
Tom Grennan [off-list ref] writes:
quoted
quoted
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
quoted
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?
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.
Nuts! I have the cart before the horse. I'll try to rearrange the series as
suggested by tomorrow. Thanks.
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

-- 
TomG

[PATCHv3 0/5] Re: tag: make list exclude !<pattern>

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:07

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(-)

-- 
1.7.8

[PATCHv3 3/5] tag --exclude option

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:07

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.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

Signed-off-by: Tom Grennan <redacted>
---
 Documentation/git-tag.txt |    6 ++++-
 builtin/tag.c             |   17 ++++++++++---
 t/t7004-tag.sh            |   56 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 74 insertions(+), 5 deletions(-)
diff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt
index 8d32b9a..470bd80 100644
--- a/Documentation/git-tag.txt
+++ b/Documentation/git-tag.txt
@@ -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).
diff --git a/builtin/tag.c b/builtin/tag.c
index 4a016d5..547f97d 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -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)
diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index f8c247a..4f1cf48 100755
--- a/t/t7004-tag.sh
+++ b/t/t7004-tag.sh
@@ -82,6 +82,10 @@ 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 excluding "mytag" should output nothing' \
+	'test `git tag -l --exclude mytag | wc -l` -eq 0'
+
 # special cases for creating tags:
 
 test_expect_success \
@@ -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
+'
+
+cat >expect <<EOF
 t210
 t211
 EOF
@@ -212,6 +225,15 @@ test_expect_success \
 '
 
 cat >expect <<EOF
+t210
+EOF
+test_expect_success \
+	'listing tags with a prefix as pattern and suffix exclusion' '
+	git tag -l --exclude "*1" "t21*" > actual &&
+	test_cmp expect actual
+'
+
+cat >expect <<EOF
 a1
 EOF
 test_expect_success \
@@ -239,6 +261,15 @@ test_expect_success \
 	test_cmp expect actual
 '
 
+cat >expect <<EOF
+v1.0.1
+EOF
+test_expect_success \
+	'listing tags with ? in the pattern and exclusion' '
+	git tag -l --exclude "v1.?.3" "v1.?.?" > actual &&
+	test_cmp expect actual
+'
+
 >expect
 test_expect_success \
 	'listing tags using v.* should print nothing because none have v.' '
@@ -263,6 +294,31 @@ test_expect_success 'tag -l can accept multiple patterns' '
 	test_cmp expect actual
 '
 
+test_expect_success 'tag -l can cancel exclusions' '
+	git tag -l --exclude "v*.3" --no-exclude "v1*" "v0*" >actual &&
+	test_cmp expect actual
+'
+
+cat >expect <<EOF
+v0.2.1
+v1.0.1
+EOF
+test_expect_success 'tag -l can accept multiple patterns and exclusions' '
+	git tag -l --exclude "v*.3" --exclude "v1.0" "v1*" "v0*" >actual &&
+	test_cmp expect actual
+'
+
+cat >expect <<EOF
+v0.2.1
+v1.0.1
+v1.1.3
+EOF
+test_expect_success \
+	'tag -l can cancel then reapply exclusions' '
+	git tag -l --exclude "v*.3" --no-exclude --exclude "v1.0" \
+		"v1*" "v0*" >actual &&
+	test_cmp expect actual
+'
 # creating and verifying lightweight tags:
 
 test_expect_success \
-- 
1.7.8

[PATCHv3 1/5] refs: add match_pattern()

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:07

Used-by: git-branch, git-for-each-ref, git-ls-remote, and git-tag

Signed-off-by: Tom Grennan <redacted>
---
 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(-)
diff --git a/builtin/branch.c b/builtin/branch.c
index cb17bc3..e46ed58 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -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, stru
 	qsort(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++) {
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index b01d76a..bd6a114 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -781,25 +781,8 @@ static int grab_single_ref(const char *refname, const unsigned char *sha1, int f
 	struct 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
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index 41c88a9..29f2b38 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -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)
diff --git a/builtin/tag.c b/builtin/tag.c
index fe7e5e5..9dcd7d2 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -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;
 
diff --git a/refs.c b/refs.c
index c9f6835..0c50e81 100644
--- a/refs.c
+++ b/refs.c
@@ -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;
+}
diff --git a/refs.h b/refs.h
index 33202b0..dd059d8 100644
--- a/refs.h
+++ b/refs.h
@@ -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 */
-- 
1.7.8

[PATCHv3 5/5] for-each-ref --exclude option

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:07

Example,
  $ git for-each-ref --format="%(refname)" refs/remotes/origin
  refs/remotes/origin/HEAD
  refs/remotes/origin/maint
  refs/remotes/origin/master
  refs/remotes/origin/next
  refs/remotes/origin/pu
  refs/remotes/origin/todo
  $ ./git-for-each-ref --format="%(refname)" --exclude "*/HEAD" refs/remotes/origin
  refs/remotes/origin/maint
  refs/remotes/origin/master
  refs/remotes/origin/next
  refs/remotes/origin/pu
  refs/remotes/origin/todo

Signed-off-by: Tom Grennan <redacted>
---
 Documentation/git-for-each-ref.txt |    7 ++++++-
 builtin/for-each-ref.c             |    8 +++++++-
 t/t6300-for-each-ref.sh            |   11 +++++++++++
 3 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt
index c872b88..5f19a8b 100644
--- a/Documentation/git-for-each-ref.txt
+++ b/Documentation/git-for-each-ref.txt
@@ -9,7 +9,8 @@ SYNOPSIS
 --------
 [verse]
 'git for-each-ref' [--count=<count>] [--shell|--perl|--python|--tcl]
-		   [(--sort=<key>)...] [--format=<format>] [<pattern>...]
+		   [(--sort=<key>)...] [--format=<format>]
+		   [--exclude=<pattern>] [<pattern>...]
 
 DESCRIPTION
 -----------
@@ -47,6 +48,10 @@ OPTIONS
 	`xx`; for example `%00` interpolates to `\0` (NUL),
 	`%09` to `\t` (TAB) and `%0a` to `\n` (LF).
 
+--exclude <pattern>::
+	Ignore refs matching the given pattern.  This has precedence
+	over any other pattern match arguments.
+
 <pattern>...::
 	If one or more patterns are given, only refs are shown that
 	match against at least one pattern, either using fnmatch(3) or
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index bd6a114..783f59f 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -91,6 +91,9 @@ static const char **used_atom;
 static cmp_type *used_atom_type;
 static int used_atom_cnt, sort_atom_limit, need_tagged, need_symref;
 
+/* list of ref patterns and ref groups (i.e. foo/) to ignore */
+static struct string_list exclude = STRING_LIST_INIT_NODUP;
+
 /*
  * Used to parse format string and sort specifiers
  */
@@ -781,7 +784,7 @@ static int grab_single_ref(const char *refname, const unsigned char *sha1, int f
 	struct refinfo *ref;
 	int cnt;
 
-	if (!match_pattern(refname, cb->grab_pattern, NULL, FNM_PATHNAME))
+	if (!match_pattern(refname, cb->grab_pattern, &exclude, FNM_PATHNAME))
 		return 0;
 
 	/*
@@ -985,6 +988,9 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
 		OPT_STRING(  0 , "format", &format, "format", "format to use for the output"),
 		OPT_CALLBACK(0 , "sort", sort_tail, "key",
 		            "field name to sort on", &opt_parse_sort),
+		OPT_CALLBACK(0, "exclude", &exclude, "pattern",
+			     "ignore pattern matching refs",
+			     parse_opt_string_list),
 		OPT_END(),
 	};
 
diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index 1721784..26df442 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -243,6 +243,17 @@ test_expect_success 'Verify descending sort' '
 '
 
 cat >expected <<\EOF
+refs/tags/testtag
+refs/heads/master
+EOF
+
+test_expect_success 'Verify exclusion with sort' '
+	git for-each-ref --format="%(refname)" --sort=-refname \
+		--exclude "*origin*" >actual &&
+	test_cmp expected actual
+'
+
+cat >expected <<\EOF
 'refs/heads/master'
 'refs/remotes/origin/master'
 'refs/tags/testtag'
-- 
1.7.8

[PATCHv3 4/5] branch --exclude option

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:07

Example,
  $ ./git-branch -r --exclude \*HEAD
  origin/maint
  origin/master
  origin/next
  origin/pu
  origin/todo

Signed-off-by: Tom Grennan <redacted>
---
 Documentation/git-branch.txt |    7 ++++++-
 builtin/branch.c             |   18 +++++++++++++-----
 t/t3200-branch.sh            |   23 +++++++++++++++++++++++
 3 files changed, 42 insertions(+), 6 deletions(-)
diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
index 0427e80..ef08872 100644
--- a/Documentation/git-branch.txt
+++ b/Documentation/git-branch.txt
@@ -10,7 +10,8 @@ SYNOPSIS
 [verse]
 'git branch' [--color[=<when>] | --no-color] [-r | -a]
 	[--list] [-v [--abbrev=<length> | --no-abbrev]]
-	[(--merged | --no-merged | --contains) [<commit>]] [<pattern>...]
+	[(--merged | --no-merged | --contains) [<commit>]]
+	[--exclude <pattern>] [<pattern>...]
 'git branch' [--set-upstream | --track | --no-track] [-l] [-f] <branchname> [<start-point>]
 'git branch' (-m | -M) [<oldbranch>] <newbranch>
 'git branch' (-d | -D) [-r] <branchname>...
@@ -166,6 +167,10 @@ start-point is either a local or remote-tracking branch.
 --contains <commit>::
 	Only list branches which contain the specified commit.
 
+--exclude <pattern>::
+	Don't list branches matching the given pattern.  This has
+	precedence over other match pattern arguments.
+
 --merged [<commit>]::
 	Only list branches whose tips are reachable from the
 	specified commit (HEAD if not specified).
diff --git a/builtin/branch.c b/builtin/branch.c
index e46ed58..ec06f66 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -243,6 +243,7 @@ struct ref_list {
 	int index, alloc, maxwidth, verbose, abbrev;
 	struct ref_item *list;
 	struct commit_list *with_commit;
+	struct string_list *exclude;
 	int kinds;
 };
 
@@ -300,7 +301,7 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,
 	if ((kind & ref_list->kinds) == 0)
 		return 0;
 
-	if (!match_pattern(refname, cb->pattern, NULL, 0))
+	if (!match_pattern(refname, cb->pattern, ref_list->exclude, 0))
 		return 0;
 
 	commit = NULL;
@@ -498,7 +499,10 @@ static void show_detached(struct ref_list *ref_list)
 	}
 }
 
-static int print_ref_list(int kinds, int detached, int verbose, int abbrev, struct commit_list *with_commit, const char **pattern)
+static int print_ref_list(int kinds, int detached, int verbose, int abbrev,
+			  struct commit_list *with_commit,
+			  struct string_list *exclude,
+			  const char **pattern)
 {
 	int i;
 	struct append_ref_cb cb;
@@ -509,6 +513,7 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru
 	ref_list.verbose = verbose;
 	ref_list.abbrev = abbrev;
 	ref_list.with_commit = with_commit;
+	ref_list.exclude = exclude;
 	if (merge_filter != NO_FILTER)
 		init_revisions(&ref_list.revs, NULL);
 	cb.ref_list = &ref_list;
@@ -530,7 +535,7 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru
 	qsort(ref_list.list, ref_list.index, sizeof(struct ref_item), ref_cmp);
 
 	detached = (detached && (kinds & REF_LOCAL_BRANCH));
-	if (detached && match_pattern("HEAD", pattern, NULL, 0))
+	if (detached && match_pattern("HEAD", pattern, exclude, 0))
 		show_detached(&ref_list);
 
 	for (i = 0; i < ref_list.index; i++) {
@@ -665,7 +670,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 	enum branch_track track;
 	int kinds = REF_LOCAL_BRANCH;
 	struct commit_list *with_commit = NULL;
-
+	struct string_list exclude = STRING_LIST_INIT_NODUP;
 	struct option options[] = {
 		OPT_GROUP("Generic options"),
 		OPT__VERBOSE(&verbose,
@@ -689,6 +694,9 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 			PARSE_OPT_HIDDEN | PARSE_OPT_LASTARG_DEFAULT,
 			parse_opt_with_commit, (intptr_t) "HEAD",
 		},
+		OPT_CALLBACK(0, "exclude", &exclude, "pattern",
+			     "ignorepattern matching branches",
+			     parse_opt_string_list),
 		OPT__ABBREV(&abbrev),
 
 		OPT_GROUP("Specific git-branch actions:"),
@@ -753,7 +761,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 		return delete_branches(argc, argv, delete > 1, kinds);
 	else if (list)
 		return print_ref_list(kinds, detached, verbose, abbrev,
-				      with_commit, argv);
+				      with_commit, &exclude, argv);
 	else if (edit_description) {
 		const char *branch_name;
 		struct strbuf branch_ref = STRBUF_INIT;
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index dd1aceb..8144bc8 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -160,6 +160,29 @@ test_expect_success 'git branch --list -d t should fail' '
 	test_path_is_missing .git/refs/heads/t
 '
 
+>expect
+test_expect_success \
+	'git branch --list --exclude "t*" "t*" should be empty' '
+	git branch ta &&
+	git branch tb &&
+	git branch --list --exclude "t*" "t*" > actual &&
+	cmp expect actual
+'
+
+cat >expect <<EOF
+  ta
+EOF
+test_expect_success \
+	'git branch --list --exclude "tb" "t*" should be "ta"' '
+	git branch --list --exclude "tb" "t*" > actual &&
+	cmp expect actual
+'
+
+test_expect_success \
+	'git branch -d ta tb should succeed' '
+	git branch -d ta tb
+'
+
 mv .git/config .git/config-saved
 
 test_expect_success 'git branch -m q q2 without config should succeed' '
-- 
1.7.8

[PATCHv3 2/5] tag --points-at option wrapper

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:07

Use the OPT_CALLBACK wrapper with "--points-at" instead of an
OPTION_CALLBACK block.

Signed-off-by: Tom Grennan <redacted>
---
 builtin/tag.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/builtin/tag.c b/builtin/tag.c
index 9dcd7d2..4a016d5 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -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()
 	};
 
-- 
1.7.8

Re: [PATCHv3 3/5] tag --exclude option

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:53:07

Tom Grennan [off-list ref] writes:
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.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

Signed-off-by: Tom Grennan <redacted>
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 hunk
diff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt
index 8d32b9a..470bd80 100644
--- a/Documentation/git-tag.txt
+++ b/Documentation/git-tag.txt
@@ -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.
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.
quoted hunk
@@ -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 1/5] refs: add match_pattern()

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:53:07

Tom Grennan [off-list ref] writes:
+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.
+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;
+}
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()

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:07

On Tue, Feb 21, 2012 at 10:33:05PM -0800, Junio C Hamano wrote:
Tom Grennan [off-list ref] writes:
quoted
+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
+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;
+}
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.
OK
- 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.
I agree.
- 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?
Yes, these should be ligically independent although the current use has
combined them.
- Is it a sane assumption that a caller that gives an exclude list will
  want neither FNM_PATHNAME semantics nor match_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. 
- 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.
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.
OK, I think that I understand, but please confirm, you'd expect no output in
the above example, right?

-- 
TomG

Re: [PATCHv3 3/5] tag --exclude option

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:07

On Tue, Feb 21, 2012 at 10:33:29PM -0800, Junio C Hamano wrote:
Tom Grennan [off-list ref] writes:
quoted
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.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

Signed-off-by: Tom Grennan <redacted>
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
diff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt
index 8d32b9a..470bd80 100644
--- a/Documentation/git-tag.txt
+++ b/Documentation/git-tag.txt
@@ -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.
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.
OK, should I also describe the --no-exclude option?
quoted
@@ -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.
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

[PATCH 0/5] modernize test style

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:11

Tom Grennan [off-list ref] writes:
On Tue, Feb 21, 2012 at 10:33:29PM -0800, Junio C Hamano wrote:
quoted
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.
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(-)

-- 
1.7.8

[PATCH 1/5] t6300 (for-each-ref): modernize style

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:11

- Guard setup with test_expect_success
- Single-quoted, tab prefaced test blocks of < 80 cols
- Redirect unwanted output

Signed-off-by: Tom Grennan <redacted>
---
 t/t6300-for-each-ref.sh |  364 +++++++++++++++++++++++++----------------------
 1 files changed, 191 insertions(+), 173 deletions(-)
diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index 1721784..12916b2 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -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
 '
-- 
1.7.8

[PATCH-w 101/105] t6300 (for-each-ref): modernize style

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:11

- Guard setup with test_expect_success
- Single-quoted, tab prefaced test blocks of < 80 cols
- Redirect unwanted output

Signed-off-by: Tom Grennan <redacted>
---
 t/t6300-for-each-ref.sh |  296 +++++++++++++++++++++++++----------------------
 1 files changed, 157 insertions(+), 139 deletions(-)
diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index 1721784..12916b2 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -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
-- 
1.7.8

[PATCH-w 102/105] t5512 (ls-remote): modernize style

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:11

- Guard setup with test_expect_success
- Single-quoted, tab prefaced test blocks of < 80 cols
- Redirect unwanted output

Signed-off-by: Tom Grennan <redacted>
---
 t/t5512-ls-remote.sh |   29 ++++++++++++++++++++---------
 1 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh
index 5c546c9..bbe650f 100755
--- a/t/t5512-ls-remote.sh
+++ b/t/t5512-ls-remote.sh
@@ -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
 '
-- 
1.7.8

[PATCH 3/5] t3200 (branch): modernize style

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:11

- 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

Signed-off-by: Tom Grennan <redacted>
---
 t/t3200-branch.sh |  593 +++++++++++++++++++++++++++--------------------------
 1 files changed, 304 insertions(+), 289 deletions(-)
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index dd1aceb..93c35cd 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -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
 	)
 '
 
-- 
1.7.8

[PATCH-w 103/105] t3200 (branch): modernize style

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:11

- 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

Signed-off-by: Tom Grennan <redacted>
---
 t/t3200-branch.sh |  457 +++++++++++++++++++++++++++--------------------------
 1 files changed, 236 insertions(+), 221 deletions(-)
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index dd1aceb..93c35cd 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -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
 	)
 '
 
-- 
1.7.8

[PATCH-w 104/105] t0040 (parse-options): modernize style

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:11

- Guard setup with test_expect_success
- Single-quoted, tab prefaced test blocks of < 80 cols
- Redirect unwanted output

Signed-off-by: Tom Grennan <redacted>
---
 t/t0040-parse-options.sh |  283 +++++++++++++++++++++-------------------------
 1 files changed, 127 insertions(+), 156 deletions(-)
diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh
index a1e4616..6416d77 100755
--- a/t/t0040-parse-options.sh
+++ b/t/t0040-parse-options.sh
@@ -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
-- 
1.7.8

[PATCH 2/5] t5512 (ls-remote): modernize style

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:11

- Guard setup with test_expect_success
- Single-quoted, tab prefaced test blocks of < 80 cols
- Redirect unwanted output

Signed-off-by: Tom Grennan <redacted>
---
 t/t5512-ls-remote.sh |   33 ++++++++++++++++++++++-----------
 1 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh
index 5c546c9..bbe650f 100755
--- a/t/t5512-ls-remote.sh
+++ b/t/t5512-ls-remote.sh
@@ -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
 '
-- 
1.7.8

[PATCH 4/5] t0040 (parse-options): modernize style

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:11

- Guard setup with test_expect_success
- Single-quoted, tab prefaced test blocks of < 80 cols
- Redirect unwanted output

Signed-off-by: Tom Grennan <redacted>
---
 t/t0040-parse-options.sh |  519 ++++++++++++++++++++++------------------------
 1 files changed, 245 insertions(+), 274 deletions(-)
diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh
index a1e4616..6416d77 100755
--- a/t/t0040-parse-options.sh
+++ b/t/t0040-parse-options.sh
@@ -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
-- 
1.7.8

[PATCH-w 105/105] t7004 (tag): modernize style

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:11

- 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

Signed-off-by: Tom Grennan <redacted>
---
 t/t7004-tag.sh | 1400 ++++++++++++++++++++++++++------------------------------
 1 files changed, 643 insertions(+), 757 deletions(-)
diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index f8c247a..6704046 100755
--- a/t/t7004-tag.sh
+++ b/t/t7004-tag.sh
@@ -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 <committer@example.com> $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 <committer@example.com> $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 committer@example.com -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 committer@example.com -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 author@example.com \
+	silent test_must_fail git tag -u author@example.com \
 		-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
-- 
1.7.8

[PATCH 5/5] t7004 (tag): modernize style

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:11

- 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

Signed-off-by: Tom Grennan <redacted>
---
 t/t7004-tag.sh | 1680 ++++++++++++++++++++++++++------------------------------
 1 files changed, 783 insertions(+), 897 deletions(-)
diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index f8c247a..6704046 100755
--- a/t/t7004-tag.sh
+++ b/t/t7004-tag.sh
@@ -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 <committer@example.com> $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 <committer@example.com> $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 committer@example.com -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 committer@example.com -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 author@example.com \
+	silent test_must_fail git tag -u author@example.com \
 		-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
-- 
1.7.8

Re: [PATCH 1/5] t6300 (for-each-ref): modernize style

From: Johannes Sixt <hidden>
Date: 2016-06-15 22:53:11

Am 3/1/2012 2:45, schrieb Tom Grennan:
+	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

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:11

On Thu, Mar 01, 2012 at 07:53:11AM +0100, Johannes Sixt wrote:
Am 3/1/2012 2:45, schrieb Tom Grennan:
quoted
+	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.)
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

[PATCHv2 0/5] modernize test style

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:12

I [off-list ref] wrote:
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.
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(-)

-- 
1.7.8

[PATCHv2 1/5] t7004 (tag): modernize style

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:12

- 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

Signed-off-by: Tom Grennan <redacted>
---
 t/t7004-tag.sh |  828 ++++++++++++++++++++++++++++++--------------------------
 1 files changed, 447 insertions(+), 381 deletions(-)
diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index f8c247a..f819f41 100755
--- a/t/t7004-tag.sh
+++ b/t/t7004-tag.sh
@@ -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 <committer@example.com> $4 -0700
+	# name, object, type, time
+	cat <<-EOF &&
+		object $2
+		type $3
+		tag $1
+		tagger C O Mitter <committer@example.com> $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 committer@example.com -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
-- 
1.7.8

[PATCHv2 2/5] t5512 (ls-remote): modernize style

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:12

Guard setup with test_expect_success

Signed-off-by: Tom Grennan <redacted>
---
 t/t5512-ls-remote.sh |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh
index 5c546c9..811dcc3 100755
--- a/t/t5512-ls-remote.sh
+++ b/t/t5512-ls-remote.sh
@@ -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
-- 
1.7.8

[PATCHv2-w 105/105] t6300 (for-each-ref): modernize style

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:12

- Guard setup with test_expect_success
- Unwound one loop to stay within the test_expect_success guard

Signed-off-by: Tom Grennan <redacted>
---
 t/t6300-for-each-ref.sh |  118 +++++++++++++++++++++++------------------------
 1 files changed, 58 insertions(+), 60 deletions(-)
diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index 1721784..ebba7d1 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -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
+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
-
-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
@@ -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
+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
-
-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 >expected <<\EOF
+test_expect_success 'Check format "local" date fields output' '
+	'"
+	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 &&
+	"'
+	(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
+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
-
-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 >expected <<\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
-
-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 >expected <<\EOF
+test_expect_success 'Verify ascending sort' '
+	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 >expected <<\EOF
+test_expect_success 'Verify descending sort' '
+	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 >expected <<\EOF
+test_expect_success 'Quoting style: shell' '
+	'"
+	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
 '
@@ -263,52 +265,51 @@ test_expect_success 'Quoting style: python' '
 	test_cmp expected actual
 '
 
-cat >expected <<\EOF
+test_expect_success 'Quoting style: tcl' '
+	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
 '
 
-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 >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
-
-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 >expected <<EOF
+test_expect_success 'Check short upstream format' '
+	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 >expected <<EOF
+test_expect_success 'Check short objectname format' '
+	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
 '
@@ -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
+test_expect_success 'Check ambiguous head and tag refs (strict)' '
+	cat >expected <<-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 &&
 	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
+test_expect_success 'Check ambiguous head and tag refs (loose)' '
+	cat >expected <<-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
 '
 
-cat >expected <<\EOF
+test_expect_success 'Check ambiguous head and tag refs II (loose)' '
+	cat >expected <<-EOF
 heads/ambiguous
 ambiguous
 EOF
-
-test_expect_success 'Check ambiguous head and tag refs II (loose)' '
 	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
-- 
1.7.8

[PATCHv2-w 103/105] t3200 (branch): modernize style

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:12

- Guard setup with test_expect_success
- Single-quoted, tab prefaced test blocks

Signed-off-by: Tom Grennan <redacted>
---
 t/t3200-branch.sh |  211 +++++++++++++++++++++++++++--------------------------
 1 files changed, 109 insertions(+), 102 deletions(-)
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index dd1aceb..7191b89 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -7,15 +7,15 @@ test_description='git branch assorted tests'
 
 . ./test-lib.sh
 
-test_expect_success \
-    'prepare a trivial repository' \
-    'echo Hello > A &&
+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)'
+	HEAD=$(git rev-parse --verify HEAD)
+'
 
 test_expect_success \
     'git branch --help should not have created a bogus branch' '
@@ -34,59 +34,59 @@ 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
+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
-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_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' '
+	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_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 &&
+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'
+	git branch j/k
+'
 
-test_expect_success \
-    'git branch l should work after branch l/m has been deleted' \
-       'git branch l/m &&
+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'
+	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 &&
+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 &&
@@ -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
-
+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 &&
         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 &&
+	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' '
+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 . &&
+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 $(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 &&
      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 &&
      ! 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 &&
      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 &&
      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' '
+	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' '
+	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' '
+	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 &&
+	test_must_fail git branch --track my11 foobar
+'
 
 # Keep this test last, as it changes the current branch
-cat >expect <<EOF
+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
-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_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_cmp expect .git/logs/refs/heads/g/h/i
+'
 
 test_expect_success 'checkout -b makes reflog by default' '
 	git checkout master &&
-- 
1.7.8

[PATCHv2-w 101/105] t7004 (tag): modernize style

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:12

- 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

Signed-off-by: Tom Grennan <redacted>
---
 t/t7004-tag.sh |  590 +++++++++++++++++++++++++++++++-------------------------
 1 files changed, 328 insertions(+), 262 deletions(-)
diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index f8c247a..f819f41 100755
--- a/t/t7004-tag.sh
+++ b/t/t7004-tag.sh
@@ -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 <committer@example.com> $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 committer@example.com -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:
 
-- 
1.7.8

[PATCHv2-w 104/105] t0040 (parse-options): modernize style

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:12

- Guard setup with test_expect_success

Signed-off-by: Tom Grennan <redacted>
---
 t/t0040-parse-options.sh |   96 +++++++++++++++++++--------------------------
 1 files changed, 41 insertions(+), 55 deletions(-)
diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh
index a1e4616..4a0b991 100755
--- a/t/t0040-parse-options.sh
+++ b/t/t0040-parse-options.sh
@@ -7,7 +7,8 @@ test_description='our own option parser'
 
 . ./test-lib.sh
 
-cat > expect << EOF
+test_expect_success 'test help' '
+	cat >expect <<-EOF &&
 usage: test-parse-options <options>
 
     -b, --boolean         get a boolean
@@ -23,7 +24,7 @@ usage: test-parse-options <options>
 
 String options
     -s, --string <string>
-                          get a string
+		''                          get a string
     --string2 <str>       get another string
     --st <st>             get another string (pervert ordering)
     -o <str>              get another string
@@ -44,16 +45,14 @@ Standard options
     -q, --quiet           be quiet
 
 EOF
-
-test_expect_success 'test help' '
+	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
+test_expect_success 'short options' '
+	cat >expect <<-\EOF &&
 boolean: 2
 integer: 1729
 timestamp: 0
@@ -64,15 +63,14 @@ 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
+test_expect_success 'long options' '
+	cat >expect <<-\EOF &&
 boolean: 2
 integer: 1729
 timestamp: 0
@@ -83,8 +81,6 @@ 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 &&
@@ -101,7 +97,8 @@ test_expect_success 'missing required value' '
 	test $? = 129
 '
 
-cat > expect << EOF
+test_expect_success 'intermingled arguments' '
+	cat >expect <<-\EOF &&
 boolean: 1
 integer: 13
 timestamp: 0
@@ -115,15 +112,14 @@ 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
 '
 
-cat > expect << EOF
+test_expect_success 'unambiguously abbreviated option' '
+	cat >expect <<-\EOF &&
 boolean: 0
 integer: 2
 timestamp: 0
@@ -134,8 +130,6 @@ 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
@@ -152,7 +146,8 @@ test_expect_success 'ambiguously abbreviated option' '
 	test $? = 129
 '
 
-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 +158,23 @@ 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 > typo.err << EOF
-error: did you mean \`--boolean\` (with two dashes ?)
-EOF
-
 test_expect_success 'detect possible typos' '
+	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 ! -s output &&
-	test_cmp typo.err output.err
+	test_cmp typo.err output.err &&
+	test_cmp expect output
 '
 
-cat > expect <<EOF
+test_expect_success 'keep some options as arguments' '
+	cat >expect <<-\EOF &&
 boolean: 0
 integer: 0
 timestamp: 0
@@ -192,14 +186,13 @@ 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
+test_expect_success 'OPT_DATE() and OPT_SET_PTR() work' '
+	cat >expect <<-\EOF &&
 boolean: 0
 integer: 0
 timestamp: 1
@@ -211,15 +204,14 @@ 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-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
+test_expect_success 'OPT_CALLBACK() and OPT_BIT() work' '
+	cat >expect <<-\EOF &&
 Callback: "four", 0
 boolean: 5
 integer: 4
@@ -231,24 +223,22 @@ 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
+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
 '
 
-cat > expect <<EOF
+test_expect_success 'OPT_BIT() and OPT_SET_INT() work' '
+	cat >expect <<-\EOF &&
 boolean: 1
 integer: 23
 timestamp: 0
@@ -259,8 +249,6 @@ 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
@@ -272,7 +260,8 @@ test_expect_success 'OPT_NEGBIT() and OPT_SET_INT() work' '
 	test_cmp expect output
 '
 
-cat > expect <<EOF
+test_expect_success 'OPT_BIT() works' '
+	cat >expect <<-\EOF &&
 boolean: 6
 integer: 0
 timestamp: 0
@@ -283,8 +272,6 @@ 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
@@ -302,7 +289,9 @@ test_expect_success 'OPT_BOOLEAN() with PARSE_OPT_NODASH works' '
 	test_cmp expect output
 '
 
-cat > expect <<EOF
+
+test_expect_success 'OPT_NUMBER_CALLBACK() works' '
+	cat >expect <<-\EOF &&
 boolean: 0
 integer: 12345
 timestamp: 0
@@ -313,14 +302,13 @@ 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
+test_expect_success 'negation of OPT_NONEG flags is not ambiguous' '
+	cat >expect <<-\EOF &&
 boolean: 0
 integer: 0
 timestamp: 0
@@ -331,19 +319,17 @@ 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'
+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
 '
-- 
1.7.8

[PATCHv2 3/5] t3200 (branch): modernize style

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:12

- Guard setup with test_expect_success
- Single-quoted, tab prefaced test blocks

Signed-off-by: Tom Grennan <redacted>
---
 t/t3200-branch.sh |  365 +++++++++++++++++++++++++++--------------------------
 1 files changed, 186 insertions(+), 179 deletions(-)
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index dd1aceb..7191b89 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -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 &&
-- 
1.7.8

[PATCHv2 4/5] t0040 (parse-options): modernize style

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:12

- Guard setup with test_expect_success

Signed-off-by: Tom Grennan <redacted>
---
 t/t0040-parse-options.sh |  438 ++++++++++++++++++++++------------------------
 1 files changed, 212 insertions(+), 226 deletions(-)
diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh
index a1e4616..4a0b991 100755
--- a/t/t0040-parse-options.sh
+++ b/t/t0040-parse-options.sh
@@ -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
 '
-- 
1.7.8

[PATCHv2 5/5] t6300 (for-each-ref): modernize style

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:12

- Guard setup with test_expect_success
- Unwound one loop to stay within the test_expect_success guard

Signed-off-by: Tom Grennan <redacted>
---
 t/t6300-for-each-ref.sh |  186 +++++++++++++++++++++++------------------------
 1 files changed, 92 insertions(+), 94 deletions(-)
diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index 1721784..ebba7d1 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -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
 '
-- 
1.7.8

[PATCHv2-w 102/105] t5512 (ls-remote): modernize style

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:12

Guard setup with test_expect_success

Signed-off-by: Tom Grennan <redacted>
---
 t/t5512-ls-remote.sh |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh
index 5c546c9..811dcc3 100755
--- a/t/t5512-ls-remote.sh
+++ b/t/t5512-ls-remote.sh
@@ -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
-- 
1.7.8

Re: [PATCHv2 0/5] modernize test style

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:53:12

Tom Grennan [off-list ref] writes:
  t7004 (tag): modernize style
  t5512 (ls-remote): modernize style
  t3200 (branch): modernize style
  t0040 (parse-options): modernize style
  t6300 (for-each-ref): modernize style
Hmph.

We would want to keep/make the codebase uniformly conform to our style
guide for longer term maintainability (this is not limited to the test
scripts) but at the same time we would strongly want to avoid churning
patches from interfering other patches that are still in flight that do
"real work".

There are only two appropriate occasions for file-wide clean-up patches
like these:

 (1) The file has not been touched for quite some time, and it is not
     expected to be touched for some time to come; or

 (2) You are going to do extensive work on the file for reasons other than
     clean-up, and nobody else is working or expected to work in the same
     area for some time to come (in other words, you _own_ the file), and
     your real work will be easier to review if it is done _after_ such a
     clean-up patch.

Let's see how active these five files are:

$ git diff --stat v1.7.9..pu --  t/t{7004,5512,3200,0040,6300}-*.sh
 t/t0040-parse-options.sh |   60 ++++++++++++++++++++++-
 t/t3200-branch.sh        |  122 ++++++++++++++++++++++++++++++++++++++++++++--
 t/t7004-tag.sh           |   96 ++++++++++++++++++++++++++++++++++++
 3 files changed, 272 insertions(+), 6 deletions(-)

Given this, I do not want to take three of your 5 patches that touch these
files at this point.  Please hold onto them and wait until topics that
touch these test scripts graduate to 'master', and then wait a bit more
until some time passes without anybody touching them, before redoing the
clean-up patches.

On the other hand, we can see that 5512 has been dormant for quite a
while.  Note that the latter diff is against 3 cycles ago:

$ git diff --stat v1.7.6..pu --  t/t{7004,5512,3200,0040,6300}-*.sh
 t/t0040-parse-options.sh |   79 +++++++++++++++-
 t/t3200-branch.sh        |  236 +++++++++++++++++++++++++++++++++++++++++-----
 t/t6300-for-each-ref.sh  |  101 +++++++++++++++++++-
 t/t7004-tag.sh           |  128 +++++++++++++++++++------
 4 files changed, 490 insertions(+), 54 deletions(-)

so 5512 and possibly 6300 may be worth reviewing.

Thanks.

Re: [PATCHv2 2/5] t5512 (ls-remote): modernize style

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:53:12

Tom Grennan [off-list ref] writes:
 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
+	"'
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 ...
	...
        EOF

No need to resend; I'll fix it up locally.        

Thanks.

Re: [PATCHv2 2/5] t5512 (ls-remote): modernize style

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:12

On Sat, Mar 03, 2012 at 12:05:05AM -0800, Junio C Hamano wrote:
Tom Grennan [off-list ref] writes:
quoted
 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
+	"'
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 ...
...
       EOF

No 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

Re: [PATCHv2 0/5] modernize test style

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:12

On Sat, Mar 03, 2012 at 12:04:54AM -0800, Junio C Hamano wrote:
On the other hand, we can see that 5512 has been dormant for quite a
while.  Note that the latter diff is against 3 cycles ago:

$ git diff --stat v1.7.6..pu --  t/t{7004,5512,3200,0040,6300}-*.sh
t/t0040-parse-options.sh |   79 +++++++++++++++-
t/t3200-branch.sh        |  236 +++++++++++++++++++++++++++++++++++++++++-----
t/t6300-for-each-ref.sh  |  101 +++++++++++++++++++-
t/t7004-tag.sh           |  128 +++++++++++++++++++------
4 files changed, 490 insertions(+), 54 deletions(-)

so 5512 and possibly 6300 may be worth reviewing.
Ack, I'll hold the others until each are quiescent for a few cycles.

Thanks.
TomG

Re: [PATCHv2 1/5] t7004 (tag): modernize style

From: Johannes Sixt <hidden>
Date: 2016-06-15 22:53:12

Am 03.03.2012 03:15, schrieb Tom Grennan:
-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.
 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

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".
 	git tag -s -F sigmsgfile file-signed-tag &&
 	get_tag_msg file-signed-tag >actual &&
 	test_cmp expect actual
 '
-- Hannes
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help