Git development
 help / color / mirror / Atom feed
* [PATCH v3 03/31] Add parse_pathspec() that converts cmdline args to struct pathspec
From: Nguyễn Thái Ngọc Duy @ 2013-01-13 12:35 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Nguyễn Thái Ngọc Duy
In-Reply-To: <1358080539-17436-1-git-send-email-pclouds@gmail.com>

Currently to fill a struct pathspec, we do:

   const char **paths;
   paths = get_pathspec(prefix, argv);
   ...
   init_pathspec(&pathspec, paths);

"paths" can only carry bare strings, which loses information from
command line arguments such as pathspec magic or the prefix part's
length for each argument.

parse_pathspec() is introduced to combine the two calls into one. The
plan is gradually replace all get_pathspec() and init_pathspec() with
parse_pathspec(). get_pathspec() now becomes a thin wrapper of
parse_pathspec().

parse_pathspec() allows the caller to reject the pathspec magics that
it does not support. When a new pathspec magic is introduced, we can
enable it per command after making sure that all underlying code has no
problem with the new magic.

"flags" parameter is currently unused. But it would allow callers to
pass certain instructions to parse_pathspec, for example forcing
literal pathspec when no magic is used.

With the introduction of parse_pathspec, there are now two functions
that can initialize struct pathspec: init_pathspec and
parse_pathspec. Any semantic changes in struct pathspec must be
reflected in both functions. init_pathspec() will be phased out in
favor of parse_pathspec().

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h |   2 ++
 dir.c   |   4 +--
 dir.h   |   2 ++
 setup.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++---------------
 4 files changed, 90 insertions(+), 26 deletions(-)

diff --git a/cache.h b/cache.h
index 72675a1..759c62a 100644
--- a/cache.h
+++ b/cache.h
@@ -481,9 +481,11 @@ struct pathspec {
 	int nr;
 	unsigned int has_wildcard:1;
 	unsigned int recursive:1;
+	unsigned magic;
 	int max_depth;
 	struct pathspec_item {
 		const char *match;
+		unsigned magic;
 		int len;
 		int nowildcard_len;
 		int flags;
diff --git a/dir.c b/dir.c
index 12a76d7..8454c13 100644
--- a/dir.c
+++ b/dir.c
@@ -323,7 +323,7 @@ int match_pathspec_depth(const struct pathspec *ps,
 /*
  * Return the length of the "simple" part of a path match limiter.
  */
-static int simple_length(const char *match)
+int simple_length(const char *match)
 {
 	int len = -1;
 
@@ -335,7 +335,7 @@ static int simple_length(const char *match)
 	}
 }
 
-static int no_wildcard(const char *string)
+int no_wildcard(const char *string)
 {
 	return string[simple_length(string)] == '\0';
 }
diff --git a/dir.h b/dir.h
index ae1bc46..0cf5ccf 100644
--- a/dir.h
+++ b/dir.h
@@ -88,6 +88,8 @@ struct dir_struct {
 #define MATCHED_RECURSIVELY 1
 #define MATCHED_FNMATCH 2
 #define MATCHED_EXACTLY 3
+extern int simple_length(const char *match);
+extern int no_wildcard(const char *string);
 extern char *common_prefix(const char **pathspec);
 extern int match_pathspec(const char **pathspec, const char *name, int namelen, int prefix, char *seen);
 extern int match_pathspec_depth(const struct pathspec *pathspec,
diff --git a/setup.c b/setup.c
index f108c4b..92adefc 100644
--- a/setup.c
+++ b/setup.c
@@ -174,7 +174,7 @@ static struct pathspec_magic {
 
 /*
  * Take an element of a pathspec and check for magic signatures.
- * Append the result to the prefix.
+ * Append the result to the prefix. Return the magic bitmap.
  *
  * For now, we only parse the syntax and throw out anything other than
  * "top" magic.
@@ -185,10 +185,14 @@ static struct pathspec_magic {
  * the prefix part must always match literally, and a single stupid
  * string cannot express such a case.
  */
-static const char *prefix_pathspec(const char *prefix, int prefixlen, const char *elt)
+static unsigned prefix_pathspec(struct pathspec_item *item,
+				const char **raw, unsigned flags,
+				const char *prefix, int prefixlen,
+				const char *elt)
 {
 	unsigned magic = 0;
 	const char *copyfrom = elt;
+	char *match;
 	int i;
 
 	if (elt[0] != ':') {
@@ -241,39 +245,95 @@ static const char *prefix_pathspec(const char *prefix, int prefixlen, const char
 	}
 
 	if (magic & PATHSPEC_FROMTOP)
-		return xstrdup(copyfrom);
+		match = xstrdup(copyfrom);
 	else
-		return prefix_path(prefix, prefixlen, copyfrom);
+		match = prefix_path(prefix, prefixlen, copyfrom);
+	*raw = item->match = match;
+	item->len = strlen(item->match);
+	item->flags = 0;
+	if (limit_pathspec_to_literal())
+		item->nowildcard_len = item->len;
+	else
+		item->nowildcard_len = simple_length(item->match);
+	if (item->nowildcard_len < item->len &&
+	    item->match[item->nowildcard_len] == '*' &&
+	    no_wildcard(item->match + item->nowildcard_len + 1))
+		item->flags |= PATHSPEC_ONESTAR;
+	return magic;
 }
 
-const char **get_pathspec(const char *prefix, const char **pathspec)
+static int pathspec_item_cmp(const void *a_, const void *b_)
 {
-	const char *entry = *pathspec;
-	const char **src, **dst;
-	int prefixlen;
+	struct pathspec_item *a, *b;
 
-	if (!prefix && !entry)
-		return NULL;
+	a = (struct pathspec_item *)a_;
+	b = (struct pathspec_item *)b_;
+	return strcmp(a->match, b->match);
+}
+
+/*
+ * Given command line arguments and a prefix, convert the input to
+ * pathspec. die() if any magic other than ones in magic_mask.
+ */
+static void parse_pathspec(struct pathspec *pathspec,
+			   unsigned magic_mask, unsigned flags,
+			   const char *prefix, const char **argv)
+{
+	struct pathspec_item *item;
+	const char *entry = *argv;
+	int i, n, prefixlen;
+
+	memset(pathspec, 0, sizeof(*pathspec));
+
+	/* No arguments, no prefix -> no pathspec */
+	if (!entry && !prefix)
+		return;
 
+	/* No arguments with prefix -> prefix pathspec */
 	if (!entry) {
-		static const char *spec[2];
-		spec[0] = prefix;
-		spec[1] = NULL;
-		return spec;
+		static const char *raw[2];
+
+		pathspec->items = item = xmalloc(sizeof(*item));
+		item->match = prefix;
+		item->nowildcard_len = item->len = strlen(prefix);
+		raw[0] = prefix;
+		raw[1] = NULL;
+		pathspec->nr = 1;
+		pathspec->raw = raw;
+		return;
 	}
 
-	/* Otherwise we have to re-write the entries.. */
-	src = pathspec;
-	dst = pathspec;
+	n = 0;
+	while (argv[n])
+		n++;
+
+	pathspec->nr = n;
+	pathspec->items = item = xmalloc(sizeof(*item) * n);
+	pathspec->raw = argv;
 	prefixlen = prefix ? strlen(prefix) : 0;
-	while (*src) {
-		*(dst++) = prefix_pathspec(prefix, prefixlen, *src);
-		src++;
+
+	for (i = 0; i < n; i++) {
+		const char *arg = argv[i];
+
+		item[i].magic = prefix_pathspec(item + i, argv + i, flags,
+						prefix, prefixlen, arg);
+		if (item[i].magic & ~magic_mask)
+			die(_("pathspec magic in '%s' is not supported"
+			      " by this command"), arg);
+		if (item[i].nowildcard_len < item[i].len)
+			pathspec->has_wildcard = 1;
+		pathspec->magic |= item[i].magic;
 	}
-	*dst = NULL;
-	if (!*pathspec)
-		return NULL;
-	return pathspec;
+
+	qsort(pathspec->items, pathspec->nr,
+	      sizeof(struct pathspec_item), pathspec_item_cmp);
+}
+
+const char **get_pathspec(const char *prefix, const char **pathspec)
+{
+	struct pathspec ps;
+	parse_pathspec(&ps, PATHSPEC_FROMTOP, 0, prefix, pathspec);
+	return ps.raw;
 }
 
 /*
-- 
1.8.0.rc2.23.g1fb49df

^ permalink raw reply related

* [PATCH v3 02/31] Add copy_pathspec
From: Nguyễn Thái Ngọc Duy @ 2013-01-13 12:35 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Nguyễn Thái Ngọc Duy
In-Reply-To: <1358080539-17436-1-git-send-email-pclouds@gmail.com>


Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/mv.c | 13 +++++++------
 cache.h      |  1 +
 dir.c        |  8 ++++++++
 3 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/builtin/mv.c b/builtin/mv.c
index 034fec9..16ce99b 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -15,8 +15,9 @@ static const char * const builtin_mv_usage[] = {
 	NULL
 };
 
-static const char **copy_pathspec(const char *prefix, const char **pathspec,
-				  int count, int base_name)
+static const char **internal_copy_pathspec(const char *prefix,
+					   const char **pathspec,
+					   int count, int base_name)
 {
 	int i;
 	const char **result = xmalloc((count + 1) * sizeof(const char *));
@@ -81,17 +82,17 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
 	if (read_cache() < 0)
 		die(_("index file corrupt"));
 
-	source = copy_pathspec(prefix, argv, argc, 0);
+	source = internal_copy_pathspec(prefix, argv, argc, 0);
 	modes = xcalloc(argc, sizeof(enum update_mode));
-	dest_path = copy_pathspec(prefix, argv + argc, 1, 0);
+	dest_path = internal_copy_pathspec(prefix, argv + argc, 1, 0);
 
 	if (dest_path[0][0] == '\0')
 		/* special case: "." was normalized to "" */
-		destination = copy_pathspec(dest_path[0], argv, argc, 1);
+		destination = internal_copy_pathspec(dest_path[0], argv, argc, 1);
 	else if (!lstat(dest_path[0], &st) &&
 			S_ISDIR(st.st_mode)) {
 		dest_path[0] = add_slash(dest_path[0]);
-		destination = copy_pathspec(dest_path[0], argv, argc, 1);
+		destination = internal_copy_pathspec(dest_path[0], argv, argc, 1);
 	} else {
 		if (argc != 1)
 			die("destination '%s' is not a directory", dest_path[0]);
diff --git a/cache.h b/cache.h
index c257953..72675a1 100644
--- a/cache.h
+++ b/cache.h
@@ -491,6 +491,7 @@ struct pathspec {
 };
 
 extern int init_pathspec(struct pathspec *, const char **);
+extern void copy_pathspec(struct pathspec *dst, const struct pathspec *src);
 extern void free_pathspec(struct pathspec *);
 extern int ce_path_match(const struct cache_entry *ce, const struct pathspec *pathspec);
 
diff --git a/dir.c b/dir.c
index e883a91..12a76d7 100644
--- a/dir.c
+++ b/dir.c
@@ -1559,6 +1559,14 @@ int init_pathspec(struct pathspec *pathspec, const char **paths)
 	return 0;
 }
 
+void copy_pathspec(struct pathspec *dst, const struct pathspec *src)
+{
+	*dst = *src;
+	dst->items = xmalloc(sizeof(struct pathspec_item) * dst->nr);
+	memcpy(dst->items, src->items,
+	       sizeof(struct pathspec_item) * dst->nr);
+}
+
 void free_pathspec(struct pathspec *pathspec)
 {
 	free(pathspec->items);
-- 
1.8.0.rc2.23.g1fb49df

^ permalink raw reply related

* [PATCH v3 01/31] clean: remove unused variable "seen"
From: Nguyễn Thái Ngọc Duy @ 2013-01-13 12:35 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Nguyễn Thái Ngọc Duy
In-Reply-To: <1358080539-17436-1-git-send-email-pclouds@gmail.com>


Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/clean.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/builtin/clean.c b/builtin/clean.c
index 69c1cda..4cdabe0 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -46,7 +46,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
 	struct strbuf buf = STRBUF_INIT;
 	struct string_list exclude_list = STRING_LIST_INIT_NODUP;
 	const char *qname;
-	char *seen = NULL;
 	struct option options[] = {
 		OPT__QUIET(&quiet, N_("do not print names of files removed")),
 		OPT__DRY_RUN(&show_only, N_("dry run")),
@@ -105,9 +104,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
 
 	fill_directory(&dir, pathspec);
 
-	if (pathspec)
-		seen = xmalloc(argc > 0 ? argc : 1);
-
 	for (i = 0; i < dir.nr; i++) {
 		struct dir_entry *ent = dir.entries[i];
 		int len, pos;
@@ -141,11 +137,9 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
 		if (lstat(ent->name, &st))
 			continue;
 
-		if (pathspec) {
-			memset(seen, 0, argc > 0 ? argc : 1);
+		if (pathspec)
 			matches = match_pathspec(pathspec, ent->name, len,
-						 0, seen);
-		}
+						 0, NULL);
 
 		if (S_ISDIR(st.st_mode)) {
 			strbuf_addstr(&directory, ent->name);
@@ -184,7 +178,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
 			}
 		}
 	}
-	free(seen);
 
 	strbuf_release(&directory);
 	string_list_clear(&exclude_list, 0);
-- 
1.8.0.rc2.23.g1fb49df

^ permalink raw reply related

* [PATCH v3 00/31] nd/parse-pathspec
From: Nguyễn Thái Ngọc Duy @ 2013-01-13 12:35 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Nguyễn Thái Ngọc Duy

Changes from v2 (it's hard to keep track of after the rebase, so I may
be missing something here):

 - rebased on top of recent master, incorporate changes in
   init_pathspec from jk/pathspec-literal and nd/pathspec-wildcard to
   parse_pathspec

 - kill strip_trailing_slash_from_submodules and treat_gitlinks
   (pretty sure it'll cause conflicts with as/check-ignore)

 - kill init_pathspec, match_pathspec, diff_tree_setup_paths and
   diff_tree_release_paths
 
 - check points for future pathspec development

As far as I understand the "pathspec unification", I'd say we are
there, with a few exceptions like "mv", external commands.. But those
are pretty much isolated.

I'll send another WIP series implementing :(icase) and :(glob), mainly
to show (me) how future pathspec feature development looks like after
this.

Nguyễn Thái Ngọc Duy (31):
  clean: remove unused variable "seen"
  Add copy_pathspec
  Add parse_pathspec() that converts cmdline args to struct pathspec
  parse_pathspec: save original pathspec for reporting
  Export parse_pathspec() and convert some get_pathspec() calls
  Guard against new pathspec magic in pathspec matching code
  clean: convert to use parse_pathspec
  parse_pathspec: add PATHSPEC_EMPTY_MATCH_ALL
  commit: convert to use parse_pathspec
  status: convert to use parse_pathspec
  rerere: convert to use parse_pathspec
  checkout: convert to use parse_pathspec
  rm: convert to use parse_pathspec
  parse_pathspec: support stripping submodule trailing slashes
  ls-files: convert to use parse_pathspec
  archive: convert to use parse_pathspec
  parse_pathspec: support stripping/checking submodule paths
  add: convert to use parse_pathspec
  Convert read_cache_preload() to take struct pathspec
  Convert unmerge_cache to take struct pathspec
  checkout: convert read_tree_some to take struct pathspec
  Convert report_path_error to take struct pathspec
  Convert refresh_index to take struct pathspec
  Convert {read,fill}_directory to take struct pathspec
  Convert add_files_to_cache to take struct pathspec
  Convert common_prefix() to use struct pathspec
  Remove diff_tree_{setup,release}_paths
  Remove init_pathspec() in favor of parse_pathspec()
  Remove match_pathspec() in favor of match_pathspec_depth()
  tree-diff: remove the use of pathspec's raw[] in follow-rename codepath
  Rename field "raw" to "_raw" in struct pathspec

 archive.c              |  18 +++--
 archive.h              |   2 +-
 builtin/add.c          | 155 +++++++++++++++----------------------
 builtin/blame.c        |  12 +--
 builtin/checkout.c     |  44 ++++++-----
 builtin/clean.c        |  21 ++---
 builtin/commit.c       |  37 +++++----
 builtin/diff-files.c   |   2 +-
 builtin/diff-index.c   |   2 +-
 builtin/diff.c         |   6 +-
 builtin/grep.c         |   6 +-
 builtin/log.c          |   2 +-
 builtin/ls-files.c     |  72 +++++++-----------
 builtin/ls-tree.c      |  10 ++-
 builtin/mv.c           |  13 ++--
 builtin/rerere.c       |   6 +-
 builtin/reset.c        |   4 +-
 builtin/rm.c           |  23 +++---
 builtin/update-index.c |   3 +-
 cache.h                |  36 +++++++--
 diff-lib.c             |   2 +-
 diff.h                 |   2 -
 dir.c                  | 202 ++++++++-----------------------------------------
 dir.h                  |   9 ++-
 merge-recursive.c      |   2 +-
 notes-merge.c          |   4 +-
 preload-index.c        |  20 ++---
 read-cache.c           |   5 +-
 rerere.c               |   6 +-
 rerere.h               |   4 +-
 resolve-undo.c         |   4 +-
 resolve-undo.h         |   2 +-
 revision.c             |  11 +--
 setup.c                | 149 ++++++++++++++++++++++++++++++------
 tree-diff.c            |  47 +++++++-----
 tree-walk.c            |   2 +
 tree.c                 |   4 +-
 tree.h                 |   2 +-
 wt-status.c            |  17 ++---
 wt-status.h            |   2 +-
 40 files changed, 460 insertions(+), 510 deletions(-)

-- 
1.8.0.rc2.23.g1fb49df

^ permalink raw reply

* Re: [PATCH 0/8] Initial support for Python 3
From: John Keeping @ 2013-01-13 12:34 UTC (permalink / raw)
  To: Pete Wyckoff
  Cc: git, Eric S. Raymond, Felipe Contreras, Sverre Rabbelier,
	Sebastian Morr
In-Reply-To: <20130113004129.GH4574@serenity.lan>

On Sun, Jan 13, 2013 at 12:41:30AM +0000, John Keeping wrote:
> On Sat, Jan 12, 2013 at 06:43:04PM -0500, Pete Wyckoff wrote:
>> Can you give me some hints about the byte/unicode string issues
>> in git-p4.py?  There's really only one place that does:
>> 
>>     p4 = subprocess.Popen("p4 -G ...")
>>     marshal.load(p4.stdout)
>> 
>> If that's the only issue, this might not be too paniful.
> 
> The problem is that what gets loaded there is a dictionary (encoded by
> p4) that maps byte strings to byte strings, so all of the accesses to
> that dictionary need to either:
> 
>    1) explicitly call encode() on a string constant
> or 2) use a byte string constant with a "b" prefix
> 
> Or we could re-write the dictionary once, which handles the keys... but
> some of the values are also used as strings and we can't handle that as
> a one-off conversion since in other places we really do want the byte
> string (think content of binary files).
> 
> Basically a thorough audit of all access to variables that come from p4
> would be needed, with explicit decode()s for authors, dates, etc.

Having thought about this a bit more, another possibility would be to
apply this transformation once using something like this (completely
untested, I haven't looked up the keys of interest):

-- >8 --

def _noop(s):
    return s

def _decode(s):
    return s.decode('utf-8')

CONVERSION_MAP = {
    'user': _decode,
    'data': _decode
}

d = marshal.load(p4.stdout)
retval = {}
for k, v in d.items():
    key = k.decode('utf-8')
    retval[key] = CONVERSION_MAP.get(key, _noop)(v)
return retval

-- 8< --

Obviously this isn't ideal but without p4 gaining a Python 3 output mode
I suspect this would be the best we could do.


John

^ permalink raw reply

* Re: missing objects -- prevention
From: Jeff King @ 2013-01-13 12:30 UTC (permalink / raw)
  To: Sitaram Chamarty; +Cc: Git Mailing List
In-Reply-To: <CAMK1S_iKARYqi_Dv90og0No7NN=WxFg+ixmRvnkvfdrcOi1r=Q@mail.gmail.com>

On Sun, Jan 13, 2013 at 06:26:53AM +0530, Sitaram Chamarty wrote:

> > Right, I meant if you have receive.fsckObjects on. It won't help this
> > situation at all, as we already do a connectivity check separate from
> > the fsck. But I do recommend it in general, just because it helps catch
> > bad objects before they gets disseminated to a wider audience (at which
> > point it is often infeasible to rewind history). And it has found git
> > bugs (e.g., null sha1s in tree entries).
> 
> I will add this.  Any idea if there's a significant performance hit?

Not usually; we are already resolving all of the sent deltas as a
precaution, anyway. I do notice after a push to GitHub there is
sometimes a second or two of pause from the server before the push
status is shown. But I haven't narrowed it down to fsck (versus
connectivity check, versus our post-receive hook).

So you may want to keep an eye on the effects (and if you have numbers,
please share :) ).

> That's always the hard part.  System admins (at the Unix level) insist
> there's nothing wrong and no disk errors and so on...  that is why I
> was interested in network errors causing problems and so on.

Yeah, I feel bad saying "well, this repo is totally corrupted, but it
couldn't possibly be git's fault, because that's not what its failure
modes look like". But luckily our Ops people are very understanding, and
most of the problems I have seen have turned out to be fs corruption
after all (the pack-refs things is the big exception).

> Thanks once again for your patient replies!

No problem. There aren't many people dealing with large-scale
server-side issues, so it's something that doesn't come up much on the
list. I'm happy to talk about it.

-Peff

^ permalink raw reply

* git list files
From: Стойчо Слепцов @ 2013-01-13 12:05 UTC (permalink / raw)
  To: git

Hi,

I was searching for some git- command to provide me a list of files
(in a git directory), same as ls,
but showing information from the last commit of the file instead.

lets, say the equivalent of the $ls -d b* within git.git root directory
would look like:

----------------
98746061 jrnieder 2010-08-12 17:11 Standardize-do-.-while-0-style   base85.c
c43cb386 pclouds  2012-10-26 22:53 Move-estimate_bisect_steps-to-li bisect.c
efc7df45 pclouds  2012-10-26 22:53 Move-print_commit_list-to-libgit bisect.h
837d395a barkalow 2010-01-18 13:06 Replace-parse_blob-with-an-expla blob.c
837d395a barkalow 2010-01-18 13:06 Replace-parse_blob-with-an-expla blob.h
ebcfa444 gitster  2012-07-23 20:56 Merge-branch-jn-block-sha1       block-sha1
d53a3503 pclouds  2012-06-07 19:05 Remove-i18n-legos-in-notifying-n branch.c
f9a482e6 peff     2012-03-26 19:51 checkout-suppress-tracking-messa branch.h
c566ea13 gitster  2013-01-11 18:34 Merge-branch-jc-merge-blobs      builtin
cf6c52fc gitster  2013-01-10 13:46 Merge-branch-jc-maint-fmt-merge- builtin.h
568508e7 gitster  2011-10-28 14:48 bulk-checkin-replace-fast-import
bulk-checkin.c
568508e7 gitster  2011-10-28 14:48 bulk-checkin-replace-fast-import
bulk-checkin.h
8c3710fd gitster  2012-06-04 11:51 tweak-bundle-verify-of-a-complet bundle.c
b76c561a gitster  2011-10-21 16:04 Merge-branch-jc-unseekable-bundl bundle.h
----------------

(pretty the same idea as what we see in github when reviewing a
repository under the "Files" tab.)

Unfortunately I couldn't find any suitable.

As suggested at http://git-scm.com/community I asked my question at
the "Git user mailing list on Google Groups which is a nice place for
beginners to ask about anything",
and one of the valuable answers was:

"Also I wouldn't hesitate to ask this question on the main Git list as
this question appears to be hard-core enough to warrant assisting of
someone knowledgeable about Git internals."

So here I am...

So is there such a command, or I have to build my own script, starting
from, lets say git-rev-list in addition with some diff?

At the beginning I was hoping that $git rev-list HEAD --no-walk
--all-match -- <paths> + some git status --porcelain could do the job
for me,
but seems git rev-list, same as git log stops at the first found
matching commit, without to take care that there are still more files
unsatisfied in the list...

isn't it supposed to satisfy all the files in the list when
--all-match -- <paths> are given?

Thank you in advance,
Blind.

^ permalink raw reply

* Re: [PATCH] tests: turn on test-lint-shell-syntax by default
From: Torsten Bögershausen @ 2013-01-13 10:25 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Torsten Bögershausen, git
In-Reply-To: <7vvcb37xfe.fsf@alter.siamese.dyndns.org>

On 12.01.13 07:00, Junio C Hamano wrote:
> Torsten Bögershausen <tboegi@web.de> writes:
> 
>> The test Makefile has a default set of lint tests which are run
>> as part of "make test".
>>
>> The macro TEST_LINT defaults to "test-lint-duplicates test-lint-executable".
>>
>> Add test-lint-shell-syntax here, to detect non-portable shell syntax early.
>>
>> Signed-off-by: Torsten Bögershausen <tboegi@web.de>
>> ---
> 
> As I said already, I do not want to do this yet without further
> reduction of false positives.
Which reinds me that the expression fishing for "which" is really poor.

How about something like the following:

-- >8 --
Subject: [PATCH] Reduce false positive in check-non-portable-shell.pl

check-non-portable-shell.pl is using simple regular expressions to
find illegal shell syntax.
Improve the expressions and reduce the chance for false positves:

"sed -i" must be followed by 1..n whitespace and 1 non whitespace
"declare" must be followed by 1..n whitespace and 1 non whitespace
"echo -n" must be followed by 1..n whitespace and 1 non whitespace
"which" must be followed by 1..n whitespace, a string, "end of line"



diff --git a/t/check-non-portable-shell.pl b/t/check-non-portable-shell.pl
index 8b5a71d..7151dd6 100755
--- a/t/check-non-portable-shell.pl
+++ b/t/check-non-portable-shell.pl
@@ -16,10 +16,10 @@ sub err {
 
 while (<>) {
 	chomp;
-	/^\s*sed\s+-i/ and err 'sed -i is not portable';
-	/^\s*echo\s+-n/ and err 'echo -n is not portable (please use printf)';
-	/^\s*declare\s+/ and err 'arrays/declare not portable';
-	/^\s*[^#]\s*which\s/ and err 'which is not portable (please use type)';
+	/^\s*sed\s+-i\s+\S/ and err 'sed -i is not portable';
+	/^\s*echo\s+-n\s+\S/ and err 'echo -n is not portable (please use printf)';
+	/^\s*declare\s+\S/ and err 'arrays/declare not portable';
+	/^\s*[^#]\s*which\s+[-a-zA-Z0-9]+$/ and err 'which is not portable (please use type)';
 	/test\s+[^=]*==/ and err '"test a == b" is not portable (please use =)';
 	# this resets our $. for each file
 	close ARGV if eof;

^ permalink raw reply related

* [PATCH v2 3/3] Add sample pre-push hook script
From: Aaron Schrab @ 2013-01-13  5:17 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano
In-Reply-To: <1356735452-21667-1-git-send-email-aaron@schrab.com>

Create a sample of a script for a pre-push hook.  The main purpose is to
illustrate how a script may parse the information which is supplied to
such a hook.  The script may also be useful to some people as-is for
avoiding to push commits which are marked as a work in progress.

Signed-off-by: Aaron Schrab <aaron@schrab.com>
---
 templates/hooks--pre-push.sample | 53 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 templates/hooks--pre-push.sample

diff --git a/templates/hooks--pre-push.sample b/templates/hooks--pre-push.sample
new file mode 100644
index 0000000..15ab6d8
--- /dev/null
+++ b/templates/hooks--pre-push.sample
@@ -0,0 +1,53 @@
+#!/bin/sh
+
+# An example hook script to verify what is about to be pushed.  Called by "git
+# push" after it has checked the remote status, but before anything has been
+# pushed.  If this script exits with a non-zero status nothing will be pushed.
+#
+# This hook is called with the following parameters:
+#
+# $1 -- Name of the remote to which the push is being done
+# $2 -- URL to which the push is being done
+#
+# If pushing without using a named remote those arguments will be equal.
+#
+# Information about the commits which are being pushed is supplied as lines to
+# the standard input in the form:
+#
+#   <local ref> <local sha1> <remote ref> <remote sha1>
+#
+# This sample shows how to prevent push of commits where the log message starts
+# with "WIP" (work in progress).
+
+remote="$1"
+url="$2"
+
+z40=0000000000000000000000000000000000000000
+
+IFS=' '
+while read local_ref local_sha remote_ref remote_sha
+do
+	if [ "$local_sha" = $z40 ]
+	then
+		# Handle delete
+	else
+		if [ "$remote_sha" = $z40 ]
+		then
+			# New branch, examine all commits
+			range="$local_sha"
+		else
+			# Update to existing branch, examine new commits
+			range="$remote_sha..$local_sha"
+		fi
+
+		# Check for WIP commit
+		commit=`git rev-list -n 1 --grep '^WIP' "$range"`
+		if [ -n "$commit" ]
+		then
+			echo "Found WIP commit in $local_ref, not pushing"
+			exit 1
+		fi
+	fi
+done
+
+exit 0
-- 
1.8.1.340.g425b78d

^ permalink raw reply related

* [PATCH v2 2/3] push: Add support for pre-push hooks
From: Aaron Schrab @ 2013-01-13  5:17 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano
In-Reply-To: <1356735452-21667-1-git-send-email-aaron@schrab.com>

Add support for a pre-push hook which can be used to determine if the
set of refs to be pushed is suitable for the target repository.  The
hook is run with two arguments specifying the name and location of the
destination repository.

Information about what is to be pushed is provided by sending lines of
the following form to the hook's standard input:

  <local ref> SP <local sha1> SP <remote ref> SP <remote sha1> LF

If the hook exits with a non-zero status, the push will be aborted.

This will allow the script to determine if the push is acceptable based
on the target repository and branch(es), the commits which are to be
pushed, and even the source branches in some cases.

Signed-off-by: Aaron Schrab <aaron@schrab.com>
---
 Documentation/githooks.txt |  29 ++++++++++
 builtin/push.c             |   1 +
 t/t5571-pre-push-hook.sh   | 129 +++++++++++++++++++++++++++++++++++++++++++++
 transport.c                |  60 +++++++++++++++++++++
 transport.h                |   1 +
 5 files changed, 220 insertions(+)
 create mode 100755 t/t5571-pre-push-hook.sh

diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt
index b9003fe..d839233 100644
--- a/Documentation/githooks.txt
+++ b/Documentation/githooks.txt
@@ -176,6 +176,35 @@ save and restore any form of metadata associated with the working tree
 (eg: permissions/ownership, ACLS, etc).  See contrib/hooks/setgitperms.perl
 for an example of how to do this.
 
+pre-push
+~~~~~~~~
+
+This hook is called by 'git push' and can be used to prevent a push from taking
+place.  The hook is called with two parameters which provide the name and
+location of the destination remote, if a named remote is not being used both
+values will be the same.
+
+Information about what is to be pushed is provided on the hook's standard
+input with lines of the form:
+
+  <local ref> SP <local sha1> SP <remote ref> SP <remote sha1> LF
+
+For instance, if the command +git push origin master:foreign+ were run the
+hook would receive a line like the following:
+
+  refs/heads/master 67890 refs/heads/foreign 12345
+
+although the full, 40-character SHA1s would be supplied.  If the foreign ref
+does not yet exist the `<remote SHA1>` will be 40 `0`.  If a ref is to be
+deleted, the `<local ref>` will be supplied as `(delete)` and the `<local
+SHA1>` will be 40 `0`.  If the local commit was specified by something other
+than a name which could be expanded (such as `HEAD~`, or a SHA1) it will be
+supplied as it was originally given.
+
+If this hook exits with a non-zero status, 'git push' will abort without
+pushing anything.  Information about why the push is rejected may be sent
+to the user by writing to standard error.
+
 [[pre-receive]]
 pre-receive
 ~~~~~~~~~~~
diff --git a/builtin/push.c b/builtin/push.c
index 8491e43..b158028 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -407,6 +407,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
 		OPT_BOOL(0, "progress", &progress, N_("force progress reporting")),
 		OPT_BIT(0, "prune", &flags, N_("prune locally removed refs"),
 			TRANSPORT_PUSH_PRUNE),
+		OPT_BIT(0, "no-verify", &flags, N_("bypass pre-push hook"), TRANSPORT_PUSH_NO_HOOK),
 		OPT_END()
 	};
 
diff --git a/t/t5571-pre-push-hook.sh b/t/t5571-pre-push-hook.sh
new file mode 100755
index 0000000..d68fed7
--- /dev/null
+++ b/t/t5571-pre-push-hook.sh
@@ -0,0 +1,129 @@
+#!/bin/sh
+
+test_description='check pre-push hooks'
+. ./test-lib.sh
+
+# Setup hook that always succeeds
+HOOKDIR="$(git rev-parse --git-dir)/hooks"
+HOOK="$HOOKDIR/pre-push"
+mkdir -p "$HOOKDIR"
+write_script "$HOOK" <<EOF
+exit 0
+EOF
+
+test_expect_success 'setup' '
+	git config push.default upstream &&
+	git init --bare repo1 &&
+	git remote add parent1 repo1 &&
+	test_commit one &&
+	git push parent1 HEAD:foreign
+'
+write_script "$HOOK" <<EOF
+exit 1
+EOF
+
+COMMIT1="$(git rev-parse HEAD)"
+export COMMIT1
+
+test_expect_success 'push with failing hook' '
+	test_commit two &&
+	test_must_fail git push parent1 HEAD
+'
+
+test_expect_success '--no-verify bypasses hook' '
+	git push --no-verify parent1 HEAD
+'
+
+COMMIT2="$(git rev-parse HEAD)"
+export COMMIT2
+
+write_script "$HOOK" <<'EOF'
+echo "$1" >actual
+echo "$2" >>actual
+cat >>actual
+EOF
+
+cat >expected <<EOF
+parent1
+repo1
+refs/heads/master $COMMIT2 refs/heads/foreign $COMMIT1
+EOF
+
+test_expect_success 'push with hook' '
+	git push parent1 master:foreign &&
+	diff expected actual
+'
+
+test_expect_success 'add a branch' '
+	git checkout -b other parent1/foreign &&
+	test_commit three
+'
+
+COMMIT3="$(git rev-parse HEAD)"
+export COMMIT3
+
+cat >expected <<EOF
+parent1
+repo1
+refs/heads/other $COMMIT3 refs/heads/foreign $COMMIT2
+EOF
+
+test_expect_success 'push to default' '
+	git push &&
+	diff expected actual
+'
+
+cat >expected <<EOF
+parent1
+repo1
+refs/tags/one $COMMIT1 refs/tags/tag1 $_z40
+HEAD~ $COMMIT2 refs/heads/prev $_z40
+EOF
+
+test_expect_success 'push non-branches' '
+	git push parent1 one:tag1 HEAD~:refs/heads/prev &&
+	diff expected actual
+'
+
+cat >expected <<EOF
+parent1
+repo1
+(delete) $_z40 refs/heads/prev $COMMIT2
+EOF
+
+test_expect_success 'push delete' '
+	git push parent1 :prev &&
+	diff expected actual
+'
+
+cat >expected <<EOF
+repo1
+repo1
+HEAD $COMMIT3 refs/heads/other $_z40
+EOF
+
+test_expect_success 'push to URL' '
+	git push repo1 HEAD &&
+	diff expected actual
+'
+
+# Test that filling pipe buffers doesn't cause failure
+# Too slow to leave enabled for general use
+if false
+then
+	printf 'parent1\nrepo1\n' >expected
+	nr=1000
+	while test $nr -lt 2000
+	do
+		nr=$(( $nr + 1 ))
+		git branch b/$nr $COMMIT3
+		echo "refs/heads/b/$nr $COMMIT3 refs/heads/b/$nr $_z40" >>expected
+	done
+
+	test_expect_success 'push many refs' '
+		git push parent1 "refs/heads/b/*:refs/heads/b/*" &&
+		diff expected actual
+	'
+fi
+
+test_done
diff --git a/transport.c b/transport.c
index 2673d27..0750a5f 100644
--- a/transport.c
+++ b/transport.c
@@ -1034,6 +1034,62 @@ static void die_with_unpushed_submodules(struct string_list *needs_pushing)
 	die("Aborting.");
 }
 
+static int run_pre_push_hook(struct transport *transport,
+			     struct ref *remote_refs)
+{
+	int ret = 0, x;
+	struct ref *r;
+	struct child_process proc;
+	struct strbuf buf;
+	const char *argv[4];
+
+	if (!(argv[0] = find_hook("pre-push")))
+		return 0;
+
+	argv[1] = transport->remote->name;
+	argv[2] = transport->url;
+	argv[3] = NULL;
+
+	memset(&proc, 0, sizeof(proc));
+	proc.argv = argv;
+	proc.in = -1;
+
+	if (start_command(&proc)) {
+		finish_command(&proc);
+		return -1;
+	}
+
+	strbuf_init(&buf, 256);
+
+	for (r = remote_refs; r; r = r->next) {
+		if (!r->peer_ref) continue;
+		if (r->status == REF_STATUS_REJECT_NONFASTFORWARD) continue;
+		if (r->status == REF_STATUS_UPTODATE) continue;
+
+		strbuf_reset(&buf);
+		strbuf_addf( &buf, "%s %s %s %s\n",
+			 r->peer_ref->name, sha1_to_hex(r->new_sha1),
+			 r->name, sha1_to_hex(r->old_sha1));
+
+		if (write_in_full(proc.in, buf.buf, buf.len) != buf.len) {
+			ret = -1;
+			break;
+		}
+	}
+
+	strbuf_release(&buf);
+
+	x = close(proc.in);
+	if (!ret)
+		ret = x;
+
+	x = finish_command(&proc);
+	if (!ret)
+		ret = x;
+
+	return ret;
+}
+
 int transport_push(struct transport *transport,
 		   int refspec_nr, const char **refspec, int flags,
 		   unsigned int *reject_reasons)
@@ -1074,6 +1130,10 @@ int transport_push(struct transport *transport,
 			flags & TRANSPORT_PUSH_MIRROR,
 			flags & TRANSPORT_PUSH_FORCE);
 
+		if (!(flags & TRANSPORT_PUSH_NO_HOOK))
+			if (run_pre_push_hook(transport, remote_refs))
+				return -1;
+
 		if ((flags & TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND) && !is_bare_repository()) {
 			struct ref *ref = remote_refs;
 			for (; ref; ref = ref->next)
diff --git a/transport.h b/transport.h
index bfd2df5..ac5a9f5 100644
--- a/transport.h
+++ b/transport.h
@@ -104,6 +104,7 @@ struct transport {
 #define TRANSPORT_RECURSE_SUBMODULES_CHECK 64
 #define TRANSPORT_PUSH_PRUNE 128
 #define TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND 256
+#define TRANSPORT_PUSH_NO_HOOK 512
 
 #define TRANSPORT_SUMMARY_WIDTH (2 * DEFAULT_ABBREV + 3)
 #define TRANSPORT_SUMMARY(x) (int)(TRANSPORT_SUMMARY_WIDTH + strlen(x) - gettext_width(x)), (x)
-- 
1.8.1.340.g425b78d

^ permalink raw reply related

* [PATCH v2 1/3] hooks: Add function to check if a hook exists
From: Aaron Schrab @ 2013-01-13  5:17 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano
In-Reply-To: <1356735452-21667-1-git-send-email-aaron@schrab.com>

Create find_hook() function to determine if a given hook exists and is
executable.  If it is, the path to the script will be returned,
otherwise NULL is returned.

This encapsulates the tests that are used to check for the existence of
a hook in one place, making it easier to modify those checks if that is
found to be necessary.  This also makes it simple for places that can
use a hook to check if a hook exists before doing, possibly lengthy,
setup work which would be pointless if no such hook is present.

The returned value is left as a static value from get_pathname() rather
than a duplicate because it is anticipated that the return value will
either be used as a boolean, immediately added to an argv_array list
which would result in it being duplicated at that point, or used to
actually run the command without much intervening work.  Callers which
need to hold onto the returned value for a longer time are expected to
duplicate the return value themselves.

Signed-off-by: Aaron Schrab <aaron@schrab.com>
---
 builtin/commit.c       |  6 ++----
 builtin/receive-pack.c | 25 +++++++++++--------------
 run-command.c          | 15 +++++++++++++--
 run-command.h          |  1 +
 4 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/builtin/commit.c b/builtin/commit.c
index d6dd3df..65d08d2 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1327,8 +1327,6 @@ static int git_commit_config(const char *k, const char *v, void *cb)
 	return git_status_config(k, v, s);
 }
 
-static const char post_rewrite_hook[] = "hooks/post-rewrite";
-
 static int run_rewrite_hook(const unsigned char *oldsha1,
 			    const unsigned char *newsha1)
 {
@@ -1339,10 +1337,10 @@ static int run_rewrite_hook(const unsigned char *oldsha1,
 	int code;
 	size_t n;
 
-	if (access(git_path(post_rewrite_hook), X_OK) < 0)
+	argv[0] = find_hook("post-rewrite");
+	if (!argv[0])
 		return 0;
 
-	argv[0] = git_path(post_rewrite_hook);
 	argv[1] = "amend";
 	argv[2] = NULL;
 
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index ff781fe..e8878de 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -182,9 +182,6 @@ struct command {
 	char ref_name[FLEX_ARRAY]; /* more */
 };
 
-static const char pre_receive_hook[] = "hooks/pre-receive";
-static const char post_receive_hook[] = "hooks/post-receive";
-
 static void rp_error(const char *err, ...) __attribute__((format (printf, 1, 2)));
 static void rp_warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
 
@@ -242,10 +239,10 @@ static int run_and_feed_hook(const char *hook_name, feed_fn feed, void *feed_sta
 	const char *argv[2];
 	int code;
 
-	if (access(hook_name, X_OK) < 0)
+	argv[0] = find_hook(hook_name);
+	if (!argv[0])
 		return 0;
 
-	argv[0] = hook_name;
 	argv[1] = NULL;
 
 	memset(&proc, 0, sizeof(proc));
@@ -331,15 +328,14 @@ static int run_receive_hook(struct command *commands, const char *hook_name,
 
 static int run_update_hook(struct command *cmd)
 {
-	static const char update_hook[] = "hooks/update";
 	const char *argv[5];
 	struct child_process proc;
 	int code;
 
-	if (access(update_hook, X_OK) < 0)
+	argv[0] = find_hook("update");
+	if (!argv[0])
 		return 0;
 
-	argv[0] = update_hook;
 	argv[1] = cmd->ref_name;
 	argv[2] = sha1_to_hex(cmd->old_sha1);
 	argv[3] = sha1_to_hex(cmd->new_sha1);
@@ -532,24 +528,25 @@ static const char *update(struct command *cmd)
 	}
 }
 
-static char update_post_hook[] = "hooks/post-update";
-
 static void run_update_post_hook(struct command *commands)
 {
 	struct command *cmd;
 	int argc;
 	const char **argv;
 	struct child_process proc;
+	char *hook;
 
+	hook = find_hook("post-update");
 	for (argc = 0, cmd = commands; cmd; cmd = cmd->next) {
 		if (cmd->error_string || cmd->did_not_exist)
 			continue;
 		argc++;
 	}
-	if (!argc || access(update_post_hook, X_OK) < 0)
+	if (!argc || !hook)
 		return;
+
 	argv = xmalloc(sizeof(*argv) * (2 + argc));
-	argv[0] = update_post_hook;
+	argv[0] = hook;
 
 	for (argc = 1, cmd = commands; cmd; cmd = cmd->next) {
 		char *p;
@@ -704,7 +701,7 @@ static void execute_commands(struct command *commands, const char *unpacker_erro
 				       0, &cmd))
 		set_connectivity_errors(commands);
 
-	if (run_receive_hook(commands, pre_receive_hook, 0)) {
+	if (run_receive_hook(commands, "pre-receive", 0)) {
 		for (cmd = commands; cmd; cmd = cmd->next) {
 			if (!cmd->error_string)
 				cmd->error_string = "pre-receive hook declined";
@@ -994,7 +991,7 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
 			unlink_or_warn(pack_lockfile);
 		if (report_status)
 			report(commands, unpack_status);
-		run_receive_hook(commands, post_receive_hook, 1);
+		run_receive_hook(commands, "post-receive", 1);
 		run_update_post_hook(commands);
 		if (auto_gc) {
 			const char *argv_gc_auto[] = {
diff --git a/run-command.c b/run-command.c
index 0471219..12d4ddb 100644
--- a/run-command.c
+++ b/run-command.c
@@ -735,6 +735,15 @@ int finish_async(struct async *async)
 #endif
 }
 
+char *find_hook(const char *name)
+{
+	char *path = git_path("hooks/%s", name);
+	if (access(path, X_OK) < 0)
+		path = NULL;
+
+	return path;
+}
+
 int run_hook(const char *index_file, const char *name, ...)
 {
 	struct child_process hook;
@@ -744,11 +753,13 @@ int run_hook(const char *index_file, const char *name, ...)
 	va_list args;
 	int ret;
 
-	if (access(git_path("hooks/%s", name), X_OK) < 0)
+	p = find_hook(name);
+	if (!p)
 		return 0;
 
+	argv_array_push(&argv, p);
+
 	va_start(args, name);
-	argv_array_push(&argv, git_path("hooks/%s", name));
 	while ((p = va_arg(args, const char *)))
 		argv_array_push(&argv, p);
 	va_end(args);
diff --git a/run-command.h b/run-command.h
index 850c638..221ce33 100644
--- a/run-command.h
+++ b/run-command.h
@@ -45,6 +45,7 @@ int start_command(struct child_process *);
 int finish_command(struct child_process *);
 int run_command(struct child_process *);
 
+extern char *find_hook(const char *name);
 extern int run_hook(const char *index_file, const char *name, ...);
 
 #define RUN_COMMAND_NO_STDIN 1
-- 
1.8.1.340.g425b78d

^ permalink raw reply related

* [PATCH v2 0/3] pre-push hook support
From: Aaron Schrab @ 2013-01-13  5:17 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano
In-Reply-To: <1356735452-21667-1-git-send-email-aaron@schrab.com>

Main changes since the initial version:

 * The first patch converts the existing hook callers to use the new
   find_hook() function.
 * Information about what is to be pushed is now sent over a pipe rather
   than passed as command-line parameters.

Aaron Schrab (3):
  hooks: Add function to check if a hook exists
  push: Add support for pre-push hooks
  Add sample pre-push hook script

 Documentation/githooks.txt       |  29 +++++++++
 builtin/commit.c                 |   6 +-
 builtin/push.c                   |   1 +
 builtin/receive-pack.c           |  25 ++++----
 run-command.c                    |  15 ++++-
 run-command.h                    |   1 +
 t/t5571-pre-push-hook.sh         | 129 +++++++++++++++++++++++++++++++++++++++
 templates/hooks--pre-push.sample |  53 ++++++++++++++++
 transport.c                      |  60 ++++++++++++++++++
 transport.h                      |   1 +
 10 files changed, 300 insertions(+), 20 deletions(-)
 create mode 100755 t/t5571-pre-push-hook.sh
 create mode 100644 templates/hooks--pre-push.sample

-- 
1.8.1.340.g425b78d

^ permalink raw reply

* Re: Suggestion: add option in git-p4 to preserve user in Git repository
From: Olivier Delalleau @ 2013-01-13  4:56 UTC (permalink / raw)
  To: Pete Wyckoff; +Cc: git, Luke Diamand
In-Reply-To: <20130112225640.GA23079@padd.com>

2013/1/12 Pete Wyckoff <pw@padd.com>:
> shish@keba.be wrote on Sat, 12 Jan 2013 14:44 -0500:
>> 2013/1/12 Pete Wyckoff <pw@padd.com>:
>> > shish@keba.be wrote on Thu, 10 Jan 2013 22:38 -0500:
>> >> I'm in a situation where I don't have P4 admin rights to use the
>> >> --preserve-user option of git-p4. However, I would like to keep user
>> >> information in the associated Git branch.
>> >>
>> >> Would it be possible to add an option for this?
>> >
>> > The --preserve-user option is used to submit somebody else's work
>> > from git to p4.  It does "p4 change -f" to edit the author of the
>> > change after it has been submitted to p4.  P4 requires admin
>> > privileges to do that.
>> >
>> > Changes that are imported _from_ p4 to git do have the correct
>> > author information.
>> >
>> > Can you explain a bit more what you're looking for?
>>
>> Sorry I wasn't clear enough. When "git p4 submit" submits changes from
>> Git to P4, it also edits the Git history and replaces the Git commits'
>> authors by the information from the Perforce account submitting the
>> changes. The advantage is that both the P4 and Git repositories share
>> the same author information, but in my case I would like to keep in
>> the Git repository the original authors (because the P4 account I'm
>> using to submit to P4 is shared by all Git users).
>
> Ah, I see what you're looking for now.  It's certainly possible
> to keep a mapping in the git side to remember who really wrote
> each change that went into p4, but there's nothing set up to do
> that now.  And it would be a fair amount of work, with many
> little details.
>
> You could put the true name in the commit message, like
> we do signed-off-by messages: "Author: Real Coder <rc@my.com>".
> That would keep the proper attribution, but not work with "git
> log --author", e.g.; you'd have to use "--grep='Real Coder'"
> instead.

Ok, thanks. I actually manage to hack my way around it, restoring the
author information with "git filter-branch" and overriding the remote
p4 tracking branch with "git update-ref". Did some limited testing and
it seems to work -- hopefully I won't have nasty surprises down the
road ;)

-=- Olivier

^ permalink raw reply

* Re: [PATCH 2/8] git_remote_helpers: fix input when running under Python 3
From: Michael Haggerty @ 2013-01-13  3:26 UTC (permalink / raw)
  To: John Keeping; +Cc: git, Eric S. Raymond, Felipe Contreras, Sverre Rabbelier
In-Reply-To: <a8c3aabfab64f49fa0cbb2d45bda79997a875ee8.1358018078.git.john@keeping.me.uk>

On 01/12/2013 08:23 PM, John Keeping wrote:
> Although 2to3 will fix most issues in Python 2 code to make it run under
> Python 3, it does not handle the new strict separation between byte
> strings and unicode strings.  There is one instance in
> git_remote_helpers where we are caught by this.
> 
> Fix it by explicitly decoding the incoming byte string into a unicode
> string.  In this instance, use the locale under which the application is
> running.
> 
> Signed-off-by: John Keeping <john@keeping.me.uk>
> ---
>  git_remote_helpers/git/importer.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/git_remote_helpers/git/importer.py b/git_remote_helpers/git/importer.py
> index e28cc8f..6814003 100644
> --- a/git_remote_helpers/git/importer.py
> +++ b/git_remote_helpers/git/importer.py
> @@ -20,7 +20,7 @@ class GitImporter(object):
>          """Returns a dictionary with refs.
>          """
>          args = ["git", "--git-dir=" + gitdir, "for-each-ref", "refs/heads"]
> -        lines = check_output(args).strip().split('\n')
> +        lines = check_output(args).decode().strip().split('\n')
>          refs = {}
>          for line in lines:
>              value, name = line.split(' ')
> 

Won't this change cause an exception if the branch names are not all
valid strings in the current locale's encoding?  I don't see how this
assumption is justified (e.g., see git-check-ref-format(1) for the rules
governing reference names).

Michael

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

^ permalink raw reply

* Re: How to setup bash completion for alias of git command
From: Ping Yin @ 2013-01-13  3:13 UTC (permalink / raw)
  To: git mailing list
In-Reply-To: <CACSwcnQu8Rx83mcGYR6NGzEhoreNR6DfiK876LF7pa9PGm30JA@mail.gmail.com>

On Sat, Jan 12, 2013 at 10:30 PM, Ping Yin <pkufranky@gmail.com> wrote:
> Following setup works for me  in ubuntu (10.04,11.04) for a long time
>
> alias gtlg='git log'
> complete -o default -o nospace -F _git_log gtlg
>
> However, in debian (testing, wheezy), it doesn't work
>
> $ gtlg or<TAB>
> gtlg or-bash: [: 1: unary operator expected
> -bash: [: 1: unary operator expected
>

with newest git version built with next branch, the same problem remains.

Ping Yin

^ permalink raw reply

* [PATCH/RFC 7/7] contrib/subtree: Handle '--prefix' argument with a slash appended
From: Techlive Zheng @ 2013-01-13  1:52 UTC (permalink / raw)
  To: git, gitster; +Cc: apenwarr, greened, Techlive Zheng
In-Reply-To: <1358041958-1998-1-git-send-email-techlivezheng@gmail.com>

'git subtree merge' will fail if the argument of '--prefix' has a slash
appended.

Signed-off-by: Techlive Zheng <techlivezheng@gmail.com>
---
 contrib/subtree/git-subtree.sh     |  2 +-
 contrib/subtree/t/t7900-subtree.sh | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 018ee32..574ff04 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -83,7 +83,7 @@ while [ $# -gt 0 ]; do
 		--annotate) annotate="$1"; shift ;;
 		--no-annotate) annotate= ;;
 		-b) branch="$1"; shift ;;
-		-P) prefix="$1"; shift ;;
+		-P) prefix="${1%/}"; shift ;;
 		-m) message="$1"; shift ;;
 		--no-prefix) prefix= ;;
 		--onto) onto="$1"; shift ;;
diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index 1492303..8e09606 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -238,6 +238,25 @@ test_expect_success 'merge new subproj history into subdir/ with --squash and --
     )
 '
 
+test_expect_success 'merge new subproj history into subdir/ with a slash appended to the argument of --prefix' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir/ FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree merge --prefix=subdir/ FETCH_HEAD &&
+        test_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''"
+    )
+'
+
 #
 # Tests for 'git subtree split'
 #
-- 
1.8.1

^ permalink raw reply related

* [PATCH/RFC 6/7] contrib/subtree: Use %B for the split commit message
From: Techlive Zheng @ 2013-01-13  1:52 UTC (permalink / raw)
  To: git, gitster; +Cc: apenwarr, greened, Techlive Zheng
In-Reply-To: <1358041958-1998-1-git-send-email-techlivezheng@gmail.com>

Use %B rather than %s%n%n%b to handle the special case of a commit that
only has a subject line.  We don't want to introduce a newline after the
subject, causing generation of a new hash.

After this commit, the newly split branch might differ from the previous
one. If this is the case, --fallback option could help.

Signed-off-by: Techlive Zheng <techlivezheng@gmail.com>
Signed-off-by: David A. Greene <greened@obbligato.org>
---
 contrib/subtree/git-subtree.sh     | 13 ++++++++++-
 contrib/subtree/git-subtree.txt    | 13 +++++++++++
 contrib/subtree/t/t7900-subtree.sh | 47 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+), 1 deletion(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 91e6e87..018ee32 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -25,6 +25,7 @@ b,branch=     create a new branch from the split subtree
 ignore-joins  ignore prior --rejoin commits
 onto=         try connecting new tree to an existing one
 rejoin        merge the new branch back into HEAD
+fallback      fallback to the obsolete commit generating mechanism
  options for 'add', 'merge', 'pull' and 'push'
 squash        merge subtree changes as a single commit
 "
@@ -45,6 +46,7 @@ ignore_joins=
 annotate=
 squash=
 message=
+fallback=
 
 debug()
 {
@@ -92,6 +94,8 @@ while [ $# -gt 0 ]; do
 		--no-ignore-joins) ignore_joins= ;;
 		--squash) squash=1 ;;
 		--no-squash) squash= ;;
+		--fallback) fallback=1 ;;
+		--no-fallback) fallback= ;;
 		--) break ;;
 		*) die "Unexpected option: $opt" ;;
 	esac
@@ -296,7 +300,14 @@ copy_commit()
 	# We're going to set some environment vars here, so
 	# do it in a subshell to get rid of them safely later
 	debug copy_commit "{$1}" "{$2}" "{$3}"
-	git log -1 --pretty=format:'%an%n%ae%n%ad%n%cn%n%ce%n%cd%n%s%n%n%b' "$1" |
+
+	if [ -z "$fallback" ]; then
+		log_format='%an%n%ae%n%ad%n%cn%n%ce%n%cd%n%B'
+	else
+		log_format='%an%n%ae%n%ad%n%cn%n%ce%n%cd%n%s%n%n%b'
+	fi
+
+	git log -1 --pretty=format:"$log_format" "$1" |
 	(
 		read GIT_AUTHOR_NAME
 		read GIT_AUTHOR_EMAIL
diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
index c5bce41..ca9f199 100644
--- a/contrib/subtree/git-subtree.txt
+++ b/contrib/subtree/git-subtree.txt
@@ -254,6 +254,19 @@ OPTIONS FOR split
 	'--rejoin' when you split, because you don't want the
 	subproject's history to be part of your project anyway.
 
+--fallback::
+	Previously, git subtree would introduce an extra new line for
+	the commits whose commit message contains only one line.
+	This behavior has been correct. Unfortunately, for those whose
+	current split branch contains these kind of commits, git subtree
+	will generate a new split branch which differs from the existing
+	split branch in these commits. It is better to use this new
+	split branch, because its commits stay intact within the mainline.
+	
+	Otherwise, the previous fault behavior could still be used with
+	this option. This option is only for a compatible purpose, newly
+	split branch should never use this option.
+
 
 EXAMPLE 1. Add command
 ----------------------
diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index ece2064..1492303 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -399,6 +399,53 @@ test_expect_success 'split subdir/ with --branch for an incompatible branch' '
     )
 '
 
+test_expect_success 'make sure commits with one line message stay intact after split' '
+    test_create_repo $test_count &&
+    test_create_repo $test_count/subproj &&
+    test_create_commit $test_count main1 &&
+    test_create_commit $test_count/subproj sub1 &&
+    (
+        cd $test_count &&
+        git fetch ./subproj master &&
+        ori_hash=$(git rev-parse FETCH_HEAD) &&
+        git branch subori FETCH_HEAD &&
+        git filter-branch --index-filter '\''git ls-files -s | sed "s-\t-&subdir/-" | GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info && mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"'\'' subori
+        git merge -m "Merge B project as our subdirectory" subori &&
+        git subtree split --prefix subdir --branch splitbr1 &&
+        new_hash_1=$(git rev-parse splitbr1) &&
+        test_equal "$ori_hash" "$new_hash_1" &&
+        git subtree split --prefix subdir --branch splitbr2 --fallback &&
+        new_hash_2=$(git rev-parse splitbr2) &&
+        test_must_fail test_equal "$ori_hash" "$new_hash_2"
+    )
+'
+
+test_expect_success 'make sure --fallback option works correctly for the existing split branch' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count"/subproj &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count"/subproj sub1 &&
+    (
+        cd $test_count &&
+        git fetch ./subproj master &&
+        ori_hash=$(git rev-parse FETCH_HEAD) &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub1 &&
+    (
+        cd $test_count &&
+        git subtree split --prefix subdir --branch splitbr1 &&
+        git subtree split --prefix subdir --branch splitbr2 --fallback &&
+        test_must_fail test_equal "$(git rev-parse splitbr1)" "$(git rev-parse splitbr2)"
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub2 &&
+    (
+        cd $test_count &&
+        test_must_fail git subtree split --prefix subdir --branch splitbr2 &&
+        git subtree split --prefix subdir --branch splitbr2 --fallback
+    )
+'
+
 #
 # Validity checking
 #
-- 
1.8.1

^ permalink raw reply related

* [PATCH/RFC 5/7] contrib/subtree: Make each test self-contained
From: Techlive Zheng @ 2013-01-13  1:52 UTC (permalink / raw)
  To: git, gitster; +Cc: apenwarr, greened, Techlive Zheng
In-Reply-To: <1358041958-1998-1-git-send-email-techlivezheng@gmail.com>

Signed-off-by: Techlive Zheng <techlivezheng@gmail.com>
---
 contrib/subtree/t/t7900-subtree.sh | 865 ++++++++++++++++++++++++++-----------
 1 file changed, 614 insertions(+), 251 deletions(-)

diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index bb4fd1f..ece2064 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -12,12 +12,6 @@ export TEST_DIRECTORY=$(pwd)/../../../t
 
 . ../../../t/test-lib.sh
 
-create()
-{
-    echo "$1" >"$1"
-    git add "$1"
-}
-
 fixnl()
 {
     t=""
@@ -37,11 +31,6 @@ multiline()
     done
 }
 
-undo()
-{
-    git reset --hard HEAD~
-}
-
 test_equal()
 {
     test_debug 'echo'
@@ -78,373 +67,746 @@ join_commits()
     echo "$commit $all"
 }
 
+test_create_commit() (
+    repo=$1
+    commit=$2
+    cd "$repo"
+    mkdir -p "$(dirname "$commit")"
+    echo "$commit" > "$commit"
+    git add "$commit"
+    git commit -m "$commit"
+)
+
 last_commit_message()
 {
     git log --pretty=format:%s -1
 }
 
-test_expect_success 'init subproj' '
-        test_create_repo subproj
-'
-
-# To the subproject!
-cd subproj
-
-test_expect_success 'add sub1' '
-        create sub1 &&
-        git commit -m "sub1" &&
-        git branch sub1 &&
-        git branch -m master subproj
-'
-
-test_expect_success 'add sub2' '
-        create sub2 &&
-        git commit -m "sub2" &&
-        git branch sub2
-'
-
-test_expect_success 'add sub3' '
-        create sub3 &&
-        git commit -m "sub3" &&
-        git branch sub3
-'
-
-# Back to mainline
-cd ..
-
-test_expect_success 'add main4' '
-        create main4 &&
-        git commit -m "main4" &&
-        git branch -m master mainline &&
-        git branch init
-'
-
-test_expect_success 'fetch subproj history' '
-        git fetch ./subproj sub1 &&
-        git branch sub1 FETCH_HEAD
-'
+#
+# Tests for 'git subtree add'
+#
 
 test_expect_success 'no pull from non-existant subtree' '
-        test_must_fail git subtree pull --prefix=subdir ./subproj sub1
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        test_must_fail git subtree pull --prefix=subdir ./subproj master
+    )
 '
 
 test_expect_success 'no merge from non-existant subtree' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
         test_must_fail git subtree merge --prefix=subdir FETCH_HEAD
+    )
 '
 
 test_expect_success 'add subproj as subtree into subdir/ with --prefix' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
         git subtree add --prefix=subdir FETCH_HEAD &&
-        test_equal "$(last_commit_message)" "Add '\''subdir/'\'' from commit '\''$(git rev-parse FETCH_HEAD)'\''" &&
-        undo
+        test_equal "$(last_commit_message)" "Add '\''subdir/'\'' from commit '\''$(git rev-parse FETCH_HEAD)'\''"
+    )
 '
 
 test_expect_success 'add subproj as subtree into subdir/ with --prefix and --message' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
         git subtree add --prefix=subdir --message="Added subproject" FETCH_HEAD &&
-        test_equal "$(last_commit_message)" "Added subproject" &&
-        undo
+        test_equal "$(last_commit_message)" "Added subproject"
+    )
 '
 
 test_expect_success 'add subproj as subtree into subdir/ with --prefix as -P and --message as -m' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
         git subtree add -P subdir -m "Added subproject" FETCH_HEAD &&
-        test_equal "$(last_commit_message)" "Added subproject" &&
-        undo
+        test_equal "$(last_commit_message)" "Added subproject"
+    )
 '
 
 test_expect_success 'add subproj as subtree into subdir/ with --squash and --prefix and --message' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
         git subtree add --prefix=subdir --message="Added subproject with squash" --squash FETCH_HEAD &&
-        test_equal "$(last_commit_message)" "Added subproject with squash" &&
-        undo
+        test_equal "$(last_commit_message)" "Added subproject with squash"
+    )
 '
 
 test_expect_success 'merge the added subproj again, should do nothing' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
         git subtree add --prefix=subdir FETCH_HEAD &&
         # this shouldn not actually do anything, since FETCH_HEAD
         # is already a parent
         git merge -s ours -m "merge -s -ours" FETCH_HEAD
+    )
 '
 
-test_expect_success 'add main-sub5' '
-        create subdir/main-sub5 &&
-        git commit -m "main-sub5"
-'
-
-test_expect_success 'add main6' '
-        create main6 &&
-        git commit -m "main6 boring"
-'
-
-test_expect_success 'add main-sub7' '
-        create subdir/main-sub7 &&
-        git commit -m "main-sub7"
-'
-
-test_expect_success 'fetch new subproj history' '
-        git fetch ./subproj sub2 &&
-        git branch sub2 FETCH_HEAD
-'
+#
+# Tests for 'git subtree merge'
+#
 
 test_expect_success 'merge new subproj history into subdir/ with --prefix' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
         git subtree merge --prefix=subdir FETCH_HEAD &&
-        test_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\'' into mainline" &&
-        undo
+        test_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''"
+    )
 '
 
 test_expect_success 'merge new subproj history into subdir/ with --prefix and --message' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
         git subtree merge --prefix=subdir --message="Merged changes from subproject" FETCH_HEAD &&
-        test_equal "$(last_commit_message)" "Merged changes from subproject" &&
-        undo
+        test_equal "$(last_commit_message)" "Merged changes from subproject"
+    )
 '
 
 test_expect_success 'merge new subproj history into subdir/ with --squash and --prefix and --message' '
+    test_create_repo "$test_count/subproj" &&
+    test_create_repo "$test_count" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
         git subtree merge --prefix=subdir --message="Merged changes from subproject using squash" --squash FETCH_HEAD &&
-        test_equal "$(last_commit_message)" "Merged changes from subproject using squash" &&
-        undo
+        test_equal "$(last_commit_message)" "Merged changes from subproject using squash"
+    )
 '
 
-test_expect_success 'merge new subproj history into subdir/' '
-        git subtree merge --prefix=subdir FETCH_HEAD &&
-        git branch pre-split
-'
+#
+# Tests for 'git subtree split'
+#
 
 test_expect_success 'split requires option --prefix' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD &&
         echo "You must provide the --prefix option." > expected &&
         test_must_fail git subtree split > actual 2>&1 &&
         test_debug "echo -n expected: " &&
         test_debug "cat expected" &&
         test_debug "echo -n actual: " &&
         test_debug "cat actual" &&
-        test_cmp expected actual &&
-        rm -f expected actual
+        test_cmp expected actual
+    )
 '
 
 test_expect_success 'split requires path given by option --prefix must exist' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD &&
         echo "'\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" > expected &&
         test_must_fail git subtree split --prefix=non-existent-directory > actual 2>&1 &&
         test_debug "echo -n expected: " &&
         test_debug "cat expected" &&
         test_debug "echo -n actual: " &&
         test_debug "cat actual" &&
-        test_cmp expected actual &&
-        rm -f expected actual
+        test_cmp expected actual
+    )
 '
 
 test_expect_success 'split subdir/ with --rejoin' '
-        spl1=$(git subtree split --prefix=subdir --annotate="*") &&
-        git branch spl1 "$spl1" &&
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub1 &&
+    test_create_commit "$test_count" main2 &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    test_create_commit "$test_count" subdir/main-sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree merge --prefix=subdir FETCH_HEAD &&
+        split_hash=$(git subtree split --prefix=subdir --annotate="*") &&
         git subtree split --prefix=subdir --annotate="*" --rejoin &&
-        test_equal "$(last_commit_message)" "Split '\''subdir/'\'' into commit '\''$spl1'\''" &&
-        undo
+        test_equal "$(last_commit_message)" "Split '\''subdir/'\'' into commit '\''$split_hash'\''"
+    )
 '
 
 test_expect_success 'split subdir/ with --rejoin and --message' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub1 &&
+    test_create_commit "$test_count" main2 &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    test_create_commit "$test_count" subdir/main-sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree merge --prefix=subdir FETCH_HEAD &&
         git subtree split --prefix=subdir --message="Split & rejoin" --annotate="*" --rejoin &&
-        test_equal "$(last_commit_message)" "Split & rejoin" &&
-        undo
+        test_equal "$(last_commit_message)" "Split & rejoin"
+    )
 '
 
 test_expect_success 'split subdir/ with --branch' '
-        spl1=$(git subtree split --prefix=subdir --message="Split & rejoin" --annotate="*" --rejoin) &&
-        undo &&
-        git subtree split --prefix=subdir --annotate="*" --branch splitbr1 &&
-        test_equal "$(git rev-parse splitbr1)" "$spl1"
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub1 &&
+    test_create_commit "$test_count" main2 &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    test_create_commit "$test_count" subdir/main-sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree merge --prefix=subdir FETCH_HEAD &&
+        split_hash=$(git subtree split --prefix=subdir --annotate="*") &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br &&
+        test_equal "$(git rev-parse subproj-br)" "$split_hash"
+    )
 '
 
 test_expect_success 'split subdir/ with --branch for an existing branch' '
-        spl1=$(git subtree split --prefix=subdir --annotate="*" --message="Split & rejoin" --rejoin) &&
-        undo &&
-        git branch splitbr2 sub1 &&
-        git subtree split --prefix=subdir --annotate="*" --branch splitbr2 &&
-        test_equal "$(git rev-parse splitbr2)" "$spl1"
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git branch subproj-br FETCH_HEAD &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub1 &&
+    test_create_commit "$test_count" main2 &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    test_create_commit "$test_count" subdir/main-sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree merge --prefix=subdir FETCH_HEAD &&
+        split_hash=$(git subtree split --prefix=subdir --annotate="*") &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br &&
+        test_equal "$(git rev-parse subproj-br)" "$split_hash"
+    )
 '
 
 test_expect_success 'split subdir/ with --branch for an incompatible branch' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git branch init HEAD &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub1 &&
+    test_create_commit "$test_count" main2 &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    test_create_commit "$test_count" subdir/main-sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree merge --prefix=subdir FETCH_HEAD &&
         test_must_fail git subtree split --prefix=subdir --branch init
+    )
 '
 
-test_expect_success 'split and rejoin' '
-        git subtree split --prefix=subdir --annotate="*" --rejoin
-'
-
-test_expect_success 'add main-sub8' '
-        create subdir/main-sub8 &&
-        git commit -m "main-sub8"
-'
-
-# To the subproject!
-cd ./subproj
-
-test_expect_success 'merge split into subproj' '
-        git fetch .. spl1 &&
-        git branch spl1 FETCH_HEAD &&
-        git merge FETCH_HEAD
-'
-
-test_expect_success 'add sub9' '
-        create sub9 &&
-        git commit -m "sub9"
-'
-
-# Back to mainline
-cd ..
-
-test_expect_success 'split for sub8' '
-        spl2=$(git subtree split --prefix=subdir/ --annotate="*" --rejoin) &&
-        git branch spl2 "$spl2"
-'
-
-test_expect_success 'add main-sub10' '
-        create subdir/main-sub10 &&
-        git commit -m "main-sub10"
-'
-
-test_expect_success 'split for sub10' '
-        spl3=$(git subtree split --prefix=subdir --annotate="*" --rejoin) &&
-        git branch spl3 "$spl3"
-'
-
-# To the subproject!
-cd ./subproj
-
-test_expect_success 'merge split into subproj' '
-        git fetch .. spl3 &&
-        git branch spl3 FETCH_HEAD &&
-        git merge FETCH_HEAD &&
-        git branch subproj-merge-spl3
-'
-
-chkm="main4 main6"
-chkms="main-sub10 main-sub5 main-sub7 main-sub8"
-chkms_sub=$(echo $chkms | multiline | sed 's,^,subdir/,' | fixnl)
-chks="sub1 sub2 sub3 sub9"
-chks_sub=$(echo $chks | multiline | sed 's,^,subdir/,' | fixnl)
+#
+# Validity checking
+#
 
 test_expect_success 'make sure exactly the right set of files ends up in the subproj' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub1 &&
+    test_create_commit "$test_count" main2 &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    test_create_commit "$test_count" subdir/main-sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree merge --prefix=subdir FETCH_HEAD &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    test_create_commit "$test_count/subproj" sub3 &&
+    test_create_commit "$test_count" subdir/main-sub3 &&
+    (
+        cd "$test_count/subproj" &&
+        git fetch .. subproj-br && git merge FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count/subproj" sub4 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub4 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    (
+        cd "$test_count/subproj" &&
+        git fetch .. subproj-br && git merge FETCH_HEAD &&
+
+        chks="sub1 sub2 sub3 sub4" &&
+        chks_sub=$(echo $chks | multiline | sed '\''s,^,subdir/,'\'' | fixnl) &&
+        chkms="main-sub1 main-sub2 main-sub3 main-sub4" &&
+        chkms_sub=$(echo $chkms | multiline | sed '\''s,^,subdir/,'\'' | fixnl) &&
+
         subfiles=$(git ls-files | fixnl) &&
         test_equal "$subfiles" "$chkms $chks"
+    )
 '
 
 test_expect_success 'make sure the subproj *only* contains commits that affect the subdir' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub1 &&
+    test_create_commit "$test_count" main2 &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    test_create_commit "$test_count" subdir/main-sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree merge --prefix=subdir FETCH_HEAD &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    test_create_commit "$test_count/subproj" sub3 &&
+    test_create_commit "$test_count" subdir/main-sub3 &&
+    (
+        cd "$test_count/subproj" &&
+        git fetch .. subproj-br && git merge FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count/subproj" sub4 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub4 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    (
+        cd "$test_count/subproj" &&
+        git fetch .. subproj-br && git merge FETCH_HEAD &&
+
+        chks="sub1 sub2 sub3 sub4" &&
+        chks_sub=$(echo $chks | multiline | sed '\''s,^,subdir/,'\'' | fixnl) &&
+        chkms="main-sub1 main-sub2 main-sub3 main-sub4" &&
+        chkms_sub=$(echo $chkms | multiline | sed '\''s,^,subdir/,'\'' | fixnl) &&
+
         allchanges=$(git log --name-only --pretty=format:"" | sort | fixnl) &&
         test_equal "$allchanges" "$chkms $chks"
-'
-
-# Back to mainline
-cd ..
-
-test_expect_success 'pull from subproj' '
-        git fetch ./subproj subproj-merge-spl3 &&
-        git branch subproj-merge-spl3 FETCH_HEAD &&
-        git subtree pull --prefix=subdir ./subproj subproj-merge-spl3
+    )
 '
 
 test_expect_success 'make sure exactly the right set of files ends up in the mainline' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub1 &&
+    test_create_commit "$test_count" main2 &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    test_create_commit "$test_count" subdir/main-sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree merge --prefix=subdir FETCH_HEAD &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    test_create_commit "$test_count/subproj" sub3 &&
+    test_create_commit "$test_count" subdir/main-sub3 &&
+    (
+        cd "$test_count/subproj" &&
+        git fetch .. subproj-br && git merge FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count/subproj" sub4 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub4 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    (
+        cd "$test_count/subproj" &&
+        git fetch .. subproj-br && git merge FETCH_HEAD
+    ) &&
+    (
+        cd "$test_count" &&
+        git subtree pull --prefix=subdir ./subproj master &&
+
+        chkm="main1 main2" &&
+        chks="sub1 sub2 sub3 sub4" &&
+        chks_sub=$(echo $chks | multiline | sed '\''s,^,subdir/,'\'' | fixnl) &&
+        chkms="main-sub1 main-sub2 main-sub3 main-sub4" &&
+        chkms_sub=$(echo $chkms | multiline | sed '\''s,^,subdir/,'\'' | fixnl) &&
+
         mainfiles=$(git ls-files | fixnl) &&
         test_equal "$mainfiles" "$chkm $chkms_sub $chks_sub"
+    )
 '
 
 test_expect_success 'make sure each filename changed exactly once in the entire history' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub1 &&
+    test_create_commit "$test_count" main2 &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    test_create_commit "$test_count" subdir/main-sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree merge --prefix=subdir FETCH_HEAD &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    test_create_commit "$test_count/subproj" sub3 &&
+    test_create_commit "$test_count" subdir/main-sub3 &&
+    (
+        cd "$test_count/subproj" &&
+        git fetch .. subproj-br && git merge FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count/subproj" sub4 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub4 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    (
+        cd "$test_count/subproj" &&
+        git fetch .. subproj-br && git merge FETCH_HEAD
+    ) &&
+    (
+        cd "$test_count" &&
+        git subtree pull --prefix=subdir ./subproj master &&
+
+        chkm="main1 main2" &&
+        chks="sub1 sub2 sub3 sub4" &&
+        chks_sub=$(echo $chks | multiline | sed '\''s,^,subdir/,'\'' | fixnl) &&
+        chkms="main-sub1 main-sub2 main-sub3 main-sub4" &&
+        chkms_sub=$(echo $chkms | multiline | sed '\''s,^,subdir/,'\'' | fixnl) &&
+
         # main-sub?? and /subdir/main-sub?? both change, because those are the
         # changes that were split into their own history.  And subdir/sub?? never
         # change, since they were *only* changed in the subtree branch.
         allchanges=$(git log --name-only --pretty=format:"" | sort | fixnl) &&
         test_equal "$allchanges" "$(echo $chkms $chkm $chks $chkms_sub | multiline | sort | fixnl)"
+    )
 '
 
 test_expect_success 'make sure the --rejoin commits never make it into subproj' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub1 &&
+    test_create_commit "$test_count" main2 &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    test_create_commit "$test_count" subdir/main-sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree merge --prefix=subdir FETCH_HEAD &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    test_create_commit "$test_count/subproj" sub3 &&
+    test_create_commit "$test_count" subdir/main-sub3 &&
+    (
+        cd "$test_count/subproj" &&
+        git fetch .. subproj-br && git merge FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count/subproj" sub4 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub4 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    (
+        cd "$test_count/subproj" &&
+        git fetch .. subproj-br && git merge FETCH_HEAD
+    ) &&
+    (
+        cd "$test_count" &&
+        git subtree pull --prefix=subdir ./subproj master &&
+
         test_equal "$(git log --pretty=format:"%s" HEAD^2 | grep -i split)" ""
+    )
 '
 
 test_expect_success 'make sure no "git subtree" tagged commits make it into subproj' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub1 &&
+    test_create_commit "$test_count" main2 &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    test_create_commit "$test_count" subdir/main-sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree merge --prefix=subdir FETCH_HEAD &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    test_create_commit "$test_count/subproj" sub3 &&
+    test_create_commit "$test_count" subdir/main-sub3 &&
+    (
+        cd "$test_count/subproj" &&
+        git fetch .. subproj-br && git merge FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count/subproj" sub4 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub4 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir --annotate="*" --branch subproj-br --rejoin
+    ) &&
+    (
+        cd "$test_count/subproj" &&
+        git fetch .. subproj-br && git merge FETCH_HEAD
+    ) &&
+    (
+        cd "$test_count" &&
+        git subtree pull --prefix=subdir ./subproj master &&
+
         # They are meaningless to subproj since one side of the merge refers to the mainline
         test_equal "$(git log --pretty=format:"%s%n%b" HEAD^2 | grep "git-subtree.*:")" ""
+    )
 '
 
-# prepare second pair of repositories
-mkdir test2
-cd test2
-
-test_expect_success 'init main' '
-        test_create_repo main
-'
-
-cd main
-
-test_expect_success 'add main1' '
-        create main1 &&
-        git commit -m "main1"
-'
-
-cd ..
-
-test_expect_success 'init sub' '
-        test_create_repo sub
-'
-
-cd sub
-
-test_expect_success 'add sub2' '
-        create sub2 &&
-        git commit -m "sub2"
-'
-
-cd ../main
-
-# check if split can find proper base without --onto
-
-test_expect_success 'add sub as subdir in main' '
-        git fetch ../sub master &&
-        git branch sub2 FETCH_HEAD &&
-        git subtree add --prefix=subdir sub2
-'
-
-cd ../sub
-
-test_expect_success 'add sub3' '
-        create sub3 &&
-        git commit -m "sub3"
-'
-
-cd ../main
-
-test_expect_success 'merge from sub' '
-        git fetch ../sub master &&
-        git branch sub3 FETCH_HEAD &&
-        git subtree merge --prefix=subdir sub3
-'
-
-test_expect_success 'add main-sub4' '
-        create subdir/main-sub4 &&
-        git commit -m "main-sub4"
-'
-
-test_expect_success 'split for main-sub4 without --onto' '
-        git subtree split --prefix=subdir --branch mainsub4
-'
-
-# at this point, the new commit parent should be sub3 if it is not,
-# something went wrong (the "newparent" of "master~" commit should
-# have been sub3, but it was not, because its cache was not set to
-# itself)
-
-test_expect_success 'check that the commit parent is sub3' '
-        test_equal "$(git log --pretty=format:%P -1 mainsub4)" "$(git rev-parse sub3)"
-'
+#
+# A new set of tests
+#
 
-test_expect_success 'add main-sub5' '
-        mkdir subdir2 &&
-        create subdir2/main-sub5 &&
-        git commit -m "main-sub5"
-'
+test_expect_success 'make sure "git subtree split" find the correct parent' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git branch subproj-ref FETCH_HEAD &&
+        git subtree merge --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub1 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir --branch subproj-br &&
+
+        # at this point, the new commit parent should be subproj-ref, if it is
+        # not, something went wrong (the "newparent" of "master~" commit should
+        # have been sub2, but it was not, because its cache was not set to
+        # itself)
+        test_equal "$(git log --pretty=format:%P -1 subproj-br)" "$(git rev-parse subproj-ref)"
+    )
+'
+
+test_expect_success 'split a new subtree without --onto option' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree add --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree merge --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub1 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir --branch subproj-br
+    ) &&
+    test_create_commit "$test_count" subdir2/main-sub2 &&
+    (
+        cd "$test_count" &&
 
-test_expect_success 'split for main-sub5 without --onto' '
         # also test that we still can split out an entirely new subtree
         # if the parent of the first commit in the tree is not empty,
         # then the new subtree has accidently been attached to something
-        git subtree split --prefix=subdir2 --branch mainsub5 &&
-        test_equal "$(git log --pretty=format:%P -1 mainsub5)" ""
+        git subtree split --prefix=subdir2 --branch subproj2-br &&
+        test_equal "$(git log --pretty=format:%P -1 subproj2-br)" ""
+    )
 '
 
 test_expect_success 'verify one file change per commit' '
+    test_create_repo "$test_count" &&
+    test_create_repo "$test_count/subproj" &&
+    test_create_commit "$test_count" main1 &&
+    test_create_commit "$test_count/subproj" sub1 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git branch sub1 FETCH_HEAD &&
+        git subtree add --prefix=subdir sub1
+    ) &&
+    test_create_commit "$test_count/subproj" sub2 &&
+    (
+        cd "$test_count" &&
+        git fetch ./subproj master &&
+        git subtree merge --prefix=subdir FETCH_HEAD
+    ) &&
+    test_create_commit "$test_count" subdir/main-sub1 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir --branch subproj-br
+    ) &&
+    test_create_commit "$test_count" subdir2/main-sub2 &&
+    (
+        cd "$test_count" &&
+        git subtree split --prefix=subdir2 --branch subproj2-br &&
+
         x= &&
         git log --pretty=format:"commit: %H" | join_commits |
         (
@@ -457,6 +819,7 @@ test_expect_success 'verify one file change per commit' '
             done
             test_equal "$x" 1
         )
+    )
 '
 
 test_done
-- 
1.8.1

^ permalink raw reply related

* [PATCH/RFC 4/7] contrib/subtree: Code cleaning and refactoring
From: Techlive Zheng @ 2013-01-13  1:52 UTC (permalink / raw)
  To: git, gitster; +Cc: apenwarr, greened, Techlive Zheng
In-Reply-To: <1358041958-1998-1-git-send-email-techlivezheng@gmail.com>

Mostly prepare for the later tests refactoring.

Signed-off-by: Techlive Zheng <techlivezheng@gmail.com>
---
 contrib/subtree/git-subtree.sh     |  66 ++++-----
 contrib/subtree/t/t7900-subtree.sh | 283 +++++++++++++++++++------------------
 2 files changed, 179 insertions(+), 170 deletions(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 138e1e0..91e6e87 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -5,7 +5,7 @@
 # Copyright (C) 2009 Avery Pennarun <apenwarr@gmail.com>
 #
 if [ $# -eq 0 ]; then
-    set -- -h
+	set -- -h
 fi
 OPTS_SPEC="\
 git subtree add   --prefix=<prefix> <commit>
@@ -110,9 +110,9 @@ if [ -z "$prefix" ]; then
 fi
 
 case "$command" in
-	add) [ -e "$prefix" ] && 
+	add) [ -e "$prefix" ] &&
 		die "prefix '$prefix' already exists." ;;
-	*)   [ -e "$prefix" ] || 
+	*)   [ -e "$prefix" ] ||
 		die "'$prefix' does not exist; use 'git subtree add'" ;;
 esac
 
@@ -181,8 +181,8 @@ cache_set()
 	oldrev="$1"
 	newrev="$2"
 	if [ "$oldrev" != "latest_old" \
-	     -a "$oldrev" != "latest_new" \
-	     -a -e "$cachedir/$oldrev" ]; then
+		-a "$oldrev" != "latest_new" \
+		-a -e "$cachedir/$oldrev" ]; then
 		die "cache for $oldrev already exists!"
 	fi
 	echo "$newrev" >"$cachedir/$oldrev"
@@ -327,7 +327,7 @@ add_msg()
 	fi
 	cat <<-EOF
 		$commit_message
-		
+
 		git-subtree-dir: $dir
 		git-subtree-mainline: $latest_old
 		git-subtree-split: $latest_new
@@ -355,7 +355,7 @@ rejoin_msg()
 	fi
 	cat <<-EOF
 		$commit_message
-		
+
 		git-subtree-dir: $dir
 		git-subtree-mainline: $latest_old
 		git-subtree-split: $latest_new
@@ -368,7 +368,7 @@ squash_msg()
 	oldsub="$2"
 	newsub="$3"
 	newsub_short=$(git rev-parse --short "$newsub")
-	
+
 	if [ -n "$oldsub" ]; then
 		oldsub_short=$(git rev-parse --short "$oldsub")
 		echo "Squashed '$dir/' changes from $oldsub_short..$newsub_short"
@@ -378,7 +378,7 @@ squash_msg()
 	else
 		echo "Squashed '$dir/' content from commit $newsub_short"
 	fi
-	
+
 	echo
 	echo "git-subtree-dir: $dir"
 	echo "git-subtree-split: $newsub"
@@ -427,7 +427,7 @@ new_squash_commit()
 	newsub="$3"
 	tree=$(toptree_for_commit $newsub) || exit $?
 	if [ -n "$old" ]; then
-		squash_msg "$dir" "$oldsub" "$newsub" | 
+		squash_msg "$dir" "$oldsub" "$newsub" |
 			git commit-tree "$tree" -p "$old" || exit $?
 	else
 		squash_msg "$dir" "" "$newsub" |
@@ -455,7 +455,7 @@ copy_or_skip()
 		else
 			nonidentical="$parent"
 		fi
-		
+
 		# sometimes both old parents map to the same newparent;
 		# eliminate duplicates
 		is_new=1
@@ -470,7 +470,7 @@ copy_or_skip()
 			p="$p -p $parent"
 		fi
 	done
-	
+
 	if [ -n "$identical" ]; then
 		echo $identical
 	else
@@ -495,14 +495,14 @@ cmd_add()
 	fi
 
 	ensure_clean
-	
+
 	if [ $# -eq 1 ]; then
 		"cmd_add_commit" "$@"
 	elif [ $# -eq 2 ]; then
 		"cmd_add_repository" "$@"
 	else
-	    say "error: parameters were '$@'"
-	    die "Provide either a refspec or a repository and refspec."
+		say "error: parameters were '$@'"
+		die "Provide either a refspec or a repository and refspec."
 	fi
 }
 
@@ -522,19 +522,19 @@ cmd_add_commit()
 	revs=$(git rev-parse $default --revs-only "$@") || exit $?
 	set -- $revs
 	rev="$1"
-	
+
 	debug "Adding $dir as '$rev'..."
 	git read-tree --prefix="$dir" $rev || exit $?
 	git checkout -- "$dir" || exit $?
 	tree=$(git write-tree) || exit $?
-	
+
 	headrev=$(git rev-parse HEAD) || exit $?
 	if [ -n "$headrev" -a "$headrev" != "$rev" ]; then
 		headp="-p $headrev"
 	else
 		headp=
 	fi
-	
+
 	if [ -n "$squash" ]; then
 		rev=$(new_squash_commit "" "" "$rev") || exit $?
 		commit=$(add_squashed_msg "$rev" "$dir" |
@@ -544,7 +544,7 @@ cmd_add_commit()
 			 git commit-tree $tree $headp -p "$rev") || exit $?
 	fi
 	git reset "$commit" || exit $?
-	
+
 	say "Added dir '$dir'"
 }
 
@@ -552,7 +552,7 @@ cmd_split()
 {
 	debug "Splitting $dir..."
 	cache_setup || exit $?
-	
+
 	if [ -n "$onto" ]; then
 		debug "Reading history for --onto=$onto..."
 		git rev-list $onto |
@@ -563,13 +563,13 @@ cmd_split()
 			cache_set $rev $rev
 		done
 	fi
-	
+
 	if [ -n "$ignore_joins" ]; then
 		unrevs=
 	else
 		unrevs="$(find_existing_splits "$dir" "$revs")"
 	fi
-	
+
 	# We can't restrict rev-list to only $dir here, because some of our
 	# parents have the $dir contents the root, and those won't match.
 	# (and rev-list --follow doesn't seem to solve this)
@@ -591,12 +591,12 @@ cmd_split()
 		debug "  parents: $parents"
 		newparents=$(cache_get $parents)
 		debug "  newparents: $newparents"
-		
+
 		tree=$(subtree_for_commit $rev "$dir")
 		debug "  tree is: $tree"
 
 		check_parents $parents
-		
+
 		# ugly.  is there no better way to tell if this is a subtree
 		# vs. a mainline commit?  Does it matter?
 		if [ -z $tree ]; then
@@ -617,7 +617,7 @@ cmd_split()
 	if [ -z "$latest_new" ]; then
 		die "No new revisions were found"
 	fi
-	
+
 	if [ -n "$rejoin" ]; then
 		debug "Merging split branch into HEAD..."
 		latest_old=$(cache_get latest_old)
@@ -645,13 +645,13 @@ cmd_merge()
 {
 	revs=$(git rev-parse $default --revs-only "$@") || exit $?
 	ensure_clean
-	
+
 	set -- $revs
 	if [ $# -ne 1 ]; then
 		die "You must provide exactly one revision.  Got: '$revs'"
 	fi
 	rev="$1"
-	
+
 	if [ -n "$squash" ]; then
 		first_split="$(find_latest_squash "$dir")"
 		if [ -z "$first_split" ]; then
@@ -697,15 +697,15 @@ cmd_pull()
 cmd_push()
 {
 	if [ $# -ne 2 ]; then
-	    die "You must provide <repository> <refspec>"
+		die "You must provide <repository> <refspec>"
 	fi
 	if [ -e "$dir" ]; then
-	    repository=$1
-	    refspec=$2
-	    echo "git push using: " $repository $refspec
-	    git push $repository $(git subtree split --prefix=$prefix):refs/heads/$refspec
+		repository=$1
+		refspec=$2
+		echo "git push using: " $repository $refspec
+		git push $repository $(git subtree split --prefix=$prefix):refs/heads/$refspec
 	else
-	    die "'$dir' must already exist. Try 'git subtree add'."
+		die "'$dir' must already exist. Try 'git subtree add'."
 	fi
 }
 
diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index abdcddb..bb4fd1f 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -4,7 +4,7 @@
 #
 test_description='Basic porcelain support for subtrees
 
-This test verifies the basic operation of the merge, pull, add
+This test verifies the basic operation of the add, pull, merge
 and split subcommands of git subtree.
 '
 
@@ -14,50 +14,73 @@ export TEST_DIRECTORY=$(pwd)/../../../t
 
 create()
 {
-	echo "$1" >"$1"
-	git add "$1"
+    echo "$1" >"$1"
+    git add "$1"
 }
 
+fixnl()
+{
+    t=""
+    while read x; do
+        t="$t$x "
+    done
+    echo $t
+}
 
-check_equal()
+multiline()
 {
-	test_debug 'echo'
-	test_debug "echo \"check a:\" \"{$1}\""
-	test_debug "echo \"      b:\" \"{$2}\""
-	if [ "$1" = "$2" ]; then
-		return 0
-	else
-		return 1
-	fi
+    while read x; do
+        set -- $x
+        for d in "$@"; do
+            echo "$d"
+        done
+    done
 }
 
-fixnl()
+undo()
 {
-	t=""
-	while read x; do
-		t="$t$x "
-	done
-	echo $t
+    git reset --hard HEAD~
 }
 
-multiline()
+test_equal()
 {
-	while read x; do
-		set -- $x
-		for d in "$@"; do
-			echo "$d"
-		done
-	done
+    test_debug 'echo'
+    test_debug "echo \"check a:\" \"{$1}\""
+    test_debug "echo \"      b:\" \"{$2}\""
+    if [ "$1" = "$2" ]; then
+        return 0
+    else
+        return 1
+    fi
 }
 
-undo()
+# Make sure no patch changes more than one file.
+# The original set of commits changed only one file each.
+# A multi-file change would imply that we pruned commits
+# too aggressively.
+join_commits()
 {
-	git reset --hard HEAD~
+    commit=
+    all=
+    while read x y; do
+        if [ -z "$x" ]; then
+            continue
+        elif [ "$x" = "commit:" ]; then
+            if [ -n "$commit" ]; then
+                echo "$commit $all"
+                all=
+            fi
+            commit="$y"
+        else
+            all="$all $y"
+        fi
+    done
+    echo "$commit $all"
 }
 
 last_commit_message()
 {
-	git log --pretty=format:%s -1
+    git log --pretty=format:%s -1
 }
 
 test_expect_success 'init subproj' '
@@ -93,7 +116,7 @@ test_expect_success 'add main4' '
         create main4 &&
         git commit -m "main4" &&
         git branch -m master mainline &&
-        git branch subdir
+        git branch init
 '
 
 test_expect_success 'fetch subproj history' '
@@ -101,40 +124,43 @@ test_expect_success 'fetch subproj history' '
         git branch sub1 FETCH_HEAD
 '
 
-test_expect_success 'no subtree exists in main tree' '
-        test_must_fail git subtree merge --prefix=subdir sub1
-'
-
 test_expect_success 'no pull from non-existant subtree' '
         test_must_fail git subtree pull --prefix=subdir ./subproj sub1
 '
 
-test_expect_success 'check if --message works for add' '
-        git subtree add --prefix=subdir --message="Added subproject" sub1 &&
-        check_equal ''"$(last_commit_message)"'' "Added subproject" &&
+test_expect_success 'no merge from non-existant subtree' '
+        test_must_fail git subtree merge --prefix=subdir FETCH_HEAD
+'
+
+test_expect_success 'add subproj as subtree into subdir/ with --prefix' '
+        git subtree add --prefix=subdir FETCH_HEAD &&
+        test_equal "$(last_commit_message)" "Add '\''subdir/'\'' from commit '\''$(git rev-parse FETCH_HEAD)'\''" &&
         undo
 '
 
-test_expect_success 'check if --message works as -m and --prefix as -P' '
-        git subtree add -P subdir -m "Added subproject using git subtree" sub1 &&
-        check_equal ''"$(last_commit_message)"'' "Added subproject using git subtree" &&
+test_expect_success 'add subproj as subtree into subdir/ with --prefix and --message' '
+        git subtree add --prefix=subdir --message="Added subproject" FETCH_HEAD &&
+        test_equal "$(last_commit_message)" "Added subproject" &&
         undo
 '
 
-test_expect_success 'check if --message works with squash too' '
-        git subtree add -P subdir -m "Added subproject with squash" --squash sub1 &&
-        check_equal ''"$(last_commit_message)"'' "Added subproject with squash" &&
+test_expect_success 'add subproj as subtree into subdir/ with --prefix as -P and --message as -m' '
+        git subtree add -P subdir -m "Added subproject" FETCH_HEAD &&
+        test_equal "$(last_commit_message)" "Added subproject" &&
         undo
 '
 
-test_expect_success 'add subproj to mainline' '
-        git subtree add --prefix=subdir/ FETCH_HEAD &&
-        check_equal ''"$(last_commit_message)"'' "Add '"'subdir/'"' from commit '"'"'''"$(git rev-parse sub1)"'''"'"'"
+test_expect_success 'add subproj as subtree into subdir/ with --squash and --prefix and --message' '
+        git subtree add --prefix=subdir --message="Added subproject with squash" --squash FETCH_HEAD &&
+        test_equal "$(last_commit_message)" "Added subproject with squash" &&
+        undo
 '
 
-# this shouldn't actually do anything, since FETCH_HEAD is already a parent
-test_expect_success 'merge fetched subproj' '
-        git merge -m "merge -s -ours" -s ours FETCH_HEAD
+test_expect_success 'merge the added subproj again, should do nothing' '
+        git subtree add --prefix=subdir FETCH_HEAD &&
+        # this shouldn not actually do anything, since FETCH_HEAD
+        # is already a parent
+        git merge -s ours -m "merge -s -ours" FETCH_HEAD
 '
 
 test_expect_success 'add main-sub5' '
@@ -157,25 +183,30 @@ test_expect_success 'fetch new subproj history' '
         git branch sub2 FETCH_HEAD
 '
 
-test_expect_success 'check if --message works for merge' '
-        git subtree merge --prefix=subdir -m "Merged changes from subproject" sub2 &&
-        check_equal ''"$(last_commit_message)"'' "Merged changes from subproject" &&
+test_expect_success 'merge new subproj history into subdir/ with --prefix' '
+        git subtree merge --prefix=subdir FETCH_HEAD &&
+        test_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\'' into mainline" &&
+        undo
+'
+
+test_expect_success 'merge new subproj history into subdir/ with --prefix and --message' '
+        git subtree merge --prefix=subdir --message="Merged changes from subproject" FETCH_HEAD &&
+        test_equal "$(last_commit_message)" "Merged changes from subproject" &&
         undo
 '
 
-test_expect_success 'check if --message for merge works with squash too' '
-        git subtree merge --prefix subdir -m "Merged changes from subproject using squash" --squash sub2 &&
-        check_equal ''"$(last_commit_message)"'' "Merged changes from subproject using squash" &&
+test_expect_success 'merge new subproj history into subdir/ with --squash and --prefix and --message' '
+        git subtree merge --prefix=subdir --message="Merged changes from subproject using squash" --squash FETCH_HEAD &&
+        test_equal "$(last_commit_message)" "Merged changes from subproject using squash" &&
         undo
 '
 
-test_expect_success 'merge new subproj history into subdir' '
+test_expect_success 'merge new subproj history into subdir/' '
         git subtree merge --prefix=subdir FETCH_HEAD &&
-        git branch pre-split &&
-        check_equal ''"$(last_commit_message)"'' "Merge commit '"'"'"$(git rev-parse sub2)"'"'"' into mainline"
+        git branch pre-split
 '
 
-test_expect_success 'Check that prefix argument is required for split' '
+test_expect_success 'split requires option --prefix' '
         echo "You must provide the --prefix option." > expected &&
         test_must_fail git subtree split > actual 2>&1 &&
         test_debug "echo -n expected: " &&
@@ -186,48 +217,52 @@ test_expect_success 'Check that prefix argument is required for split' '
         rm -f expected actual
 '
 
-test_expect_success 'Check that the <prefix> exists for a split' '
-        echo "'"'"'non-existent-directory'"'"'" does not exist\; use "'"'"'git subtree add'"'"'" > expected &&
+test_expect_success 'split requires path given by option --prefix must exist' '
+        echo "'\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" > expected &&
         test_must_fail git subtree split --prefix=non-existent-directory > actual 2>&1 &&
         test_debug "echo -n expected: " &&
         test_debug "cat expected" &&
         test_debug "echo -n actual: " &&
         test_debug "cat actual" &&
-        test_cmp expected actual
-#        rm -f expected actual
+        test_cmp expected actual &&
+        rm -f expected actual
 '
 
-test_expect_success 'check if --message works for split+rejoin' '
-        spl1=''"$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"'' &&
+test_expect_success 'split subdir/ with --rejoin' '
+        spl1=$(git subtree split --prefix=subdir --annotate="*") &&
         git branch spl1 "$spl1" &&
-        check_equal ''"$(last_commit_message)"'' "Split & rejoin" &&
+        git subtree split --prefix=subdir --annotate="*" --rejoin &&
+        test_equal "$(last_commit_message)" "Split '\''subdir/'\'' into commit '\''$spl1'\''" &&
         undo
 '
 
-test_expect_success 'check split with --branch' '
-        spl1=$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin) &&
+test_expect_success 'split subdir/ with --rejoin and --message' '
+        git subtree split --prefix=subdir --message="Split & rejoin" --annotate="*" --rejoin &&
+        test_equal "$(last_commit_message)" "Split & rejoin" &&
+        undo
+'
+
+test_expect_success 'split subdir/ with --branch' '
+        spl1=$(git subtree split --prefix=subdir --message="Split & rejoin" --annotate="*" --rejoin) &&
         undo &&
-        git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --branch splitbr1 &&
-        check_equal ''"$(git rev-parse splitbr1)"'' "$spl1"
+        git subtree split --prefix=subdir --annotate="*" --branch splitbr1 &&
+        test_equal "$(git rev-parse splitbr1)" "$spl1"
 '
 
-test_expect_success 'check split with --branch for an existing branch' '
-        spl1=''"$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"'' &&
+test_expect_success 'split subdir/ with --branch for an existing branch' '
+        spl1=$(git subtree split --prefix=subdir --annotate="*" --message="Split & rejoin" --rejoin) &&
         undo &&
         git branch splitbr2 sub1 &&
-        git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --branch splitbr2 &&
-        check_equal ''"$(git rev-parse splitbr2)"'' "$spl1"
+        git subtree split --prefix=subdir --annotate="*" --branch splitbr2 &&
+        test_equal "$(git rev-parse splitbr2)" "$spl1"
 '
 
-test_expect_success 'check split with --branch for an incompatible branch' '
-        test_must_fail git subtree split --prefix subdir --onto FETCH_HEAD --branch subdir
+test_expect_success 'split subdir/ with --branch for an incompatible branch' '
+        test_must_fail git subtree split --prefix=subdir --branch init
 '
 
-test_expect_success 'check split+rejoin' '
-        spl1=''"$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"'' &&
-        undo &&
-        git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --rejoin &&
-        check_equal ''"$(last_commit_message)"'' "Split '"'"'subdir/'"'"' into commit '"'"'"$spl1"'"'"'"
+test_expect_success 'split and rejoin' '
+        git subtree split --prefix=subdir --annotate="*" --rejoin
 '
 
 test_expect_success 'add main-sub8' '
@@ -253,8 +288,8 @@ test_expect_success 'add sub9' '
 cd ..
 
 test_expect_success 'split for sub8' '
-        split2=''"$(git subtree split --annotate='"'*'"' --prefix subdir/ --rejoin)"''
-        git branch split2 "$split2"
+        spl2=$(git subtree split --prefix=subdir/ --annotate="*" --rejoin) &&
+        git branch spl2 "$spl2"
 '
 
 test_expect_success 'add main-sub10' '
@@ -263,7 +298,7 @@ test_expect_success 'add main-sub10' '
 '
 
 test_expect_success 'split for sub10' '
-        spl3=''"$(git subtree split --annotate='"'*'"' --prefix subdir --rejoin)"'' &&
+        spl3=$(git subtree split --prefix=subdir --annotate="*" --rejoin) &&
         git branch spl3 "$spl3"
 '
 
@@ -284,13 +319,13 @@ chks="sub1 sub2 sub3 sub9"
 chks_sub=$(echo $chks | multiline | sed 's,^,subdir/,' | fixnl)
 
 test_expect_success 'make sure exactly the right set of files ends up in the subproj' '
-        subfiles=''"$(git ls-files | fixnl)"'' &&
-        check_equal "$subfiles" "$chkms $chks"
+        subfiles=$(git ls-files | fixnl) &&
+        test_equal "$subfiles" "$chkms $chks"
 '
 
-test_expect_success 'make sure the subproj history *only* contains commits that affect the subdir' '
-        allchanges=''"$(git log --name-only --pretty=format:'"''"' | sort | fixnl)"'' &&
-        check_equal "$allchanges" "$chkms $chks"
+test_expect_success 'make sure the subproj *only* contains commits that affect the subdir' '
+        allchanges=$(git log --name-only --pretty=format:"" | sort | fixnl) &&
+        test_equal "$allchanges" "$chkms $chks"
 '
 
 # Back to mainline
@@ -303,25 +338,25 @@ test_expect_success 'pull from subproj' '
 '
 
 test_expect_success 'make sure exactly the right set of files ends up in the mainline' '
-        mainfiles=''"$(git ls-files | fixnl)"'' &&
-        check_equal "$mainfiles" "$chkm $chkms_sub $chks_sub"
+        mainfiles=$(git ls-files | fixnl) &&
+        test_equal "$mainfiles" "$chkm $chkms_sub $chks_sub"
 '
 
 test_expect_success 'make sure each filename changed exactly once in the entire history' '
         # main-sub?? and /subdir/main-sub?? both change, because those are the
         # changes that were split into their own history.  And subdir/sub?? never
         # change, since they were *only* changed in the subtree branch.
-        allchanges=''"$(git log --name-only --pretty=format:'"''"' | sort | fixnl)"'' &&
-        check_equal "$allchanges" ''"$(echo $chkms $chkm $chks $chkms_sub | multiline | sort | fixnl)"''
+        allchanges=$(git log --name-only --pretty=format:"" | sort | fixnl) &&
+        test_equal "$allchanges" "$(echo $chkms $chkm $chks $chkms_sub | multiline | sort | fixnl)"
 '
 
 test_expect_success 'make sure the --rejoin commits never make it into subproj' '
-        check_equal ''"$(git log --pretty=format:'"'%s'"' HEAD^2 | grep -i split)"'' ""
+        test_equal "$(git log --pretty=format:"%s" HEAD^2 | grep -i split)" ""
 '
 
 test_expect_success 'make sure no "git subtree" tagged commits make it into subproj' '
         # They are meaningless to subproj since one side of the merge refers to the mainline
-        check_equal ''"$(git log --pretty=format:'"'%s%n%b'"' HEAD^2 | grep "git-subtree.*:")"'' ""
+        test_equal "$(git log --pretty=format:"%s%n%b" HEAD^2 | grep "git-subtree.*:")" ""
 '
 
 # prepare second pair of repositories
@@ -359,7 +394,7 @@ cd ../main
 test_expect_success 'add sub as subdir in main' '
         git fetch ../sub master &&
         git branch sub2 FETCH_HEAD &&
-        git subtree add --prefix subdir sub2
+        git subtree add --prefix=subdir sub2
 '
 
 cd ../sub
@@ -374,7 +409,7 @@ cd ../main
 test_expect_success 'merge from sub' '
         git fetch ../sub master &&
         git branch sub3 FETCH_HEAD &&
-        git subtree merge --prefix subdir sub3
+        git subtree merge --prefix=subdir sub3
 '
 
 test_expect_success 'add main-sub4' '
@@ -383,7 +418,7 @@ test_expect_success 'add main-sub4' '
 '
 
 test_expect_success 'split for main-sub4 without --onto' '
-        git subtree split --prefix subdir --branch mainsub4
+        git subtree split --prefix=subdir --branch mainsub4
 '
 
 # at this point, the new commit parent should be sub3 if it is not,
@@ -392,7 +427,7 @@ test_expect_success 'split for main-sub4 without --onto' '
 # itself)
 
 test_expect_success 'check that the commit parent is sub3' '
-        check_equal ''"$(git log --pretty=format:%P -1 mainsub4)"'' ''"$(git rev-parse sub3)"''
+        test_equal "$(git log --pretty=format:%P -1 mainsub4)" "$(git rev-parse sub3)"
 '
 
 test_expect_success 'add main-sub5' '
@@ -405,49 +440,23 @@ test_expect_success 'split for main-sub5 without --onto' '
         # also test that we still can split out an entirely new subtree
         # if the parent of the first commit in the tree is not empty,
         # then the new subtree has accidently been attached to something
-        git subtree split --prefix subdir2 --branch mainsub5 &&
-        check_equal ''"$(git log --pretty=format:%P -1 mainsub5)"'' ""
+        git subtree split --prefix=subdir2 --branch mainsub5 &&
+        test_equal "$(git log --pretty=format:%P -1 mainsub5)" ""
 '
 
-# make sure no patch changes more than one file.  The original set of commits
-# changed only one file each.  A multi-file change would imply that we pruned
-# commits too aggressively.
-joincommits()
-{
-	commit=
-	all=
-	while read x y; do
-		#echo "{$x}" >&2
-		if [ -z "$x" ]; then
-			continue
-		elif [ "$x" = "commit:" ]; then
-			if [ -n "$commit" ]; then
-				echo "$commit $all"
-				all=
-			fi
-			commit="$y"
-		else
-			all="$all $y"
-		fi
-	done
-	echo "$commit $all"
-}
-
 test_expect_success 'verify one file change per commit' '
         x= &&
-        list=''"$(git log --pretty=format:'"'commit: %H'"' | joincommits)"'' &&
-#        test_debug "echo HERE" &&
-#        test_debug "echo ''"$list"''" &&
-        (git log --pretty=format:'"'commit: %H'"' | joincommits |
-        (       while read commit a b; do
-		        test_debug "echo Verifying commit "''"$commit"''
-		        test_debug "echo a: "''"$a"''
-		        test_debug "echo b: "''"$b"''
-		        check_equal "$b" ""
-		        x=1
-	        done
-	        check_equal "$x" 1
-        ))
+        git log --pretty=format:"commit: %H" | join_commits |
+        (
+            while read commit a b; do
+                test_debug "echo Verifying commit $commit"
+                test_debug "echo a: $a"
+                test_debug "echo b: $b"
+                test_equal "$b" ""
+                x=1
+            done
+            test_equal "$x" 1
+        )
 '
 
 test_done
-- 
1.8.1

^ permalink raw reply related

* [PATCH/RFC 3/7] contrib/subtree: Remove test number comments
From: Techlive Zheng @ 2013-01-13  1:52 UTC (permalink / raw)
  To: git, gitster; +Cc: apenwarr, greened, Techlive Zheng
In-Reply-To: <1358041958-1998-1-git-send-email-techlivezheng@gmail.com>

From: "David A. Greene" <greened@obbligato.org>

Delete the comments indicating test numbers as it causes maintenance
headaches.  t*.sh -i will help us find any broken tests.

Signed-off-by: David A. Greene <greened@obbligato.org>
Signed-off-by: Techlive Zheng <techlivezheng@gmail.com>
---
 contrib/subtree/t/t7900-subtree.sh | 55 --------------------------------------
 1 file changed, 55 deletions(-)

diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index 3e02aeb..abdcddb 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -60,7 +60,6 @@ last_commit_message()
 	git log --pretty=format:%s -1
 }
 
-# 1
 test_expect_success 'init subproj' '
         test_create_repo subproj
 '
@@ -68,7 +67,6 @@ test_expect_success 'init subproj' '
 # To the subproject!
 cd subproj
 
-# 2
 test_expect_success 'add sub1' '
         create sub1 &&
         git commit -m "sub1" &&
@@ -76,14 +74,12 @@ test_expect_success 'add sub1' '
         git branch -m master subproj
 '
 
-# 3
 test_expect_success 'add sub2' '
         create sub2 &&
         git commit -m "sub2" &&
         git branch sub2
 '
 
-# 4
 test_expect_success 'add sub3' '
         create sub3 &&
         git commit -m "sub3" &&
@@ -93,7 +89,6 @@ test_expect_success 'add sub3' '
 # Back to mainline
 cd ..
 
-# 5
 test_expect_success 'add main4' '
         create main4 &&
         git commit -m "main4" &&
@@ -101,101 +96,85 @@ test_expect_success 'add main4' '
         git branch subdir
 '
 
-# 6
 test_expect_success 'fetch subproj history' '
         git fetch ./subproj sub1 &&
         git branch sub1 FETCH_HEAD
 '
 
-# 7
 test_expect_success 'no subtree exists in main tree' '
         test_must_fail git subtree merge --prefix=subdir sub1
 '
 
-# 8
 test_expect_success 'no pull from non-existant subtree' '
         test_must_fail git subtree pull --prefix=subdir ./subproj sub1
 '
 
-# 9
 test_expect_success 'check if --message works for add' '
         git subtree add --prefix=subdir --message="Added subproject" sub1 &&
         check_equal ''"$(last_commit_message)"'' "Added subproject" &&
         undo
 '
 
-# 10
 test_expect_success 'check if --message works as -m and --prefix as -P' '
         git subtree add -P subdir -m "Added subproject using git subtree" sub1 &&
         check_equal ''"$(last_commit_message)"'' "Added subproject using git subtree" &&
         undo
 '
 
-# 11
 test_expect_success 'check if --message works with squash too' '
         git subtree add -P subdir -m "Added subproject with squash" --squash sub1 &&
         check_equal ''"$(last_commit_message)"'' "Added subproject with squash" &&
         undo
 '
 
-# 12
 test_expect_success 'add subproj to mainline' '
         git subtree add --prefix=subdir/ FETCH_HEAD &&
         check_equal ''"$(last_commit_message)"'' "Add '"'subdir/'"' from commit '"'"'''"$(git rev-parse sub1)"'''"'"'"
 '
 
-# 13
 # this shouldn't actually do anything, since FETCH_HEAD is already a parent
 test_expect_success 'merge fetched subproj' '
         git merge -m "merge -s -ours" -s ours FETCH_HEAD
 '
 
-# 14
 test_expect_success 'add main-sub5' '
         create subdir/main-sub5 &&
         git commit -m "main-sub5"
 '
 
-# 15
 test_expect_success 'add main6' '
         create main6 &&
         git commit -m "main6 boring"
 '
 
-# 16
 test_expect_success 'add main-sub7' '
         create subdir/main-sub7 &&
         git commit -m "main-sub7"
 '
 
-# 17
 test_expect_success 'fetch new subproj history' '
         git fetch ./subproj sub2 &&
         git branch sub2 FETCH_HEAD
 '
 
-# 18
 test_expect_success 'check if --message works for merge' '
         git subtree merge --prefix=subdir -m "Merged changes from subproject" sub2 &&
         check_equal ''"$(last_commit_message)"'' "Merged changes from subproject" &&
         undo
 '
 
-# 19
 test_expect_success 'check if --message for merge works with squash too' '
         git subtree merge --prefix subdir -m "Merged changes from subproject using squash" --squash sub2 &&
         check_equal ''"$(last_commit_message)"'' "Merged changes from subproject using squash" &&
         undo
 '
 
-# 20
 test_expect_success 'merge new subproj history into subdir' '
         git subtree merge --prefix=subdir FETCH_HEAD &&
         git branch pre-split &&
         check_equal ''"$(last_commit_message)"'' "Merge commit '"'"'"$(git rev-parse sub2)"'"'"' into mainline"
 '
 
-# 21
 test_expect_success 'Check that prefix argument is required for split' '
         echo "You must provide the --prefix option." > expected &&
         test_must_fail git subtree split > actual 2>&1 &&
@@ -207,7 +186,6 @@ test_expect_success 'Check that prefix argument is required for split' '
         rm -f expected actual
 '
 
-# 22
 test_expect_success 'Check that the <prefix> exists for a split' '
         echo "'"'"'non-existent-directory'"'"'" does not exist\; use "'"'"'git subtree add'"'"'" > expected &&
         test_must_fail git subtree split --prefix=non-existent-directory > actual 2>&1 &&
@@ -219,7 +197,6 @@ test_expect_success 'Check that the <prefix> exists for a split' '
 #        rm -f expected actual
 '
 
-# 23
 test_expect_success 'check if --message works for split+rejoin' '
         spl1=''"$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"'' &&
         git branch spl1 "$spl1" &&
@@ -227,7 +204,6 @@ test_expect_success 'check if --message works for split+rejoin' '
         undo
 '
 
-# 24
 test_expect_success 'check split with --branch' '
         spl1=$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin) &&
         undo &&
@@ -235,7 +211,6 @@ test_expect_success 'check split with --branch' '
         check_equal ''"$(git rev-parse splitbr1)"'' "$spl1"
 '
 
-# 25
 test_expect_success 'check split with --branch for an existing branch' '
         spl1=''"$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"'' &&
         undo &&
@@ -244,13 +219,10 @@ test_expect_success 'check split with --branch for an existing branch' '
         check_equal ''"$(git rev-parse splitbr2)"'' "$spl1"
 '
 
-# 26
 test_expect_success 'check split with --branch for an incompatible branch' '
         test_must_fail git subtree split --prefix subdir --onto FETCH_HEAD --branch subdir
 '
 
-
-# 27
 test_expect_success 'check split+rejoin' '
         spl1=''"$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"'' &&
         undo &&
@@ -258,7 +230,6 @@ test_expect_success 'check split+rejoin' '
         check_equal ''"$(last_commit_message)"'' "Split '"'"'subdir/'"'"' into commit '"'"'"$spl1"'"'"'"
 '
 
-# 28
 test_expect_success 'add main-sub8' '
         create subdir/main-sub8 &&
         git commit -m "main-sub8"
@@ -267,14 +238,12 @@ test_expect_success 'add main-sub8' '
 # To the subproject!
 cd ./subproj
 
-# 29
 test_expect_success 'merge split into subproj' '
         git fetch .. spl1 &&
         git branch spl1 FETCH_HEAD &&
         git merge FETCH_HEAD
 '
 
-# 30
 test_expect_success 'add sub9' '
         create sub9 &&
         git commit -m "sub9"
@@ -283,19 +252,16 @@ test_expect_success 'add sub9' '
 # Back to mainline
 cd ..
 
-# 31
 test_expect_success 'split for sub8' '
         split2=''"$(git subtree split --annotate='"'*'"' --prefix subdir/ --rejoin)"''
         git branch split2 "$split2"
 '
 
-# 32
 test_expect_success 'add main-sub10' '
         create subdir/main-sub10 &&
         git commit -m "main-sub10"
 '
 
-# 33
 test_expect_success 'split for sub10' '
         spl3=''"$(git subtree split --annotate='"'*'"' --prefix subdir --rejoin)"'' &&
         git branch spl3 "$spl3"
@@ -304,7 +270,6 @@ test_expect_success 'split for sub10' '
 # To the subproject!
 cd ./subproj
 
-# 34
 test_expect_success 'merge split into subproj' '
         git fetch .. spl3 &&
         git branch spl3 FETCH_HEAD &&
@@ -318,13 +283,11 @@ chkms_sub=$(echo $chkms | multiline | sed 's,^,subdir/,' | fixnl)
 chks="sub1 sub2 sub3 sub9"
 chks_sub=$(echo $chks | multiline | sed 's,^,subdir/,' | fixnl)
 
-# 35
 test_expect_success 'make sure exactly the right set of files ends up in the subproj' '
         subfiles=''"$(git ls-files | fixnl)"'' &&
         check_equal "$subfiles" "$chkms $chks"
 '
 
-# 36
 test_expect_success 'make sure the subproj history *only* contains commits that affect the subdir' '
         allchanges=''"$(git log --name-only --pretty=format:'"''"' | sort | fixnl)"'' &&
         check_equal "$allchanges" "$chkms $chks"
@@ -333,20 +296,17 @@ test_expect_success 'make sure the subproj history *only* contains commits that
 # Back to mainline
 cd ..
 
-# 37
 test_expect_success 'pull from subproj' '
         git fetch ./subproj subproj-merge-spl3 &&
         git branch subproj-merge-spl3 FETCH_HEAD &&
         git subtree pull --prefix=subdir ./subproj subproj-merge-spl3
 '
 
-# 38
 test_expect_success 'make sure exactly the right set of files ends up in the mainline' '
         mainfiles=''"$(git ls-files | fixnl)"'' &&
         check_equal "$mainfiles" "$chkm $chkms_sub $chks_sub"
 '
 
-# 39
 test_expect_success 'make sure each filename changed exactly once in the entire history' '
         # main-sub?? and /subdir/main-sub?? both change, because those are the
         # changes that were split into their own history.  And subdir/sub?? never
@@ -355,12 +315,10 @@ test_expect_success 'make sure each filename changed exactly once in the entire
         check_equal "$allchanges" ''"$(echo $chkms $chkm $chks $chkms_sub | multiline | sort | fixnl)"''
 '
 
-# 40
 test_expect_success 'make sure the --rejoin commits never make it into subproj' '
         check_equal ''"$(git log --pretty=format:'"'%s'"' HEAD^2 | grep -i split)"'' ""
 '
 
-# 41
 test_expect_success 'make sure no "git subtree" tagged commits make it into subproj' '
         # They are meaningless to subproj since one side of the merge refers to the mainline
         check_equal ''"$(git log --pretty=format:'"'%s%n%b'"' HEAD^2 | grep "git-subtree.*:")"'' ""
@@ -370,14 +328,12 @@ test_expect_success 'make sure no "git subtree" tagged commits make it into subp
 mkdir test2
 cd test2
 
-# 42
 test_expect_success 'init main' '
         test_create_repo main
 '
 
 cd main
 
-# 43
 test_expect_success 'add main1' '
         create main1 &&
         git commit -m "main1"
@@ -385,14 +341,12 @@ test_expect_success 'add main1' '
 
 cd ..
 
-# 44
 test_expect_success 'init sub' '
         test_create_repo sub
 '
 
 cd sub
 
-# 45
 test_expect_success 'add sub2' '
         create sub2 &&
         git commit -m "sub2"
@@ -402,7 +356,6 @@ cd ../main
 
 # check if split can find proper base without --onto
 
-# 46
 test_expect_success 'add sub as subdir in main' '
         git fetch ../sub master &&
         git branch sub2 FETCH_HEAD &&
@@ -411,7 +364,6 @@ test_expect_success 'add sub as subdir in main' '
 
 cd ../sub
 
-# 47
 test_expect_success 'add sub3' '
         create sub3 &&
         git commit -m "sub3"
@@ -419,20 +371,17 @@ test_expect_success 'add sub3' '
 
 cd ../main
 
-# 48
 test_expect_success 'merge from sub' '
         git fetch ../sub master &&
         git branch sub3 FETCH_HEAD &&
         git subtree merge --prefix subdir sub3
 '
 
-# 49
 test_expect_success 'add main-sub4' '
         create subdir/main-sub4 &&
         git commit -m "main-sub4"
 '
 
-# 50
 test_expect_success 'split for main-sub4 without --onto' '
         git subtree split --prefix subdir --branch mainsub4
 '
@@ -442,19 +391,16 @@ test_expect_success 'split for main-sub4 without --onto' '
 # have been sub3, but it was not, because its cache was not set to
 # itself)
 
-# 51
 test_expect_success 'check that the commit parent is sub3' '
         check_equal ''"$(git log --pretty=format:%P -1 mainsub4)"'' ''"$(git rev-parse sub3)"''
 '
 
-# 52
 test_expect_success 'add main-sub5' '
         mkdir subdir2 &&
         create subdir2/main-sub5 &&
         git commit -m "main-sub5"
 '
 
-# 53
 test_expect_success 'split for main-sub5 without --onto' '
         # also test that we still can split out an entirely new subtree
         # if the parent of the first commit in the tree is not empty,
@@ -487,7 +433,6 @@ joincommits()
 	echo "$commit $all"
 }
 
-# 54
 test_expect_success 'verify one file change per commit' '
         x= &&
         list=''"$(git log --pretty=format:'"'commit: %H'"' | joincommits)"'' &&
-- 
1.8.1

^ permalink raw reply related

* [PATCH/RFC 2/7] contrib/subtree: Ignore testing directory
From: Techlive Zheng @ 2013-01-13  1:52 UTC (permalink / raw)
  To: git, gitster; +Cc: apenwarr, greened, Techlive Zheng
In-Reply-To: <1358041958-1998-1-git-send-email-techlivezheng@gmail.com>

Signed-off-by: Techlive Zheng <techlivezheng@gmail.com>
---
 contrib/subtree/.gitignore | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/contrib/subtree/.gitignore b/contrib/subtree/.gitignore
index 91360a3..59aeeb4 100644
--- a/contrib/subtree/.gitignore
+++ b/contrib/subtree/.gitignore
@@ -1,6 +1,5 @@
 *~
 git-subtree
-git-subtree.xml
 git-subtree.1
-mainline
-subproj
+git-subtree.xml
+t/trash\ directory.*
-- 
1.8.1

^ permalink raw reply related

* [PATCH/RFC 1/7] contrib/subtree: Add vim modeline
From: Techlive Zheng @ 2013-01-13  1:52 UTC (permalink / raw)
  To: git, gitster; +Cc: apenwarr, greened, Techlive Zheng
In-Reply-To: <1358041958-1998-1-git-send-email-techlivezheng@gmail.com>

Signed-off-by: Techlive Zheng <techlivezheng@gmail.com>
---
 contrib/subtree/git-subtree.sh     | 2 ++
 contrib/subtree/t/t7900-subtree.sh | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 920c664..138e1e0 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -710,3 +710,5 @@ cmd_push()
 }
 
 "cmd_$command" "$@"
+
+# vim: set ts=4 sw=4 noet
diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index bc2eeb0..3e02aeb 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -506,3 +506,5 @@ test_expect_success 'verify one file change per commit' '
 '
 
 test_done
+
+# vim: set et ts=4 sw=4
-- 
1.8.1

^ permalink raw reply related

* [PATCH/RFC 0/7] mutiple improvements
From: Techlive Zheng @ 2013-01-13  1:52 UTC (permalink / raw)
  To: git, gitster; +Cc: apenwarr, greened, Techlive Zheng

* refactor tests for 'git subtree'
  * rearrange some tests
  * clean up unnecessary quotes
  * make each test self-contained
* keep commit intact after the split by using '%B'
* handle '--prefix' argument with slash appended correctly

David A. Greene (1):
  contrib/subtree: Remove test number comments

Techlive Zheng (6):
  contrib/subtree: Add vim modeline
  contrib/subtree: Ignore testing directory
  contrib/subtree: Code cleaning and refactoring
  contrib/subtree: Make each test self-contained
  contrib/subtree: Use %B for the split commit message
  contrib/subtree: Handle '--prefix' argument with a slash appended

 contrib/subtree/.gitignore         |    5 +-
 contrib/subtree/git-subtree.sh     |   83 ++-
 contrib/subtree/git-subtree.txt    |   13 +
 contrib/subtree/t/t7900-subtree.sh | 1233 +++++++++++++++++++++++-------------
 4 files changed, 872 insertions(+), 462 deletions(-)

-- 
1.8.1

^ permalink raw reply

* Re: missing objects -- prevention
From: Sitaram Chamarty @ 2013-01-13  0:57 UTC (permalink / raw)
  To: Jeff King; +Cc: Git Mailing List
In-Reply-To: <CAMK1S_iKARYqi_Dv90og0No7NN=WxFg+ixmRvnkvfdrcOi1r=Q@mail.gmail.com>

Uggh...

On Sun, Jan 13, 2013 at 6:26 AM, Sitaram Chamarty <sitaramc@gmail.com> wrote:

> the object store -- the old ones were not dereferenced).

I meant *un* referenced of course :)

^ permalink raw reply

* Re: missing objects -- prevention
From: Sitaram Chamarty @ 2013-01-13  0:56 UTC (permalink / raw)
  To: Jeff King; +Cc: Git Mailing List
In-Reply-To: <20130112131358.GB21875@sigill.intra.peff.net>

On Sat, Jan 12, 2013 at 6:43 PM, Jeff King <peff@peff.net> wrote:
> On Sat, Jan 12, 2013 at 06:39:52AM +0530, Sitaram Chamarty wrote:
>
>> >   1. The repo has a ref R pointing at commit X.
>> >
>> >   2. A user starts a push to another ref, Q, of commit Y that builds on
>> >      X. Git advertises ref R, so the sender knows they do not need to
>> >      send X, but only Y. The user then proceeds to send the packfile
>> >      (which might take a very long time).
>> >
>> >   3. Meanwhile, another user deletes ref R. X becomes unreferenced.
>>
>> The gitolite logs show that no deletion of refs has happened.
>
> To be pedantic, step 3 could also be rewinding R to a commit before X.
> Anything that causes X to become unreferenced.

Right, but there were no rewinds also; I should have mentioned that.
(Gitolite log files mark rewinds and deletes specially, so they're
easy to search.  There were two attempted rewinds but they failed the
gitolite update hook so -- while the new objects would have landed in
the object store -- the old ones were not dereferenced).

>> > There is a race with simultaneously deleting and packing refs. It
>> > doesn't cause object db corruption, but it will cause refs to "rewind"
>> > back to their packed versions. I have seen that one in practice (though
>> > relatively rare). I fixed it in b3f1280, which is not yet in any
>> > released version.
>>
>> This is for the packed-refs file right?  And it could result in a ref
>> getting deleted right?
>
> Yes, if the ref was not previously packed, it could result in the ref
> being deleted entirely.
>
>> I said above that the gitolite logs say no ref was deleted.  What if
>> the ref "deletion" happened because of this race, making the rest of
>> your 4-step scenario above possible?
>
> It's possible. I do want to highlight how unlikely it is, though.

Agreed.

>> > up in the middle, or fsck rejects the pack). We have historically left
>>
>> fsck... you mean if I had 'receive.fsckObjects' true, right?  I don't.
>>  Should I?  Would it help this overall situation?  As I understand it,
>> thats only about the internals of each object to check corruption, and
>> cannot detect a *missing* object on the local object store.
>
> Right, I meant if you have receive.fsckObjects on. It won't help this
> situation at all, as we already do a connectivity check separate from
> the fsck. But I do recommend it in general, just because it helps catch
> bad objects before they gets disseminated to a wider audience (at which
> point it is often infeasible to rewind history). And it has found git
> bugs (e.g., null sha1s in tree entries).

I will add this.  Any idea if there's a significant performance hit?

>> > At GitHub, we've taken to just cleaning them up aggressively (I think
>> > after an hour), though I am tempted to put in an optional signal/atexit
>>
>> OK; I'll do the same then.  I suppose a cron job is the best way; I
>> didn't find any config for expiring these files.
>
> If you run "git prune --expire=1.hour.ago", it should prune stale
> tmp_pack_* files more than an hour old. But you may not be comfortable
> with such a short expiration for the objects themselves. :)
>
>> Thanks again for your help.  I'm going to treat it (for now) as a
>> disk/fs error after hearing from you about the other possibility I
>> mentioned above, although I find it hard to believe one repo can be
>> hit buy *two* races occurring together!
>
> Yeah, the race seems pretty unlikely (though it could be just the one
> race with a rewind). As I said, I haven't actually ever seen it in
> practice. In my experience, though, disk/fs issues do not manifest as
> just missing objects, but as corrupted packfiles (e.g., the packfile
> directory entry ends up pointing to the wrong inode, which is easy to
> see because the inode's content is actually a reflog). And then of
> course with the packfile unreadable, you have missing objects. But YMMV,
> depending on the fs and what's happened to the machine to cause the fs
> problem.

That's always the hard part.  System admins (at the Unix level) insist
there's nothing wrong and no disk errors and so on...  that is why I
was interested in network errors causing problems and so on.

Anyway, now that I know the tmp_pack_* files are caused mostly by
failed pushes than by failed auto-gc, at least I can deal with the
immediate problem easily!

Thanks once again for your patient replies!

sitaram


-- 
Sitaram

^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox