Commit graph

34 commits

Author SHA1 Message Date
Denton Liu 77128ed90e contrib/subtree: ensure only one rev is provided
While looking at the inline help for git-subtree.sh, I noticed that

	git subtree split --prefix=<prefix> <commit...>

was given as an option. However, it only really makes sense to provide
one revision because of the way the commits are forwarded to rev-parse
so change "<commit...>" to "<commit>" to reflect this. In addition,
check the arguments to ensure that only one rev is provided for all
subcommands that accept a commit.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
Acked-by: Avery Pennarun <apenwarr@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-12 17:38:03 +09:00
Roger Strain 19ad68d95d subtree: performance improvement for finding unexpected parent commits
After testing a previous patch at larger scale, a performance issue was
detected when using git show to locate parent revisions, with a single
run of the git show command taking 2 seconds or longer in a complex repo.
When the command is required tens or hundreds of times in a run of the
script, the additional wait time is unaccepatable. Replacing the command
with git rev-parse resulted in significantly increased performance, with
the command in question returning instantly.

Signed-off-by: Roger Strain <rstrain@swri.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-10-12 23:28:32 +09:00
Strain, Roger L 68f8ff8151 subtree: improve decision on merges kept in split
When multiple identical parents are detected for a commit being considered
for copying, explicitly check whether one is the common merge base between
the commits. If so, the other commit can be used as the identical parent;
if not, a merge must be performed to maintain history.

In some situations two parents of a merge commit may appear to both have
identical subtree content with each other and the current commit. However,
those parents can potentially come from different commit graphs.

Previous behavior would simply select one of the identical parents to
serve as the replacement for this commit, based on the order in which they
were processed.

New behavior compares the merge base between the commits to determine if
a new merge commit is necessary to maintain history despite the identical
content.

Signed-off-by: Strain, Roger L <roger.strain@swri.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-10-07 08:09:34 +09:00
Strain, Roger L 315a84f9aa subtree: use commits before rejoins for splits
Adds recursive evaluation of parent commits which were not part of the
initial commit list when performing a split.

Split expects all relevant commits to be reachable from the target commit
but not reachable from any previous rejoins. However, a branch could be
based on a commit prior to a rejoin, then later merged back into the
current code. In this case, a parent to the commit will not be present in
the initial list of commits, trigging an "incorrect order" warning.

Previous behavior was to consider that commit to have no parent, creating
an original commit containing all subtree content. This commit is not
present in an existing subtree commit graph, changing commit hashes and
making pushing to a subtree repo impossible.

New behavior will recursively check these unexpected parent commits to
track them back to either an earlier rejoin, or a true original commit.
The generated synthetic commits will properly match previously-generated
commits, allowing successful pushing to a prior subtree repo.

Signed-off-by: Strain, Roger L <roger.strain@swri.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-10-07 08:09:34 +09:00
Strain, Roger L dd21d43b58 subtree: make --ignore-joins pay attention to adds
Changes the behavior of --ignore-joins to always consider a subtree add
commit, and ignore only splits and squashes.

The --ignore-joins option is documented to ignore prior --rejoin commits.
However, it additionally ignored subtree add commits generated when a
subtree was initially added to a repo.

Due to the logic which determines whether a commit is a mainline commit
or a subtree commit (namely, the presence or absence of content in the
subtree prefix) this causes commits before the initial add to appear to
be part of the subtree. An --ignore-joins split would therefore consider
those commits part of the subtree history and include them at the
beginning of the synthetic history, causing the resulting hashes to be
incorrect for all later commits.

Signed-off-by: Strain, Roger L <roger.strain@swri.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-10-07 08:09:34 +09:00
Strain, Roger L 565e4b7981 subtree: refactor split of a commit into standalone method
In a particularly complex repo, subtree split was not creating
compatible splits for pushing back to a separate repo. Addressing
one of the issues requires recursive handling of parent commits
that were not initially considered by the algorithm. This commit
makes no functional changes, but relocates the code to be called
recursively into a new method to simply comparisons of later
commits.

Signed-off-by: Strain, Roger L <roger.strain@swri.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-10-07 08:09:34 +09:00
Stephen R Guglielmo 8841b5222c subtree: fix add and pull for GPG-signed commits
If log.showsignature is true (or --show-signature is passed) while
performing a `subtree add` or `subtree pull`, the command fails.

toptree_for_commit() calls `log` and passes the output to `commit-tree`.
If this output shows the GPG signature data, `commit-tree` throws a
fatal error.

This commit fixes the issue by adding --no-show-signature to `log` calls
in a few places, as well as using the more appropriate `rev-parse`
instead where possible.

Signed-off-by: Stephen R Guglielmo <srg@guglielmo.us>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-02-23 14:36:59 -08:00
David Aguilar d7fd792e1b subtree: adjust function definitions to match CodingGuidelines
We prefer a space between the function name and the parentheses, and no
space inside the parentheses.

The opening "{" should also be on the same line.

Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: David Aguilar <davvid@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-07-27 19:10:24 -07:00
David Aguilar 6ae6a23318 subtree: adjust style to match CodingGuidelines
Prefer "test" over "[ ... ]", use double-quotes around variables, break
long lines, and properly indent "case" statements.

Helped-by: Johannes Sixt <j6t@kdbg.org>
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: David Aguilar <davvid@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-07-27 19:10:22 -07:00
David Aguilar 0f12c7d4d1 subtree: fix "git subtree split --rejoin"
"git merge" in v2.9 prevents merging unrelated histories.

"git subtree split --rejoin" creates unrelated histories when
creating a split repo from a raw sub-directory that did not
originate from an invocation of "git subtree add".

Restore the original behavior by passing --allow-unrelated-histories
when merging subtrees.  This ensures that the synthetic history
created by "git subtree split" can be merged.

Add a test to ensure that this feature works as advertised.

Reported-by: Brett Cundal <brett.cundal@iugome.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: David Aguilar <davvid@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-07-26 13:57:00 -07:00
Junio C Hamano dd65a9e5e3 Merge branch 'dw/subtree-split-do-not-drop-merge'
The "split" subcommand of "git subtree" (in contrib/) incorrectly
skipped merges when it shouldn't, which was corrected.

* dw/subtree-split-do-not-drop-merge:
  contrib/subtree: fix "subtree split" skipped-merge bug
2016-02-03 14:16:03 -08:00
Junio C Hamano a039a79e9d Merge branch 'rm/subtree-unwrap-tags'
"git subtree" (in contrib/) records the tag object name in the
commit log message when a subtree is added using a tag, without
peeling it down to the underlying commit.  The tag needs to be
peeled when "git subtree split" wants to work on the commit, but
the command forgot to do so.

* rm/subtree-unwrap-tags:
  contrib/subtree: unwrap tag refs
2016-01-22 13:08:45 -08:00
Dave Ware 933cfeb90b contrib/subtree: fix "subtree split" skipped-merge bug
'git subtree split' can incorrectly skip a merge even when both parents
act on the subtree, provided the merge results in a tree identical to
one of the parents. Fix by copying the merge if at least one parent is
non-identical, and the non-identical parent is not an ancestor of the
identical parent.

Also, add a test case which checks that a descendant remains a
descendent on the subtree in this case.

Signed-off-by: Dave Ware <davidw@realtimegenomics.com>
Reviewed-by: David A. Greene <greened@obbligato.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-01-20 14:53:18 -08:00
Rob Mayoff 5d65fe312e contrib/subtree: unwrap tag refs
If a subtree was added using a tag ref, the tag ref is stored in
the subtree commit message instead of the underlying commit's ref.
To split or push subsequent changes to the subtree, the subtree
command needs to unwrap the tag ref.  This patch makes it do so.

The problem was described in a message to the mailing list from
Junio C Hamano dated 29 Apr 2014, with the subject "Re: git subtree
issue in more recent versions". The archived message can be found
at <http://comments.gmane.org/gmane.comp.version-control.git/247503>.

Signed-off-by: Rob Mayoff <mayoff@dqd.com>
Signed-off-by: Jeff King <peff@peff.net>
2015-11-24 16:53:35 -05:00
Techlive Zheng d16031caf1 contrib/subtree: Handle '--prefix' argument with a slash appended
'git subtree merge' will fail if the argument of '--prefix' has a slash
appended.

Signed-off-by: Techlive Zheng <techlivezheng@gmail.com>
Signed-off-by: David A. Greene <greened@obbligato.org>
Signed-off-by: Jeff King <peff@peff.net>
2015-11-13 00:02:56 -05:00
Alexey Shumkin 5b6ab38bd3 contrib/subtree: respect spaces in a repository path
Remote repository may have spaces in its path, so take it into account.

Also, as far as there are no tests for the `push` command, add them.

Signed-off-by: Alexey Shumkin <Alex.Crezoff@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-09-08 11:09:13 -07:00
Alexey Shumkin c61eb4106d t7900-subtree: test the "space in a subdirectory name" case
In common case there can be spaces in a subdirectory name. Change tests
accorgingly to this statement.

Also, as far as a call to the `rejoin_msg` function (in `cmd_split`)
does not take into account such a case this patch fixes commit message
when `--rejoin` option is set .

Besides, as `fixnl` and `multiline` functions did not take into account
the "new" tested "space in a subdirectory name" case they become unused
and redundant, so they are removed.

Signed-off-by: Alexey Shumkin <Alex.Crezoff@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-09-08 11:09:10 -07:00
Junio C Hamano 7a06e63f82 Merge branch 'da/subtree-date-confusion'
"git subtree" (in contrib/) depended on "git log" output to be
stable, which was a no-no.  Apply a workaround to force a
particular date format.

* da/subtree-date-confusion:
  contrib/subtree: ignore log.date configuration
2015-08-03 11:01:31 -07:00
David Aguilar e7aac44ed2 contrib/subtree: ignore log.date configuration
git-subtree's log format string uses "%ad" and "%cd", which
respect the user's configured log.date value.

This is problematic for git-subtree because it needs to use real
dates so that copied commits come through unchanged.

Add a test and tweak the format strings to use %aD and %cD
so that the default date format is used instead.

Reported-by: Bryan Jacobs <b@q3q.us>
Signed-off-by: David Aguilar <davvid@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-07-23 15:08:41 -07:00
Junio C Hamano b54301bdad Merge branch 'dl/subtree-avoid-tricky-echo'
"git subtree" script (in contrib/) used "echo -n" to produce
progress messages in a non-portable way.

* dl/subtree-avoid-tricky-echo:
  contrib/subtree: portability fix for string printing
2015-05-22 12:41:45 -07:00
Danny Lin 2ded109b51 contrib/subtree: portability fix for string printing
'echo -n' is not portable, but this script used it as a way to give
a string followed by a carriage return for progress messages.
Introduce a new helper shell function "progress" and use printf as a
more portable way to do this.  As a side effect, this makes it
unnecessary to have a raw CR in our source, which can be munged in
some shells.  For example, MsysGit trims CR before executing a shell
script file in order to make it work right on Windows even if it
uses CRLF as linefeeds.

While at it, replace "echo" using printf in debug() and say() to
eliminate the temptation of reintroducing the same bug.

Signed-off-by: Danny Lin <danny0838@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-05-08 12:09:38 -07:00
Danny Lin 6ccc71a9d0 contrib/subtree: there's no push --squash
The documentation says that --squash is for 'add', 'merge',
'pull' and 'push', while --squash actually doesn't change
the behavior of 'push'. Correct the documentation.

Signed-off-by: Danny Lin <danny0838@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-05-07 11:03:32 -07:00
James Denholm 6f1871fe0f contrib/subtree: allow adding an annotated tag
cmd_add_commit() is passed FETCH_HEAD by cmd_add_repository, which
is then rev-parsed into an object name.  However, if the user is
fetching a tag rather than a branch HEAD, such as by executing:

  $ git subtree add -P oldGit https://github.com/git/git.git tags/v1.8.0

the object name refers to a tag and is never peeled, and the git
commit-tree call (line 561) slaps us in the face because it doesn't
peel tags to commits.

Because peeling a committish doesn't do anything if it's already a
commit, fix by peeling the object name before assigning it to $rev
using peel_committish() from git:git-sh-setup.sh, a pre-existing
dependency of git-subtree.

Reported-by: Kevin Cagle <kcagle@micron.com>
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: James Denholm <nod.helm@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-05-13 12:33:26 -07:00
Jeff King cba5e28426 subtree: initialize "prefix" variable
We parse the "--prefix" command-line option into the
"$prefix" shell variable. However, if we do not see such an
option, the variable is left with whatever value it had in
the environment. We should initialize it to a known value,
like we do for other variables.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-03-17 15:19:52 -07:00
Anthony Baire 1c3e0f007c subtree: fix argument validation in add/pull/push
When working with a remote repository add/pull/push do not accept a
<refspec> as parameter but just a <ref>. They should accept any
well-formatted ref name.

This patch:
 - relaxes the check the <ref> argument in "git subtree add <repo>"
   (previous code would not accept a ref name that does not exist
   locally too, new code only ensures that the ref is well formatted)

 - add the same check in "git subtree pull/push" + check the number of
   parameters

 - update the doc to use <ref> instead of <refspec>

Signed-off-by: Anthony Baire <Anthony.Baire@irisa.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-01-13 14:37:52 -08:00
Junio C Hamano a5203a3f04 Merge branch 'lf/echo-n-is-not-portable'
* lf/echo-n-is-not-portable:
  Avoid using `echo -n` anywhere
2013-08-01 11:52:43 -07:00
Lukas Fleischer 19c3c5fdcb Avoid using echo -n anywhere
`echo -n` is non-portable. The POSIX specification says:

    Conforming applications that wish to do prompting without <newline>
    characters or that could possibly be expecting to echo a -n, should
    use the printf utility derived from the Ninth Edition system.

Since all of the affected shell scripts use a POSIX shell shebang,
replace `echo -n` invocations with printf.

Signed-off-by: Lukas Fleischer <git@cryptocrack.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-29 09:56:58 -07:00
Junio C Hamano 779fd737d7 Merge branch 'dm/unbash-subtree'
It turns out that git-subtree script does not have to be run with
bash.

* dm/unbash-subtree:
  contrib/git-subtree: Use /bin/sh interpreter instead of /bin/bash
2013-06-05 14:56:24 -07:00
Dmitry Marakasov 6912ea952b contrib/git-subtree: Use /bin/sh interpreter instead of /bin/bash
Use /bin/sh interpreter instead of /bin/bash for contrib/git-subtree:
it's required for systems which don't use bash by default (for example,
FreeBSD), while there seem to be no bashisms in the script (confirmed
by looking through the source and tesing subtree functionality with
FreeBSD's /bin/sh) to require specifically bash and not the generic
posix shell.

Signed-off-by: Dmitry Marakasov <amdmi3@amdmi3.ru>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-05-21 09:24:17 -07:00
John Keeping 3212d56ce5 contrib/subtree: don't delete remote branches if split fails
When using "git subtree push" to split out a subtree and push it to a
remote repository, we do not detect if the split command fails which
causes the LHS of the refspec to be empty, deleting the remote branch.

Fix this by pulling the result of the split command into a variable so
that we can die if the command fails.

Reported-by: Steffen Jaeckel <steffen.jaeckel@stzedn.de>
Signed-off-by: John Keeping <john@keeping.me.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-05-01 10:13:32 -07:00
David A. Greene 111dc0eea0 contrib/subtree: fix synopsis
Fix the documentation of add to show that a repository can be
specified along with a commit.

Suggested by Yann Dirson <dirson@bertin.fr>.

Signed-off-by: David A. Greene <greened@obbligato.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-02-05 15:23:05 -08:00
David A. Greene 10a49587fa contrib/subtree: better error handling for 'subtree add'
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 <greened@obbligato.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-02-05 15:22:36 -08:00
Techlive Zheng a5b8e28e4e contrib/subtree: use %B for split subject/body
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 <techlivezheng@gmail.com>
Signed-off-by: David A. Greene <greened@obbligato.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-02-05 15:22:12 -08:00
David A. Greene 634392b262 Add 'contrib/subtree/' from commit 'd3a04e06c77d57978bb5230361c64946232cc346'
git-subtree-dir: contrib/subtree
git-subtree-mainline: e8dde3e5f9
git-subtree-split: d3a04e06c7
2012-04-09 20:22:55 -05:00