Git development
 help / color / mirror / Atom feed
* [PATCH 1/2] add: update pathless 'add [-u|-A]' warning to reflect change of plan
From: Matthieu Moy @ 2013-03-11  8:01 UTC (permalink / raw)
  To: git, gitster; +Cc: Matthieu Moy
In-Reply-To: <vpqk3pefjs4.fsf@grenoble-inp.fr>

We originally thought the transition would need a period where "git add
[-u|-A]" without pathspec would be forbidden, but the warning is big
enough to scare people and teach them not to use it (or, if so, to
understand the consequences).

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
 builtin/add.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/builtin/add.c b/builtin/add.c
index 0dd014e..ab1c9e8 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -328,9 +328,9 @@ static void warn_pathless_add(const char *option_name, const char *short_name) {
 	 * this is not the original behavior and can't be
 	 * changed until users trained themselves not to type
 	 * "git add -u" or "git add -A". For now, we warn and
-	 * keep the old behavior. Later, this warning can be
-	 * turned into a die(...), and eventually we may
-	 * reallow the command with a new behavior.
+	 * keep the old behavior. Later, the behavior can be changed
+	 * to tree-wide, keeping the warning for a while, and
+	 * eventually we can drop the warning.
 	 */
 	warning(_("The behavior of 'git add %s (or %s)' with no path argument from a\n"
 		  "subdirectory of the tree will change in Git 2.0 and should not be used anymore.\n"
-- 
1.8.2.rc3.16.g0a33571.dirty

^ permalink raw reply related

* Re: [PATCH 1/2] require pathspec for "git add -u/-A"
From: Matthieu Moy @ 2013-03-11  8:00 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Jeff King
In-Reply-To: <7vboaqbeou.fsf@alter.siamese.dyndns.org>

Junio C Hamano <gitster@pobox.com> writes:

> So let's squash these two steps into one and keep that in 'next'
> until 2.0 ships.

OK, then we may update the comment describing the plan (for people
digging in the code to find out what the plan is). Small patch serie
follows with this (will probably give conflict with your patch, feel
free to drop if resolving them is too painful given the benefit) and
another minor improvement.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

^ permalink raw reply

* Re: [PATCH 1/2] require pathspec for "git add -u/-A"
From: Junio C Hamano @ 2013-03-11  7:04 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: git, Jeff King
In-Reply-To: <vpqmwubgsqy.fsf@grenoble-inp.fr>

Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:

> Junio C Hamano <gitster@pobox.com> writes:
>
>> As promised in 0fa2eb530fb7 (add: warn when -u or -A is used without
>> pathspec, 2013-01-28), "git add -u/-A" that is run without pathspec
>> in a subdirectory will stop working sometime before Git 2.0, to wean
>> users off of the old default, in preparation for adopting the new
>> default in Git 2.0.
>
> I originally thought this step was necessary, but I changed my mind. The
> warning is big enough and doesn't need to be turned into an error.

I tend to agree.

The plan requires the warning to be big enough and warning period to
be long enough so that by the time Git 2.0 is released, no existing
users will run "git add -u/-A" without pathspec expecting it to
limit the operation to the current directory, so an extra step to
error out such a command invocation is simply redundant.  If it is
not redundant, that would only mean that the warning period was not
long enough.  The only effect the extra "error it out" step would
have is to hurt the people who jump on Git bandwagon after such
release ships, as they do not have any reason to retrain their
fingers---they instead can just get used to the new behaviour right
away.

So let's squash these two steps into one and keep that in 'next'
until 2.0 ships.

Thanks for an injection of sanity.

^ permalink raw reply

* Re: [PATCH 0/2] fix git-archive with empty trees
From: Junio C Hamano @ 2013-03-11  5:25 UTC (permalink / raw)
  To: Jeff King; +Cc: git, René Scharfe
In-Reply-To: <20130311045811.GA13510@sigill.intra.peff.net>

Jeff King <peff@peff.net> writes:

> On Sun, Mar 10, 2013 at 09:31:24PM -0400, Jeff King wrote:
>
>> I noticed that "git archive" will barf when the root tree is empty.
>> [...]
>> I didn't bother even looking at empty subtrees. AFAIK, git should never
>> produce them (it omits the tree entirely if there is no content in it).
>> You would have to fake it using hash-object manually. I suspect it would
>> work just fine, as we already exercise the empty-dir code paths in the
>> tests I did add.
>
> Curious, I went ahead and tested this. It does indeed work as expected.

Interesting.

> The following tests can be squashed into patch 2/2 if we want:

Why not---will do.  Thanks.

> diff --git a/t/t5004-archive-corner-cases.sh b/t/t5004-archive-corner-cases.sh
> index 395dd58..cdb7d7a 100755
> --- a/t/t5004-archive-corner-cases.sh
> +++ b/t/t5004-archive-corner-cases.sh
> @@ -80,4 +80,23 @@ test_expect_success 'archive complains about pathspec on empty tree' '
>  	test_must_fail git archive --format=tar HEAD -- foo >/dev/null
>  '
>  
> +test_expect_success 'create a commit with an empty subtree' '
> +	empty_tree=$(git hash-object -t tree /dev/null) &&
> +	root_tree=$(printf "040000 tree $empty_tree\tsub\n" | git mktree)
> +'
> +
> +test_expect_success 'archive empty subtree with no pathspec' '
> +	git archive --format=tar $root_tree >subtree-all.tar &&
> +	make_dir extract &&
> +	"$TAR" xf subtree-all.tar -C extract &&
> +	check_dir extract sub
> +'
> +
> +test_expect_success 'archive empty subtree by direct pathspec' '
> +	git archive --format=tar $root_tree -- sub >subtree-path.tar &&
> +	make_dir extract &&
> +	"$TAR" xf subtree-path.tar -C extract &&
> +	check_dir extract sub
> +'
> +
>  test_done

^ permalink raw reply

* Re: Memory corruption when rebasing with git version 1.8.1.5 on arch
From: Jeff King @ 2013-03-11  5:18 UTC (permalink / raw)
  To: Bernhard Posselt; +Cc: git
In-Reply-To: <513C7267.2090608@bernhard-posselt.com>

On Sun, Mar 10, 2013 at 12:45:43PM +0100, Bernhard Posselt wrote:

> >   valgrind -q --trace-children=yes --log-file=/tmp/valgrind.out \
> >     git pull --rebase https://github.com/Raydiation/core
> 
> The log file was empty and it seemed to apply everything nice when
> running valgrind. When i tried to run it without valgrind it failed
> with memory corruption.

Thanks, we are maybe getting closer. It's weird that it works OK with
valgrind. If the valgrind log is empty, though, I'm confused about where
the output you pasted below came from.

> ==22291== Invalid write of size 1
> ==22291==    at 0x4C2DB93: memcpy@@GLIBC_2.14 (in
> /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
> ==22291==    by 0x4076B1: update_pre_post_images (in /usr/lib/git-core/git)
> ==22291==    by 0x40A60F: apply_fragments (in /usr/lib/git-core/git)
> ==22291==    by 0x40C29F: check_patch_list (in /usr/lib/git-core/git)
> ==22291==    by 0x40CC35: apply_patch (in /usr/lib/git-core/git)
> ==22291==    by 0x40F584: cmd_apply (in /usr/lib/git-core/git)
> ==22291==    by 0x4058E7: handle_internal_command (in /usr/lib/git-core/git)
> ==22291==    by 0x404DD1: main (in /usr/lib/git-core/git)

Hmm, it would be nice to have line numbers. Can you try compiling with
"-g -O0"?

The function where the problem is deals with whitespace munging. Just a
guess, but do you have any whitespace config options set (e.g.,
apply.whitespace)?

-Peff

^ permalink raw reply

* Re: [PATCH v2 05/23] contrib/subtree: Add commands pull_all and push_all
From: Junio C Hamano @ 2013-03-11  5:03 UTC (permalink / raw)
  To: Paul Campbell
  Cc: git, David Greene, bibendi, Peter Jaros, Avery Pennarun,
	Win Treese, Wayne Walter
In-Reply-To: <1362958891-26941-6-git-send-email-pcampbell@kemitix.net>

Paul Campbell <pcampbell@kemitix.net> writes:

> From: bibendi <bibendi@bk.ru>
>
> For each subtree listed in .gittrees perform a push or a pull.
>
> Signed-off-by: Paul Campbell <pcampbell@kemitix.net>
>
> Conflicts:
> 	contrib/subtree/git-subtree.sh

The "Conflicts:" part is totally irrelevant.  Please remove.

> ---
>  contrib/subtree/git-subtree.sh | 25 ++++++++++++++++++++++---
>  1 file changed, 22 insertions(+), 3 deletions(-)
>
> diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
> index 1aff956..ddae56e 100755
> --- a/contrib/subtree/git-subtree.sh
> +++ b/contrib/subtree/git-subtree.sh
> @@ -12,6 +12,7 @@ git subtree add   --prefix=<prefix> <commit>
>  git subtree add   --prefix=<prefix> <repository> <commit>
>  git subtree merge --prefix=<prefix> <commit>
>  git subtree pull  --prefix=<prefix> <repository> <refspec...>
> +git subtree pull_all

Why isn't it "pull --all"?

>  git subtree push  --prefix=<prefix> <repository> <refspec...>

Where did "push_all" go?

> +cmd_pull_all()
> +{
> +    git config -f .gittrees -l | grep subtree | grep path | grep -o '=.*' | grep -o '[^=].*' |

"grep -o" is not even in POSIX.  Besides, what is this trying to
parse?  Is it expected to match lines like

	path.subtree=trash

with this, or is it more like you only want something like this:

	subtree.over/there.path=foo

in which case you would want to read with something like

	sed -n -e 's/^subtree\...*\.path=\(.*\)/\1/p'

instead (modulo the usual caveat on $IFS whitespaces in path)?

> +        while read path; do
> +            git subtree pull -P $path master || exit $?
> +        done
> +}

I'd stop looking at this series myself at this step for now.

^ permalink raw reply

* Re: [PATCH 0/2] fix git-archive with empty trees
From: Jeff King @ 2013-03-11  4:58 UTC (permalink / raw)
  To: git; +Cc: René Scharfe
In-Reply-To: <20130311013123.GA11692@sigill.intra.peff.net>

On Sun, Mar 10, 2013 at 09:31:24PM -0400, Jeff King wrote:

> I noticed that "git archive" will barf when the root tree is empty.
> [...]
> I didn't bother even looking at empty subtrees. AFAIK, git should never
> produce them (it omits the tree entirely if there is no content in it).
> You would have to fake it using hash-object manually. I suspect it would
> work just fine, as we already exercise the empty-dir code paths in the
> tests I did add.

Curious, I went ahead and tested this. It does indeed work as expected.
The following tests can be squashed into patch 2/2 if we want:

diff --git a/t/t5004-archive-corner-cases.sh b/t/t5004-archive-corner-cases.sh
index 395dd58..cdb7d7a 100755
--- a/t/t5004-archive-corner-cases.sh
+++ b/t/t5004-archive-corner-cases.sh
@@ -80,4 +80,23 @@ test_expect_success 'archive complains about pathspec on empty tree' '
 	test_must_fail git archive --format=tar HEAD -- foo >/dev/null
 '
 
+test_expect_success 'create a commit with an empty subtree' '
+	empty_tree=$(git hash-object -t tree /dev/null) &&
+	root_tree=$(printf "040000 tree $empty_tree\tsub\n" | git mktree)
+'
+
+test_expect_success 'archive empty subtree with no pathspec' '
+	git archive --format=tar $root_tree >subtree-all.tar &&
+	make_dir extract &&
+	"$TAR" xf subtree-all.tar -C extract &&
+	check_dir extract sub
+'
+
+test_expect_success 'archive empty subtree by direct pathspec' '
+	git archive --format=tar $root_tree -- sub >subtree-path.tar &&
+	make_dir extract &&
+	"$TAR" xf subtree-path.tar -C extract &&
+	check_dir extract sub
+'
+
 test_done

^ permalink raw reply related

* Re: [PATCH v2 04/23] contrib/subtree: Teach push and pull to use .gittrees for defaults
From: Junio C Hamano @ 2013-03-11  3:35 UTC (permalink / raw)
  To: Paul Campbell; +Cc: git, David Greene, bibendi, Avery Pennarun, Wayne Walter
In-Reply-To: <1362958891-26941-5-git-send-email-pcampbell@kemitix.net>

> From: bibendi <bibendi@bk.ru>
>
> Look in the config file .gittrees for a default repository and
> refspec or commit when they are not provided on the command line.
>
> Uses the .gittrees config file in a similar way to how git-submodule
> uses the .gitmodules file.

What the patch does can be read from the code, but what benefit
would users get by the extra file?

>  cmd_pull()
>  {
> -	ensure_clean
> -	git fetch "$@" || exit $?
> -	revs=FETCH_HEAD
> -	set -- $revs
> -	cmd_merge "$@"
> +    if [ $# -ne 1 ]; then

Broken indentation?

> +	    die "You must provide <branch>"
> +	fi

It used to allow "git fetch $there" and let the configured
remote.$there.fetch refspec to decide what gets fetched, and also it
used to allow "git fetch $there $that_branch" to explicitly fetch
the named branch.  But this change insists that the user has to give
what gets fetched from the command line and forbids the user from
giving where to fetch from, it seems.  Isn't it a regression?  Why
is it a good idea to forbid such uses that the script used to
accept?

The proposed log message does not explain why it is not a
regression, or why accepting some use patterns that the script used
to allow was a bug that needs to be diagnosed with this new
conditional.

> +	if [ -e "$dir" ]; then
> +	    ensure_clean
> +	    repository=$(git config -f .gittrees subtree.$prefix.url)
> +	    refspec=$1
> +	    git fetch $repository $refspec || exit $?
> +	    echo "git fetch using: " $repository $refspec

Why are these variable references outside the dq pair?

^ permalink raw reply

* Re: [PATCH v2 03/23] contrib/subtree: Teach add to store repository & branch in .gittrees
From: Junio C Hamano @ 2013-03-11  3:24 UTC (permalink / raw)
  To: Paul Campbell; +Cc: git, David Greene, Matt Hoffman, Wayne Walter
In-Reply-To: <1362958891-26941-4-git-send-email-pcampbell@kemitix.net>

Paul Campbell <pcampbell@kemitix.net> writes:

> From: Matt Hoffman <matt.hoffman@quantumretail.com>
>
> The repository and branch of a subtree added with the add command is
> stored in the .gittrees file.
>
> Signed-off-by: Paul Campbell <pcampbell@kemitix.net>
> ---
>  contrib/subtree/git-subtree.sh | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
> index caf4988..7b70251 100755
> --- a/contrib/subtree/git-subtree.sh
> +++ b/contrib/subtree/git-subtree.sh
> @@ -528,6 +528,14 @@ cmd_add_repository()
>  	revs=FETCH_HEAD
>  	set -- $revs
>  	cmd_add_commit "$@"
> +  
> +  # now add it to our list of repos 
> +  git config -f .gittrees --unset subtree.$dir.url
> +  git config -f .gittrees --add subtree.$dir.url $repository
> +  git config -f .gittrees --unset subtree.$dir.path
> +  git config -f .gittrees --add subtree.$dir.path $dir
> +  git config -f .gittrees --unset subtree.$dir.branch
> +  git config -f .gittrees --add subtree.$dir.branch $refspec

Existing code in the function this touches seem to be written
carefully to allow $IFS whitespace in $dir, but this change butchers
it, it seems.

Also, where does $refspec come from?  When this is called from
cmd_add_repository(), there is an assignment to the variable, but it
is not all clear.  As git-subtree declares it won't work with
anything but bash, I think things like this should take advantage of
being written for bash by using "local" and passing arguments
explicitly instead of relying on global variables, which POSIX shell
scripts cannot afford to do but bash scripts can.

>  }
>  
>  cmd_add_commit()

^ permalink raw reply

* Re: [PATCH v2 02/23] contrib/subtree: Add command from-submodule
From: Junio C Hamano @ 2013-03-11  3:19 UTC (permalink / raw)
  To: Paul Campbell
  Cc: git, David Greene, Peter Jaros, Avery Pennarun, Wayne Walter
In-Reply-To: <1362958891-26941-3-git-send-email-pcampbell@kemitix.net>

Paul Campbell <pcampbell@kemitix.net> writes:

> @@ -721,4 +722,31 @@ cmd_push()
>  	fi
>  }
>  
> +cmd_from-submodule()
> +{

I know contrib/subtree does not work with anything other than bash,
and bash may accept this as a valid function name, but if you can
avoid it easily I would prefer not to see a non-POSIX construct like
this in my tree, even in contrib/ part:

  http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_230

because people often reference random parts of the tree and mimick
what existing code does.

> +	ensure_clean
> +
> +	local submodule_sha=$(git submodule status $prefix | cut -d ' ' -f 2)

Is $prefix guaranteed not to have any $IFS whitespaces?

> +	# Remove references to submodule.
> +	git config --remove-section submodule.$prefix
> +	git config --file .gitmodules --remove-section submodule.$prefix
> +	git add .gitmodules
> +
> +	# Move submodule aside.
> +	local tmp_repo="$(mktemp -d /tmp/git-subtree.XXXXX)"

Doesn't "git subtree" honor TMPDIR?  Not complaining, but being
curious.

> +	rm -r $tmp_repo
> +	mv $prefix $tmp_repo
> +	git rm $prefix

Is $prefix guaranteed not to have any $IFS whitespaces?

> +
> +	# Commit changes.
> +	git commit -m "Remove '$prefix/' submodule"
> +
> +	# subtree add from submodule repo.
> +	cmd_add_repository $tmp_repo HEAD
> +
> +	# Remove submodule repo.
> +	rm -rf $tmp_repo
> +}
> +
>  "cmd_$command" "$@"

^ permalink raw reply

* Re: [PATCH/RFC] Make help behaviour more consistent
From: Junio C Hamano @ 2013-03-11  3:03 UTC (permalink / raw)
  To: Kevin Bracey; +Cc: git
In-Reply-To: <1362937729-9050-1-git-send-email-kevin@bracey.fi>

Kevin Bracey <kevin@bracey.fi> writes:

> Previously, the command "help" and the option "-h" behaved differently
> depending on whether a command was specified or not. Old user interface:
>
> Commands with no defaults show usage: "git"           "git CMD"
> To specifically request usage:        "git help"      "git CMD -h"
> To get a manual page:                 "git help git"  "git help CMD"
>
> Two significant usability flaws here:
>  - If using man, "man git" to side-step "git help" is obvious. But if
>    trying to use help.format=web, how to get the root html page? My
>    technique was "git help XXX" and click the "git(1) suite" link at the
>    bottom. "git help git" is non-obvious and apparently undocumented
>    (it's not mentioned by "git", "git help", or "git help help"...).
>
>  - Because git itself didn't support -h (and thus actually printed less
>    if you specified it), the general availability of -h for commands was
>    non-obvious. I didn't know about it until I started this patch.

Hmm, I feel more confused than convinced after reading the above
three times.  Perhaps that is because I am too used to the way how
"git" potty itself behaves, especially the part that "git help git"
is the way to ask "git" (the first token on the command line) to
give me "help" about "git" (the second) itself.

Having said that, I would agree that "git -h" that shows a "unknown
option" error message that lists the supported command line options
(just like how it reacts to "git -x") is less friendly than "git"
that knows "-h" to show the short help text, and that part of the
patch is a definite improvement.  But other than that I do not see
any "significant usablity flow" in it.

The patch seems to do a lot more than just teaching "git" to react
to "-h" to give a short usage, instead of doing the generic "I do
not know -h option" thing.  I am not sure what merit these other
changes of this patch have.

In the introductory part, you list three possibilities, but there is
the fourth "git help help" to ask "git" to give me "help" about
"help".  Depending on where one comes from, that may also seem just
as odd as "git help git" (again, I personally find neither is odd,
though). Would this change help with that "usability flaw" as well?

Undecided...

^ permalink raw reply

* [PATCH 2/2] archive: handle commits with an empty tree
From: Jeff King @ 2013-03-11  1:32 UTC (permalink / raw)
  To: git; +Cc: René Scharfe
In-Reply-To: <20130311013123.GA11692@sigill.intra.peff.net>

git-archive relies on get_pathspec to convert its argv into
a list of pathspecs. When get_pathspec is given an empty
argv list, it returns a single pathspec, the empty string,
to indicate that everything matches. When we feed this to
our path_exists function, we typically see that the pathspec
turns up at least one item in the tree, and we are happy.

But when our tree is empty, we erroneously think it is
because the pathspec is too limited, when in fact it is
simply that there is nothing to be found in the tree. This
is a weird corner case, but the correct behavior is almost
certainly to produce an empty archive, not to exit with an
error.

This patch teaches git-archive to create empty archives when
there is no pathspec given (we continue to complain if a
pathspec is given, since it obviously is not matched). It
also confirms that the tar and zip writers produce sane
output in this instance.

Signed-off-by: Jeff King <peff@peff.net>
---
 archive.c                       |   2 +-
 t/t5004-archive-corner-cases.sh |  83 ++++++++++++++++++++++++++++++++++++++++
 t/t5004/empty.zip               | Bin 0 -> 62 bytes
 3 files changed, 84 insertions(+), 1 deletion(-)
 create mode 100755 t/t5004-archive-corner-cases.sh
 create mode 100644 t/t5004/empty.zip

diff --git a/archive.c b/archive.c
index 93e00bb..d254fa5 100644
--- a/archive.c
+++ b/archive.c
@@ -234,7 +234,7 @@ static void parse_pathspec_arg(const char **pathspec,
 	ar_args->pathspec = pathspec = get_pathspec("", pathspec);
 	if (pathspec) {
 		while (*pathspec) {
-			if (!path_exists(ar_args->tree, *pathspec))
+			if (**pathspec && !path_exists(ar_args->tree, *pathspec))
 				die("path not found: %s", *pathspec);
 			pathspec++;
 		}
diff --git a/t/t5004-archive-corner-cases.sh b/t/t5004-archive-corner-cases.sh
new file mode 100755
index 0000000..395dd58
--- /dev/null
+++ b/t/t5004-archive-corner-cases.sh
@@ -0,0 +1,83 @@
+#!/bin/sh
+
+test_description='test corner cases of git-archive'
+. ./test-lib.sh
+
+test_expect_success 'create commit with empty tree' '
+	git commit --allow-empty -m foo
+'
+
+# Make a dir and clean it up afterwards
+make_dir() {
+	mkdir "$1" &&
+	test_when_finished "rm -rf '$1'"
+}
+
+# Check that the dir given in "$1" contains exactly the
+# set of paths given as arguments.
+check_dir() {
+	dir=$1; shift
+	{
+		echo "$dir" &&
+		for i in "$@"; do
+			echo "$dir/$i"
+		done
+	} | sort >expect &&
+	find "$dir" -print | sort >actual &&
+	test_cmp expect actual
+}
+
+test_expect_success 'tar archive of empty tree is empty' '
+	git archive --format=tar HEAD >empty.tar &&
+	make_dir extract &&
+	"$TAR" xf empty.tar -C extract &&
+	check_dir extract
+'
+
+test_expect_success 'tar archive of empty tree with prefix' '
+	git archive --format=tar --prefix=foo/ HEAD >prefix.tar &&
+	make_dir extract &&
+	"$TAR" xf prefix.tar -C extract &&
+	check_dir extract foo
+'
+
+test_expect_success UNZIP 'zip archive of empty tree is empty' '
+	# Detect the exit code produced when our particular flavor of unzip
+	# sees an empty archive. Infozip will generate a warning and exit with
+	# code 1. But in the name of sanity, we do not expect other unzip
+	# implementations to do the same thing (it would be perfectly
+	# reasonable to exit 0, for example).
+	#
+	# This makes our test less rigorous on some platforms (unzip may not
+	# handle the empty repo at all, making our later check of its exit code
+	# a no-op). But we cannot do anything reasonable except skip the test
+	# on such platforms anyway, and this is the moral equivalent.
+	"$GIT_UNZIP" "$TEST_DIRECTORY"/t5004/empty.zip
+	expect_code=$?
+
+	git archive --format=zip HEAD >empty.zip &&
+	make_dir extract &&
+	(
+		cd extract &&
+		test_expect_code $expect_code "$GIT_UNZIP" ../empty.zip
+	) &&
+	check_dir extract
+'
+
+test_expect_success UNZIP 'zip archive of empty tree with prefix' '
+	# We do not have to play exit-code tricks here, because our
+	# result should not be empty; it has a directory in it.
+	git archive --format=zip --prefix=foo/ HEAD >prefix.zip &&
+	make_dir extract &&
+	(
+		cd extract &&
+		"$GIT_UNZIP" ../prefix.zip
+	) &&
+	check_dir extract foo
+'
+
+test_expect_success 'archive complains about pathspec on empty tree' '
+	test_must_fail git archive --format=tar HEAD -- foo >/dev/null
+'
+
+test_done
diff --git a/t/t5004/empty.zip b/t/t5004/empty.zip
new file mode 100644
index 0000000000000000000000000000000000000000..1a76bb600558dc94913a80076fe8dbdef13c1b15
GIT binary patch
literal 62
zcmWIWW@TeQ0~!oz$rh;wDW;amhRMmM$%ZCLW|oGQX-P%~24+b{=4q+M#^$N!DF&$k
D8w?B~

literal 0
HcmV?d00001

-- 
1.8.2.rc3.4.gc6ed371

^ permalink raw reply related

* [PATCH 1/2] test-lib: factor out $GIT_UNZIP setup
From: Jeff King @ 2013-03-11  1:31 UTC (permalink / raw)
  To: git; +Cc: René Scharfe
In-Reply-To: <20130311013123.GA11692@sigill.intra.peff.net>

We set up the $GIT_UNZIP variable and lazy prereq in
multiple places (and the next patch is about to add another
one). Let's factor it out to avoid repeating ourselves.

Signed-off-by: Jeff King <peff@peff.net>
---
 t/t0024-crlf-archive.sh | 6 ------
 t/t5003-archive-zip.sh  | 6 ------
 t/test-lib.sh           | 6 ++++++
 3 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/t/t0024-crlf-archive.sh b/t/t0024-crlf-archive.sh
index 5378787..4e9fa3c 100755
--- a/t/t0024-crlf-archive.sh
+++ b/t/t0024-crlf-archive.sh
@@ -3,12 +3,6 @@ test_description='respect crlf in git archive'
 test_description='respect crlf in git archive'
 
 . ./test-lib.sh
-GIT_UNZIP=${GIT_UNZIP:-unzip}
-
-test_lazy_prereq UNZIP '
-	"$GIT_UNZIP" -v
-	test $? -ne 127
-'
 
 test_expect_success setup '
 
diff --git a/t/t5003-archive-zip.sh b/t/t5003-archive-zip.sh
index 7cfe9ca..0f5b42b 100755
--- a/t/t5003-archive-zip.sh
+++ b/t/t5003-archive-zip.sh
@@ -3,15 +3,9 @@ SUBSTFORMAT=%H%n
 test_description='git archive --format=zip test'
 
 . ./test-lib.sh
-GIT_UNZIP=${GIT_UNZIP:-unzip}
 
 SUBSTFORMAT=%H%n
 
-test_lazy_prereq UNZIP '
-	"$GIT_UNZIP" -v
-	test $? -ne 127
-'
-
 test_lazy_prereq UNZIP_SYMLINKS '
 	(
 		mkdir unzip-symlinks &&
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 9e7f6b4..1f51025 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -760,3 +760,9 @@ test -w / || test_set_prereq SANITY
 # When the tests are run as root, permission tests will report that
 # things are writable when they shouldn't be.
 test -w / || test_set_prereq SANITY
+
+GIT_UNZIP=${GIT_UNZIP:-unzip}
+test_lazy_prereq UNZIP '
+	"$GIT_UNZIP" -v
+	test $? -ne 127
+'
-- 
1.8.2.rc3.4.gc6ed371

^ permalink raw reply related

* [PATCH 0/2] fix git-archive with empty trees
From: Jeff King @ 2013-03-11  1:31 UTC (permalink / raw)
  To: git; +Cc: René Scharfe

I noticed that "git archive" will barf when the root tree is empty.
Instead, it should probably return an empty archive. I doubt many people
really care about this corner case in practice, but it seems like we
should handle it more gracefully (and it's an easy fix).

It came to my attention because we track failed git-archive invocations
at GitHub, and a particular repo had a two commits: adding some content,
then reverting the original commit. You can also get there with "commit
--allow-empty" on a new branch (which is what the tests do).

I didn't bother even looking at empty subtrees. AFAIK, git should never
produce them (it omits the tree entirely if there is no content in it).
You would have to fake it using hash-object manually. I suspect it would
work just fine, as we already exercise the empty-dir code paths in the
tests I did add.

  [1/2]: test-lib: factor out $GIT_UNZIP setup
  [2/2]: archive: handle commits with an empty tree

-Peff

^ permalink raw reply

* Re: [PATCH/RFC] Make help behaviour more consistent
From: Philip Oakley @ 2013-03-10 23:56 UTC (permalink / raw)
  To: Kevin Bracey; +Cc: git
In-Reply-To: <1362937729-9050-1-git-send-email-kevin@bracey.fi>

On 10/03/13 17:48, Kevin Bracey wrote:
> Previously, the command "help" and the option "-h" behaved differently
> depending on whether a command was specified or not. Old user interface:
>
> Commands with no defaults show usage: "git"           "git CMD"
> To specifically request usage:        "git help"      "git CMD -h"
> To get a manual page:                 "git help git"  "git help CMD"
>

I agree they were inconsistent, but the change should also consider how 
the help for 'git help' should be provided as well.

I have some patches in preparation for also listing the commonly used 
guides, which can also be accessed by the existing `git help <guide>` 
e.g. 'tutorial' (but not user-manual or everday git unfortunately).

http://permalink.gmane.org/gmane.comp.version-control.git/217354

I have a new version in prep but my ubuntu m/c is out of action.

> Two significant usability flaws here:
>   - If using man, "man git" to side-step "git help" is obvious. But if
>     trying to use help.format=web, how to get the root html page? My
>     technique was "git help XXX" and click the "git(1) suite" link at the
>     bottom. "git help git" is non-obvious and apparently undocumented
>     (it's not mentioned by "git", "git help", or "git help help"...).
>
>   - Because git itself didn't support -h (and thus actually printed less
>     if you specified it), the general availability of -h for commands was
>     non-obvious. I didn't know about it until I started this patch.
>
> Tidy this up, so that help and -h do not change behaviour depending on
> whether a command is specified or not. New, consistent user interface:
>
> Commands with no defaults show usage: "git"           "git CMD"
> To specifically request usage:        "git -h"        "git CMD -h"
> To get a manual page:                 "git help"      "git help CMD".
>
> "git help git" is still accepted. The legacy "--help" option behaves as
> before, which means "git --help" on its own is now a synonym for "git
> -h", not "git help", and it remains consistent with GNU Coding
> Guidelines.
>
> So the only change to existing command behaviour is that "git help" or
> "git help -w" now opens the git manual page, rather than showing common
> commands.
>
> "git -h cmd" is also accepted as a synonym for "git cmd -h", as per
> Linus's rationale for treating "git cmd --help" as a synonym for "git
> --help cmd".
>
> Option list shown in command-line usage re-ordered to match the manual
> page, and git and git-help manual pages edited to reflect the new help
> behaviour.
>
> Signed-off-by: Kevin Bracey <kevin@bracey.fi>
> ---
>   Documentation/git-help.txt | 22 +++++++++-------------
>   Documentation/git.txt      | 17 ++++++++---------
>   builtin/help.c             |  9 +--------
>   git.c                      | 40 +++++++++++++++++++++++-----------------
>   4 files changed, 41 insertions(+), 47 deletions(-)
>
> diff --git a/Documentation/git-help.txt b/Documentation/git-help.txt
> index e07b6dc..25def9f 100644
> --- a/Documentation/git-help.txt
> +++ b/Documentation/git-help.txt
> @@ -13,19 +13,16 @@ SYNOPSIS
>   DESCRIPTION
>   -----------
>
> -With no options and no COMMAND given, the synopsis of the 'git'
> -command and a list of the most commonly used Git commands are printed
> -on the standard output.
> -
>   If the option '--all' or '-a' is given, then all available commands are
>   printed on the standard output.
>
> -If a Git subcommand is named, a manual page for that subcommand is brought
> +Otherwise, a manual page for Git or the specified Git command is brought
>   up. The 'man' program is used by default for this purpose, but this
>   can be overridden by other options or configuration variables.
>
>   Note that `git --help ...` is identical to `git help ...` because the
> -former is internally converted into the latter.
> +former is internally converted into the latter.  Also, to supplement
> +`git help`, most Git commands offer the option '-h' to print usage.
>
>   OPTIONS
>   -------
> @@ -36,14 +33,13 @@ OPTIONS
>
>   -i::
>   --info::
> -	Display manual page for the command in the 'info' format. The
> -	'info' program will be used for that purpose.
> +	Display manual page in the 'info' format. The 'info' program will
> +	be used for that purpose.
>
>   -m::
>   --man::
> -	Display manual page for the command in the 'man' format. This
> -	option may be used to override a value set in the
> -	'help.format' configuration variable.
> +	Display manual page in the 'man' format. This option may be used to
> +	override a value set in the 'help.format' configuration variable.
>   +
>   By default the 'man' program will be used to display the manual page,
>   but the 'man.viewer' configuration variable may be used to choose
> @@ -51,8 +47,8 @@ other display programs (see below).
>
>   -w::
>   --web::
> -	Display manual page for the command in the 'web' (HTML)
> -	format. A web browser will be used for that purpose.
> +	Display manual page in the 'web' (HTML)	format. A web browser will
> +	be used for that purpose.
>   +
>   The web browser can be specified using the configuration variable
>   'help.browser', or 'web.browser' if the former is not set. If none of
> diff --git a/Documentation/git.txt b/Documentation/git.txt
> index 9d29ed5..51cdca2 100644
> --- a/Documentation/git.txt
> +++ b/Documentation/git.txt
> @@ -9,7 +9,7 @@ git - the stupid content tracker
>   SYNOPSIS
>   --------
>   [verse]
> -'git' [--version] [--help] [-c <name>=<value>]
> +'git' [--version] [--help] [-h] [-c <name>=<value>]
>       [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
>       [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
>       [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
> @@ -361,16 +361,15 @@ OPTIONS
>   --version::
>   	Prints the Git suite version that the 'git' program came from.
>
> ---help::
> +-h::
>   	Prints the synopsis and a list of the most commonly used
> -	commands. If the option '--all' or '-a' is given then all
> -	available commands are printed. If a Git command is named this
> -	option will bring up the manual page for that command.
> +	commands. Most Git commands also provide a '-h'	option to
> +	show their own synopsis.
>   +
> -Other options are available to control how the manual page is
> -displayed. See linkgit:git-help[1] for more information,
> -because `git --help ...` is converted internally into `git
> -help ...`.
> +For compatibility, `git --help` is also implemented. With no
> +following options, it is equivalent to `git -h`. Otherwise it is
> +converted internally into `git help ...`, which will open a manual
> +page. See linkgit:git-help[1] for more information.
>
>   -c <name>=<value>::
>   	Pass a configuration parameter to the command. The value
> diff --git a/builtin/help.c b/builtin/help.c
> index d1d7181..ef4706a 100644
> --- a/builtin/help.c
> +++ b/builtin/help.c
> @@ -432,13 +432,6 @@ int cmd_help(int argc, const char **argv, const char *prefix)
>   		return 0;
>   	}
>
> -	if (!argv[0]) {
> -		printf(_("usage: %s%s"), _(git_usage_string), "\n\n");
> -		list_common_cmds_help();
> -		printf("\n%s\n", _(git_more_info_string));
> -		return 0;
> -	}
> -
>   	setup_git_directory_gently(&nongit);
>   	git_config(git_help_config, NULL);
>
> @@ -447,7 +440,7 @@ int cmd_help(int argc, const char **argv, const char *prefix)
>   	if (help_format == HELP_FORMAT_NONE)
>   		help_format = parse_help_format(DEFAULT_HELP_FORMAT);
>
> -	alias = alias_lookup(argv[0]);
> +	alias = argv[0] ? alias_lookup(argv[0]) : NULL;
>   	if (alias && !is_git_command(argv[0])) {
>   		printf_ln(_("`git %s' is aliased to `%s'"), argv[0], alias);
>   		return 0;
> diff --git a/git.c b/git.c
> index b10c18b..82a74c5 100644
> --- a/git.c
> +++ b/git.c
> @@ -6,10 +6,10 @@
>   #include "run-command.h"
>
>   const char git_usage_string[] =
> -	"git [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]\n"
> +	"git [--version] [--help] [-h] [-c name=value]\n"
> +	"           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]\n"
>   	"           [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]\n"
>   	"           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]\n"
> -	"           [-c name=value] [--help]\n"
>   	"           <command> [<args>]";
>
>   const char git_more_info_string[] =
> @@ -17,6 +17,7 @@ const char git_more_info_string[] =
>
>   static struct startup_info git_startup_info;
>   static int use_pager = -1;
> +static int show_usage;
>
>   static void commit_pager_choice(void) {
>   	switch (use_pager) {
> @@ -40,17 +41,6 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
>   		if (cmd[0] != '-')
>   			break;
>
> -		/*
> -		 * For legacy reasons, the "version" and "help"
> -		 * commands can be written with "--" prepended
> -		 * to make them look like flags.
> -		 */
> -		if (!strcmp(cmd, "--help") || !strcmp(cmd, "--version"))
> -			break;
> -
> -		/*
> -		 * Check remaining flags.
> -		 */
>   		if (!prefixcmp(cmd, "--exec-path")) {
>   			cmd += 11;
>   			if (*cmd == '=')
> @@ -143,6 +133,25 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
>   			setenv(GIT_LITERAL_PATHSPECS_ENVIRONMENT, "0", 1);
>   			if (envchanged)
>   				*envchanged = 1;
> +		} else if (!strcmp(cmd, "--version")) {
> +			/* Alternative spelling for "git version" */
> +			(*argv)[0] += 2;
> +			break;
> +		} else if (!strcmp(cmd, "--help")) {
> +			if (*argc > 1) {
> +				/* Alternative spelling for "git help XXX" */
> +				(*argv)[0] += 2;
> +				break;
> +			} else
> +				show_usage = 1;
> +		} else if (!strcmp(cmd, "-h")) {
> +			if (*argc > 1 && (*argv)[1][0] != '-') {
> +				/* Turn "git -h cmd" into "git cmd -h" */
> +				(*argv)[0] = (*argv)[1];
> +				(*argv)[1] = "-h";
> +				break;
> +			} else
> +				show_usage = 1;
>   		} else {
>   			fprintf(stderr, "Unknown option: %s\n", cmd);
>   			usage(git_usage_string);
> @@ -537,10 +546,7 @@ int main(int argc, const char **argv)
>   	argv++;
>   	argc--;
>   	handle_options(&argv, &argc, NULL);
> -	if (argc > 0) {
> -		if (!prefixcmp(argv[0], "--"))
> -			argv[0] += 2;
> -	} else {
> +	if (argc <= 0 || show_usage) {
>   		/* The user didn't specify a command; give them help */
>   		commit_pager_choice();
>   		printf("usage: %s\n\n", git_usage_string);
>

^ permalink raw reply

* [PATCH v2 23/23] contrib/subtree: Fix order of case switches so default case is last
From: Paul Campbell @ 2013-03-10 23:41 UTC (permalink / raw)
  To: git; +Cc: David Greene, Paul Campbell, Matt Hoffman, Avery Pennarun,
	Nate Jones
In-Reply-To: <1362958891-26941-1-git-send-email-pcampbell@kemitix.net>

Signed-off-by: Paul Campbell <pcampbell@kemitix.net>
---
 contrib/subtree/git-subtree.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index aaee6ae..fb6f044 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -113,9 +113,9 @@ prefix="${prefix%/}";
 command="$1"
 shift
 case "$command" in
-    add|merge|pull|from-submodule|pull-all|push-all|prune) default= ;;
+	add|merge|pull|pull-all|push-all|from-submodule|prune) default= ;;
+	split|push|diff|list) default="--default HEAD" ;;
 	*) die "Unknown command '$command'" ;;
-    split|push|diff|list) default="--default HEAD" ;;
 esac
 
 if [ -z "$prefix" -a "$command" != "pull-all" -a "$command" != "push-all" -a "$command" != "list" -a "$command" != "prune" ]; then
-- 
1.8.2.rc1

^ permalink raw reply related

* [PATCH v2 22/23] contrib/subtree: Parameters repository/branch for push/pull are optional
From: Paul Campbell @ 2013-03-10 23:41 UTC (permalink / raw)
  To: git
  Cc: David Greene, Paul Campbell, Matt Hoffman, Avery Pennarun,
	Herman van Rink, Wayne Walter
In-Reply-To: <1362958891-26941-1-git-send-email-pcampbell@kemitix.net>

Signed-off-by: Paul Campbell <pcampbell@kemitix.net>
---
 contrib/subtree/git-subtree.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 263ea9f..aaee6ae 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -11,10 +11,10 @@ OPTS_SPEC="\
 git subtree add   --prefix=<prefix> <commit>
 git subtree add   --prefix=<prefix> <repository> <commit>
 git subtree merge --prefix=<prefix> <commit>
-git subtree pull  --prefix=<prefix> <repository> <refspec...>
+git subtree pull  --prefix=<prefix> [<repository> [<refspec>...]]
 git subtree pull-all
 git subtree push-all
-git subtree push  --prefix=<prefix> <repository> <refspec...>
+git subtree push  --prefix=<prefix> [<repository> [<refspec>...]]
 git subtree list
 git subtree split --prefix=<prefix> <commit...>
 git subtree diff  --prefix=<prefix> [<repository> [<refspec>...]]
-- 
1.8.2.rc1

^ permalink raw reply related

* [PATCH v2 21/23] contrib/subtree: Convert spaces to tabs and remove some trailing whitespace
From: Paul Campbell @ 2013-03-10 23:41 UTC (permalink / raw)
  To: git
  Cc: David Greene, Herman van Rink, Paul Campbell, Peter Jaros,
	James Roper, Michael Hart, Matt Hoffman, Avery Pennarun,
	Jakub Suder, Nate Jones, bibendi, Win Treese, Wayne Walter
In-Reply-To: <1362958891-26941-1-git-send-email-pcampbell@kemitix.net>

From: Herman van Rink <rink@initfour.nl>

Signed-off-by: Paul Campbell <pcampbell@kemitix.net>

Conflicts:
	contrib/subtree/.gitignore
	contrib/subtree/git-subtree.sh
	contrib/subtree/test.sh
---

It's a nasty formatting only patch and I won't be surprised or too dissappiointed
if this doesn't make it. Or are the rules for this more lax for contrib? How else
can contrib be brought in-line with coding standards?

 contrib/subtree/git-subtree.sh | 213 +++++++++++++++++++++--------------------
 1 file changed, 109 insertions(+), 104 deletions(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 3582a55..263ea9f 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -92,7 +92,7 @@ while [ $# -gt 0 ]; do
 		-b) branch="$1"; shift ;;
 		-P) prefix="$1"; shift ;;
 		-m) message="$1"; shift ;;
-        -f|--force) force=1 ;;
+		-f|--force) force=1 ;;
 		--no-prefix) prefix= ;;
 		--onto) onto="$1"; shift ;;
 		--no-onto) onto= ;;
@@ -123,8 +123,10 @@ if [ -z "$prefix" -a "$command" != "pull-all" -a "$command" != "push-all" -a "$c
 fi
 
 case "$command" in
-    pull-all);;
-    push-all);;
+	pull-all);;
+	push-all);;
+	list);;
+	prune);;
 	add) [ -e "$prefix" ] && 
 		die "prefix '$prefix' already exists." ;;
 	*)   [ -e "$prefix" ] || 
@@ -541,14 +543,14 @@ cmd_add_repository()
 	revs=FETCH_HEAD
 	set -- $revs
 	cmd_add_commit "$@"
-  
-  # now add it to our list of repos 
-  git config -f .gittrees --unset subtree.$dir.url
-  git config -f .gittrees --add subtree.$dir.url $repository
-  git config -f .gittrees --unset subtree.$dir.path
-  git config -f .gittrees --add subtree.$dir.path $dir
-  git config -f .gittrees --unset subtree.$dir.branch
-  git config -f .gittrees --add subtree.$dir.branch $refspec
+
+	# now add it to our list of repos
+	git config -f .gittrees --unset subtree.$dir.url
+	git config -f .gittrees --add subtree.$dir.url $repository
+	git config -f .gittrees --unset subtree.$dir.path
+	git config -f .gittrees --add subtree.$dir.path $dir
+	git config -f .gittrees --unset subtree.$dir.branch
+	git config -f .gittrees --add subtree.$dir.branch $refspec
 }
 
 cmd_add_commit()
@@ -721,89 +723,91 @@ cmd_merge()
 
 cmd_pull()
 {
-  if [ $# -gt 2 ]; then
-	    die "You should provide either <refspec> or <repository> <refspec>"
+	if [ $# -gt 2 ]; then
+		die "You should provide either <refspec> or <repository> <refspec>"
 	fi
 	if [ -e "$dir" ]; then
-	    ensure_clean
-      if [ $# -eq 1 ]; then 
-	      repository=$(git config -f .gittrees subtree.$prefix.url)
-	      refspec=$1
-      elif [ $# -eq 2 ]; then 
-        repository=$1
-        refspec=$2
-      else 
-	      repository=$(git config -f .gittrees subtree.$prefix.url)
-        refspec=$(git config -f .gittrees subtree.$prefix.branch)
-      fi
-	    git fetch $repository $refspec || exit $?
-	    echo "git fetch using: " $repository $refspec
-	    revs=FETCH_HEAD
-	    set -- $revs
-	    cmd_merge "$@"
+		ensure_clean
+		if [ $# -eq 1 ]; then
+			repository=$(git config -f .gittrees subtree.$prefix.url)
+			refspec=$1
+		elif [ $# -eq 2 ]; then
+			repository=$1
+			refspec=$2
+		else
+			repository=$(git config -f .gittrees subtree.$prefix.url)
+			refspec=$(git config -f .gittrees subtree.$prefix.branch)
+		fi
+		git fetch $repository $refspec || exit $?
+		echo "git fetch using: " $repository $refspec
+		revs=FETCH_HEAD
+		set -- $revs
+		cmd_merge "$@"
 	else
-	    die "'$dir' must already exist. Try 'git subtree add'."
+		die "'$dir' must already exist. Try 'git subtree add'."
 	fi
 }
 
-cmd_diff() 
-{
-    if [ -e "$dir" ]; then
-        if [ $# -eq 1 ]; then 
-            repository=$(git config -f .gittrees subtree.$prefix.url)
-            refspec=$1
-        elif [ $# -eq 2 ]; then 
-            repository=$1
-            refspec=$2
-        else
-            repository=$(git config -f .gittrees subtree.$prefix.url)
-            refspec=$(git config -f .gittrees subtree.$prefix.branch)
-        fi
-        # this is ugly, but I don't know of a better way to do it. My git-fu is weak. 
-        # git diff-tree expects a treeish, but I have only a repository and branch name.
-        # I don't know how to turn that into a treeish without creating a remote.
-        # Please change this if you know a better way! 
-        tmp_remote=__diff-tmp
-        git remote rm $tmp_remote > /dev/null 2>&1
-        git remote add -t $refspec $tmp_remote $repository > /dev/null
-        # we fetch as a separate step so we can pass -q (quiet), which isn't an option for "git remote"
-        # could this instead be "git fetch -q $repository $refspec" and leave aside creating the remote?
-        # Still need a treeish for the diff-tree command...
-        git fetch -q $tmp_remote 
-        git diff-tree -p refs/remotes/$tmp_remote/$refspec
-        git remote rm $tmp_remote > /dev/null 2>&1
-    else 
-        die "Cannot resolve directory '$dir'. Please point to an existing subtree directory to diff. Try 'git subtree add' to add a subtree."
-    fi
+cmd_diff()
+{
+	if [ -e "$dir" ]; then
+		if [ $# -eq 1 ]; then
+			repository=$(git config -f .gittrees subtree.$prefix.url)
+			refspec=$1
+		elif [ $# -eq 2 ]; then
+			repository=$1
+			refspec=$2
+		else
+			repository=$(git config -f .gittrees subtree.$prefix.url)
+			refspec=$(git config -f .gittrees subtree.$prefix.branch)
+		fi
+		# this is ugly, but I don't know of a better way to do it. My git-fu is weak.
+		# git diff-tree expects a treeish, but I have only a repository and branch name.
+		# I don't know how to turn that into a treeish without creating a remote.
+		# Please change this if you know a better way!
+		tmp_remote=__diff-tmp
+		git remote rm $tmp_remote > /dev/null 2>&1
+		git remote add -t $refspec $tmp_remote $repository > /dev/null
+		# we fetch as a separate step so we can pass -q (quiet), which isn't an option for "git remote"
+		# could this instead be "git fetch -q $repository $refspec" and leave aside creating the remote?
+		# Still need a treeish for the diff-tree command...
+		git fetch -q $tmp_remote
+		git diff-tree -p refs/remotes/$tmp_remote/$refspec
+		git remote rm $tmp_remote > /dev/null 2>&1
+	else
+		die "Cannot resolve directory '$dir'. Please point to an existing subtree directory to diff. Try 'git subtree add' to add a subtree."
+	fi
 }
 
 cmd_push()
 {
 	if [ $# -gt 2 ]; then
-	    die "You shold provide either <refspec> or <repository> <refspec>"
+		die "You shold provide either <refspec> or <repository> <refspec>"
 	fi
 	if [ -e "$dir" ]; then
-      if [ $# -eq 1 ]; then 
-	      repository=$(git config -f .gittrees subtree.$prefix.url)
-        refspec=$1
-      elif [ $# -eq 2 ]; then 
-        repository=$1
-        refspec=$2
-      else
-	      repository=$(git config -f .gittrees subtree.$prefix.url)
-        refspec=$(git config -f .gittrees subtree.$prefix.branch)
-      fi
-        push_opts=
-        if [ "$force" == "1" ]; then 
-            push_opts="$push_opts --force"
-        fi
-	    echo "git push using: " $repository $refspec
-	    rev=$(git subtree split --prefix=$prefix)
-	    if [ -n "$rev" ]; then
-	        git push $push_opts $repository $rev:refs/heads/$refspec
-	    else
-	        die "Couldn't push, 'git subtree split' failed."
-	    fi
+		if [ $# -eq 1 ]; then
+			repository=$(git config -f .gittrees subtree.$prefix.url)
+			refspec=$1
+		elif [ $# -eq 2 ]; then
+			repository=$1
+			refspec=$2
+		else
+			repository=$(git config -f .gittrees subtree.$prefix.url)
+			refspec=$(git config -f .gittrees subtree.$prefix.branch)
+		fi
+
+		push_opts=
+		if [ "$force" == "1" ]; then
+		  push_opts="$push_opts --force"
+		fi
+
+		echo "git push using: " $repository $refspec
+		rev=$(git subtree split --prefix=$prefix)
+		if [ -n "$rev" ]; then
+			git push $push_opts $repository $rev:refs/heads/$refspec
+		else
+			die "Couldn't push, 'git subtree split' failed."
+		fi
 	else
 	    die "'$dir' must already exist. Try 'git subtree add'."
 	fi
@@ -831,6 +835,7 @@ cmd_from-submodule()
 	git commit -m "Remove '$prefix/' submodule"
 
 	# subtree add from submodule repo.
+	# TODO: Could be determin HEAD to be a specific branch
 	cmd_add_repository $tmp_repo HEAD
 
 	# Update .gittrees with the original repo url
@@ -841,46 +846,46 @@ cmd_from-submodule()
 	rm -rf $tmp_repo
 }
 
-subtree_list() 
+subtree_list()
 {
-    git config -f .gittrees -l | grep subtree | grep path | grep -o '=.*' | grep -o '[^=].*' |
-    while read path; do 
-        repository=$(git config -f .gittrees subtree.$path.url)
-        refspec=$(git config -f .gittrees subtree.$path.branch)
-        echo "    $path        (merged from $repository branch $refspec) "
-    done
+	git config -f .gittrees -l | grep subtree | grep path | grep -o '=.*' | grep -o '[^=].*' |
+	while read path; do
+		repository=$(git config -f .gittrees subtree.$path.url)
+		refspec=$(git config -f .gittrees subtree.$path.branch)
+		echo "	$path		(merged from $repository branch $refspec) "
+	done
 }
 
 cmd_list()
 {
-  subtree_list 
+  subtree_list
 }
 
 cmd_prune()
 {
-    git config -f .gittrees -l | grep subtree | grep path | grep -o '=.*' | grep -o '[^=].*' |
-    while read path; do
-        if [ ! -e "$path" ]; then
-            echo "pruning $path"
-            git config -f .gittrees --remove-section subtree.$path
-        fi
-    done
+	git config -f .gittrees -l | grep subtree | grep path | grep -o '=.*' | grep -o '[^=].*' |
+	while read path; do
+		if [ ! -e "$path" ]; then
+			echo "pruning $path"
+			git config -f .gittrees --remove-section subtree.$path
+		fi
+	done
 }
 
 cmd_pull-all()
 {
-    git config -f .gittrees -l | grep subtree | grep path | grep -o '=.*' | grep -o '[^=].*' |
-        while read path; do
-            git subtree pull -P $path master || exit $?
-        done
+	git config -f .gittrees -l | grep subtree | grep path | grep -o '=.*' | grep -o '[^=].*' |
+	while read path; do
+		git subtree pull -P $path $(git config -f .gittrees subtree.$path.url) $(git config -f .gittrees subtree.$path.branch) || exit $?
+	done
 }
 
 cmd_push-all()
 {
-    git config -f .gittrees -l | grep subtree | grep path | grep -o '=.*' | grep -o '[^=].*' |
-        while read path; do
-            git subtree push -P $path master || exit $?
-        done
+	git config -f .gittrees -l | grep subtree | grep path | grep -o '=.*' | grep -o '[^=].*' |
+	while read path; do
+		git subtree push -P $path $(git config -f .gittrees subtree.$path.url) $(git config -f .gittrees subtree.$path.branch) || exit $?
+	done
 }
 
 "cmd_$command" "$@"
-- 
1.8.2.rc1

^ permalink raw reply related

* [PATCH v2 20/23] contrib/subtree: Teach push to use --force option
From: Paul Campbell @ 2013-03-10 23:41 UTC (permalink / raw)
  To: git
  Cc: David Greene, James Roper, Paul Campbell, Matt Hoffman,
	Michael Hart, Avery Pennarun, Jakub Suder, John Yani,
	Wayne Walter
In-Reply-To: <1362958891-26941-1-git-send-email-pcampbell@kemitix.net>

From: James Roper <jroper@vz.net>

Signed-off-by: Paul Campbell <pcampbell@kemitix.net>

Conflicts:
	contrib/subtree/git-subtree.sh

Signed-off-by: Paul Campbell <pcampbell@kemitix.net>
---
 contrib/subtree/git-subtree.sh  | 9 ++++++++-
 contrib/subtree/git-subtree.txt | 5 +++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 4605203..3582a55 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -32,6 +32,8 @@ 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
+ options for 'push'
+f,force       use force push
  options for 'add', 'merge', 'pull' and 'push'
 squash        merge subtree changes as a single commit
 "
@@ -90,6 +92,7 @@ while [ $# -gt 0 ]; do
 		-b) branch="$1"; shift ;;
 		-P) prefix="$1"; shift ;;
 		-m) message="$1"; shift ;;
+        -f|--force) force=1 ;;
 		--no-prefix) prefix= ;;
 		--onto) onto="$1"; shift ;;
 		--no-onto) onto= ;;
@@ -790,10 +793,14 @@ cmd_push()
 	      repository=$(git config -f .gittrees subtree.$prefix.url)
         refspec=$(git config -f .gittrees subtree.$prefix.branch)
       fi
+        push_opts=
+        if [ "$force" == "1" ]; then 
+            push_opts="$push_opts --force"
+        fi
 	    echo "git push using: " $repository $refspec
 	    rev=$(git subtree split --prefix=$prefix)
 	    if [ -n "$rev" ]; then
-	        git push $repository $rev:refs/heads/$refspec
+	        git push $push_opts $repository $rev:refs/heads/$refspec
 	    else
 	        die "Couldn't push, 'git subtree split' failed."
 	    fi
diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
index 385bde8..9e9eb9e 100644
--- a/contrib/subtree/git-subtree.txt
+++ b/contrib/subtree/git-subtree.txt
@@ -278,6 +278,11 @@ OPTIONS FOR split
 	'--rejoin' when you split, because you don't want the
 	subproject's history to be part of your project anyway.
 
+OPTIONS FOR push
+----------------
+-f::
+--force::
+    Uses 'git push --force'.
 
 EXAMPLE 1. Add command
 ----------------------
-- 
1.8.2.rc1

^ permalink raw reply related

* [PATCH v2 19/23] contrib/subtree: Document list command
From: Paul Campbell @ 2013-03-10 23:41 UTC (permalink / raw)
  To: git
  Cc: David Greene, Herman van Rink, Paul Campbell, Peter Jaros,
	Matt Hoffman, Avery Pennarun, Wayne Walter
In-Reply-To: <1362958891-26941-1-git-send-email-pcampbell@kemitix.net>

From: Herman van Rink <rink@initfour.nl>

Signed-off-by: Paul Campbell <pcampbell@kemitix.net>

Conflicts:
	git-subtree.sh
---
 contrib/subtree/git-subtree.sh  | 1 +
 contrib/subtree/git-subtree.txt | 4 ++++
 2 files changed, 5 insertions(+)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 84c90c7..4605203 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -15,6 +15,7 @@ git subtree pull  --prefix=<prefix> <repository> <refspec...>
 git subtree pull-all
 git subtree push-all
 git subtree push  --prefix=<prefix> <repository> <refspec...>
+git subtree list
 git subtree split --prefix=<prefix> <commit...>
 git subtree diff  --prefix=<prefix> [<repository> [<refspec>...]]
 git subtree from-submodule --prefix=<prefix>
diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
index b485ab5..385bde8 100644
--- a/contrib/subtree/git-subtree.txt
+++ b/contrib/subtree/git-subtree.txt
@@ -15,6 +15,7 @@ SYNOPSIS
 'git subtree' pull-all
 'git subtree' push-all
 'git subtree' push  --prefix=<prefix> [<repository> [<refspec>...]]
+'git subtree' list
 'git subtree' split --prefix=<prefix> <commit...>
 'git subtree' from-submodule --prefix=<prefix>
 'git subtree' prune
@@ -108,6 +109,9 @@ push::
 push-all::
 	Perform a pull operation on all in .gittrees registered subtrees.
 
+list::
+	Show a list of the in .gittrees registered subtrees
+
 split::
 	Extract a new, synthetic project history from the
 	history of the <prefix> subtree.  The new history
-- 
1.8.2.rc1

^ permalink raw reply related

* [PATCH v2 18/23] contrib/subtree: Add missing commands to SYNOPSIS
From: Paul Campbell @ 2013-03-10 23:41 UTC (permalink / raw)
  To: git; +Cc: David Greene, Herman van Rink, Paul Campbell, Avery Pennarun,
	John Yani
In-Reply-To: <1362958891-26941-1-git-send-email-pcampbell@kemitix.net>

From: Herman van Rink <rink@initfour.nl>

Add pull-all, push-all, from-submodule, prune and diff commands
to SYNOPSIS.

Add alternate parameter option for add command.

Use long-form option for specifying prefix.

Signed-off-by: Paul Campbell <pcampbell@kemitix.net>

Conflicts:
	contrib/subtree/git-subtree.txt
---
 contrib/subtree/git-subtree.txt | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
index 48ba158..b485ab5 100644
--- a/contrib/subtree/git-subtree.txt
+++ b/contrib/subtree/git-subtree.txt
@@ -9,13 +9,16 @@ git-subtree - Merge subtrees together and split repository into subtrees
 SYNOPSIS
 --------
 [verse]
-'git subtree' add   -P <prefix> <refspec>
-'git subtree' add   -P <prefix> <repository> <refspec>
-'git subtree' pull  -P <prefix> <repository> <refspec...>
-'git subtree' push  -P <prefix> <repository> <refspec...>
-'git subtree' merge -P <prefix> <commit>
-'git subtree' split -P <prefix> [OPTIONS] [<commit>]
-
+'git subtree' add   --prefix=<prefix> <repository> <refspec>
+'git subtree' merge --prefix=<prefix> <commit>
+'git subtree' pull  --prefix=<prefix> [<repository> [<refspec>...]]
+'git subtree' pull-all
+'git subtree' push-all
+'git subtree' push  --prefix=<prefix> [<repository> [<refspec>...]]
+'git subtree' split --prefix=<prefix> <commit...>
+'git subtree' from-submodule --prefix=<prefix>
+'git subtree' prune
+'git subtree' diff  --prefix=<prefix> [<repository> [<refspec>...]]
 
 DESCRIPTION
 -----------
-- 
1.8.2.rc1

^ permalink raw reply related

* [PATCH v2 17/23] contrib/subtree: Document from-submodule and prune commands
From: Paul Campbell @ 2013-03-10 23:41 UTC (permalink / raw)
  To: git; +Cc: David Greene, Herman van Rink, Paul Campbell, Avery Pennarun
In-Reply-To: <1362958891-26941-1-git-send-email-pcampbell@kemitix.net>

From: Herman van Rink <rink@initfour.nl>

Signed-off-by: Paul Campbell <pcampbell@kemitix.net>
---
 contrib/subtree/git-subtree.txt | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
index c8fc103..48ba158 100644
--- a/contrib/subtree/git-subtree.txt
+++ b/contrib/subtree/git-subtree.txt
@@ -129,6 +129,16 @@ split::
 	Note that if you use '--squash' when you merge, you
 	should usually not just '--rejoin' when you split.
 
+from-submodule::
+	Convert a git submodule to a subtree.
+	The module is removed from the .gitmodules file and
+	the repo contents are integrated as a subtree.
+
+prune::
+	Cleanup .gittrees entries for which the subtree nolonger exists.
+
+diff::
+	TO BE DOCUMENTED
 
 OPTIONS
 -------
-- 
1.8.2.rc1

^ permalink raw reply related

* [PATCH v2 16/23] contrib/subtree: Document pull-all and push-all
From: Paul Campbell @ 2013-03-10 23:41 UTC (permalink / raw)
  To: git
  Cc: David Greene, Herman van Rink, Paul Campbell, Avery Pennarun,
	Michael Schubert, Wayne Walter
In-Reply-To: <1362958891-26941-1-git-send-email-pcampbell@kemitix.net>

From: Herman van Rink <rink@initfour.nl>

Signed-off-by: Paul Campbell <pcampbell@kemitix.net>
---
 contrib/subtree/git-subtree.txt | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
index e0957ee..c8fc103 100644
--- a/contrib/subtree/git-subtree.txt
+++ b/contrib/subtree/git-subtree.txt
@@ -92,13 +92,19 @@ pull::
 	Exactly like 'merge', but parallels 'git pull' in that
 	it fetches the given commit from the specified remote
 	repository.
-	
+
+pull-all::
+	Perform a pull operation on all in .gittrees registered subtrees.
+
 push::
 	Does a 'split' (see below) using the <prefix> supplied
 	and then does a 'git push' to push the result to the 
 	repository and refspec. This can be used to push your
 	subtree to different branches of the remote repository.
 
+push-all::
+	Perform a pull operation on all in .gittrees registered subtrees.
+
 split::
 	Extract a new, synthetic project history from the
 	history of the <prefix> subtree.  The new history
-- 
1.8.2.rc1

^ permalink raw reply related

* [PATCH v2 15/23] contrib/subtree: Teach from-submodule to add new subtree to .gittrees
From: Paul Campbell @ 2013-03-10 23:41 UTC (permalink / raw)
  To: git; +Cc: David Greene, Herman van Rink, Paul Campbell, Peter Jaros
In-Reply-To: <1362958891-26941-1-git-send-email-pcampbell@kemitix.net>

From: Herman van Rink <rink@initfour.nl>

Signed-off-by: Paul Campbell <pcampbell@kemitix.net>

Conflicts:
	git-subtree.sh
---
 contrib/subtree/git-subtree.sh | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index ae7d1fe..84c90c7 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -806,6 +806,7 @@ cmd_from-submodule()
 	ensure_clean
 
 	local submodule_sha=$(git submodule status $prefix | cut -d ' ' -f 2)
+	local submodule_orig_repo=$(git config --file .gitmodules submodule.$prefix.url)
 
 	# Remove references to submodule.
 	git config --remove-section submodule.$prefix
@@ -824,6 +825,10 @@ cmd_from-submodule()
 	# subtree add from submodule repo.
 	cmd_add_repository $tmp_repo HEAD
 
+	# Update .gittrees with the original repo url
+	git config --file .gittrees --unset subtree.$prefix.url
+	git config --file .gittrees subtree.$prefix.url $submodule_orig_repo
+
 	# Remove submodule repo.
 	rm -rf $tmp_repo
 }
-- 
1.8.2.rc1

^ permalink raw reply related

* [PATCH v2 14/23] contrib/subtree: Remove trailing slash from prefix parameter
From: Paul Campbell @ 2013-03-10 23:41 UTC (permalink / raw)
  To: git; +Cc: David Greene, Herman van Rink, Paul Campbell, Avery Pennarun
In-Reply-To: <1362958891-26941-1-git-send-email-pcampbell@kemitix.net>

From: Herman van Rink <rink@initfour.nl>

Conflicts:
	git-subtree.sh

Signed-off-by: Paul Campbell <pcampbell@kemitix.net>
---
 contrib/subtree/git-subtree.sh | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index d67fe5a..ae7d1fe 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -103,6 +103,9 @@ while [ $# -gt 0 ]; do
 	esac
 done
 
+# Remove trailing slash
+prefix="${prefix%/}";
+
 command="$1"
 shift
 case "$command" in
-- 
1.8.2.rc1

^ permalink raw reply related


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