[RFC] Moving main git-subtree development. to GitHub

2017-07-31 Thread David A. Greene
Hello all,

I have decided that moving git-subtree development off of the main git
mailing list is the best way to address the needs of git-subtree users
while providing the flexibility necessary to get it in shape for
eventual "official" status in the git project.

Over the last year and a half I have been working on some new features
for git-subtree, motivated by day-job requirements.  Much of that effort
has been spent hardening the new code in a real work environment, driven
by real-world needs.  I believe it is now ready for public consumption.
However, because it is a large change, it will need lots of public
exposure before it can be considered safe for general use.  Essentially,
I would like to do a "beta" release of the new code while not impacting
existing users of git-subtree in contrib.

During this time and due to work and life commitments, I have not been
able to keep up with the git mailing list as I would like.  Questions
and patches related to git-subtree have languished and I don't want to
lose that good work by our users.  Therefore, I would like to transfer
the main development activity over to GitHub.  GitHub's patch tracking,
review and feedback infrastructure works better for me that a large
mailing list with patches sent via e-mail.  It is easy to lose things in
a sea of conversations.  It's completely personal preference but I think
a switch to GitHub will also make tracking git-subtree's progress easier
for users.  Moving the main development to GitHub will also allow
git-subtree users to be more visible, ask questions and help each other
out.

Going forward, I would like to do the main feature and bug fix work on
GitHub and periodically subtree-merge to git's main repository under
contrib when the code has stabilized and we are reasonably confident
interfaces are stable.  This will allow us to experiment with new ideas
while keeping a stable codebase for end users.  I expect a lot of
re-engineering of the core bits of git-subtree to bring it into
compliance with git's coding standards, support new features and provide
a better user experience.

I believe keeping a stable git-subtree in contrib is valuable.
git-subtree and git-submodule provide alternative solutions to similar
problems, as well as each solving problems the other does not.
Anecdotally, I noticed an uptick in git-subtree user activity after the
move into contrib.  I would like to maintain that visibilty.

Does this mode of operation work for the larger git community?  Are
there suggestions of how to make this work as smoothly as possible?

Thank you for your feedback and support of git-subtree!

  -David


Re: [PATCH v5 1/1] contrib/subtree: Add a test for subtree rebase that loses commits

2016-06-28 Thread David A. Greene
Junio C Hamano <gits...@pobox.com> writes:

> gree...@obbligato.org (David A. Greene) writes:
>
>>> I also notice that files_subtree/master4 does not appear in any of
>>> the verification in the three tests that use the history being
>>> prepared here, i.e. if master4 is silently dropped while master5 is
>>> kept, such a bug won't be caught by them.
>>
>> Ah, good catch.  I should add a test for that.
>>
>> Let me do a re-roll of this since I think you bring up some excellent
>> points.  Might be a few days due to work obbligations.
>
> A friendly ping to see if I missed anything that happened after this
> message...

Just sent it.  I guess it took more than a few days... :)

   -David
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] contrib/subtree: Remove --annotate

2016-06-28 Thread David A. Greene
Junio C Hamano <gits...@pobox.com> writes:

> gree...@obbligato.org (David A. Greene) writes:
>
>> Just to clarify, what is the expectation of things in contrib?
>> Basically the same as other code?
>
> That heavily depends on your exit strategy.
>
> If the aspiration is to move up to exit, then the quality and
> stability expectation is basically the same as stuff in core, and we
> need to strive to keep it stable and high quality.

This is the strategy I was planning to pursue.  After extensive
experience with git-subtree and some local enhancements I have in
real-world work, I am convinced it is a great complementary tool to
git-submodule.  It seems odd to me to have one in core and one not.

>  * If the integration between "git subtree" and the rest of the
>system is loose (in other words, if your improved version of "git
>subtree" taken from Git 2.8 is dropped into an even newer version
>of Git 2.13, or an older version like Git 2.4 for that matter, is
>it expected to work, given the promise of interface stability git
>core gives you?), there is not much technical reason why it must
>stay in core.  Of course, your improvements may need to take
>advantage of improvements on the core side and your new "git
>subtree" may start to require at least Git 2.8, or you may even
>send patches to the core side to extend and enhance the services
>you use from the core side, but as long as that happens only
>occasionally and the dependency does not require lock-step
>upgrade, we can still call such an integration "loose" and moving
>out will still be a viable possibility.

The enhancements to git-subtree that I have and/or am planning to
implement will probably require some changes to core, mostly bugfixes.
Some of the rebase tests I've sent are heading in that direction.  They
are problems I discovered while trying to enhance subtree.

>  * If you expect the pace of improvement would be far faster than
>the release schedule of git core (usually a cycle lasts for 8 to
>12 weeks), moving out would give users a shorter turnaround for
>getting new and improved "git subtree".

I don't think this is a concern.

>  * It may even turn out that the users are a lot more tolerant for
>instability (e.g. removal of rarely used features) in "git
>subtree" than they require the git core proper to be stable, in
>which case moving up (rather than moving out) to apply the same
>stability requirement to "git subtree" as the rest of the system
>would be undesirable.

That's a fair point.  Besides than removing this --annotate option, I
anticipate two other potentially breaking changes:

1. Reorganizing metadata to be more useful - The metadata tags are
   somewhat misleading at the moment and there is additional metadata
   I've thought about adding.

2. Changing the split algorithm to reuse more of git core -
   Specifically, I would like to leverage filter-branch to eliminate a
   bunch of custom code in the split algorithm.  In fact doing so would
   fix a couple of bugs that have come in.  My intent for this change is
   to not alter the resulting history from what split does now (except
   fixing the known bugs) but I can't absolutely guarantee that will be
   the case until I implement it and try it out.

>  * Moving up and staying in has a big social implication. It gives
>the version that comes with git core an appearance of being
>authoritative, even when other people fork the project.
>
>- This discourages incompatible forks (e.g. when one such fork
>  finds the need to improve the "metadata" left by merge
>  operation and used by split, the resulting repository managed
>  by it may no longer usable by other variants of "git subtree",
>  and if there is one in-tree "authoritative" one that is
>  maintained, such a fork will not get wide adoption without
>  taking compatibility issues into account).

Other than the metadata rework mentioned above, I personally don't
anticipate a lot of change to it.  Some ideas have come in from
elsewhere but I'm not yet convinced they're necessary.  My guess is that
any future metadata changes will be more for convenience than any core
fnctionality.  Thus, they could be added in a backward-compatible way.

>- On the other hand, if the "authoritative" one moves too slowly,
>  that may hinder progress.  An exit by "moving out" to become
>  one of the projects that help people's Git-life would result in
>  two or more honestly competing forks of "git subtree", which
>  might give users a better end-result after a few years, even
>  though the users who happened 

Re: [PATCH] contrib/subtree: add repo url to commit messages

2016-05-21 Thread David A. Greene
Mathias Nyman  writes:

> For recalling where a subtree came from; git-subtree operations 'add'
> and 'pull', when called with the  parameter add this to the
> commit message:
> git-subtree-repo: 

I am sorry it tooks a couple of months to respond.  I am finally coming
up for air at work.

What is the future intent of this?  I've toyed with the idea of adding
something like this either as commit message metadata or in .gitconfig
but every time I get ready to pull the trigger, I question what it will
be used for.

Having been using git-subtree in anger for a couple of years now, I
frequently pull subtree updates from multiple sources, so noting a
particular repository is not only mostly meaningless, it may actually be
misleading in that a quick perusal of the logs may lead one to think
commits were draw from fewer places than they actually were.

I don't think it would be a good idea, for example, to have git-subtree
use this information to auto-guess from where to pull future commits.
Again, I think that would be misleading behavior.

 -David

> Other operations that don't have the  information, like
> 'merge' and 'add' without , are unchanged. Users with such a
> workflow will continue to be on their own with the --message parameter,
> if they'd like to record where the subtree came from.
>
> Signed-off-by: Mathias Nyman 
> Based-on-patch-by: Nicola Paolucci 
> ---
>  contrib/subtree/git-subtree.sh | 73 
> --
>  1 file changed, 49 insertions(+), 24 deletions(-)
>
> diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
> index 7a39b30..7cf73c0 100755
> --- a/contrib/subtree/git-subtree.sh
> +++ b/contrib/subtree/git-subtree.sh
> @@ -335,18 +335,21 @@ add_msg()
>   dir="$1"
>   latest_old="$2"
>   latest_new="$3"
> + repo="$4" # optional
>   if [ -n "$message" ]; then
>   commit_message="$message"
>   else
>   commit_message="Add '$dir/' from commit '$latest_new'"
>   fi
> - cat <<-EOF
> - $commit_message
> - 
> - git-subtree-dir: $dir
> - git-subtree-mainline: $latest_old
> - git-subtree-split: $latest_new
> - EOF
> + echo $commit_message
> + echo
> + echo git-subtree-dir: $dir
> + echo git-subtree-mainline: $latest_old
> + echo git-subtree-split: $latest_new
> + if [ -n "$repo" ]; then
> + repo_url=$(get_repository_url "$repo")
> + echo "git-subtree-repo: $repo_url"
> + fi
>  }
>  
>  add_squashed_msg()
> @@ -382,8 +385,9 @@ squash_msg()
>   dir="$1"
>   oldsub="$2"
>   newsub="$3"
> + repo="$4" # optional
>   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"
> @@ -397,6 +401,10 @@ squash_msg()
>   echo
>   echo "git-subtree-dir: $dir"
>   echo "git-subtree-split: $newsub"
> + if [ -n "$repo" ]; then
> + repo_url=$(get_repository_url "$repo")
> + echo "git-subtree-repo: $repo_url"
> + fi
>  }
>  
>  toptree_for_commit()
> @@ -440,12 +448,13 @@ new_squash_commit()
>   old="$1"
>   oldsub="$2"
>   newsub="$3"
> + repo="$4" # optional
>   tree=$(toptree_for_commit $newsub) || exit $?
>   if [ -n "$old" ]; then
> - squash_msg "$dir" "$oldsub" "$newsub" | 
> + squash_msg "$dir" "$oldsub" "$newsub" "$repo" |
>   git commit-tree "$tree" -p "$old" || exit $?
>   else
> - squash_msg "$dir" "" "$newsub" |
> + squash_msg "$dir" "" "$newsub" "$repo" |
>   git commit-tree "$tree" || exit $?
>   fi
>  }
> @@ -517,6 +526,16 @@ ensure_valid_ref_format()
>   die "'$1' does not look like a ref"
>  }
>  
> +get_repository_url()
> +{
> + repo=$1
> + repo_url=$(git config --get remote.$repo.url)
> + if [ -z "$repo_url" ]; then
> + repo_url=$repo
> + fi
> + echo $repo_url
> +}
> +
>  cmd_add()
>  {
>   if [ -e "$dir" ]; then
> @@ -548,19 +567,18 @@ cmd_add()
>  cmd_add_repository()
>  {
>   echo "git fetch" "$@"
> - repository=$1
> + repo=$1
>   refspec=$2
>   git fetch "$@" || exit $?
>   revs=FETCH_HEAD
> - set -- $revs
> + set -- $revs $repo
>   cmd_add_commit "$@"
>  }
>  
>  cmd_add_commit()
>  {
> - revs=$(git rev-parse $default --revs-only "$@") || exit $?
> - set -- $revs
> - rev="$1"
> + rev=$(git rev-parse $default --revs-only "$1") || exit $?
> + repo="$2" # optional
>   
>   debug "Adding $dir as '$rev'..."
>   git read-tree --prefix="$dir" $rev || exit $?
> @@ -575,12 +593,12 @@ cmd_add_commit()
>   fi

Re: Subtree split unsquashes everything

2016-05-21 Thread David A. Greene
Joseph Musser  writes:

> I ran `git subtree split -P=subdir/subdir/ -b newbranch` and the
> outcome seems to be perfect except that each squash merge has turned
> into a full merge, bringing along all history from the other repo. Why
> does it do this and how can I preserve my repo history, including only
> squashes from the subtree remote repo like it is today?

The only thing that --squash does on an add/merge/pull is a read-tree of
the fetched commit into a new commit in the host repository which is
then merged in to the host repository's branch.  It also annotates the
hash of the original commit in the git-subtree-split metadata.

As the split code processes commits it records parents to link up the
history to that in the subtree's original repository.  Crucially, the
git-subtree-split metadata of the commit message git-subtree creates for
squashes lists the original commit ID of the squashd commit.  That lets
git-subtree hook up split commits back to the original project history.
I believe that's why the split branch is showing the full history.  It's
baked into the split algorithm.

Presumably you split the subdirectory from the same working repository
in which you added the subtree commits in the first place.  Thus the
history of the original project is all there (it was fetched when the
subtree was added/merged).  I have not tested this, but I wonder what
would happen if you either deleted that history from the host repository
or you cloned the host repository to a new place and tried the split
there.  The original hisory wouldn't be there and git-subtree would not
have it to hook up to.

I have mentioned before that I'm working on a complete overhaul of the
split code.  Since git-subtree split it typically used to send commits
back to the original subtree repository, I never imagined that someone
would *not* want to get the original history back.  If the squash were
not reversed we would not be able to merge the history back in to the
original repository.  If keeping squashes is truly desired I will have
to think about how to do that, likely as a non-default option to split
or even an entirely different command.

  -David
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Subtree Split Includes Commits Outside Prefix Directory

2016-05-21 Thread David A. Greene
ELI  writes:

> I then reviewed the commit history of contrib/subtree/git-subtree.sh
> and determined that the last successful subtree push was performed
> prior to the integration of this change:
> https://git.kernel.org/cgit/git/git.git/commit/contrib/subtree/git-subtree.sh?id=933cfeb90b5d03b4096db6d60494a6eedea25d03
>
> As a next step, I reversed that patch on my local install of git
> subtree, and the result was a successful subtree push.

So you're saying that this patch caused a regression?

> Unfortunately, I have not yet reproduced this with a test main project
> and subprojects, and I cannot make the project I observed it in
> public.

I very much want to see a testcase for this.  I'm planning to
fundamentally rewrite the split code this year and want to make sure it
covers everything it does now and fixes a few bugs that have been
exposed lately.

It's tough to revert that patch since it fixed a problem for someone and
we don't have a testcase demonstrating the problem you encountered.  Not
saying your problem isn't important but we need to understand it and
have a way to flag it before fixing or hiding it with a revert of the
above patch.

   -David
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Git subtree stumbles over annotated tags

2016-05-21 Thread David A. Greene
Gregor Jasny  writes:

> Hello,
>
> On 10/03/16 16:51, Gregor Jasny wrote:
>> today I discovered that it's a bad idea to "git subtree pull" from an
>> annotated tag. This issue got discussed in those two threads:
>>
>> http://comments.gmane.org/gmane.comp.version-control.git/247503> 
>> http://comments.gmane.org/gmane.comp.version-control.git/248395>
>> I was under the impression that it is fixed in recent versions of git
>> but my homebrew 2.7.0 still behaves badly. If I run the attached script
>> to reproduce the issue I get the following error message:
>
> For the record: this bug was already fixed in November:
> https://github.com/git/git/commit/5d65fe312e22594b7fec7349945fb0072987716b#diff-59f70cbe935ec223e3df413b94cab740
>
> Would it make sense to cherry-pick it into 2.7.x?

I wouldn't object to it if you can prepare the patch but git-subtree is
under heavy development and I don't have the free cycles to maintain a
"release" version of it.

  -David
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 0/3] subtree: add 'git-subtree-repo' and list command

2016-05-21 Thread David A. Greene
Nicola Paolucci  writes:

> To my knowledge 'git subtree' currently lacks a way to
> track where injected repositories come from originally.
> Adding this information allows for useful extensions to 
> the command and makes it easier to use subtrees to track
> external dependencies.

Thanks for working on this.  I just sent a reply to your earlier
iteration.

What is the intent for use of this?  Is it simply to record from where
commits were pulled or do you intend to use this information later on to
have git-subtree guess from where to fetch future commits?

I would be opposed to the latter because I think it potentially limits
the utility of git-subtree and may be misleading.  I frequently pull
commits for a subtree from several different clones of the same
reposiory.  How does git-subtree list handle that situation?

Does git-subtree list really print out repository information for every
commit added by git-subtree?  That's potentially a lot of commits.  It
might be more useful to aggregate repository information and only dump
out unique URLs.  In any case, processing all commits seems like a ton
of work for such a simple operation.  Maybe this information should be
cached in .gitconfig.

I'm actually in the middle of cleaing up metadata but I'm not going to
block these commits due to that.  Just be aware that it may change a
bit.

  -David
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] contrib/subtree: Split history with empty trees correctly

2016-02-02 Thread David A. Greene
Marcus Brinkmann  writes:

>> Are you still able to do a re-roll on this?
>
> I have to admit that my interest has declined steeply since
> discovering that subtree-split and filter-branch --subtree-filter give
> different results from "git svn" on the subdirectory.  The reason is
> that git-svn includes all commits for revisions that regular "svn log"
> gives on that directory, which includes commits that serve as branch
> points only or that are empty except for unhandled properties.

What do you mean by "branch points only?"

It's ok if you can't do a reroll.  I can't work on it right now but
perhaps when I get back to cleaning up the split code I can take what
you have and incoporate it.  I do very much appreciate your work on
this!

> While empty commits for unhandled properties wouldn't be fatal,
> missing branch points make "git svn" really unhappy when asked to
> rebuild .git/svn.

[ I may have misunderstood your intent, see below. ]

I just want to make sure I understand your situation.  You used git-svn
to mirror a project to git and then used git-subtree to incorporate that
mirror into a larger project?

Why is the split being done?  If there's an active Subversion repository
being mirrors it's much better to commit changes back to the Subversion
repository than to the git mirror.

> As migration from SVN is my main motivation at this point to use a
> subtree filter at this point (git-svn is just very slow - about one
> week on our repository), I am somewhat stuck and back to using
> git-svn. Although hacking up something with filter-branch seems like a
> remote option, it's probably nothing that generalizes.

Ok, maybe I misunderstood your situation.  Are you converting one big
repository via git-svn and then trying to break out individual
directories into smaller projects?

git-svn + git-subtree/git-filter-branch is not the best way to do that.
svn-all-fast-export is far superior for a one-off conversion and makes
splitting repositories a breeze.  It happens during conversion rather
than as a post-processing step.

https://techbase.kde.org/Projects/MoveToGit/UsingSvn2Git

> It didn't help that "make test" in contrib/subtree gives me 27 out of
> 29 failed tests (with no indication how to figure out what exactly
> failed).

Huh.  I don't know why that would happen.  Did you build the git tools
first?  A testing run using --debug and --verbose (see the Makefile in
contrib/subtree/t) would be informative.  I understand if you don't have
time to do that.  I haven't seen such failures before so I'm curious as
to what happened.

  -David
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] contrib/subtree: Split history with empty trees correctly

2016-01-27 Thread David A. Greene
[ Sorry it took a few days to reply.  I am absolutely slammed at work
  and will be for the next few weeks at least.  The good news is that
  it's resulting in some nice work on git-subtree!  :) ]

Marcus Brinkmann <m.brinkm...@semantics.de> writes:

> On 01/20/2016 05:05 AM, David A. Greene wrote:
>> Marcus Brinkmann <m.brinkm...@semantics.de> writes:
>> 
>>> 'git subtree split' will fail if the history of the subtree has empty
>>> tree commits (or trees that are considered empty, such as submodules).
>>> This fix keeps track of this condition and correctly follows the history
>>> over such commits.
>> 
>> Thanks for working on this!  Please add a test to t7900-subtree.sh.
>
> I couldn't get the tests to run and I couldn't find documentation on how
> to run it.  If you enlighten me I can add a test :)

Just run "make test" in contrib/subtree.  You have to build git first.

>> Can you explain the logic here?  The old code appears to be using the
>> lack of a tree to filter out "mainline" commits from the subtree history
>> when splitting.  If that test is only done before seeing a proper
>> subtree commit and never after, then any commit mainline commit
>> following the first subtree commit in the rev list will miss being
>> marked with set_notree and the cache will not have the identity entry
>> added.
>> 
>> Test #36 in t7900-subtree.sh has a mainline commit listed after the
>> first subtree commit in the rev list, I believe.
>> 
>> I'm not positive your change is wrong, I'd just like to understand it
>> better.  I'd also like a comment explaining why it works so future
>> developers don't get confused.  Overall, I am trying to better comment
>> the code as I make my own changes.
>
> It's possible the patch does not work for some cases.  For example, I
> don't know how the rejoin variant of splits work.

I'm not so much worried about catching all cases of the bug you
identified, though it would be good if the patch did.  I'm much more
concerned about not causing a regression in existing functionality.

> Some observations:
>
> 1) The notree list is never actually used except to identify which
> commits have been visited in check_parents.

It's really verifying that we visited parents before children in the
split code, I think.  That seems like a good check to keep.

Let me make sure I understand your fix too.  Are you essentially
skipping empty commits when splitting?  You original patch said that
split failed but didn't say how.  Did git-subtree spit out an error
message, or did the failure manifest in some other way?  If I knew the
failure mode it might help me understand your changes better.

I see you explain the proble below (thanks!) but I'd still like to know
how you discovered it.  It will help in constructing a test.

> 2) I have no idea what use case is covered by the "if [ -n "$newparents"
> ]; then cache_set $rev $rev; fi".  I left it in purely for traditional
> reasons.  So, clarifying that would go a long way in understanding the
> code, and if there is a test for that, I will figure it out.

As far as I understand things, $newparents being non-empty means that
the commits parents were split out and $newparents contains the hashes
of the split commits, so that when this commit is split it can set up
the proper parent links.

If the commit doesn't have a tree in the subdirectory, then I *think*
the split codesimply sets the identity entry in the cache so that any
future commit that has this (empty) one as a parent will see it in the
$newparents list.  Since copy_or_skip checks for parents with empty
trees and does not link split commits to them, I don't understand the
purpose of including these commits in $newparents.

So you may very well be right that it just doesn't matter if we skip
these altogether.

> 3a) The bug happens because on the first commit that deletes the subdir,
> newparents will not be empty, and the "cache_set $rev $rev" will kick in
> and subsequently (when the subdir is added again) the history will
> divert into the $rev commit which is not rewritten, but part of the
> unsplit tree.  This seems very wrong to me!  See 2).

Ah, so the problem isn't empty commits per se, it's the fact that a
subdirectory was deleted and re-added.  That makes sense.  I didn't
understand that from your original commit message though I now remember
you discussed it in the first e-mail you sent.  It would be good to
clarify this in the final commit.

I agree that the behavior you describe is wrong.  So the fix basically
relies on the fact that there is some tree in the subdirectory, which
later gets deleted, but since "found_first_commit" triggered, we'll just
skip those empty commits and never see them in the 

Re: [PATCH] contrib/subtree: Split history with empty trees correctly

2016-01-27 Thread David A. Greene
Marcus Brinkmann  writes:

> With my patch, "git subtree split -P" produces the same result (for my
> data set) as "git filter-branch --subdirectory-filter", which is much
> faster, because it selects the revisions to rewrite before rewriting.
> As I am not using any of the advanced features of "git subtree", I will
> just use "git filter-branch" instead.

Heh.  :)

I hope to replace all that ugly split code with filter-branch as you
describe but there are some cases where it differs.  It may be that your
changes fix some of that.

Are you still able to do a re-roll on this?

  -David
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] contrib/subtree: Remove --annotate

2016-01-05 Thread David A. Greene
Junio C Hamano <gits...@pobox.com> writes:

> David Greene <gree...@obbligato.org> writes:
>
>> From: "David A. Greene" <gree...@obbligato.org>
>>
>> Remove --annotate.  This obviates the need for an --unannotate
>> command, which is both an obvious addition and difficult to define
>> due to the numerous ways one might want to specify how to edit
>> commit messages.  git has other tools more suited to rewriting
>> commit messages and it's easy enough to use them after a subtree
>> split.  Such tools include filter-branch, rebase -i and
>> commit --amend.
>
> I do not think that "there are other ways to do this" is a good
> justification for removing a feature, unless it can be shown that
> nobody is using it, of course.

I thought you might say that.  :)

I honestly don't know how much it's used.  Obviously someone uses it
because we got a request a couple of years ago for an --unannotate
option and the ensuing discussion made it clear that that's not a
trivial thing.

The original author is not active anymore so I don't even know why it
was added in the first place.  I don't know how to get data about usage.

I'm in the process of getting git-subtree into shape so it can move out
of contrib into the main area.  Is there a policy for interface changes
to things in contrib?

There are a few other things I'm working on that will involve slight
semantic changes.  I was planning to do those similarly to how push
changed with git 2.0.  Make the current behavior default, emit a warning
and switch the default after a few releases.  This is all being done to
make git-subtree faster, take advanted of new git features since it was
opriginally written and generally make it more solid and predictable.  I
could do the deprecate/remote thing with --annotate if that sounds
better to you.

My thinking on this change runs as follows:

- --annotate isn't as powerful/flexible as other git commit message
  rewrite tools.

- Its obvious pair feature --unannotate isn't trivial to do -- people
  didn't even agree on what it *should* do.  It won't be added any
  time soon, if at all, so don't advertise something that naturally
  leads people to request it.

- We really shouldn't lie about the state of this.  --annotate feels
  tacked-on and incomplete.  It would be best to not have it at all if
  we can't do it right.

- Better to make the change now before moving out of contrib.

If you really don't want to get rid of this, I guess that's ok but my
preference as maintainer is to reduce the feature set to those things
people seem to actually regularly use (according to my very unscientific
Google searches) and add features as requested/evaluated.  --annotate
isn't a huge maintenance burdern but some of those other changes I
mentioned do in fact significantly reduce the maintenance burden of
git-subtree.  I hope I will have some leeway with those, even if they
change semantics slightly.

>> @@ -319,7 +315,7 @@ copy_commit()
>>  GIT_COMMITTER_NAME \
>>  GIT_COMMITTER_EMAIL \
>>  GIT_COMMITTER_DATE
>> -(printf "%s" "$annotate"; cat ) |
>> +(echo -n ""; cat ) |
>
> I can see that by changing "printf something" with 'echo -n ""', you
> are making it clear that we are stopping to add that something to
> the pipeline, but (1) I think the intended effect of running 'echo
> -n' on an empty string is to do nothing, and (2) 'echo -n' is not
> portable [*1*], so this leaves a puzzling code that makes future
> readers scratch their heads.
>
> I wonder why this cannot be simply the removal of the entire line,
> making the resulting implementation more like this:
>
> git log -1 --pretty=format:... "$1" |
> (
> read ... various variables ...
> export ... various variables ...
> - (printf "%s" "$annotate"; cat ) |
> git commit-tree "$2" $3 # reads the rest of stdin
> ) || die "cannot copy"
>
> That is, just feed the remainder of what is coming directly to the
> command?

That makes sense.  Thanks.

   -David
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] Add a test for subtree rebase that loses commits

2016-01-05 Thread David A. Greene
Eric Sunshine <sunsh...@sunshineco.com> writes:

> On Mon, Jan 4, 2016 at 11:40 PM, David Greene <gree...@obbligato.org> wrote:
>> This test merges an external tree in as a subtree, makes some commits
>> on top of it and splits it back out.  In the process the added commits
>> are lost.  This is marked to expect failure so that we don't forget to
>> fix it.
>>
>> Signed-off-by: David A. Greene <gree...@obbligato.org>
>> ---
>> diff --git a/t/t3427-rebase-subtree.sh b/t/t3427-rebase-subtree.sh
>> @@ -0,0 +1,68 @@
>> +#!/bin/sh
>> +
>> +test_description='git rebase tests for -Xsubtree
>> +
>> +This test runs git rebase and tests the subtree strategy.
>> +'
>> +. ./test-lib.sh
>> +
>> +addfile() {
>> +name=$1
>> +echo $(basename ${name}) > ${name}
>> +${git} add ${name}
>> +${git} commit -m "Add $(basename ${name})"
>> +}
>
> What is this function for? It doesn't seem to be used at all by this script.

Nothing.  I had sent a mail saying not to apply the patch but it
bounced.  :)

Will fix.

>> +check_equal()
>> +{
>
> Style: Place brace on the same line as the function declaration.
>
>> +   test_debug 'echo'
>> +   test_debug "echo \"check a:\" \"{$1}\""
>> +   test_debug "echo \"  b:\" \"{$2}\""
>> +   if [ "$1" = "$2" ]; then
>
> Style: Use 'test' rather than '[', drop semi-colon, and place 'then'
> on its own line.

Ok.

>> +   return 0
>> +   else
>> +   return 1
>> +   fi
>
> This entire if/else/fi can be rephrased as just a single line at the
> end of the function:
>
> test "$1" = "$2"
>
> the result of which will be 0 if the strings are equal, else 1, thus
> there's no need for if/else/fi.

Ok.

>> +}
>
> Isn't check_equal() pretty much a (less generic) re-invention of
> t/test-lib-functions.sh:verbose()?

Dunno.  I'll have to look.

>> +last_commit_message()
>> +{
>> +   git log --pretty=format:%s -1
>> +}
>
> Are there plans to re-use this function by more than the current
> single call site? If not, it might be just as clear to assign the
> result of the expression to an aptly named variable directly in the
> caller:
>
>last_commit_msg=$(git log --pretty=format:%s -1)
>
> or something.

The intent is to add more tests later.  In fact I have at least a couple
more to add.

>> +test_expect_success 'setup' '
>> +   test_commit README &&
>> +   mkdir files &&
>> +   cd files &&
>> +   git init &&
>> +   test_commit master1 &&
>> +   test_commit master2 &&
>> +   test_commit master3 &&
>> +   cd .. &&
>
> Mentioned by Torsten: If any command before "cd .." fails, then "cd
> .." won't be invoked, and subsequent tests will be executed in the
> wrong directory. Use a subshell to overcome this problem since the
> current directory of the parent shell is not impacted by the subshell
> (thus you can drop the "cd .." altogether):
>
> mkdir files &&
> (
> cd files &&
> git init &&
> ...
> ) &&
> ...

Yep.  Thanks.

>> +   test_debug "echo Add project master to master" &&
>> +   git fetch files master &&
>> +   git branch files-master FETCH_HEAD &&
>> +   test_debug "echo Add subtree master to master via subtree" &&
>> +   git read-tree --prefix=files_subtree files-master &&
>> +   git checkout -- files_subtree &&
>> +   tree=$(git write-tree) &&
>> +   head=$(git rev-parse HEAD) &&
>> +   rev=$(git rev-parse --verify files-master^0) &&
>> +   commit=$(git commit-tree -p ${head} -p ${rev} -m "Add subproject 
>> master" ${tree}) &&
>
> Nit: This could be less syntactically noisy by dropping the
> unnecessary braces: ${head} -> $head

Ok.  It's the style I usually use but I'll go with the git convention.

>> +   git reset ${commit} &&
>> +   cd files_subtree &&
>> +   test_commit master4 &&
>> +   cd .. &&
>> +   test_commit files_subtree/master5
>> +'
>> +
>> +# Does not preserve master4 and master5.
>> +test_expect_failure 'Rebase default' '
>> +   git checkout -b rebase-default master &&
>> +   git filter-branch --prune-empty -f --subdirectory-filter 
>> files_subtree &&
>> +   git commit -m "Empty commit" --allow-empty &&
>> +   git rebase -Xsubtree=files_subtree  --preserve-merges --onto 
>> files-master master &&
>
> Style: Too many spaces before --preserve-merges.

Thanks.

>> +   check_equal "$(last_commit_message)" "files_subtree/master5"
>
> Hmm, is checking the commit message the best way to determine if the
> expected commit was there? Why not check the commit ID instead or
> something?

I'll look into that.

Thanks for the good feedback!

  -David
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Odd rebase behavior

2015-12-18 Thread David A. Greene
John Keeping  writes:

> It seems that the problem is introduces by --preserve-merges (and
> -Xsubtree causes something interesting to happen as well).  I see the
> following behaviour:

Thanks for narrowing this down!  Is it possible this is actually a
cherry-pick problem since --preserve-merges forces rebase to use
cherry-pick?

> git rebase -Xsubtree=files_subtree --onto files-master master
>
>   fatal: Could not parse object 
> 'b15c4133fc3146e1330c84159886f0f7a09fbf43^'
>   Unknown exit code (128) from command: git-merge-recursive
> b15c4133fc3146e1330c84159886f0f7a09fbf43^ -- HEAD
> b15c4133fc3146e1330c84159886f0f7a09fbf43

Ah, good!  I had seen this behavior as well but couldn't remember what I
did to trigger it.

I don't think I have the expertise to fix rebase and/or cherry-pick.
What's the process for adding these tests to the testbase and marking
them so the appropriate person can fix them?  I see a lot of TODO tests.
Should I mark these similarly and propose a patch to the testbase?

 -David
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Odd rebase behavior

2015-12-15 Thread David A. Greene
Hi,

The attached tests do not do what I expected them to do.  I commented
out the tests involving the new rebase empty commit behavior I just
sent.  The uncommented tests show the strange behavior.

According to the rebase man page, rebase gathers commits as in "git log
..HEAD."  However, that is not what happens in the tests
below.  Some of the commits disappear.

The test basically does this:

- Setup a master project and a subproject, merged via a subtree-like
  merge (this is how git-subtree does it).

- Add some commits to the subproject directory after the subtree merge,
  to create some history not in the original subproject.

- filter-branch --subdirectory-filter to extract commits from the
  subproject directory.

- Rebase those commits back on to the original subproject repository.

The above loses all commits made after the subproject is merged into
the main project.

Note that the rebase is a little wonky.  filter-branch creates a
disconnected graph and the rebase is invoked with =master.
I'm not sure how rebase is supposed to operate in this case (if it is
supported at all) but it definitely is not doing the master..HEAD thing.

Replacing "master" with "--root" causes rebase to do the right thing.

This seems like a bug to me, even with the strange  on a
disconnected graph.  At the very least git should not silently lose
commits.

I can think of two ways this could be resolved:

- Forbid this kind of operation and error our with a message (when
   and HEAD do not share ancestry)

- Make it work as if --root were specified

Thoughts?

 -David

--->8---

#!/bin/sh

test_description='git rebase tests for empty commits

This test runs git rebase and tests handling of empty commits.
'
. ./test-lib.sh

addfile() {
name=$1
echo $(basename ${name}) > ${name}
${git} add ${name}
${git} commit -m "Add $(basename ${name})"
}

check_equal()
{
test_debug 'echo'
test_debug "echo \"check a:\" \"{$1}\""
test_debug "echo \"  b:\" \"{$2}\""
if [ "$1" = "$2" ]; then
return 0
else
return 1
fi
}

last_commit_message()
{
git log --pretty=format:%s -1
}

test_expect_success 'setup' '
test_commit README &&
mkdir files &&
cd files &&
git init &&
test_commit master1 &&
test_commit master2 &&
test_commit master3 &&
cd .. &&
test_debug "echo Add project master to master" &&
git fetch files master &&
git branch files-master FETCH_HEAD &&
test_debug "echo Add subtree master to master via subtree" &&
git read-tree --prefix=files_subtree files-master &&
git checkout -- files_subtree &&
tree=$(git write-tree) &&
head=$(git rev-parse HEAD) &&
rev=$(git rev-parse --verify files-master^0) &&
commit=$(git commit-tree -p ${head} -p ${rev} -m "Add subproject 
master" ${tree}) &&
git reset ${commit} &&
cd files_subtree &&
test_commit master4 &&
cd .. &&
test_commit files_subtree/master5
'

# Does not preserve master4 and master5.
test_expect_success 'Rebase default' '
git checkout -b rebase-default master &&
git filter-branch --prune-empty -f --subdirectory-filter files_subtree 
&&
git commit -m "Empty commit" --allow-empty &&
git rebase -Xsubtree=files_subtree  --preserve-merges --onto 
files-master master &&
check_equal "$(last_commit_message)" "files_subtree/master5"
'

# Does not preserve master4, master5 and empty.
test_expect_success 'Rebase --keep-empty' '
git checkout -b rebase-keep-empty master &&
git filter-branch --prune-empty -f --subdirectory-filter files_subtree 
&&
git commit -m "Empty commit" --allow-empty &&
git rebase -Xsubtree=files_subtree --keep-empty --preserve-merges 
--onto files-master master &&
check_equal "$(last_commit_message)" "Empty commit"
'


# Does not preserve master4 and master5.
#test_expect_success 'Rebase --keep-redundant' '
#   git checkout -b rebase-keep-redundant master &&
#   git filter-branch --prune-empty -f --subdirectory-filter files_subtree 
&&
#   git commit -m "Empty commit" --allow-empty &&
#   git rebase -Xsubtree=files_subtree --keep-redundant --preserve-merges 
--onto files-master master &&
#   check_equal "$(last_commit_message)" "files_subtree/master5"
#'


# Does not preserve master4, master5 and empty.
#test_expect_success 'Rebase --keep-empty --keep-redundant' '
#   git checkout -b rebase-keep-empty-keep-redundant master &&
#   git filter-branch --prune-empty -f --subdirectory-filter files_subtree 
&&
#   git commit -m "Empty commit" --allow-empty &&
#   git rebase -Xsubtree=files_subtree --keep-empty --keep-redundant 
--preserve-merges --onto files-master master &&
#   check_equal "$(last_commit_message)" "Empty commit"
#'


test_done
--
To 

rebase -X subtree

2015-11-30 Thread David A. Greene
Hi,

I had a particular notion of what rebase -X subtree would do but I am
apparently mistaken.  What should be the result of the script below?  I
expected commits to be replayed on top of master with their trees
adjusted to move files into a "files" directory.  In the first case, the
rebase seems to have done nothing.  In the second case I get an error:

First, rewinding head to replay your work on top of it...
fatal: Could not parse object '6c0826e4cf4b1f44ebafbd4084c1f0066a59d112^'
Unknown exit code (128) from command: git-merge-recursive 
6c0826e4cf4b1f44ebafbd4084c1f0066a
59d112^ -- HEAD 6c0826e4cf4b1f44ebafbd4084c1f0066a59d112
   

If "files" exists and I use rebase -X subtree it replays the commits,
moving trees out from under "files," as I would expect.  Is it not
possible to use git rebase to move trees under a new subdirectory?

I know that I can use filter-branch to accomplish what I want, I'm just
curious whether git rebase is expected to behave as I thought.  At the
very least, it seems a better error message in the orphan branch case
would be helpful.

Thanks for you help!

  -David

#!/bin/bash

function addfile {
name=$1
echo ${name} > ${name}
git add ${name}
git commit -m "Add ${name}"
}

mkdir rebasetest1
cd rebasetest1
git init

addfile README

git checkout -b work

addfile file1

git rebase -X subtree=files --onto master master

cd ..

mkdir rebasetest2
cd rebasetest2
git init

addfile README

git checkout --orphan work

addfile file1

git rebase -X subtree=files --onto master --root
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] contrib/subtree: unwrap tag refs

2015-11-12 Thread David A. Greene
Rob Mayoff  writes:

> diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
> index 9f06571..b051600 100755
> --- a/contrib/subtree/git-subtree.sh
> +++ b/contrib/subtree/git-subtree.sh
> @@ -245,7 +245,10 @@ find_latest_squash()
>   case "$a" in
>   START) sq="$b" ;;
>   git-subtree-mainline:) main="$b" ;;
> - git-subtree-split:) sub="$b" ;;
> + git-subtree-split:)
> + sub="$b"

Why include the above line?

> + sub="$(git rev-parse "$b^0")" || die "could not 
> rev-parse split hash $b from commit $sq"

This seems like odd quoting.  Would not this do the same?

sub="$(git rev-parse $b^0)" || die "could not 
rev-parse split hash $b from commit $sq"

Perhaps I am missing something.

> + ;;
>   END)
>   if [ -n "$sub" ]; then
>   if [ -n "$main" ]; then
> @@ -278,7 +281,10 @@ find_existing_splits()
>   case "$a" in
>   START) sq="$b" ;;
>   git-subtree-mainline:) main="$b" ;;
> - git-subtree-split:) sub="$b" ;;
> + git-subtree-split:)
> + sub="$b"

And here too.

> + sub="$(git rev-parse "$b^0")" || die "could not 
> rev-parse split hash $b from commit $sq"

Same as above.

-David
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/7] contrib/subtree: Clean and refactor test code

2015-11-10 Thread David A. Greene
David Greene <gree...@obbligato.org> writes:

Just a ping to ask if anyone has looked at this.  Apparently send-email
uses the commit author as the From address.  These messages are actually
from me, sent on behalf of the commit authors.

I've got more coming, but want to get these in first as they clean up
the testsuite and will make adding future changes easier.

  -David

> From: Techlive Zheng <techlivezh...@gmail.com>
>
> Mostly prepare for the later tests refactoring.  This moves some
> common code to helper functions and generally cleans things up to be
> more presentable.
>
> Signed-off-by: Techlive Zheng <techlivezh...@gmail.com>
> Signed-off-by: David A. Greene <gree...@obbligato.org>
> ---
>  contrib/subtree/t/Makefile |  31 ---
>  contrib/subtree/t/t7900-subtree.sh | 103 
> -
>  2 files changed, 79 insertions(+), 55 deletions(-)
>
> diff --git a/contrib/subtree/t/Makefile b/contrib/subtree/t/Makefile
> index c864810..276898e 100644
> --- a/contrib/subtree/t/Makefile
> +++ b/contrib/subtree/t/Makefile
> @@ -13,11 +13,23 @@ TAR ?= $(TAR)
>  RM ?= rm -f
>  PROVE ?= prove
>  DEFAULT_TEST_TARGET ?= test
> +TEST_LINT ?= test-lint
> +
> +ifdef TEST_OUTPUT_DIRECTORY
> +TEST_RESULTS_DIRECTORY = $(TEST_OUTPUT_DIRECTORY)/test-results
> +else
> +TEST_RESULTS_DIRECTORY = ../../../t/test-results
> +endif
>  
>  # Shell quote;
>  SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
> +PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
> +TEST_RESULTS_DIRECTORY_SQ = $(subst ','\'',$(TEST_RESULTS_DIRECTORY))
>  
> -T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)
> +T = $(sort $(wildcard t[0-9][0-9][0-9][0-9]-*.sh))
> +TSVN = $(sort $(wildcard t91[0-9][0-9]-*.sh))
> +TGITWEB = $(sort $(wildcard t95[0-9][0-9]-*.sh))
> +THELPERS = $(sort $(filter-out $(T),$(wildcard *.sh)))
>  
>  all: $(DEFAULT_TEST_TARGET)
>  
> @@ -26,20 +38,22 @@ test: pre-clean $(TEST_LINT)
>  
>  prove: pre-clean $(TEST_LINT)
>   @echo "*** prove ***"; GIT_CONFIG=.git/config $(PROVE) --exec 
> '$(SHELL_PATH_SQ)' $(GIT_PROVE_OPTS) $(T) :: $(GIT_TEST_OPTS)
> - $(MAKE) clean
> + $(MAKE) clean-except-prove-cache
>  
>  $(T):
>   @echo "*** $@ ***"; GIT_CONFIG=.git/config '$(SHELL_PATH_SQ)' $@ 
> $(GIT_TEST_OPTS)
>  
>  pre-clean:
> - $(RM) -r test-results
> + $(RM) -r '$(TEST_RESULTS_DIRECTORY_SQ)'
>  
> -clean:
> - $(RM) -r 'trash directory'.* test-results
> +clean-except-prove-cache:
> + $(RM) -r 'trash directory'.* '$(TEST_RESULTS_DIRECTORY_SQ)'
>   $(RM) -r valgrind/bin
> +
> +clean: clean-except-prove-cache
>   $(RM) .prove
>  
> -test-lint: test-lint-duplicates test-lint-executable
> +test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax
>  
>  test-lint-duplicates:
>   @dups=`echo $(T) | tr ' ' '\n' | sed 's/-.*//' | sort | uniq -d` && \
> @@ -51,12 +65,15 @@ test-lint-executable:
>   test -z "$$bad" || { \
>   echo >&2 "non-executable tests:" $$bad; exit 1; }
>  
> +test-lint-shell-syntax:
> + @'$(PERL_PATH_SQ)' ../../../t/check-non-portable-shell.pl $(T) 
> $(THELPERS)
> +
>  aggregate-results-and-cleanup: $(T)
>   $(MAKE) aggregate-results
>   $(MAKE) clean
>  
>  aggregate-results:
> - for f in ../../../t/test-results/t*-*.counts; do \
> + for f in '$(TEST_RESULTS_DIRECTORY_SQ)'/t*-*.counts; do \
>   echo "$$f"; \
>   done | '$(SHELL_PATH_SQ)' ../../../t/aggregate-results.sh
>  
> diff --git a/contrib/subtree/t/t7900-subtree.sh 
> b/contrib/subtree/t/t7900-subtree.sh
> index dfbe443..f9dda3d 100755
> --- a/contrib/subtree/t/t7900-subtree.sh
> +++ b/contrib/subtree/t/t7900-subtree.sh
> @@ -5,7 +5,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.
>  '
>  
> @@ -20,7 +20,6 @@ create()
>   git add "$1"
>  }
>  
> -
>  check_equal()
>  {
>   test_debug 'echo'
> @@ -38,6 +37,30 @@ undo()
>   git reset --hard HEAD~
>  }
>  
> +# 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()
> +{
> + commit=
> + all=
> + while read x y; do
> + if [ -z "$x" ]; then
> + continue
> +  

[PATCH 1/8] contrib/subtree: Use %B for split subject/body

2013-02-18 Thread David A. Greene
From: Techlive Zheng techlivezh...@gmail.com

Use %B to format the commit message and body to avoid an extra newline
if a commit only has a subject line.

Signed-off-by: Techlive Zheng techlivezh...@gmail.com
Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/t/t7900-subtree.sh |   11 +++
 1 file changed, 11 insertions(+)

diff --git a/contrib/subtree/t/t7900-subtree.sh 
b/contrib/subtree/t/t7900-subtree.sh
index 80d3399..8dd6a82 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -226,6 +226,17 @@ test_expect_success 'check hash of split' '
check_equal ''$new_hash'' $subdir_hash
 '
 
+test_expect_success 'check hash of split' '
+spl1=$(git subtree split --prefix subdir) 
+undo 
+git subtree split --prefix subdir --branch splitbr1test 
+check_equal ''$(git rev-parse splitbr1test)'' $spl1
+git checkout splitbr1test 
+new_hash=$(git rev-parse HEAD~2) 
+git checkout mainline 
+check_equal ''$new_hash'' $subdir_hash
+'
+
 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 
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/8] contrib/subtree: Fix whitespaces

2013-02-18 Thread David A. Greene
From: Techlive Zheng techlivezh...@gmail.com

Previous code does not fulfill Git's whitespace policy.

Signed-off-by: Techlive Zheng techlivezh...@gmail.com
Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/git-subtree.sh |   68 
 contrib/subtree/git-subtree.txt|   42 ++---
 contrib/subtree/t/t7900-subtree.sh |  326 +---
 3 files changed, 206 insertions(+), 230 deletions(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 8a23f58..6c3929b 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -5,7 +5,7 @@
 # Copyright (C) 2009 Avery Pennarun apenw...@gmail.com
 #
 if [ $# -eq 0 ]; then
-set -- -h
+   set -- -h
 fi
 OPTS_SPEC=\
 git subtree add   --prefix=prefix commit
@@ -111,9 +111,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
 
@@ -182,8 +182,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
@@ -305,7 +305,7 @@ copy_commit()
read GIT_COMMITTER_NAME
read GIT_COMMITTER_EMAIL
read GIT_COMMITTER_DATE
-   export  GIT_AUTHOR_NAME \
+   export GIT_AUTHOR_NAME \
GIT_AUTHOR_EMAIL \
GIT_AUTHOR_DATE \
GIT_COMMITTER_NAME \
@@ -328,7 +328,7 @@ add_msg()
fi
cat -EOF
$commit_message
-   
+
git-subtree-dir: $dir
git-subtree-mainline: $latest_old
git-subtree-split: $latest_new
@@ -356,7 +356,7 @@ rejoin_msg()
fi
cat -EOF
$commit_message
-   
+
git-subtree-dir: $dir
git-subtree-mainline: $latest_old
git-subtree-split: $latest_new
@@ -369,7 +369,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
@@ -379,7 +379,7 @@ squash_msg()
else
echo Squashed '$dir/' content from commit $newsub_short
fi
-   
+
echo
echo git-subtree-dir: $dir
echo git-subtree-split: $newsub
@@ -428,7 +428,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 |
@@ -456,7 +456,7 @@ copy_or_skip()
else
nonidentical=$parent
fi
-   
+
# sometimes both old parents map to the same newparent;
# eliminate duplicates
is_new=1
@@ -471,7 +471,7 @@ copy_or_skip()
p=$p -p $parent
fi
done
-   
+
if [ -n $identical ]; then
echo $identical
else
@@ -496,7 +496,7 @@ cmd_add()
fi
 
ensure_clean
-   
+
if [ $# -eq 1 ]; then
git rev-parse -q --verify $1^{commit} /dev/null ||
die '$1' does not refer to a commit
@@ -513,8 +513,8 @@ cmd_add()
 
cmd_add_repository $@
else
-   say error: parameters were '$@'
-   die Provide either a commit or a repository and commit.
+   say error: parameters were '$@'
+   die Provide either a commit or a repository and commit.
fi
 }
 
@@ -534,19 +534,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 |
@@ -556,7 +556,7

[PATCH 3/8] contrib/subtree: Ignore testing directory

2013-02-18 Thread David A. Greene
From: Techlive Zheng techlivezh...@gmail.com

Signed-off-by: Techlive Zheng techlivezh...@gmail.com
Signed-off-by: David A. Greene gree...@obbligato.org
---
 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.7.10.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 4/8] contrib/subtree: Code cleaning and refactoring

2013-02-18 Thread David A. Greene
From: Techlive Zheng techlivezh...@gmail.com

Mostly prepare for the later tests refactoring.

Signed-off-by: Techlive Zheng techlivezh...@gmail.com
Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/t/t7900-subtree.sh |  256 +++-
 1 file changed, 136 insertions(+), 120 deletions(-)

diff --git a/contrib/subtree/t/t7900-subtree.sh 
b/contrib/subtree/t/t7900-subtree.sh
index c7f9e1a..3787408 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.
 '
 
@@ -18,19 +18,6 @@ create()
git add $1
 }
 
-
-check_equal()
-{
-   test_debug 'echo'
-   test_debug echo \check a:\ \{$1}\
-   test_debug echo \  b:\ \{$2}\
-   if [ $1 = $2 ]; then
-   return 0
-   else
-   return 1
-   fi
-}
-
 fixnl()
 {
t=
@@ -55,6 +42,43 @@ undo()
git reset --hard HEAD~
 }
 
+test_equal()
+{
+   if test $1 = $2
+   then
+   return 0
+   else
+   test_debug 'echo'
+   test_debug echo \check a:\ \{$1}\
+   test_debug echo \  b:\ \{$2}\
+   return 1
+   fi
+}
+
+# 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()
+{
+   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
@@ -97,7 +121,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' '
@@ -105,40 +129,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-existent subtree' '
+   test_must_fail git subtree pull --prefix=subdir ./subproj sub1
 '
 
-test_expect_success 'no pull from non-existant subtree' '
-   test_must_fail git subtree pull --prefix=subdir ./subproj sub1
+test_expect_success 'no merge from non-existent subtree' '
+   test_must_fail git subtree merge --prefix=subdir FETCH_HEAD
 '
 
-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 '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

[PATCH 5/8] contrib/subtree: Make each test self-contained

2013-02-18 Thread David A. Greene
From: Techlive Zheng techlivezh...@gmail.com

Signed-off-by: Techlive Zheng techlivezh...@gmail.com
Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/t/t7900-subtree.sh | 1000 +---
 1 file changed, 693 insertions(+), 307 deletions(-)

diff --git a/contrib/subtree/t/t7900-subtree.sh 
b/contrib/subtree/t/t7900-subtree.sh
index 3787408..eee032d 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()
 {
if test $1 = $2
@@ -79,392 +68,789 @@ join_commits()
echo $commit $all
 }
 
+test_create_commit() (
+   repo=$1
+   commit=$2
+   cd $repo
+   mkdir -p $(dirname $commit) \
+   || error Could not create directory for commit
+   echo $commit $commit
+   git add $commit || error Could not add commit
+   git commit -m $commit || error Could not 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
-'
-
-# Save this hash for testing later.
-
-subdir_hash=`git rev-parse HEAD`
-
-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
-'
+subtree_test_count=0
+next_test() {
+   subtree_test_count=$(($subtree_test_count+1))
+}
 
-test_expect_success 'fetch subproj history' '
-   git fetch ./subproj sub1 
-   git branch sub1 FETCH_HEAD
-'
+#
+# Tests for 'git subtree add'
+#
 
+next_test
 test_expect_success 'no pull from non-existent subtree' '
-   test_must_fail git subtree pull --prefix=subdir ./subproj sub1
+   test_create_repo $subtree_test_count 
+   test_create_repo $subtree_test_count/subproj 
+   test_create_commit $subtree_test_count main1 
+   test_create_commit $subtree_test_count/subproj sub1 
+   (
+   cd $subtree_test_count 
+   git fetch ./subproj master 
+   test_must_fail git subtree pull --prefix=subdir ./subproj master
+   )
 '
 
+next_test
 test_expect_success 'no merge from non-existent subtree' '
-   test_must_fail git subtree merge --prefix=subdir FETCH_HEAD
+   test_create_repo $subtree_test_count 
+   test_create_repo $subtree_test_count/subproj 
+   test_create_commit $subtree_test_count main1 
+   test_create_commit $subtree_test_count/subproj sub1 
+   (
+   cd $subtree_test_count 
+   git fetch ./subproj master 
+   test_must_fail git subtree merge --prefix=subdir FETCH_HEAD
+   )
 '
 
+next_test
 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_create_repo $subtree_test_count 
+   test_create_repo $subtree_test_count/subproj 
+   test_create_commit $subtree_test_count main1 
+   test_create_commit $subtree_test_count/subproj sub1 
+   (
+   cd $subtree_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)'\''
+   )
 '
 
+next_test
 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_create_repo $subtree_test_count 
+   test_create_repo $subtree_test_count/subproj 
+   test_create_commit $subtree_test_count main1 
+   test_create_commit $subtree_test_count/subproj sub1 
+   (
+   cd $subtree_test_count 
+   git fetch ./subproj master 
+   git subtree add --prefix=subdir --message=Added subproject 
FETCH_HEAD 
+   test_equal $(last_commit_message) Added subproject
+   )
 '
 
+next_test
 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

[PATCH 6/8] contrib/subtree: Handle '--prefix' argument with a slash appended

2013-02-18 Thread David A. Greene
From: Techlive Zheng techlivezh...@gmail.com

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

Signed-off-by: Techlive Zheng techlivezh...@gmail.com
Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/git-subtree.sh |2 +-
 contrib/subtree/t/t7900-subtree.sh |   20 
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 6c3929b..1b3df99 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -82,7 +82,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 eee032d..5c6c73d 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -255,6 +255,26 @@ test_expect_success 'merge new subproj history into 
subdir/ with --squash and --
)
 '
 
+next_test
+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.7.10.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 7/8] contrib/subtree: Remove --annotate

2013-02-18 Thread David A. Greene
From: David A. Greene gree...@obbligato.org

Remove --annotate.  This obviates the need for an --unannotate
command.  We really want a more generalized commit message rewrite
mechanism.

Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/git-subtree.sh |6 +
 contrib/subtree/t/t7900-subtree.sh |   50 ++--
 2 files changed, 26 insertions(+), 30 deletions(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 1b3df99..2aceadc 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -21,7 +21,6 @@ d show debug messages
 P,prefix= the name of the subdir to split out
 m,message=use the given message as the commit message for the merge commit
  options for 'split'
-annotate= add a prefix to commit message of new commits
 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
@@ -43,7 +42,6 @@ command=
 onto=
 rejoin=
 ignore_joins=
-annotate=
 squash=
 message=
 
@@ -79,8 +77,6 @@ while [ $# -gt 0 ]; do
case $opt in
-q) quiet=1 ;;
-d) debug=1 ;;
-   --annotate) annotate=$1; shift ;;
-   --no-annotate) annotate= ;;
-b) branch=$1; shift ;;
-P) prefix=${1%/}; shift ;;
-m) message=$1; shift ;;
@@ -311,7 +307,7 @@ copy_commit()
GIT_COMMITTER_NAME \
GIT_COMMITTER_EMAIL \
GIT_COMMITTER_DATE
-   (echo -n $annotate; cat ) |
+   (echo -n ; cat ) |
git commit-tree $2 $3  # reads the rest of stdin
) || die Can't copy commit $1
 }
diff --git a/contrib/subtree/t/t7900-subtree.sh 
b/contrib/subtree/t/t7900-subtree.sh
index 5c6c73d..fa2a6c3 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -338,8 +338,8 @@ test_expect_success 'split subdir/ with --rejoin' '
cd $subtree_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 
+   split_hash=$(git subtree split --prefix=subdir) 
+   git subtree split --prefix=subdir --rejoin 
test_equal $(last_commit_message) Split '\''subdir/'\'' into 
commit '\''$split_hash'\''
)
  '
@@ -363,7 +363,7 @@ test_expect_success 'split subdir/ with --rejoin and 
--message' '
cd $subtree_test_count 
git fetch ./subproj master 
git subtree merge --prefix=subdir FETCH_HEAD 
-   git subtree split --prefix=subdir --message=Split  rejoin 
--annotate=* --rejoin 
+   git subtree split --prefix=subdir --message=Split  rejoin 
--rejoin 
test_equal $(last_commit_message) Split  rejoin
)
 '
@@ -387,8 +387,8 @@ test_expect_success 'split subdir/ with --branch' '
cd $subtree_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 
+   split_hash=$(git subtree split --prefix=subdir) 
+   git subtree split --prefix=subdir --branch subproj-br 
test_equal $(git rev-parse subproj-br) $split_hash
)
  '
@@ -413,8 +413,8 @@ test_expect_success 'split subdir/ with --branch for an 
existing branch' '
cd $subtree_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 
+   split_hash=$(git subtree split --prefix=subdir) 
+   git subtree split --prefix=subdir --branch subproj-br 
test_equal $(git rev-parse subproj-br) $split_hash
)
 '
@@ -466,7 +466,7 @@ test_expect_success 'make sure exactly the right set of 
files ends up in the sub
cd $subtree_test_count 
git fetch ./subproj master 
git subtree merge --prefix=subdir FETCH_HEAD 
-   git subtree split --prefix=subdir --annotate=* --branch 
subproj-br --rejoin
+   git subtree split --prefix=subdir --branch subproj-br --rejoin
) 
test_create_commit $subtree_test_count/subproj sub3 
test_create_commit $subtree_test_count subdir/main-sub3 
@@ -477,12 +477,12 @@ test_expect_success 'make sure exactly the right set of 
files ends up

[PATCH 8/8] Remove test artifaces from clean rule

2013-02-18 Thread David A. Greene
From: David A. Greene gree...@obbligato.org

There should be no need to remove 'mainline' nd 'subproj'
in the Makefile as these should always be created under the
test directory.

Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/Makefile |1 -
 1 file changed, 1 deletion(-)

diff --git a/contrib/subtree/Makefile b/contrib/subtree/Makefile
index b507505..09f4c9d 100644
--- a/contrib/subtree/Makefile
+++ b/contrib/subtree/Makefile
@@ -50,4 +50,3 @@ test:
 
 clean:
rm -f *~ *.xml *.html *.1
-   rm -rf subproj mainline
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Rebased git-subtree changes

2013-02-05 Thread David A. Greene
Here's a re-send of the git-subtree patches after rebasing onto
master.  Hopefully Junio will have better luck applying these.

-David

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 02/13] contrib/subtree: Use %B for Split Subject/Body

2013-02-05 Thread David A. Greene
From: Techlive Zheng techlivezh...@gmail.com

Use %B to format the commit message and body to avoid an extra newline
if a commit only has a subject line.

Signed-off-by: Techlive Zheng techlivezh...@gmail.com
Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/git-subtree.sh |2 +-
 contrib/subtree/t/t7900-subtree.sh |   15 +++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 920c664..5598210 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -296,7 +296,7 @@ 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 |
+   git log -1 --pretty=format:'%an%n%ae%n%ad%n%cn%n%ce%n%cd%n%B' $1 |
(
read GIT_AUTHOR_NAME
read GIT_AUTHOR_EMAIL
diff --git a/contrib/subtree/t/t7900-subtree.sh 
b/contrib/subtree/t/t7900-subtree.sh
index 6cf9fb9..3f17f55 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -74,6 +74,10 @@ test_expect_success 'add sub1' '
 git branch -m master subproj
 '
 
+# Save this hash for testing later.
+
+subdir_hash=`git rev-parse HEAD`
+
 test_expect_success 'add sub2' '
 create sub2 
 git commit -m sub2 
@@ -211,6 +215,17 @@ test_expect_success 'check split with --branch' '
 check_equal ''$(git rev-parse splitbr1)'' $spl1
 '
 
+test_expect_success 'check hash of split' '
+spl1=$(git subtree split --prefix subdir) 
+undo 
+git subtree split --prefix subdir --branch splitbr1test 
+check_equal ''$(git rev-parse splitbr1test)'' $spl1
+git checkout splitbr1test 
+new_hash=$(git rev-parse HEAD~2) 
+git checkout mainline 
+check_equal ''$new_hash'' $subdir_hash
+'
+
 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 
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 03/13] contrib/subtree: Better Error Handling for add

2013-02-05 Thread David A. Greene
From: David A. Greene gree...@obbligato.org

Check refspecs for validity before passing them on to other commands.
This lets us generate more helpful error messages.

Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/git-subtree.sh |   12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 5598210..771f39d 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -497,12 +497,18 @@ cmd_add()
ensure_clean

if [ $# -eq 1 ]; then
-   cmd_add_commit $@
+   git rev-parse -q --verify $1^{commit} /dev/null ||
+   die '$1' does not refer to a commit
+
+   cmd_add_commit $@
elif [ $# -eq 2 ]; then
-   cmd_add_repository $@
+   git rev-parse -q --verify $2^{commit} /dev/null ||
+   die '$2' does not refer to a commit
+
+   cmd_add_repository $@
else
say error: parameters were '$@'
-   die Provide either a refspec or a repository and refspec.
+   die Provide either a commit or a repository and commit.
fi
 }
 
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 04/13] contrib/subtree: Fix Synopsis

2013-02-05 Thread David A. Greene
From: David A. Greene gree...@obbligato.org

Fix the documentation of add to show that a repository can be
specified along with a commit.

Suggested by Yann Dirson dir...@bertin.fr.

Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/git-subtree.sh  |6 ++
 contrib/subtree/git-subtree.txt |3 ++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 771f39d..8a23f58 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -9,6 +9,7 @@ if [ $# -eq 0 ]; then
 fi
 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 push  --prefix=prefix repository refspec...
@@ -502,6 +503,11 @@ cmd_add()
 
cmd_add_commit $@
elif [ $# -eq 2 ]; then
+   # Technically we could accept a refspec here but we're
+   # just going to turn around and add FETCH_HEAD under the
+   # specified directory.  Allowing a refspec might be
+   # misleading because we won't do anything with any other
+   # branches fetched via the refspec.
git rev-parse -q --verify $2^{commit} /dev/null ||
die '$2' does not refer to a commit
 
diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
index c5bce41..7ba853e 100644
--- a/contrib/subtree/git-subtree.txt
+++ b/contrib/subtree/git-subtree.txt
@@ -9,7 +9,8 @@ git-subtree - Merge subtrees together and split repository into 
subtrees
 SYNOPSIS
 
 [verse]
-'git subtree' add   -P prefix commit
+'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
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 06/13] contrib/subtree: Make the Manual Directory if Needed

2013-02-05 Thread David A. Greene
From: Jesper L. Nielsen lya...@gmail.com

Before install git-subtree documentation, make sure the manpage
directory exists.

Signed-off-by: Jesper L. Nielsen lya...@gmail.com
Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/Makefile |1 +
 1 file changed, 1 insertion(+)

diff --git a/contrib/subtree/Makefile b/contrib/subtree/Makefile
index 36ae3e4..b507505 100644
--- a/contrib/subtree/Makefile
+++ b/contrib/subtree/Makefile
@@ -35,6 +35,7 @@ install: $(GIT_SUBTREE)
 install-doc: install-man
 
 install-man: $(GIT_SUBTREE_DOC)
+   $(INSTALL) -d -m 755 $(DESTDIR)$(man1dir)
$(INSTALL) -m 644 $^ $(DESTDIR)$(man1dir)
 
 $(GIT_SUBTREE_DOC): $(GIT_SUBTREE_XML)
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 09/13] contrib/subtree: Ignore testing directory

2013-02-05 Thread David A. Greene
From: Techlive Zheng techlivezh...@gmail.com

Signed-off-by: Techlive Zheng techlivezh...@gmail.com
Signed-off-by: David A. Greene gree...@obbligato.org
---
 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.7.10.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 08/13] contrib/subtree: Add vim modeline

2013-02-05 Thread David A. Greene
From: Techlive Zheng techlivezh...@gmail.com

Signed-off-by: Techlive Zheng techlivezh...@gmail.com
Signed-off-by: David A. Greene gree...@obbligato.org
---
 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 6c3929b..c72af95 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -722,3 +722,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 e6a3702..e6bcd50 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -466,3 +466,5 @@ test_expect_success 'verify one file change per commit' '
 '
 
 test_done
+
+# vim: set ts=4 sw=4 noet
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 07/13] contrib/subtree: Fix whitespaces

2013-02-05 Thread David A. Greene
From: Techlive Zheng techlivezh...@gmail.com

Previous code does not fulfill Git's whitespace policy.

Signed-off-by: Techlive Zheng techlivezh...@gmail.com
Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/git-subtree.sh |   68 
 contrib/subtree/git-subtree.txt|   42 ++---
 contrib/subtree/t/t7900-subtree.sh |  314 ++--
 3 files changed, 212 insertions(+), 212 deletions(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 8a23f58..6c3929b 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -5,7 +5,7 @@
 # Copyright (C) 2009 Avery Pennarun apenw...@gmail.com
 #
 if [ $# -eq 0 ]; then
-set -- -h
+   set -- -h
 fi
 OPTS_SPEC=\
 git subtree add   --prefix=prefix commit
@@ -111,9 +111,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
 
@@ -182,8 +182,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
@@ -305,7 +305,7 @@ copy_commit()
read GIT_COMMITTER_NAME
read GIT_COMMITTER_EMAIL
read GIT_COMMITTER_DATE
-   export  GIT_AUTHOR_NAME \
+   export GIT_AUTHOR_NAME \
GIT_AUTHOR_EMAIL \
GIT_AUTHOR_DATE \
GIT_COMMITTER_NAME \
@@ -328,7 +328,7 @@ add_msg()
fi
cat -EOF
$commit_message
-   
+
git-subtree-dir: $dir
git-subtree-mainline: $latest_old
git-subtree-split: $latest_new
@@ -356,7 +356,7 @@ rejoin_msg()
fi
cat -EOF
$commit_message
-   
+
git-subtree-dir: $dir
git-subtree-mainline: $latest_old
git-subtree-split: $latest_new
@@ -369,7 +369,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
@@ -379,7 +379,7 @@ squash_msg()
else
echo Squashed '$dir/' content from commit $newsub_short
fi
-   
+
echo
echo git-subtree-dir: $dir
echo git-subtree-split: $newsub
@@ -428,7 +428,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 |
@@ -456,7 +456,7 @@ copy_or_skip()
else
nonidentical=$parent
fi
-   
+
# sometimes both old parents map to the same newparent;
# eliminate duplicates
is_new=1
@@ -471,7 +471,7 @@ copy_or_skip()
p=$p -p $parent
fi
done
-   
+
if [ -n $identical ]; then
echo $identical
else
@@ -496,7 +496,7 @@ cmd_add()
fi
 
ensure_clean
-   
+
if [ $# -eq 1 ]; then
git rev-parse -q --verify $1^{commit} /dev/null ||
die '$1' does not refer to a commit
@@ -513,8 +513,8 @@ cmd_add()
 
cmd_add_repository $@
else
-   say error: parameters were '$@'
-   die Provide either a commit or a repository and commit.
+   say error: parameters were '$@'
+   die Provide either a commit or a repository and commit.
fi
 }
 
@@ -534,19 +534,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 |
@@ -556,7 +556,7

[PATCH 05/13] contrib/subtree: Honor DESTDIR

2013-02-05 Thread David A. Greene
From: Adam Tkac at...@redhat.com

Teach git-subtree's Makefile to honor DESTDIR.

Signed-off-by: Adam Tkac at...@redhat.com
Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/Makefile |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/contrib/subtree/Makefile b/contrib/subtree/Makefile
index 05cdd5c..36ae3e4 100644
--- a/contrib/subtree/Makefile
+++ b/contrib/subtree/Makefile
@@ -30,12 +30,12 @@ $(GIT_SUBTREE): $(GIT_SUBTREE_SH)
 doc: $(GIT_SUBTREE_DOC)
 
 install: $(GIT_SUBTREE)
-   $(INSTALL) -m 755 $(GIT_SUBTREE) $(libexecdir)
+   $(INSTALL) -m 755 $(GIT_SUBTREE) $(DESTDIR)$(libexecdir)
 
 install-doc: install-man
 
 install-man: $(GIT_SUBTREE_DOC)
-   $(INSTALL) -m 644 $^ $(man1dir)
+   $(INSTALL) -m 644 $^ $(DESTDIR)$(man1dir)
 
 $(GIT_SUBTREE_DOC): $(GIT_SUBTREE_XML)
xmlto -m $(MANPAGE_NORMAL_XSL)  man $^
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 13/13] contrib/subtree: Remove --annotate

2013-02-05 Thread David A. Greene
From: David A. Greene gree...@obbligato.org

Remove --annotate.  This obviates the need for an --unannotate
command.  We really want a more generalized commit message rewrite
mechanism.

Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/git-subtree.sh |6 +
 contrib/subtree/t/t7900-subtree.sh |   50 ++--
 2 files changed, 26 insertions(+), 30 deletions(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 0493e47..888a191 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -21,7 +21,6 @@ d show debug messages
 P,prefix= the name of the subdir to split out
 m,message=use the given message as the commit message for the merge commit
  options for 'split'
-annotate= add a prefix to commit message of new commits
 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
@@ -43,7 +42,6 @@ command=
 onto=
 rejoin=
 ignore_joins=
-annotate=
 squash=
 message=
 
@@ -79,8 +77,6 @@ while [ $# -gt 0 ]; do
case $opt in
-q) quiet=1 ;;
-d) debug=1 ;;
-   --annotate) annotate=$1; shift ;;
-   --no-annotate) annotate= ;;
-b) branch=$1; shift ;;
-P) prefix=${1%/}; shift ;;
-m) message=$1; shift ;;
@@ -311,7 +307,7 @@ copy_commit()
GIT_COMMITTER_NAME \
GIT_COMMITTER_EMAIL \
GIT_COMMITTER_DATE
-   (echo -n $annotate; cat ) |
+   (echo -n ; cat ) |
git commit-tree $2 $3  # reads the rest of stdin
) || die Can't copy commit $1
 }
diff --git a/contrib/subtree/t/t7900-subtree.sh 
b/contrib/subtree/t/t7900-subtree.sh
index 1afd544..59889f1 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -318,8 +318,8 @@ test_expect_success 'split subdir/ with --rejoin' '
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 
+   split_hash=$(git subtree split --prefix=subdir) 
+   git subtree split --prefix=subdir --rejoin 
test_equal $(last_commit_message) Split '\''subdir/'\'' into 
commit '\''$split_hash'\''
)
  '
@@ -342,7 +342,7 @@ test_expect_success 'split subdir/ with --rejoin and 
--message' '
cd $test_count 
git fetch ./subproj master 
git subtree merge --prefix=subdir FETCH_HEAD 
-   git subtree split --prefix=subdir --message=Split  rejoin 
--annotate=* --rejoin 
+   git subtree split --prefix=subdir --message=Split  rejoin 
--rejoin 
test_equal $(last_commit_message) Split  rejoin
)
 '
@@ -365,8 +365,8 @@ test_expect_success 'split subdir/ with --branch' '
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 
+   split_hash=$(git subtree split --prefix=subdir) 
+   git subtree split --prefix=subdir --branch subproj-br 
test_equal $(git rev-parse subproj-br) $split_hash
)
  '
@@ -390,8 +390,8 @@ test_expect_success 'split subdir/ with --branch for an 
existing branch' '
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 
+   split_hash=$(git subtree split --prefix=subdir) 
+   git subtree split --prefix=subdir --branch subproj-br 
test_equal $(git rev-parse subproj-br) $split_hash
)
 '
@@ -441,7 +441,7 @@ test_expect_success 'make sure exactly the right set of 
files ends up in the sub
cd $test_count 
git fetch ./subproj master 
git subtree merge --prefix=subdir FETCH_HEAD 
-   git subtree split --prefix=subdir --annotate=* --branch 
subproj-br --rejoin
+   git subtree split --prefix=subdir --branch subproj-br --rejoin
) 
test_create_commit $test_count/subproj sub3 
test_create_commit $test_count subdir/main-sub3 
@@ -452,12 +452,12 @@ test_expect_success 'make sure exactly the right set of 
files ends up in the sub
test_create_commit $test_count/subproj

[PATCH 12/13] contrib/subtree: Handle '--prefix' argument with a slash appended

2013-02-05 Thread David A. Greene
From: Techlive Zheng techlivezh...@gmail.com

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

Signed-off-by: Techlive Zheng techlivezh...@gmail.com
Signed-off-by: David A. Greene gree...@obbligato.org
---
 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 c72af95..0493e47 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -82,7 +82,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 769b116..1afd544 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -239,6 +239,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.7.10.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 10/13] contrib/subtree: Code cleaning and refactoring

2013-02-05 Thread David A. Greene
From: Techlive Zheng techlivezh...@gmail.com

Mostly prepare for the later tests refactoring.

Signed-off-by: Techlive Zheng techlivezh...@gmail.com
Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/t/t7900-subtree.sh |  270 ++--
 1 file changed, 136 insertions(+), 134 deletions(-)

diff --git a/contrib/subtree/t/t7900-subtree.sh 
b/contrib/subtree/t/t7900-subtree.sh
index e6bcd50..9cfaaf9 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.
 '
 
@@ -18,19 +18,6 @@ create()
git add $1
 }
 
-
-check_equal()
-{
-   test_debug 'echo'
-   test_debug echo \check a:\ \{$1}\
-   test_debug echo \  b:\ \{$2}\
-   if [ $1 = $2 ]; then
-   return 0
-   else
-   return 1
-   fi
-}
-
 fixnl()
 {
t=
@@ -55,6 +42,42 @@ undo()
git reset --hard HEAD~
 }
 
+test_equal()
+{
+   test_debug 'echo'
+   test_debug echo \check a:\ \{$1}\
+   test_debug echo \  b:\ \{$2}\
+   if [ $1 = $2 ]; then
+   return 0
+   else
+   return 1
+   fi
+}
+
+# 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()
+{
+   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
@@ -97,7 +120,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' '
@@ -105,40 +128,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

[PATCH 11/13] contrib/subtree: Make each test self-contained

2013-02-05 Thread David A. Greene
From: Techlive Zheng techlivezh...@gmail.com

Signed-off-by: Techlive Zheng techlivezh...@gmail.com
Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/t/t7900-subtree.sh |  871 +---
 1 file changed, 613 insertions(+), 258 deletions(-)

diff --git a/contrib/subtree/t/t7900-subtree.sh 
b/contrib/subtree/t/t7900-subtree.sh
index 9cfaaf9..769b116 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,381 +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
-'
-
-# Save this hash for testing later.
-
-subdir_hash=`git rev-parse HEAD`
-
-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
-'
+#
+# Tests for 'git subtree add'
+#
 
-test_expect_success 'fetch subproj history' '
-   git fetch ./subproj sub1 
-   git branch sub1 FETCH_HEAD
-'
 
 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

[PATCH 01/13] contrib/subtree: Remove Test Number Comments

2013-02-04 Thread David A. Greene
From: David A. Greene gree...@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 gree...@obbligato.org
---
 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 bc2eeb0..6cf9fb9 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 21 
@@ -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 21 
@@ -219,7 +197,6 @@ test_expect_success 'Check that the prefix exists for a 
split' '
 #rm -f expected actual

[PATCH 02/13] contrib/subtree: Use %B for Split Subject/Body

2013-02-04 Thread David A. Greene
From: Techlive Zheng techlivezh...@gmail.com

Use %B to format the commit message and body to avoid an extra newline
if a commit only has a subject line.

Signed-off-by: Techlive Zheng techlivezh...@gmail.com
Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/git-subtree.sh |2 +-
 contrib/subtree/t/t7900-subtree.sh |   15 +++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 920c664..5598210 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -296,7 +296,7 @@ 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 |
+   git log -1 --pretty=format:'%an%n%ae%n%ad%n%cn%n%ce%n%cd%n%B' $1 |
(
read GIT_AUTHOR_NAME
read GIT_AUTHOR_EMAIL
diff --git a/contrib/subtree/t/t7900-subtree.sh 
b/contrib/subtree/t/t7900-subtree.sh
index 6cf9fb9..3f17f55 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -74,6 +74,10 @@ test_expect_success 'add sub1' '
 git branch -m master subproj
 '
 
+# Save this hash for testing later.
+
+subdir_hash=`git rev-parse HEAD`
+
 test_expect_success 'add sub2' '
 create sub2 
 git commit -m sub2 
@@ -211,6 +215,17 @@ test_expect_success 'check split with --branch' '
 check_equal ''$(git rev-parse splitbr1)'' $spl1
 '
 
+test_expect_success 'check hash of split' '
+spl1=$(git subtree split --prefix subdir) 
+undo 
+git subtree split --prefix subdir --branch splitbr1test 
+check_equal ''$(git rev-parse splitbr1test)'' $spl1
+git checkout splitbr1test 
+new_hash=$(git rev-parse HEAD~2) 
+git checkout mainline 
+check_equal ''$new_hash'' $subdir_hash
+'
+
 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 
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 03/13] contrib/subtree: Better Error Handling for add

2013-02-04 Thread David A. Greene
From: David A. Greene gree...@obbligato.org

Check refspecs for validity before passing them on to other commands.
This lets us generate more helpful error messages.

Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/git-subtree.sh |   12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 5598210..771f39d 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -497,12 +497,18 @@ cmd_add()
ensure_clean

if [ $# -eq 1 ]; then
-   cmd_add_commit $@
+   git rev-parse -q --verify $1^{commit} /dev/null ||
+   die '$1' does not refer to a commit
+
+   cmd_add_commit $@
elif [ $# -eq 2 ]; then
-   cmd_add_repository $@
+   git rev-parse -q --verify $2^{commit} /dev/null ||
+   die '$2' does not refer to a commit
+
+   cmd_add_repository $@
else
say error: parameters were '$@'
-   die Provide either a refspec or a repository and refspec.
+   die Provide either a commit or a repository and commit.
fi
 }
 
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 04/13] contrib/subtree: Fix Synopsis

2013-02-04 Thread David A. Greene
From: David A. Greene gree...@obbligato.org

Fix the documentation of add to show that a repository can be
specified along with a commit.

Suggested by Yann Dirson dir...@bertin.fr.

Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/git-subtree.sh  |6 ++
 contrib/subtree/git-subtree.txt |3 ++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 771f39d..8a23f58 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -9,6 +9,7 @@ if [ $# -eq 0 ]; then
 fi
 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 push  --prefix=prefix repository refspec...
@@ -502,6 +503,11 @@ cmd_add()
 
cmd_add_commit $@
elif [ $# -eq 2 ]; then
+   # Technically we could accept a refspec here but we're
+   # just going to turn around and add FETCH_HEAD under the
+   # specified directory.  Allowing a refspec might be
+   # misleading because we won't do anything with any other
+   # branches fetched via the refspec.
git rev-parse -q --verify $2^{commit} /dev/null ||
die '$2' does not refer to a commit
 
diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
index c5bce41..7ba853e 100644
--- a/contrib/subtree/git-subtree.txt
+++ b/contrib/subtree/git-subtree.txt
@@ -9,7 +9,8 @@ git-subtree - Merge subtrees together and split repository into 
subtrees
 SYNOPSIS
 
 [verse]
-'git subtree' add   -P prefix commit
+'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
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 05/13] contrib/subtree: Honor DESTDIR

2013-02-04 Thread David A. Greene
From: Adam Tkac at...@redhat.com

Teach git-subtree's Makefile to honor DESTDIR.

Signed-off-by: Adam Tkac at...@redhat.com
Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/Makefile |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/contrib/subtree/Makefile b/contrib/subtree/Makefile
index 05cdd5c..36ae3e4 100644
--- a/contrib/subtree/Makefile
+++ b/contrib/subtree/Makefile
@@ -30,12 +30,12 @@ $(GIT_SUBTREE): $(GIT_SUBTREE_SH)
 doc: $(GIT_SUBTREE_DOC)
 
 install: $(GIT_SUBTREE)
-   $(INSTALL) -m 755 $(GIT_SUBTREE) $(libexecdir)
+   $(INSTALL) -m 755 $(GIT_SUBTREE) $(DESTDIR)$(libexecdir)
 
 install-doc: install-man
 
 install-man: $(GIT_SUBTREE_DOC)
-   $(INSTALL) -m 644 $^ $(man1dir)
+   $(INSTALL) -m 644 $^ $(DESTDIR)$(man1dir)
 
 $(GIT_SUBTREE_DOC): $(GIT_SUBTREE_XML)
xmlto -m $(MANPAGE_NORMAL_XSL)  man $^
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 06/13] contrib/subtree: Make the Manual Directory if Needed

2013-02-04 Thread David A. Greene
From: Jesper L. Nielsen lya...@gmail.com

Before install git-subtree documentation, make sure the manpage
directory exists.

Signed-off-by: Jesper L. Nielsen lya...@gmail.com
Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/Makefile |1 +
 1 file changed, 1 insertion(+)

diff --git a/contrib/subtree/Makefile b/contrib/subtree/Makefile
index 36ae3e4..b507505 100644
--- a/contrib/subtree/Makefile
+++ b/contrib/subtree/Makefile
@@ -35,6 +35,7 @@ install: $(GIT_SUBTREE)
 install-doc: install-man
 
 install-man: $(GIT_SUBTREE_DOC)
+   $(INSTALL) -d -m 755 $(DESTDIR)$(man1dir)
$(INSTALL) -m 644 $^ $(DESTDIR)$(man1dir)
 
 $(GIT_SUBTREE_DOC): $(GIT_SUBTREE_XML)
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 07/13] contrib/subtree: Fix whitespaces

2013-02-04 Thread David A. Greene
From: Techlive Zheng techlivezh...@gmail.com

Previous code does not fulfill Git's whitespace policy.

Signed-off-by: Techlive Zheng techlivezh...@gmail.com
Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/git-subtree.sh |   68 
 contrib/subtree/git-subtree.txt|   42 ++---
 contrib/subtree/t/t7900-subtree.sh |  314 ++--
 3 files changed, 212 insertions(+), 212 deletions(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 8a23f58..6c3929b 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -5,7 +5,7 @@
 # Copyright (C) 2009 Avery Pennarun apenw...@gmail.com
 #
 if [ $# -eq 0 ]; then
-set -- -h
+   set -- -h
 fi
 OPTS_SPEC=\
 git subtree add   --prefix=prefix commit
@@ -111,9 +111,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
 
@@ -182,8 +182,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
@@ -305,7 +305,7 @@ copy_commit()
read GIT_COMMITTER_NAME
read GIT_COMMITTER_EMAIL
read GIT_COMMITTER_DATE
-   export  GIT_AUTHOR_NAME \
+   export GIT_AUTHOR_NAME \
GIT_AUTHOR_EMAIL \
GIT_AUTHOR_DATE \
GIT_COMMITTER_NAME \
@@ -328,7 +328,7 @@ add_msg()
fi
cat -EOF
$commit_message
-   
+
git-subtree-dir: $dir
git-subtree-mainline: $latest_old
git-subtree-split: $latest_new
@@ -356,7 +356,7 @@ rejoin_msg()
fi
cat -EOF
$commit_message
-   
+
git-subtree-dir: $dir
git-subtree-mainline: $latest_old
git-subtree-split: $latest_new
@@ -369,7 +369,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
@@ -379,7 +379,7 @@ squash_msg()
else
echo Squashed '$dir/' content from commit $newsub_short
fi
-   
+
echo
echo git-subtree-dir: $dir
echo git-subtree-split: $newsub
@@ -428,7 +428,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 |
@@ -456,7 +456,7 @@ copy_or_skip()
else
nonidentical=$parent
fi
-   
+
# sometimes both old parents map to the same newparent;
# eliminate duplicates
is_new=1
@@ -471,7 +471,7 @@ copy_or_skip()
p=$p -p $parent
fi
done
-   
+
if [ -n $identical ]; then
echo $identical
else
@@ -496,7 +496,7 @@ cmd_add()
fi
 
ensure_clean
-   
+
if [ $# -eq 1 ]; then
git rev-parse -q --verify $1^{commit} /dev/null ||
die '$1' does not refer to a commit
@@ -513,8 +513,8 @@ cmd_add()
 
cmd_add_repository $@
else
-   say error: parameters were '$@'
-   die Provide either a commit or a repository and commit.
+   say error: parameters were '$@'
+   die Provide either a commit or a repository and commit.
fi
 }
 
@@ -534,19 +534,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 |
@@ -556,7 +556,7

[PATCH 09/13] contrib/subtree: Ignore testing directory

2013-02-04 Thread David A. Greene
From: Techlive Zheng techlivezh...@gmail.com

Signed-off-by: Techlive Zheng techlivezh...@gmail.com
Signed-off-by: David A. Greene gree...@obbligato.org
---
 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.7.10.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 08/13] contrib/subtree: Add vim modeline

2013-02-04 Thread David A. Greene
From: Techlive Zheng techlivezh...@gmail.com

Signed-off-by: Techlive Zheng techlivezh...@gmail.com
Signed-off-by: David A. Greene gree...@obbligato.org
---
 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 6c3929b..c72af95 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -722,3 +722,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 e6a3702..e6bcd50 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -466,3 +466,5 @@ test_expect_success 'verify one file change per commit' '
 '
 
 test_done
+
+# vim: set ts=4 sw=4 noet
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 13/13] contrib/subtree: Remove --annotate

2013-02-04 Thread David A. Greene
From: David A. Greene gree...@obbligato.org

Remove --annotate.  This obviates the need for an --unannotate
command.  We really want a more generalized commit message rewrite
mechanism.

Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/git-subtree.sh |6 +
 contrib/subtree/t/t7900-subtree.sh |   50 ++--
 2 files changed, 26 insertions(+), 30 deletions(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 0493e47..888a191 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -21,7 +21,6 @@ d show debug messages
 P,prefix= the name of the subdir to split out
 m,message=use the given message as the commit message for the merge commit
  options for 'split'
-annotate= add a prefix to commit message of new commits
 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
@@ -43,7 +42,6 @@ command=
 onto=
 rejoin=
 ignore_joins=
-annotate=
 squash=
 message=
 
@@ -79,8 +77,6 @@ while [ $# -gt 0 ]; do
case $opt in
-q) quiet=1 ;;
-d) debug=1 ;;
-   --annotate) annotate=$1; shift ;;
-   --no-annotate) annotate= ;;
-b) branch=$1; shift ;;
-P) prefix=${1%/}; shift ;;
-m) message=$1; shift ;;
@@ -311,7 +307,7 @@ copy_commit()
GIT_COMMITTER_NAME \
GIT_COMMITTER_EMAIL \
GIT_COMMITTER_DATE
-   (echo -n $annotate; cat ) |
+   (echo -n ; cat ) |
git commit-tree $2 $3  # reads the rest of stdin
) || die Can't copy commit $1
 }
diff --git a/contrib/subtree/t/t7900-subtree.sh 
b/contrib/subtree/t/t7900-subtree.sh
index 1afd544..59889f1 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -318,8 +318,8 @@ test_expect_success 'split subdir/ with --rejoin' '
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 
+   split_hash=$(git subtree split --prefix=subdir) 
+   git subtree split --prefix=subdir --rejoin 
test_equal $(last_commit_message) Split '\''subdir/'\'' into 
commit '\''$split_hash'\''
)
  '
@@ -342,7 +342,7 @@ test_expect_success 'split subdir/ with --rejoin and 
--message' '
cd $test_count 
git fetch ./subproj master 
git subtree merge --prefix=subdir FETCH_HEAD 
-   git subtree split --prefix=subdir --message=Split  rejoin 
--annotate=* --rejoin 
+   git subtree split --prefix=subdir --message=Split  rejoin 
--rejoin 
test_equal $(last_commit_message) Split  rejoin
)
 '
@@ -365,8 +365,8 @@ test_expect_success 'split subdir/ with --branch' '
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 
+   split_hash=$(git subtree split --prefix=subdir) 
+   git subtree split --prefix=subdir --branch subproj-br 
test_equal $(git rev-parse subproj-br) $split_hash
)
  '
@@ -390,8 +390,8 @@ test_expect_success 'split subdir/ with --branch for an 
existing branch' '
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 
+   split_hash=$(git subtree split --prefix=subdir) 
+   git subtree split --prefix=subdir --branch subproj-br 
test_equal $(git rev-parse subproj-br) $split_hash
)
 '
@@ -441,7 +441,7 @@ test_expect_success 'make sure exactly the right set of 
files ends up in the sub
cd $test_count 
git fetch ./subproj master 
git subtree merge --prefix=subdir FETCH_HEAD 
-   git subtree split --prefix=subdir --annotate=* --branch 
subproj-br --rejoin
+   git subtree split --prefix=subdir --branch subproj-br --rejoin
) 
test_create_commit $test_count/subproj sub3 
test_create_commit $test_count subdir/main-sub3 
@@ -452,12 +452,12 @@ test_expect_success 'make sure exactly the right set of 
files ends up in the sub
test_create_commit $test_count/subproj

[PATCH 12/13] contrib/subtree: Handle '--prefix' argument with a slash appended

2013-02-04 Thread David A. Greene
From: Techlive Zheng techlivezh...@gmail.com

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

Signed-off-by: Techlive Zheng techlivezh...@gmail.com
Signed-off-by: David A. Greene gree...@obbligato.org
---
 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 c72af95..0493e47 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -82,7 +82,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 769b116..1afd544 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -239,6 +239,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.7.10.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 10/13] contrib/subtree: Code cleaning and refactoring

2013-02-04 Thread David A. Greene
From: Techlive Zheng techlivezh...@gmail.com

Mostly prepare for the later tests refactoring.

Signed-off-by: Techlive Zheng techlivezh...@gmail.com
Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/t/t7900-subtree.sh |  270 ++--
 1 file changed, 136 insertions(+), 134 deletions(-)

diff --git a/contrib/subtree/t/t7900-subtree.sh 
b/contrib/subtree/t/t7900-subtree.sh
index e6bcd50..9cfaaf9 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.
 '
 
@@ -18,19 +18,6 @@ create()
git add $1
 }
 
-
-check_equal()
-{
-   test_debug 'echo'
-   test_debug echo \check a:\ \{$1}\
-   test_debug echo \  b:\ \{$2}\
-   if [ $1 = $2 ]; then
-   return 0
-   else
-   return 1
-   fi
-}
-
 fixnl()
 {
t=
@@ -55,6 +42,42 @@ undo()
git reset --hard HEAD~
 }
 
+test_equal()
+{
+   test_debug 'echo'
+   test_debug echo \check a:\ \{$1}\
+   test_debug echo \  b:\ \{$2}\
+   if [ $1 = $2 ]; then
+   return 0
+   else
+   return 1
+   fi
+}
+
+# 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()
+{
+   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
@@ -97,7 +120,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' '
@@ -105,40 +128,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

[PATCH 11/13] contrib/subtree: Make each test self-contained

2013-02-04 Thread David A. Greene
From: Techlive Zheng techlivezh...@gmail.com

Signed-off-by: Techlive Zheng techlivezh...@gmail.com
Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/t/t7900-subtree.sh |  871 +---
 1 file changed, 613 insertions(+), 258 deletions(-)

diff --git a/contrib/subtree/t/t7900-subtree.sh 
b/contrib/subtree/t/t7900-subtree.sh
index 9cfaaf9..769b116 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,381 +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
-'
-
-# Save this hash for testing later.
-
-subdir_hash=`git rev-parse HEAD`
-
-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
-'
+#
+# Tests for 'git subtree add'
+#
 
-test_expect_success 'fetch subproj history' '
-   git fetch ./subproj sub1 
-   git branch sub1 FETCH_HEAD
-'
 
 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

Revised git-subtree Patches

2013-01-08 Thread David A. Greene
Here is the set of revised patches to git-subtree.  I think I've
got everything cleaned up now.

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/7] Remove Test Number Comments

2013-01-08 Thread David A. Greene
From: David A. Greene gree...@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 gree...@obbligato.org
---
 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 bc2eeb0..6cf9fb9 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 21 
@@ -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 21 
@@ -219,7 +197,6 @@ test_expect_success 'Check that the prefix exists for a 
split' '
 #rm -f expected actual

[PATCH 3/7] contrib/subtree: Add --unannotate

2013-01-08 Thread David A. Greene
From: James Nylen jny...@gmail.com

Teach git-subtree about --unannotate.  This option strips a prefix
from a commit message when doing a subtree split.

Signed-off-by: James Nylen jny...@gmail.com

Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/git-subtree.sh |   11 +--
 contrib/subtree/git-subtree.txt|   15 +++
 contrib/subtree/t/t7900-subtree.sh |   12 ++--
 3 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 5341b36..cac0680 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -21,6 +21,7 @@ P,prefix= the name of the subdir to split out
 m,message=use the given message as the commit message for the merge commit
  options for 'split'
 annotate= add a prefix to commit message of new commits
+unannotate=   remove a prefix from new commit messages (supports bash globbing)
 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
@@ -43,6 +44,7 @@ onto=
 rejoin=
 ignore_joins=
 annotate=
+unannotate=
 squash=
 message=
 
@@ -80,6 +82,8 @@ while [ $# -gt 0 ]; do
-d) debug=1 ;;
--annotate) annotate=$1; shift ;;
--no-annotate) annotate= ;;
+   --unannotate) unannotate=$1; shift ;;
+   --no-unannotate) unannotate= ;;
-b) branch=$1; shift ;;
-P) prefix=$1; shift ;;
-m) message=$1; shift ;;
@@ -314,8 +318,11 @@ copy_commit()
GIT_COMMITTER_NAME \
GIT_COMMITTER_EMAIL \
GIT_COMMITTER_DATE
-   (echo -n $annotate; cat ) |
-   git commit-tree $2 $3  # reads the rest of stdin
+   (
+   read FIRST_LINE
+   echo $annotate${FIRST_LINE#$unannotate}
+   cat  # reads the rest of stdin
+   ) | git commit-tree $2 $3
) || die Can't copy commit $1
 }
 
diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
index c5bce41..75aa690 100644
--- a/contrib/subtree/git-subtree.txt
+++ b/contrib/subtree/git-subtree.txt
@@ -198,6 +198,21 @@ OPTIONS FOR split
git subtree tries to make it work anyway, particularly
if you use --rejoin, but it may not always be effective.
 
+--unannotate=annotation::
+   This option is only valid for the split command.
+
+   When generating synthetic history, try to remove the prefix
+   annotation from each commit message (using bash's strip
+   shortest match from beginning command, which supports
+   globbing).  This makes sense if you format library commits
+   like library: Change something or other when you're working
+   in your project's repository, but you want to remove this
+   prefix when pushing back to the library's upstream repository.
+   (In this case --unannotate='*: ' would work well.)
+   
+   Like --annotate,  you need to use the same annotation
+   whenever you split, or you may run into problems.
+
 -b branch::
 --branch=branch::
This option is only valid for the split command.
diff --git a/contrib/subtree/t/t7900-subtree.sh 
b/contrib/subtree/t/t7900-subtree.sh
index 3f17f55..de45e34 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -143,7 +143,7 @@ test_expect_success 'merge fetched subproj' '
 
 test_expect_success 'add main-sub5' '
 create subdir/main-sub5 
-git commit -m main-sub5
+git commit -m subproj: main-sub5
 '
 
 test_expect_success 'add main6' '
@@ -153,7 +153,7 @@ test_expect_success 'add main6' '
 
 test_expect_success 'add main-sub7' '
 create subdir/main-sub7 
-git commit -m main-sub7
+git commit -m subproj: main-sub7
 '
 
 test_expect_success 'fetch new subproj history' '
@@ -226,6 +226,14 @@ test_expect_success 'check hash of split' '
 check_equal ''$new_hash'' $subdir_hash
 '
 
+test_expect_success 'check --unannotate' '
+spl1=$(git subtree split --unannotate='subproj:' --prefix subdir 
--onto FETCH_HEAD --message Split  rejoin --rejoin) 
+undo 
+git subtree split --unannotate='subproj:' --prefix subdir --onto 
FETCH_HEAD --branch splitunann 
+check_equal ''$(git rev-parse splitunann)'' $spl1 
+check_equal ''$(git log splitunann | grep subproj)'' 
+'
+
 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 
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo

[PATCH 5/7] contrib/subtree: Fix Synopsis

2013-01-08 Thread David A. Greene
From: David A. Greene gree...@obbligato.org

Fix the documentation of add to show that a repository can be
specified along with a commit.

Suggested by Yann Dirson dir...@bertin.fr.

Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/git-subtree.sh  |6 ++
 contrib/subtree/git-subtree.txt |3 ++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index d53eaee..0e9ea0f 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -9,6 +9,7 @@ if [ $# -eq 0 ]; then
 fi
 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 push  --prefix=prefix repository refspec...
@@ -513,6 +514,11 @@ cmd_add()
 
cmd_add_commit $@
elif [ $# -eq 2 ]; then
+   # Technically we could accept a refspec here but we're
+   # just going to turn around and add FETCH_HEAD under the
+   # specified directory.  Allowing a refspec might be
+   # misleading because we won't do anything with any other
+   # branches fetched via the refspec.
git rev-parse -q --verify $2^{commit} /dev/null ||
 die '$2' does not refer to a commit
 
diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
index 75aa690..078d4ac 100644
--- a/contrib/subtree/git-subtree.txt
+++ b/contrib/subtree/git-subtree.txt
@@ -9,7 +9,8 @@ git-subtree - Merge subtrees together and split repository into 
subtrees
 SYNOPSIS
 
 [verse]
-'git subtree' add   -P prefix commit
+'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
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 7/7] contrib/subtree: Make the Manual Directory if Needed

2013-01-08 Thread David A. Greene
From: Jesper L. Nielsen lya...@gmail.com

Before install git-subtree documentation, make sure the manpage
directory exists.

Signed-off-by: Jesper L. Nielsen lya...@gmail.com

Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/Makefile |1 +
 1 file changed, 1 insertion(+)

diff --git a/contrib/subtree/Makefile b/contrib/subtree/Makefile
index 36ae3e4..b507505 100644
--- a/contrib/subtree/Makefile
+++ b/contrib/subtree/Makefile
@@ -35,6 +35,7 @@ install: $(GIT_SUBTREE)
 install-doc: install-man
 
 install-man: $(GIT_SUBTREE_DOC)
+   $(INSTALL) -d -m 755 $(DESTDIR)$(man1dir)
$(INSTALL) -m 644 $^ $(DESTDIR)$(man1dir)
 
 $(GIT_SUBTREE_DOC): $(GIT_SUBTREE_XML)
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 6/7] contrib/subtree: Honor DESTDIR

2013-01-08 Thread David A. Greene
From: Adam Tkac at...@redhat.com

Teach git-subtree's Makefile to honor DESTDIR.

Signed-off-by: Adam Tkac at...@redhat.com

Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/Makefile |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/contrib/subtree/Makefile b/contrib/subtree/Makefile
index 05cdd5c..36ae3e4 100644
--- a/contrib/subtree/Makefile
+++ b/contrib/subtree/Makefile
@@ -30,12 +30,12 @@ $(GIT_SUBTREE): $(GIT_SUBTREE_SH)
 doc: $(GIT_SUBTREE_DOC)
 
 install: $(GIT_SUBTREE)
-   $(INSTALL) -m 755 $(GIT_SUBTREE) $(libexecdir)
+   $(INSTALL) -m 755 $(GIT_SUBTREE) $(DESTDIR)$(libexecdir)
 
 install-doc: install-man
 
 install-man: $(GIT_SUBTREE_DOC)
-   $(INSTALL) -m 644 $^ $(man1dir)
+   $(INSTALL) -m 644 $^ $(DESTDIR)$(man1dir)
 
 $(GIT_SUBTREE_DOC): $(GIT_SUBTREE_XML)
xmlto -m $(MANPAGE_NORMAL_XSL)  man $^
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


git-subtree Patches to Apply

2012-12-31 Thread David A. Greene
Here are all of the patches for git-subtree that have been posted to
the mailing list that I could apply and test in a reasonable amount of
time.  These are all rebased from trunk as of tonight.

Many apologies for being *so* behind.  Work has been a bear but I'm
hoping things will ease up in the new year and I can be more regularly
active.  But still, don't expect same-day service.  :)

These are also available on branch toupstream via

git clone gitol...@sources.obbligato.org:git.git

and

http://sources.obbligato.org
http://sources.obbligato.org/?p=git.git;a=summary

Junio, can you apply these?  Thanks!

 -David

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/8] Use %B for Split Subject/Body

2012-12-31 Thread David A. Greene
From: Techlive Zheng techlivezh...@gmail.com

Use %B to format the commit message and body to avoid an extra newline
if a commit only has a subject line.

Author:Techlive Zheng techlivezh...@gmail.com

Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/git-subtree.sh |5 +++
 contrib/subtree/t/t7900-subtree.sh |   73 ++--
 2 files changed, 49 insertions(+), 29 deletions(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 920c664..f2b6d4a 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -296,7 +296,12 @@ 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}
+   # 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.
git log -1 --pretty=format:'%an%n%ae%n%ad%n%cn%n%ce%n%cd%n%s%n%n%b' 
$1 |
+#  git log -1 --pretty=format:'%an%n%ae%n%ad%n%cn%n%ce%n%cd%n%B' $1 |
(
read GIT_AUTHOR_NAME
read GIT_AUTHOR_EMAIL
diff --git a/contrib/subtree/t/t7900-subtree.sh 
b/contrib/subtree/t/t7900-subtree.sh
index bc2eeb0..93eeb09 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -76,6 +76,10 @@ test_expect_success 'add sub1' '
 git branch -m master subproj
 '
 
+# Save this hash for testing later.
+
+subdir_hash=`git rev-parse HEAD`
+
 # 3
 test_expect_success 'add sub2' '
 create sub2 
@@ -155,7 +159,6 @@ test_expect_success 'add main-sub5' '
 create subdir/main-sub5 
 git commit -m main-sub5
 '
-
 # 15
 test_expect_success 'add main6' '
 create main6 
@@ -235,7 +238,19 @@ test_expect_success 'check split with --branch' '
 check_equal ''$(git rev-parse splitbr1)'' $spl1
 '
 
-# 25
+#25
+test_expect_success 'check hash of split' '
+spl1=$(git subtree split --prefix subdir) 
+undo 
+git subtree split --prefix subdir --branch splitbr1test 
+check_equal ''$(git rev-parse splitbr1test)'' $spl1
+git checkout splitbr1test 
+new_hash=$(git rev-parse HEAD~2) 
+git checkout mainline 
+check_equal ''$new_hash'' $subdir_hash
+'
+
+# 26
 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 +259,13 @@ test_expect_success 'check split with --branch for an 
existing branch' '
 check_equal ''$(git rev-parse splitbr2)'' $spl1
 '
 
-# 26
+# 27
 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
+# 28
 test_expect_success 'check split+rejoin' '
 spl1=''$(git subtree split --annotate=''*'' --prefix subdir --onto 
FETCH_HEAD --message Split  rejoin --rejoin)'' 
 undo 
@@ -258,7 +273,7 @@ test_expect_success 'check split+rejoin' '
 check_equal ''$(last_commit_message)'' Split '''subdir/''' into 
commit '''$spl1'''
 '
 
-# 28
+# 29
 test_expect_success 'add main-sub8' '
 create subdir/main-sub8 
 git commit -m main-sub8
@@ -267,14 +282,14 @@ test_expect_success 'add main-sub8' '
 # To the subproject!
 cd ./subproj
 
-# 29
+# 30
 test_expect_success 'merge split into subproj' '
 git fetch .. spl1 
 git branch spl1 FETCH_HEAD 
 git merge FETCH_HEAD
 '
 
-# 30
+# 31
 test_expect_success 'add sub9' '
 create sub9 
 git commit -m sub9
@@ -283,19 +298,19 @@ test_expect_success 'add sub9' '
 # Back to mainline
 cd ..
 
-# 31
+# 32
 test_expect_success 'split for sub8' '
 split2=''$(git subtree split --annotate=''*'' --prefix subdir/ 
--rejoin)''
 git branch split2 $split2
 '
 
-# 32
+# 33
 test_expect_success 'add main-sub10' '
 create subdir/main-sub10 
 git commit -m main-sub10
 '
 
-# 33
+# 34
 test_expect_success 'split for sub10' '
 spl3=''$(git subtree split --annotate=''*'' --prefix subdir 
--rejoin)'' 
 git branch spl3 $spl3
@@ -304,7 +319,7 @@ test_expect_success 'split for sub10' '
 # To the subproject!
 cd ./subproj
 
-# 34
+# 35
 test_expect_success 'merge split into subproj' '
 git fetch .. spl3 
 git branch spl3 FETCH_HEAD 
@@ -318,13 +333,13 @@ chkms_sub=$(echo $chkms | multiline | sed 's,^,subdir/,' 
| fixnl)
 chks=sub1 sub2 sub3 sub9
 chks_sub=$(echo $chks | multiline | sed 's,^,subdir/,' | fixnl)
 
-# 35
+# 36
 test_expect_success 'make sure exactly the right set of files ends up in the 
subproj' '
 subfiles=''$(git ls-files | fixnl)'' 
 check_equal

[PATCH 2/8] Add --unannotate

2012-12-31 Thread David A. Greene
From: James Nylen jny...@gmail.com

Teach git-subtree about --unannotate.  This option strips a prefix
from a commit message when doing a subtree split.

Author:James Nylen jny...@gmail.com

Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/git-subtree.sh |   11 +-
 contrib/subtree/git-subtree.txt|   15 
 contrib/subtree/t/t7900-subtree.sh |   73 
 3 files changed, 65 insertions(+), 34 deletions(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index f2b6d4a..7ceb413 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -21,6 +21,7 @@ P,prefix= the name of the subdir to split out
 m,message=use the given message as the commit message for the merge commit
  options for 'split'
 annotate= add a prefix to commit message of new commits
+unannotate=   remove a prefix from new commit messages (supports bash globbing)
 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
@@ -43,6 +44,7 @@ onto=
 rejoin=
 ignore_joins=
 annotate=
+unannotate=
 squash=
 message=
 
@@ -80,6 +82,8 @@ while [ $# -gt 0 ]; do
-d) debug=1 ;;
--annotate) annotate=$1; shift ;;
--no-annotate) annotate= ;;
+   --unannotate) unannotate=$1; shift ;;
+   --no-unannotate) unannotate= ;;
-b) branch=$1; shift ;;
-P) prefix=$1; shift ;;
-m) message=$1; shift ;;
@@ -315,8 +319,11 @@ copy_commit()
GIT_COMMITTER_NAME \
GIT_COMMITTER_EMAIL \
GIT_COMMITTER_DATE
-   (echo -n $annotate; cat ) |
-   git commit-tree $2 $3  # reads the rest of stdin
+   (
+   read FIRST_LINE
+   echo $annotate${FIRST_LINE#$unannotate}
+   cat  # reads the rest of stdin
+   ) | git commit-tree $2 $3
) || die Can't copy commit $1
 }
 
diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
index 0c44fda..ae420aa 100644
--- a/contrib/subtree/git-subtree.txt
+++ b/contrib/subtree/git-subtree.txt
@@ -198,6 +198,21 @@ OPTIONS FOR split
git subtree tries to make it work anyway, particularly
if you use --rejoin, but it may not always be effective.
 
+--unannotate=annotation::
+   This option is only valid for the split command.
+
+   When generating synthetic history, try to remove the prefix
+   annotation from each commit message (using bash's strip
+   shortest match from beginning command, which supports
+   globbing).  This makes sense if you format library commits
+   like library: Change something or other when you're working
+   in your project's repository, but you want to remove this
+   prefix when pushing back to the library's upstream repository.
+   (In this case --unannotate='*: ' would work well.)
+   
+   Like --annotate,  you need to use the same annotation
+   whenever you split, or you may run into problems.
+
 -b branch::
 --branch=branch::
This option is only valid for the split command.
diff --git a/contrib/subtree/t/t7900-subtree.sh 
b/contrib/subtree/t/t7900-subtree.sh
index 93eeb09..9816da5 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -157,7 +157,7 @@ test_expect_success 'merge fetched subproj' '
 # 14
 test_expect_success 'add main-sub5' '
 create subdir/main-sub5 
-git commit -m main-sub5
+git commit -m subproj: main-sub5
 '
 # 15
 test_expect_success 'add main6' '
@@ -168,7 +168,7 @@ test_expect_success 'add main6' '
 # 16
 test_expect_success 'add main-sub7' '
 create subdir/main-sub7 
-git commit -m main-sub7
+git commit -m subproj: main-sub7
 '
 
 # 17
@@ -238,7 +238,7 @@ test_expect_success 'check split with --branch' '
 check_equal ''$(git rev-parse splitbr1)'' $spl1
 '
 
-#25
+# 25
 test_expect_success 'check hash of split' '
 spl1=$(git subtree split --prefix subdir) 
 undo 
@@ -251,6 +251,15 @@ test_expect_success 'check hash of split' '
 '
 
 # 26
+test_expect_success 'check --unannotate' '
+spl1=$(git subtree split --unannotate='subproj:' --prefix subdir 
--onto FETCH_HEAD --message Split  rejoin --rejoin) 
+undo 
+git subtree split --unannotate='subproj:' --prefix subdir --onto 
FETCH_HEAD --branch splitunann 
+check_equal ''$(git rev-parse splitunann)'' $spl1 
+check_equal ''$(git log splitunann | grep subproj)'' 
+'
+
+# 27
 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

[PATCH 3/8] Better Error Handling for add

2012-12-31 Thread David A. Greene
From: David A. Greene gree...@obbligato.org

Check refspecs for validity before passing them on to other commands.
This lets us generate more helpful error messages.

Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/git-subtree.sh |   12 
 1 file changed, 12 insertions(+)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 7ceb413..b8a807a 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -509,8 +509,20 @@ cmd_add()
ensure_clean

if [ $# -eq 1 ]; then
+   ref=$(git check-ref-format --normalize refs/heads/$1) ||
+die '$1' is not a valid refspec.  Are you missing a branch?
+
+   rev=$(git rev-parse --verify $1) ||
+die '$1' is not a valid refspec.  Are you missing a branch?
+
cmd_add_commit $@
elif [ $# -eq 2 ]; then
+   ref=$(git check-ref-format --normalize refs/heads/$2) ||
+die '$2' is not a valid refspec.
+
+   rev=$(git rev-parse --verify $2) ||
+die '$2' is not a valid refspec.
+
cmd_add_repository $@
else
say error: parameters were '$@'
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 4/8] Fix Synopsis

2012-12-31 Thread David A. Greene
From: David A. Greene gree...@obbligato.org

Fix the documentation of add to show that a repository can be
specified along with a commit.

Change commit to refspec in the synopsis for add.

Suggested by Yann Dirson dir...@bertin.fr.

Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/git-subtree.sh  |3 ++-
 contrib/subtree/git-subtree.txt |3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index b8a807a..ad62dfb 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -8,7 +8,8 @@ if [ $# -eq 0 ]; then
 set -- -h
 fi
 OPTS_SPEC=\
-git subtree add   --prefix=prefix commit
+git subtree add   --prefix=prefix refspec
+git subtree add   --prefix=prefix repository refspec
 git subtree merge --prefix=prefix commit
 git subtree pull  --prefix=prefix repository refspec...
 git subtree push  --prefix=prefix repository refspec...
diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
index ae420aa..89c2d6e 100644
--- a/contrib/subtree/git-subtree.txt
+++ b/contrib/subtree/git-subtree.txt
@@ -9,7 +9,8 @@ git-subtree - Merge subtrees together and split repository into 
subtrees
 SYNOPSIS
 
 [verse]
-'git subtree' add   -P prefix commit
+'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
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 5/8] Honor DESTDIR

2012-12-31 Thread David A. Greene
From: Adam Tkac at...@redhat.com

Teach git-subtree's Makefile to honor DESTDIR.

Author:Adam Tkac at...@redhat.com

Signed-off-by:Adam Tkac at...@redhat.com

Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/Makefile |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/contrib/subtree/Makefile b/contrib/subtree/Makefile
index 05cdd5c..36ae3e4 100644
--- a/contrib/subtree/Makefile
+++ b/contrib/subtree/Makefile
@@ -30,12 +30,12 @@ $(GIT_SUBTREE): $(GIT_SUBTREE_SH)
 doc: $(GIT_SUBTREE_DOC)
 
 install: $(GIT_SUBTREE)
-   $(INSTALL) -m 755 $(GIT_SUBTREE) $(libexecdir)
+   $(INSTALL) -m 755 $(GIT_SUBTREE) $(DESTDIR)$(libexecdir)
 
 install-doc: install-man
 
 install-man: $(GIT_SUBTREE_DOC)
-   $(INSTALL) -m 644 $^ $(man1dir)
+   $(INSTALL) -m 644 $^ $(DESTDIR)$(man1dir)
 
 $(GIT_SUBTREE_DOC): $(GIT_SUBTREE_XML)
xmlto -m $(MANPAGE_NORMAL_XSL)  man $^
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 6/8] Make the Manual Directory if Needed

2012-12-31 Thread David A. Greene
From: Jesper L. Nielsen lya...@gmail.com

Before install git-subtree documentation, make sure the manpage
directory exists.

Author:Jesper L. Nielsen lya...@gmail.com

Signed-off-by:Jesper L. Nielsen lya...@gmail.com

Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/Makefile |1 +
 1 file changed, 1 insertion(+)

diff --git a/contrib/subtree/Makefile b/contrib/subtree/Makefile
index 36ae3e4..52d6fb9 100644
--- a/contrib/subtree/Makefile
+++ b/contrib/subtree/Makefile
@@ -35,6 +35,7 @@ install: $(GIT_SUBTREE)
 install-doc: install-man
 
 install-man: $(GIT_SUBTREE_DOC)
+   mkdir -p $(man1dir)
$(INSTALL) -m 644 $^ $(DESTDIR)$(man1dir)
 
 $(GIT_SUBTREE_DOC): $(GIT_SUBTREE_XML)
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 8/8] Fix Documentation Typo

2012-12-31 Thread David A. Greene
From: Michael Schubert msc...@elegosoft.com

split is documented below push so fix the reference to it in
push's documentation.

Author:Michael Schubert msc...@elegosoft.com

Signed-off-by:Michael Schubert msc...@elegosoft.com

Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/git-subtree.txt |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
index 89c2d6e..078d4ac 100644
--- a/contrib/subtree/git-subtree.txt
+++ b/contrib/subtree/git-subtree.txt
@@ -94,7 +94,7 @@ pull::
repository.

 push::
-   Does a 'split' (see above) using the prefix supplied
+   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.
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 7/8] Ignore git-subtree

2012-12-31 Thread David A. Greene
From: Michael Schubert msc...@elegosoft.com

Add the git-subtree command executable to .gitignore.

Author:Michael Schubert msc...@elegosoft.com

Signed-off-by:Michael Schubert msc...@elegosoft.com

Signed-off-by: David A. Greene gree...@obbligato.org
---
 contrib/subtree/.gitignore |1 +
 1 file changed, 1 insertion(+)

diff --git a/contrib/subtree/.gitignore b/contrib/subtree/.gitignore
index 7e77c9d..91360a3 100644
--- a/contrib/subtree/.gitignore
+++ b/contrib/subtree/.gitignore
@@ -1,4 +1,5 @@
 *~
+git-subtree
 git-subtree.xml
 git-subtree.1
 mainline
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html