2013-05-20 22:24:34 +02:00
|
|
|
#!/bin/sh
|
2009-04-24 20:13:34 +02:00
|
|
|
#
|
|
|
|
# git-subtree.sh: split/join git repositories in subdirectories of this one
|
|
|
|
#
|
2009-04-24 21:48:41 +02:00
|
|
|
# Copyright (C) 2009 Avery Pennarun <apenwarr@gmail.com>
|
2009-04-24 20:13:34 +02:00
|
|
|
#
|
2021-04-27 23:17:30 +02:00
|
|
|
|
subtree: fix the GIT_EXEC_PATH sanity check to work on Windows
In 22d550749361 (subtree: don't fuss with PATH, 2021-04-27), `git
subtree` was broken thoroughly on Windows.
The reason is that it assumes Unix semantics, where `PATH` is
colon-separated, and it assumes that `$GIT_EXEC_PATH:` is a verbatim
prefix of `$PATH`. Neither are true, the latter in particular because
`GIT_EXEC_PATH` is a Windows-style path, while `PATH` is a Unix-style
path list.
Let's make extra certain that `$GIT_EXEC_PATH` and the first component
of `$PATH` refer to different entities before erroring out.
We do that by using the `test <path1> -ef <path2>` command that verifies
that the inode of `<path1>` and of `<path2>` is the same.
Sadly, this construct is non-portable, according to
https://pubs.opengroup.org/onlinepubs/009695399/utilities/test.html.
However, it does not matter in practice because we still first look
whether `$GIT_EXEC_PREFIX` is string-identical to the first component of
`$PATH`. This will give us the expected result everywhere but in Git for
Windows, and Git for Windows' own Bash _does_ handle the `-ef` operator.
Just in case that we _do_ need to show the error message _and_ are
running in a shell that lacks support for `-ef`, we simply suppress the
error output for that part.
This fixes https://github.com/git-for-windows/git/issues/3260
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-06-14 14:41:52 +02:00
|
|
|
if test -z "$GIT_EXEC_PATH" || ! test -f "$GIT_EXEC_PATH/git-sh-setup" || {
|
|
|
|
test "${PATH#"${GIT_EXEC_PATH}:"}" = "$PATH" &&
|
|
|
|
test ! "$GIT_EXEC_PATH" -ef "${PATH%%:*}" 2>/dev/null
|
|
|
|
}
|
subtree: don't fuss with PATH
Scripts needing to fuss with with adding $(git --exec-prefix) PATH
before loading git-sh-setup is a thing of the past. As far as I can
tell, it's been a thing of the past since since Git v1.2.0 (2006-02-12),
or more specifically, since 77cb17e940 (Exec git programs without using
PATH, 2006-01-10). However, it stuck around in contrib scripts and in
third-party scripts for long enough that it wasn't unusual to see.
Originally `git subtree` didn't fuss with PATH, but when people
(including the original subtree author) had problems, because it was a
common thing to see, it seemed that having subtree fuss with PATH was a
reasonable solution.
Here is an abridged history of fussing with PATH in subtree:
2987e6add3 (Add explicit path of git installation by 'git --exec-path', Gianluca Pacchiella, 2009-08-20)
As pointed out by documentation, the correct use of 'git-sh-setup' is
using $(git --exec-path) to avoid problems with not standard
installations.
-. git-sh-setup
+. $(git --exec-path)/git-sh-setup
33aaa697a2 (Improve patch to use git --exec-path: add to PATH instead, Avery Pennarun, 2009-08-26)
If you (like me) are using a modified git straight out of its source
directory (ie. without installing), then --exec-path isn't actually correct.
Add it to the PATH instead, so if it is correct, it'll work, but if it's
not, we fall back to the previous behaviour.
-. $(git --exec-path)/git-sh-setup
+PATH=$(git --exec-path):$PATH
+. git-sh-setup
9c632ea29c ((Hopefully) fix PATH setting for msysgit, Avery Pennarun, 2010-06-24)
Reported by Evan Shaw. The problem is that $(git --exec-path) includes a
'git' binary which is incompatible with the one in /usr/bin; if you run it,
it gives you an error about libiconv2.dll.
+OPATH=$PATH
PATH=$(git --exec-path):$PATH
. git-sh-setup
+PATH=$OPATH # apparently needed for some versions of msysgit
df2302d774 (Another fix for PATH and msysgit, Avery Pennarun, 2010-06-24)
Evan Shaw tells me the previous fix didn't work. Let's use this one
instead, which he says does work.
This fix is kind of wrong because it will run the "correct" git-sh-setup
*after* the one in /usr/bin, if there is one, which could be weird if you
have multiple versions of git installed. But it works on my Linux and his
msysgit, so it's obviously better than what we had before.
-OPATH=$PATH
-PATH=$(git --exec-path):$PATH
+PATH=$PATH:$(git --exec-path)
. git-sh-setup
-PATH=$OPATH # apparently needed for some versions of msysgit
First of all, I disagree with Gianluca's reading of the documentation:
- I haven't gone back to read what the documentation said in 2009, but
in my reading of the 2021 documentation is that it includes "$(git
--exec-path)/" in the synopsis for illustrative purposes, not to say
it's the proper way.
- After being executed by `git`, the git exec path should be the very
first entry in PATH, so it shouldn't matter.
- None of the scripts that are part of git do it that way.
But secondly, the root reason for fussing with PATH seems to be that
Avery didn't know that he needs to set GIT_EXEC_PATH if he's going to
use git from the source directory without installing.
And finally, Evan's issue is clearly just a bug in msysgit. I assume
that msysgit has since fixed the issue, and also msysgit has been
deprecated for 6 years now, so let's drop the workaround for it.
So, remove the line fussing with PATH. However, since subtree *is* in
'contrib/' and it might get installed in funny ways by users
after-the-fact, add a sanity check to the top of the script, checking
that it is installed correctly.
Signed-off-by: Luke Shumaker <lukeshu@datawire.io>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-04-27 23:17:37 +02:00
|
|
|
then
|
2021-06-14 14:41:53 +02:00
|
|
|
basename=${0##*[/\\]}
|
subtree: don't fuss with PATH
Scripts needing to fuss with with adding $(git --exec-prefix) PATH
before loading git-sh-setup is a thing of the past. As far as I can
tell, it's been a thing of the past since since Git v1.2.0 (2006-02-12),
or more specifically, since 77cb17e940 (Exec git programs without using
PATH, 2006-01-10). However, it stuck around in contrib scripts and in
third-party scripts for long enough that it wasn't unusual to see.
Originally `git subtree` didn't fuss with PATH, but when people
(including the original subtree author) had problems, because it was a
common thing to see, it seemed that having subtree fuss with PATH was a
reasonable solution.
Here is an abridged history of fussing with PATH in subtree:
2987e6add3 (Add explicit path of git installation by 'git --exec-path', Gianluca Pacchiella, 2009-08-20)
As pointed out by documentation, the correct use of 'git-sh-setup' is
using $(git --exec-path) to avoid problems with not standard
installations.
-. git-sh-setup
+. $(git --exec-path)/git-sh-setup
33aaa697a2 (Improve patch to use git --exec-path: add to PATH instead, Avery Pennarun, 2009-08-26)
If you (like me) are using a modified git straight out of its source
directory (ie. without installing), then --exec-path isn't actually correct.
Add it to the PATH instead, so if it is correct, it'll work, but if it's
not, we fall back to the previous behaviour.
-. $(git --exec-path)/git-sh-setup
+PATH=$(git --exec-path):$PATH
+. git-sh-setup
9c632ea29c ((Hopefully) fix PATH setting for msysgit, Avery Pennarun, 2010-06-24)
Reported by Evan Shaw. The problem is that $(git --exec-path) includes a
'git' binary which is incompatible with the one in /usr/bin; if you run it,
it gives you an error about libiconv2.dll.
+OPATH=$PATH
PATH=$(git --exec-path):$PATH
. git-sh-setup
+PATH=$OPATH # apparently needed for some versions of msysgit
df2302d774 (Another fix for PATH and msysgit, Avery Pennarun, 2010-06-24)
Evan Shaw tells me the previous fix didn't work. Let's use this one
instead, which he says does work.
This fix is kind of wrong because it will run the "correct" git-sh-setup
*after* the one in /usr/bin, if there is one, which could be weird if you
have multiple versions of git installed. But it works on my Linux and his
msysgit, so it's obviously better than what we had before.
-OPATH=$PATH
-PATH=$(git --exec-path):$PATH
+PATH=$PATH:$(git --exec-path)
. git-sh-setup
-PATH=$OPATH # apparently needed for some versions of msysgit
First of all, I disagree with Gianluca's reading of the documentation:
- I haven't gone back to read what the documentation said in 2009, but
in my reading of the 2021 documentation is that it includes "$(git
--exec-path)/" in the synopsis for illustrative purposes, not to say
it's the proper way.
- After being executed by `git`, the git exec path should be the very
first entry in PATH, so it shouldn't matter.
- None of the scripts that are part of git do it that way.
But secondly, the root reason for fussing with PATH seems to be that
Avery didn't know that he needs to set GIT_EXEC_PATH if he's going to
use git from the source directory without installing.
And finally, Evan's issue is clearly just a bug in msysgit. I assume
that msysgit has since fixed the issue, and also msysgit has been
deprecated for 6 years now, so let's drop the workaround for it.
So, remove the line fussing with PATH. However, since subtree *is* in
'contrib/' and it might get installed in funny ways by users
after-the-fact, add a sanity check to the top of the script, checking
that it is installed correctly.
Signed-off-by: Luke Shumaker <lukeshu@datawire.io>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-04-27 23:17:37 +02:00
|
|
|
echo >&2 'It looks like either your git installation or your'
|
|
|
|
echo >&2 'git-subtree installation is broken.'
|
|
|
|
echo >&2
|
|
|
|
echo >&2 "Tips:"
|
|
|
|
echo >&2 " - If \`git --exec-path\` does not print the correct path to"
|
|
|
|
echo >&2 " your git install directory, then set the GIT_EXEC_PATH"
|
|
|
|
echo >&2 " environment variable to the correct directory."
|
2021-06-14 14:41:53 +02:00
|
|
|
echo >&2 " - Make sure that your \`$basename\` file is either in your"
|
subtree: don't fuss with PATH
Scripts needing to fuss with with adding $(git --exec-prefix) PATH
before loading git-sh-setup is a thing of the past. As far as I can
tell, it's been a thing of the past since since Git v1.2.0 (2006-02-12),
or more specifically, since 77cb17e940 (Exec git programs without using
PATH, 2006-01-10). However, it stuck around in contrib scripts and in
third-party scripts for long enough that it wasn't unusual to see.
Originally `git subtree` didn't fuss with PATH, but when people
(including the original subtree author) had problems, because it was a
common thing to see, it seemed that having subtree fuss with PATH was a
reasonable solution.
Here is an abridged history of fussing with PATH in subtree:
2987e6add3 (Add explicit path of git installation by 'git --exec-path', Gianluca Pacchiella, 2009-08-20)
As pointed out by documentation, the correct use of 'git-sh-setup' is
using $(git --exec-path) to avoid problems with not standard
installations.
-. git-sh-setup
+. $(git --exec-path)/git-sh-setup
33aaa697a2 (Improve patch to use git --exec-path: add to PATH instead, Avery Pennarun, 2009-08-26)
If you (like me) are using a modified git straight out of its source
directory (ie. without installing), then --exec-path isn't actually correct.
Add it to the PATH instead, so if it is correct, it'll work, but if it's
not, we fall back to the previous behaviour.
-. $(git --exec-path)/git-sh-setup
+PATH=$(git --exec-path):$PATH
+. git-sh-setup
9c632ea29c ((Hopefully) fix PATH setting for msysgit, Avery Pennarun, 2010-06-24)
Reported by Evan Shaw. The problem is that $(git --exec-path) includes a
'git' binary which is incompatible with the one in /usr/bin; if you run it,
it gives you an error about libiconv2.dll.
+OPATH=$PATH
PATH=$(git --exec-path):$PATH
. git-sh-setup
+PATH=$OPATH # apparently needed for some versions of msysgit
df2302d774 (Another fix for PATH and msysgit, Avery Pennarun, 2010-06-24)
Evan Shaw tells me the previous fix didn't work. Let's use this one
instead, which he says does work.
This fix is kind of wrong because it will run the "correct" git-sh-setup
*after* the one in /usr/bin, if there is one, which could be weird if you
have multiple versions of git installed. But it works on my Linux and his
msysgit, so it's obviously better than what we had before.
-OPATH=$PATH
-PATH=$(git --exec-path):$PATH
+PATH=$PATH:$(git --exec-path)
. git-sh-setup
-PATH=$OPATH # apparently needed for some versions of msysgit
First of all, I disagree with Gianluca's reading of the documentation:
- I haven't gone back to read what the documentation said in 2009, but
in my reading of the 2021 documentation is that it includes "$(git
--exec-path)/" in the synopsis for illustrative purposes, not to say
it's the proper way.
- After being executed by `git`, the git exec path should be the very
first entry in PATH, so it shouldn't matter.
- None of the scripts that are part of git do it that way.
But secondly, the root reason for fussing with PATH seems to be that
Avery didn't know that he needs to set GIT_EXEC_PATH if he's going to
use git from the source directory without installing.
And finally, Evan's issue is clearly just a bug in msysgit. I assume
that msysgit has since fixed the issue, and also msysgit has been
deprecated for 6 years now, so let's drop the workaround for it.
So, remove the line fussing with PATH. However, since subtree *is* in
'contrib/' and it might get installed in funny ways by users
after-the-fact, add a sanity check to the top of the script, checking
that it is installed correctly.
Signed-off-by: Luke Shumaker <lukeshu@datawire.io>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-04-27 23:17:37 +02:00
|
|
|
echo >&2 " PATH or in your git exec path (\`$(git --exec-path)\`)."
|
2021-06-14 14:41:53 +02:00
|
|
|
echo >&2 " - You should run git-subtree as \`git ${basename#git-}\`,"
|
|
|
|
echo >&2 " not as \`$basename\`." >&2
|
subtree: don't fuss with PATH
Scripts needing to fuss with with adding $(git --exec-prefix) PATH
before loading git-sh-setup is a thing of the past. As far as I can
tell, it's been a thing of the past since since Git v1.2.0 (2006-02-12),
or more specifically, since 77cb17e940 (Exec git programs without using
PATH, 2006-01-10). However, it stuck around in contrib scripts and in
third-party scripts for long enough that it wasn't unusual to see.
Originally `git subtree` didn't fuss with PATH, but when people
(including the original subtree author) had problems, because it was a
common thing to see, it seemed that having subtree fuss with PATH was a
reasonable solution.
Here is an abridged history of fussing with PATH in subtree:
2987e6add3 (Add explicit path of git installation by 'git --exec-path', Gianluca Pacchiella, 2009-08-20)
As pointed out by documentation, the correct use of 'git-sh-setup' is
using $(git --exec-path) to avoid problems with not standard
installations.
-. git-sh-setup
+. $(git --exec-path)/git-sh-setup
33aaa697a2 (Improve patch to use git --exec-path: add to PATH instead, Avery Pennarun, 2009-08-26)
If you (like me) are using a modified git straight out of its source
directory (ie. without installing), then --exec-path isn't actually correct.
Add it to the PATH instead, so if it is correct, it'll work, but if it's
not, we fall back to the previous behaviour.
-. $(git --exec-path)/git-sh-setup
+PATH=$(git --exec-path):$PATH
+. git-sh-setup
9c632ea29c ((Hopefully) fix PATH setting for msysgit, Avery Pennarun, 2010-06-24)
Reported by Evan Shaw. The problem is that $(git --exec-path) includes a
'git' binary which is incompatible with the one in /usr/bin; if you run it,
it gives you an error about libiconv2.dll.
+OPATH=$PATH
PATH=$(git --exec-path):$PATH
. git-sh-setup
+PATH=$OPATH # apparently needed for some versions of msysgit
df2302d774 (Another fix for PATH and msysgit, Avery Pennarun, 2010-06-24)
Evan Shaw tells me the previous fix didn't work. Let's use this one
instead, which he says does work.
This fix is kind of wrong because it will run the "correct" git-sh-setup
*after* the one in /usr/bin, if there is one, which could be weird if you
have multiple versions of git installed. But it works on my Linux and his
msysgit, so it's obviously better than what we had before.
-OPATH=$PATH
-PATH=$(git --exec-path):$PATH
+PATH=$PATH:$(git --exec-path)
. git-sh-setup
-PATH=$OPATH # apparently needed for some versions of msysgit
First of all, I disagree with Gianluca's reading of the documentation:
- I haven't gone back to read what the documentation said in 2009, but
in my reading of the 2021 documentation is that it includes "$(git
--exec-path)/" in the synopsis for illustrative purposes, not to say
it's the proper way.
- After being executed by `git`, the git exec path should be the very
first entry in PATH, so it shouldn't matter.
- None of the scripts that are part of git do it that way.
But secondly, the root reason for fussing with PATH seems to be that
Avery didn't know that he needs to set GIT_EXEC_PATH if he's going to
use git from the source directory without installing.
And finally, Evan's issue is clearly just a bug in msysgit. I assume
that msysgit has since fixed the issue, and also msysgit has been
deprecated for 6 years now, so let's drop the workaround for it.
So, remove the line fussing with PATH. However, since subtree *is* in
'contrib/' and it might get installed in funny ways by users
after-the-fact, add a sanity check to the top of the script, checking
that it is installed correctly.
Signed-off-by: Luke Shumaker <lukeshu@datawire.io>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-04-27 23:17:37 +02:00
|
|
|
exit 126
|
|
|
|
fi
|
|
|
|
|
2009-04-24 20:13:34 +02:00
|
|
|
OPTS_SPEC="\
|
2009-05-30 07:10:14 +02:00
|
|
|
git subtree add --prefix=<prefix> <commit>
|
2013-11-27 19:34:09 +01:00
|
|
|
git subtree add --prefix=<prefix> <repository> <ref>
|
2009-04-25 05:41:19 +02:00
|
|
|
git subtree merge --prefix=<prefix> <commit>
|
subtree: give the docs a once-over
Just went through the docs looking for anything inaccurate or that can
be improved.
In the '-h' text, in the man page synopsis, and in the man page
description: Normalize the ordering of the list of sub-commands: 'add',
'merge', 'split', 'pull', 'push'. This allows us to kinda separate the
lower-level add/merge/split from the higher-level pull/push.
'-h' text:
- correction: Indicate that split's arg is optional.
- clarity: Emphasize that 'pull' takes the 'add'/'merge' flags.
man page:
- correction: State that all subcommands take options (it seemed to
indicate that only 'split' takes any options other than '-P').
- correction: 'split' only guarantees that the results are identical if
the flags are identical.
- correction: The flag is named '--ignore-joins', not '--ignore-join'.
- completeness: Clarify that 'push' always operates on HEAD, and that
'split' operates on HEAD if no local commit is given.
- clarity: In the description, when listing commands, repeat what their
arguments are. This way the reader doesn't need to flip back and
forth between the command description and the synopsis and the full
description to understand what's being said.
- clarity: In the <variables> used to give command arguments, give
slightly longer, descriptive names. Like <local-commit> instead of
just <commit>.
- clarity: Emphasize that 'pull' takes the 'add'/'merge' flags.
- style: In the synopsis, list options before the subcommand. This
makes things line up and be much more readable when shown
non-monospace (such as in `make html`), and also more closely matches
other man pages (like `git-submodule.txt`).
- style: Use the correct syntax for indicating the options ([<options>]
instead of [OPTIONS]).
- style: In the synopsis, separate 'pull' and 'push' from the other
lower-level commands. I think this helps readability.
- style: Code-quote things in prose that seem like they should be
code-quoted, like '.gitmodules', flags, or full commands.
- style: Minor wording improvements, like more consistent mood (many
of the command descriptions start in the imperative mood and switch
to the indicative mode by the end). That sort of thing.
- style: Capitalize "ID".
- style: Remove the "This option is only valid for XXX command" remarks
from each option, and instead rely on the section headings.
- style: Since that line is getting edited anyway, switch "behaviour" to
American "behavior".
- style: Trim trailing whitespace.
`todo`:
- style: Trim trailing whitespace.
Signed-off-by: Luke Shumaker <lukeshu@datawire.io>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-04-27 23:17:44 +02:00
|
|
|
git subtree split --prefix=<prefix> [<commit>]
|
2013-11-27 19:34:09 +01:00
|
|
|
git subtree pull --prefix=<prefix> <repository> <ref>
|
2021-04-27 23:17:47 +02:00
|
|
|
git subtree push --prefix=<prefix> <repository> <refspec>
|
2009-04-24 20:13:34 +02:00
|
|
|
--
|
2009-04-25 04:36:06 +02:00
|
|
|
h,help show the help
|
|
|
|
q quiet
|
2009-04-27 00:06:08 +02:00
|
|
|
d show debug messages
|
2010-01-12 22:38:21 +01:00
|
|
|
P,prefix= the name of the subdir to split out
|
2021-04-27 23:17:46 +02:00
|
|
|
options for 'split' (also: 'push')
|
2009-04-26 14:59:12 +02:00
|
|
|
annotate= add a prefix to commit message of new commits
|
2009-05-30 07:05:43 +02:00
|
|
|
b,branch= create a new branch from the split subtree
|
|
|
|
ignore-joins ignore prior --rejoin commits
|
2009-04-25 04:36:06 +02:00
|
|
|
onto= try connecting new tree to an existing one
|
|
|
|
rejoin merge the new branch back into HEAD
|
2021-04-27 23:17:46 +02:00
|
|
|
options for 'add' and 'merge' (also: 'pull', 'split --rejoin', and 'push --rejoin')
|
2009-05-30 06:48:07 +02:00
|
|
|
squash merge subtree changes as a single commit
|
2021-04-27 23:17:45 +02:00
|
|
|
m,message= use the given message as the commit message for the merge commit
|
2009-04-24 20:13:34 +02:00
|
|
|
"
|
2010-06-24 07:53:05 +02:00
|
|
|
|
2021-04-27 23:17:43 +02:00
|
|
|
indent=0
|
|
|
|
|
2022-06-28 12:05:34 +02:00
|
|
|
# Usage: say [MSG...]
|
|
|
|
say () {
|
|
|
|
if test -z "$arg_quiet"
|
|
|
|
then
|
|
|
|
printf '%s\n' "$*"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:41 +02:00
|
|
|
# Usage: debug [MSG...]
|
2016-07-28 02:16:50 +02:00
|
|
|
debug () {
|
2021-04-27 23:17:35 +02:00
|
|
|
if test -n "$arg_debug"
|
2016-07-28 02:16:49 +02:00
|
|
|
then
|
2021-04-27 23:17:43 +02:00
|
|
|
printf "%$(($indent * 2))s%s\n" '' "$*" >&2
|
2009-04-27 00:06:08 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:41 +02:00
|
|
|
# Usage: progress [MSG...]
|
2016-07-28 02:16:50 +02:00
|
|
|
progress () {
|
2022-06-28 12:05:34 +02:00
|
|
|
if test -z "$arg_quiet"
|
2016-07-28 02:16:49 +02:00
|
|
|
then
|
2021-04-27 23:17:42 +02:00
|
|
|
if test -z "$arg_debug"
|
|
|
|
then
|
|
|
|
# Debug mode is off.
|
|
|
|
#
|
|
|
|
# Print one progress line that we keep updating (use
|
|
|
|
# "\r" to return to the beginning of the line, rather
|
|
|
|
# than "\n" to start a new line). This only really
|
|
|
|
# works when stderr is a terminal.
|
|
|
|
printf "%s\r" "$*" >&2
|
|
|
|
else
|
|
|
|
# Debug mode is on. The `debug` function is regularly
|
|
|
|
# printing to stderr.
|
|
|
|
#
|
|
|
|
# Don't do the one-line-with-"\r" thing, because on a
|
|
|
|
# terminal the debug output would overwrite and hide the
|
|
|
|
# progress output. Add a "progress:" prefix to make the
|
|
|
|
# progress output and the debug output easy to
|
|
|
|
# distinguish. This ensures maximum readability whether
|
|
|
|
# stderr is a terminal or a file.
|
|
|
|
printf "progress: %s\n" "$*" >&2
|
|
|
|
fi
|
2009-04-24 20:13:34 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:41 +02:00
|
|
|
# Usage: assert CMD...
|
2016-07-28 02:16:50 +02:00
|
|
|
assert () {
|
2016-07-28 02:16:49 +02:00
|
|
|
if ! "$@"
|
|
|
|
then
|
2021-04-27 23:17:36 +02:00
|
|
|
die "assertion failed: $*"
|
2009-04-24 20:24:38 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:30 +02:00
|
|
|
main () {
|
|
|
|
if test $# -eq 0
|
|
|
|
then
|
|
|
|
set -- -h
|
|
|
|
fi
|
2021-04-27 23:17:48 +02:00
|
|
|
set_args="$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)"
|
|
|
|
eval "$set_args"
|
2021-04-27 23:17:30 +02:00
|
|
|
. git-sh-setup
|
|
|
|
require_work_tree
|
2016-07-28 02:16:49 +02:00
|
|
|
|
2021-04-27 23:17:48 +02:00
|
|
|
# First figure out the command and whether we use --rejoin, so
|
|
|
|
# that we can provide more helpful validation when we do the
|
|
|
|
# "real" flag parsing.
|
|
|
|
arg_split_rejoin=
|
|
|
|
allow_split=
|
|
|
|
allow_addmerge=
|
|
|
|
while test $# -gt 0
|
|
|
|
do
|
|
|
|
opt="$1"
|
|
|
|
shift
|
|
|
|
case "$opt" in
|
|
|
|
--annotate|-b|-P|-m|--onto)
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--rejoin)
|
|
|
|
arg_split_rejoin=1
|
|
|
|
;;
|
|
|
|
--no-rejoin)
|
|
|
|
arg_split_rejoin=
|
|
|
|
;;
|
|
|
|
--)
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
arg_command=$1
|
|
|
|
case "$arg_command" in
|
|
|
|
add|merge|pull)
|
|
|
|
allow_addmerge=1
|
|
|
|
;;
|
|
|
|
split|push)
|
|
|
|
allow_split=1
|
|
|
|
allow_addmerge=$arg_split_rejoin
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
die "Unknown command '$arg_command'"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
# Reset the arguments array for "real" flag parsing.
|
|
|
|
eval "$set_args"
|
|
|
|
|
|
|
|
# Begin "real" flag parsing.
|
2022-06-28 12:05:34 +02:00
|
|
|
arg_quiet=
|
2021-04-27 23:17:48 +02:00
|
|
|
arg_debug=
|
|
|
|
arg_prefix=
|
|
|
|
arg_split_branch=
|
|
|
|
arg_split_onto=
|
|
|
|
arg_split_ignore_joins=
|
|
|
|
arg_split_annotate=
|
|
|
|
arg_addmerge_squash=
|
|
|
|
arg_addmerge_message=
|
2021-04-27 23:17:30 +02:00
|
|
|
while test $# -gt 0
|
|
|
|
do
|
|
|
|
opt="$1"
|
2016-07-28 02:16:49 +02:00
|
|
|
shift
|
2021-04-27 23:17:30 +02:00
|
|
|
|
|
|
|
case "$opt" in
|
|
|
|
-q)
|
2022-06-28 12:05:34 +02:00
|
|
|
arg_quiet=1
|
2021-04-27 23:17:30 +02:00
|
|
|
;;
|
|
|
|
-d)
|
2021-04-27 23:17:35 +02:00
|
|
|
arg_debug=1
|
2021-04-27 23:17:30 +02:00
|
|
|
;;
|
|
|
|
--annotate)
|
2021-04-27 23:17:48 +02:00
|
|
|
test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
|
2021-04-27 23:17:35 +02:00
|
|
|
arg_split_annotate="$1"
|
2021-04-27 23:17:30 +02:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--no-annotate)
|
2021-04-27 23:17:48 +02:00
|
|
|
test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
|
2021-04-27 23:17:35 +02:00
|
|
|
arg_split_annotate=
|
2021-04-27 23:17:30 +02:00
|
|
|
;;
|
|
|
|
-b)
|
2021-04-27 23:17:48 +02:00
|
|
|
test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
|
2021-04-27 23:17:35 +02:00
|
|
|
arg_split_branch="$1"
|
2021-04-27 23:17:30 +02:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-P)
|
2021-04-27 23:17:35 +02:00
|
|
|
arg_prefix="${1%/}"
|
2021-04-27 23:17:30 +02:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-m)
|
2021-04-27 23:17:48 +02:00
|
|
|
test -n "$allow_addmerge" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
|
2021-04-27 23:17:35 +02:00
|
|
|
arg_addmerge_message="$1"
|
2021-04-27 23:17:30 +02:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--no-prefix)
|
2021-04-27 23:17:35 +02:00
|
|
|
arg_prefix=
|
2021-04-27 23:17:30 +02:00
|
|
|
;;
|
|
|
|
--onto)
|
2021-04-27 23:17:48 +02:00
|
|
|
test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
|
2021-04-27 23:17:35 +02:00
|
|
|
arg_split_onto="$1"
|
2021-04-27 23:17:30 +02:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--no-onto)
|
2021-04-27 23:17:48 +02:00
|
|
|
test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
|
2021-04-27 23:17:35 +02:00
|
|
|
arg_split_onto=
|
2021-04-27 23:17:30 +02:00
|
|
|
;;
|
|
|
|
--rejoin)
|
2021-04-27 23:17:48 +02:00
|
|
|
test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
|
2021-04-27 23:17:30 +02:00
|
|
|
;;
|
|
|
|
--no-rejoin)
|
2021-04-27 23:17:48 +02:00
|
|
|
test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
|
2021-04-27 23:17:30 +02:00
|
|
|
;;
|
|
|
|
--ignore-joins)
|
2021-04-27 23:17:48 +02:00
|
|
|
test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
|
2021-04-27 23:17:35 +02:00
|
|
|
arg_split_ignore_joins=1
|
2021-04-27 23:17:30 +02:00
|
|
|
;;
|
|
|
|
--no-ignore-joins)
|
2021-04-27 23:17:48 +02:00
|
|
|
test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
|
2021-04-27 23:17:35 +02:00
|
|
|
arg_split_ignore_joins=
|
2021-04-27 23:17:30 +02:00
|
|
|
;;
|
|
|
|
--squash)
|
2021-04-27 23:17:48 +02:00
|
|
|
test -n "$allow_addmerge" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
|
2021-04-27 23:17:35 +02:00
|
|
|
arg_addmerge_squash=1
|
2021-04-27 23:17:30 +02:00
|
|
|
;;
|
|
|
|
--no-squash)
|
2021-04-27 23:17:48 +02:00
|
|
|
test -n "$allow_addmerge" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
|
2021-04-27 23:17:35 +02:00
|
|
|
arg_addmerge_squash=
|
2021-04-27 23:17:30 +02:00
|
|
|
;;
|
|
|
|
--)
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
die "Unexpected option: $opt"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
|
2021-04-27 23:17:35 +02:00
|
|
|
if test -z "$arg_prefix"
|
2021-04-27 23:17:30 +02:00
|
|
|
then
|
|
|
|
die "You must provide the --prefix option."
|
|
|
|
fi
|
|
|
|
|
2021-04-27 23:17:35 +02:00
|
|
|
case "$arg_command" in
|
2021-04-27 23:17:30 +02:00
|
|
|
add)
|
2021-04-27 23:17:35 +02:00
|
|
|
test -e "$arg_prefix" &&
|
|
|
|
die "prefix '$arg_prefix' already exists."
|
2016-07-28 02:16:49 +02:00
|
|
|
;;
|
|
|
|
*)
|
2021-04-27 23:17:35 +02:00
|
|
|
test -e "$arg_prefix" ||
|
|
|
|
die "'$arg_prefix' does not exist; use 'git subtree add'"
|
2016-07-28 02:16:49 +02:00
|
|
|
;;
|
2009-04-24 20:13:34 +02:00
|
|
|
esac
|
2021-04-27 23:17:30 +02:00
|
|
|
|
2021-04-27 23:17:35 +02:00
|
|
|
dir="$(dirname "$arg_prefix/.")"
|
2021-04-27 23:17:30 +02:00
|
|
|
|
2021-04-27 23:17:35 +02:00
|
|
|
debug "command: {$arg_command}"
|
2022-06-28 12:05:34 +02:00
|
|
|
debug "quiet: {$arg_quiet}"
|
2021-04-27 23:17:30 +02:00
|
|
|
debug "dir: {$dir}"
|
|
|
|
debug "opts: {$*}"
|
|
|
|
debug
|
|
|
|
|
2021-04-27 23:17:35 +02:00
|
|
|
"cmd_$arg_command" "$@"
|
2021-04-27 23:17:30 +02:00
|
|
|
}
|
2009-04-24 20:13:34 +02:00
|
|
|
|
2021-04-27 23:17:41 +02:00
|
|
|
# Usage: cache_setup
|
2016-07-28 02:16:50 +02:00
|
|
|
cache_setup () {
|
2021-04-27 23:17:41 +02:00
|
|
|
assert test $# = 0
|
2009-04-24 20:24:38 +02:00
|
|
|
cachedir="$GIT_DIR/subtree-cache/$$"
|
2016-07-28 02:16:49 +02:00
|
|
|
rm -rf "$cachedir" ||
|
|
|
|
die "Can't delete old cachedir: $cachedir"
|
|
|
|
mkdir -p "$cachedir" ||
|
|
|
|
die "Can't create new cachedir: $cachedir"
|
|
|
|
mkdir -p "$cachedir/notree" ||
|
|
|
|
die "Can't create new cachedir: $cachedir/notree"
|
2009-04-24 20:13:34 +02:00
|
|
|
debug "Using cachedir: $cachedir" >&2
|
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:41 +02:00
|
|
|
# Usage: cache_get [REVS...]
|
2016-07-28 02:16:50 +02:00
|
|
|
cache_get () {
|
2016-07-28 02:16:49 +02:00
|
|
|
for oldrev in "$@"
|
|
|
|
do
|
|
|
|
if test -r "$cachedir/$oldrev"
|
|
|
|
then
|
2009-04-24 20:13:34 +02:00
|
|
|
read newrev <"$cachedir/$oldrev"
|
|
|
|
echo $newrev
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:41 +02:00
|
|
|
# Usage: cache_miss [REVS...]
|
2016-07-28 02:16:50 +02:00
|
|
|
cache_miss () {
|
2016-07-28 02:16:49 +02:00
|
|
|
for oldrev in "$@"
|
|
|
|
do
|
|
|
|
if ! test -r "$cachedir/$oldrev"
|
|
|
|
then
|
2010-11-10 05:18:36 +01:00
|
|
|
echo $oldrev
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2021-12-08 03:11:58 +01:00
|
|
|
# Usage: check_parents [REVS...]
|
2016-07-28 02:16:50 +02:00
|
|
|
check_parents () {
|
2021-12-08 03:11:58 +01:00
|
|
|
missed=$(cache_miss "$@") || exit $?
|
2021-04-27 23:17:43 +02:00
|
|
|
local indent=$(($indent + 1))
|
2016-07-28 02:16:49 +02:00
|
|
|
for miss in $missed
|
|
|
|
do
|
|
|
|
if ! test -r "$cachedir/notree/$miss"
|
|
|
|
then
|
2021-04-27 23:17:43 +02:00
|
|
|
debug "incorrect order: $miss"
|
|
|
|
process_split_commit "$miss" ""
|
2010-11-10 05:18:36 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:41 +02:00
|
|
|
# Usage: set_notree REV
|
2016-07-28 02:16:50 +02:00
|
|
|
set_notree () {
|
2021-04-27 23:17:41 +02:00
|
|
|
assert test $# = 1
|
2010-11-10 05:18:36 +01:00
|
|
|
echo "1" > "$cachedir/notree/$1"
|
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:41 +02:00
|
|
|
# Usage: cache_set OLDREV NEWREV
|
2016-07-28 02:16:50 +02:00
|
|
|
cache_set () {
|
2021-04-27 23:17:41 +02:00
|
|
|
assert test $# = 2
|
2009-04-24 20:13:34 +02:00
|
|
|
oldrev="$1"
|
|
|
|
newrev="$2"
|
2016-07-28 02:16:49 +02:00
|
|
|
if test "$oldrev" != "latest_old" &&
|
|
|
|
test "$oldrev" != "latest_new" &&
|
|
|
|
test -e "$cachedir/$oldrev"
|
|
|
|
then
|
2009-04-24 20:13:34 +02:00
|
|
|
die "cache for $oldrev already exists!"
|
|
|
|
fi
|
|
|
|
echo "$newrev" >"$cachedir/$oldrev"
|
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:41 +02:00
|
|
|
# Usage: rev_exists REV
|
2016-07-28 02:16:50 +02:00
|
|
|
rev_exists () {
|
2021-04-27 23:17:41 +02:00
|
|
|
assert test $# = 1
|
2016-07-28 02:16:49 +02:00
|
|
|
if git rev-parse "$1" >/dev/null 2>&1
|
|
|
|
then
|
2009-05-30 07:05:43 +02:00
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:41 +02:00
|
|
|
# Usage: try_remove_previous REV
|
|
|
|
#
|
|
|
|
# If a commit doesn't have a parent, this might not work. But we only want
|
2009-04-25 06:06:45 +02:00
|
|
|
# to remove the parent from the rev-list, and since it doesn't exist, it won't
|
|
|
|
# be there anyway, so do nothing in that case.
|
2016-07-28 02:16:50 +02:00
|
|
|
try_remove_previous () {
|
2021-04-27 23:17:41 +02:00
|
|
|
assert test $# = 1
|
2016-07-28 02:16:49 +02:00
|
|
|
if rev_exists "$1^"
|
|
|
|
then
|
2009-04-25 06:06:45 +02:00
|
|
|
echo "^$1^"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:41 +02:00
|
|
|
# Usage: find_latest_squash DIR
|
2016-07-28 02:16:50 +02:00
|
|
|
find_latest_squash () {
|
2021-04-27 23:17:41 +02:00
|
|
|
assert test $# = 1
|
2009-05-30 10:11:43 +02:00
|
|
|
debug "Looking for latest squash ($dir)..."
|
2021-04-27 23:17:43 +02:00
|
|
|
local indent=$(($indent + 1))
|
|
|
|
|
2009-05-30 09:18:27 +02:00
|
|
|
dir="$1"
|
2009-05-30 10:11:43 +02:00
|
|
|
sq=
|
|
|
|
main=
|
|
|
|
sub=
|
2009-10-02 21:22:15 +02:00
|
|
|
git log --grep="^git-subtree-dir: $dir/*\$" \
|
2018-02-23 21:41:25 +01:00
|
|
|
--no-show-signature --pretty=format:'START %H%n%s%n%n%b%nEND%n' HEAD |
|
2016-07-28 02:16:49 +02:00
|
|
|
while read a b junk
|
|
|
|
do
|
2009-05-30 10:11:43 +02:00
|
|
|
debug "$a $b $junk"
|
|
|
|
debug "{{$sq/$main/$sub}}"
|
2009-05-30 09:18:27 +02:00
|
|
|
case "$a" in
|
2016-07-28 02:16:49 +02:00
|
|
|
START)
|
|
|
|
sq="$b"
|
|
|
|
;;
|
|
|
|
git-subtree-mainline:)
|
|
|
|
main="$b"
|
|
|
|
;;
|
|
|
|
git-subtree-split:)
|
2021-04-27 23:17:38 +02:00
|
|
|
sub="$(git rev-parse "$b^{commit}")" ||
|
2016-07-28 02:16:49 +02:00
|
|
|
die "could not rev-parse split hash $b from commit $sq"
|
|
|
|
;;
|
|
|
|
END)
|
|
|
|
if test -n "$sub"
|
|
|
|
then
|
|
|
|
if test -n "$main"
|
|
|
|
then
|
|
|
|
# a rejoin commit?
|
|
|
|
# Pretend its sub was a squash.
|
2021-04-27 23:17:45 +02:00
|
|
|
sq=$(git rev-parse --verify "$sq^2") ||
|
|
|
|
die
|
2009-05-30 09:18:27 +02:00
|
|
|
fi
|
2016-07-28 02:16:49 +02:00
|
|
|
debug "Squash found: $sq $sub"
|
|
|
|
echo "$sq" "$sub"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
sq=
|
|
|
|
main=
|
|
|
|
sub=
|
|
|
|
;;
|
2009-05-30 09:18:27 +02:00
|
|
|
esac
|
2021-04-27 23:17:31 +02:00
|
|
|
done || exit $?
|
2009-05-30 09:18:27 +02:00
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:41 +02:00
|
|
|
# Usage: find_existing_splits DIR REV
|
2016-07-28 02:16:50 +02:00
|
|
|
find_existing_splits () {
|
2021-04-27 23:17:41 +02:00
|
|
|
assert test $# = 2
|
2009-04-24 22:48:08 +02:00
|
|
|
debug "Looking for prior splits..."
|
2021-04-27 23:17:43 +02:00
|
|
|
local indent=$(($indent + 1))
|
|
|
|
|
2009-04-24 22:48:08 +02:00
|
|
|
dir="$1"
|
2021-04-27 23:17:41 +02:00
|
|
|
rev="$2"
|
2009-05-30 10:11:43 +02:00
|
|
|
main=
|
|
|
|
sub=
|
2018-09-28 20:35:38 +02:00
|
|
|
local grep_format="^git-subtree-dir: $dir/*\$"
|
2021-04-27 23:17:35 +02:00
|
|
|
if test -n "$arg_split_ignore_joins"
|
2018-09-28 20:35:38 +02:00
|
|
|
then
|
|
|
|
grep_format="^Add '$dir/' from commit '"
|
|
|
|
fi
|
|
|
|
git log --grep="$grep_format" \
|
2021-04-27 23:17:41 +02:00
|
|
|
--no-show-signature --pretty=format:'START %H%n%s%n%n%b%nEND%n' "$rev" |
|
2016-07-28 02:16:49 +02:00
|
|
|
while read a b junk
|
|
|
|
do
|
2009-04-24 22:48:08 +02:00
|
|
|
case "$a" in
|
2016-07-28 02:16:49 +02:00
|
|
|
START)
|
|
|
|
sq="$b"
|
|
|
|
;;
|
|
|
|
git-subtree-mainline:)
|
|
|
|
main="$b"
|
|
|
|
;;
|
|
|
|
git-subtree-split:)
|
2021-04-27 23:17:38 +02:00
|
|
|
sub="$(git rev-parse "$b^{commit}")" ||
|
2016-07-28 02:16:49 +02:00
|
|
|
die "could not rev-parse split hash $b from commit $sq"
|
|
|
|
;;
|
|
|
|
END)
|
2021-04-27 23:17:43 +02:00
|
|
|
debug "Main is: '$main'"
|
2016-07-28 02:16:49 +02:00
|
|
|
if test -z "$main" -a -n "$sub"
|
|
|
|
then
|
|
|
|
# squash commits refer to a subtree
|
|
|
|
debug " Squash: $sq from $sub"
|
|
|
|
cache_set "$sq" "$sub"
|
|
|
|
fi
|
|
|
|
if test -n "$main" -a -n "$sub"
|
|
|
|
then
|
|
|
|
debug " Prior: $main -> $sub"
|
|
|
|
cache_set $main $sub
|
|
|
|
cache_set $sub $sub
|
|
|
|
try_remove_previous "$main"
|
|
|
|
try_remove_previous "$sub"
|
|
|
|
fi
|
|
|
|
main=
|
|
|
|
sub=
|
|
|
|
;;
|
2009-04-24 22:48:08 +02:00
|
|
|
esac
|
2021-04-27 23:17:31 +02:00
|
|
|
done || exit $?
|
2009-04-24 22:48:08 +02:00
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:41 +02:00
|
|
|
# Usage: copy_commit REV TREE FLAGS_STR
|
2016-07-28 02:16:50 +02:00
|
|
|
copy_commit () {
|
2021-04-27 23:17:41 +02:00
|
|
|
assert test $# = 3
|
2009-05-30 06:47:59 +02:00
|
|
|
# We're going to set some environment vars here, so
|
2009-04-24 20:45:02 +02:00
|
|
|
# do it in a subshell to get rid of them safely later
|
2009-04-26 22:53:57 +02:00
|
|
|
debug copy_commit "{$1}" "{$2}" "{$3}"
|
2018-02-23 21:41:25 +01:00
|
|
|
git log -1 --no-show-signature --pretty=format:'%an%n%ae%n%aD%n%cn%n%ce%n%cD%n%B' "$1" |
|
2009-04-24 20:45:02 +02:00
|
|
|
(
|
|
|
|
read GIT_AUTHOR_NAME
|
|
|
|
read GIT_AUTHOR_EMAIL
|
|
|
|
read GIT_AUTHOR_DATE
|
|
|
|
read GIT_COMMITTER_NAME
|
|
|
|
read GIT_COMMITTER_EMAIL
|
|
|
|
read GIT_COMMITTER_DATE
|
2009-04-24 21:48:41 +02:00
|
|
|
export GIT_AUTHOR_NAME \
|
|
|
|
GIT_AUTHOR_EMAIL \
|
|
|
|
GIT_AUTHOR_DATE \
|
|
|
|
GIT_COMMITTER_NAME \
|
|
|
|
GIT_COMMITTER_EMAIL \
|
|
|
|
GIT_COMMITTER_DATE
|
2016-07-28 02:16:49 +02:00
|
|
|
(
|
2021-04-27 23:17:35 +02:00
|
|
|
printf "%s" "$arg_split_annotate"
|
2016-07-28 02:16:49 +02:00
|
|
|
cat
|
|
|
|
) |
|
2009-04-24 20:45:02 +02:00
|
|
|
git commit-tree "$2" $3 # reads the rest of stdin
|
|
|
|
) || die "Can't copy commit $1"
|
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:41 +02:00
|
|
|
# Usage: add_msg DIR LATEST_OLD LATEST_NEW
|
2016-07-28 02:16:50 +02:00
|
|
|
add_msg () {
|
2021-04-27 23:17:41 +02:00
|
|
|
assert test $# = 3
|
2009-04-25 05:28:30 +02:00
|
|
|
dir="$1"
|
|
|
|
latest_old="$2"
|
|
|
|
latest_new="$3"
|
2021-04-27 23:17:35 +02:00
|
|
|
if test -n "$arg_addmerge_message"
|
2016-07-28 02:16:49 +02:00
|
|
|
then
|
2021-04-27 23:17:35 +02:00
|
|
|
commit_message="$arg_addmerge_message"
|
2010-01-09 19:55:35 +01:00
|
|
|
else
|
|
|
|
commit_message="Add '$dir/' from commit '$latest_new'"
|
|
|
|
fi
|
2021-04-27 23:17:45 +02:00
|
|
|
if test -n "$arg_split_rejoin"
|
|
|
|
then
|
|
|
|
# If this is from a --rejoin, then rejoin_msg has
|
|
|
|
# already inserted the `git-subtree-xxx:` tags
|
|
|
|
echo "$commit_message"
|
|
|
|
return
|
|
|
|
fi
|
2009-04-25 05:28:30 +02:00
|
|
|
cat <<-EOF
|
2010-01-09 19:55:35 +01:00
|
|
|
$commit_message
|
2016-07-28 02:16:49 +02:00
|
|
|
|
2009-04-25 05:28:30 +02:00
|
|
|
git-subtree-dir: $dir
|
|
|
|
git-subtree-mainline: $latest_old
|
|
|
|
git-subtree-split: $latest_new
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:41 +02:00
|
|
|
# Usage: add_squashed_msg REV DIR
|
2016-07-28 02:16:50 +02:00
|
|
|
add_squashed_msg () {
|
2021-04-27 23:17:41 +02:00
|
|
|
assert test $# = 2
|
2021-04-27 23:17:35 +02:00
|
|
|
if test -n "$arg_addmerge_message"
|
2016-07-28 02:16:49 +02:00
|
|
|
then
|
2021-04-27 23:17:35 +02:00
|
|
|
echo "$arg_addmerge_message"
|
2010-01-09 19:55:35 +01:00
|
|
|
else
|
|
|
|
echo "Merge commit '$1' as '$2'"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:41 +02:00
|
|
|
# Usage: rejoin_msg DIR LATEST_OLD LATEST_NEW
|
2016-07-28 02:16:50 +02:00
|
|
|
rejoin_msg () {
|
2021-04-27 23:17:41 +02:00
|
|
|
assert test $# = 3
|
2009-04-24 21:48:41 +02:00
|
|
|
dir="$1"
|
|
|
|
latest_old="$2"
|
|
|
|
latest_new="$3"
|
2021-04-27 23:17:35 +02:00
|
|
|
if test -n "$arg_addmerge_message"
|
2016-07-28 02:16:49 +02:00
|
|
|
then
|
2021-04-27 23:17:35 +02:00
|
|
|
commit_message="$arg_addmerge_message"
|
2010-01-09 19:55:35 +01:00
|
|
|
else
|
|
|
|
commit_message="Split '$dir/' into commit '$latest_new'"
|
|
|
|
fi
|
2009-04-24 21:48:41 +02:00
|
|
|
cat <<-EOF
|
2010-01-12 22:38:34 +01:00
|
|
|
$commit_message
|
2016-07-28 02:16:49 +02:00
|
|
|
|
2009-04-24 21:48:41 +02:00
|
|
|
git-subtree-dir: $dir
|
2009-04-24 22:48:08 +02:00
|
|
|
git-subtree-mainline: $latest_old
|
|
|
|
git-subtree-split: $latest_new
|
2009-04-24 21:48:41 +02:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:41 +02:00
|
|
|
# Usage: squash_msg DIR OLD_SUBTREE_COMMIT NEW_SUBTREE_COMMIT
|
2016-07-28 02:16:50 +02:00
|
|
|
squash_msg () {
|
2021-04-27 23:17:41 +02:00
|
|
|
assert test $# = 3
|
2009-05-30 09:18:27 +02:00
|
|
|
dir="$1"
|
|
|
|
oldsub="$2"
|
|
|
|
newsub="$3"
|
|
|
|
newsub_short=$(git rev-parse --short "$newsub")
|
2016-07-28 02:16:49 +02:00
|
|
|
|
|
|
|
if test -n "$oldsub"
|
|
|
|
then
|
2009-05-30 10:11:43 +02:00
|
|
|
oldsub_short=$(git rev-parse --short "$oldsub")
|
|
|
|
echo "Squashed '$dir/' changes from $oldsub_short..$newsub_short"
|
|
|
|
echo
|
2018-02-23 21:41:25 +01:00
|
|
|
git log --no-show-signature --pretty=tformat:'%h %s' "$oldsub..$newsub"
|
|
|
|
git log --no-show-signature --pretty=tformat:'REVERT: %h %s' "$newsub..$oldsub"
|
2009-05-30 10:11:43 +02:00
|
|
|
else
|
|
|
|
echo "Squashed '$dir/' content from commit $newsub_short"
|
|
|
|
fi
|
2016-07-28 02:16:49 +02:00
|
|
|
|
2009-05-30 10:11:43 +02:00
|
|
|
echo
|
|
|
|
echo "git-subtree-dir: $dir"
|
|
|
|
echo "git-subtree-split: $newsub"
|
2009-05-30 09:18:27 +02:00
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:41 +02:00
|
|
|
# Usage: toptree_for_commit COMMIT
|
2016-07-28 02:16:50 +02:00
|
|
|
toptree_for_commit () {
|
2021-04-27 23:17:41 +02:00
|
|
|
assert test $# = 1
|
2009-04-25 03:49:19 +02:00
|
|
|
commit="$1"
|
2018-02-23 21:41:25 +01:00
|
|
|
git rev-parse --verify "$commit^{tree}" || exit $?
|
2009-04-25 03:49:19 +02:00
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:41 +02:00
|
|
|
# Usage: subtree_for_commit COMMIT DIR
|
2016-07-28 02:16:50 +02:00
|
|
|
subtree_for_commit () {
|
2021-04-27 23:17:41 +02:00
|
|
|
assert test $# = 2
|
2009-04-25 03:49:19 +02:00
|
|
|
commit="$1"
|
|
|
|
dir="$2"
|
|
|
|
git ls-tree "$commit" -- "$dir" |
|
2016-07-28 02:16:49 +02:00
|
|
|
while read mode type tree name
|
|
|
|
do
|
|
|
|
assert test "$name" = "$dir"
|
|
|
|
assert test "$type" = "tree" -o "$type" = "commit"
|
|
|
|
test "$type" = "commit" && continue # ignore submodules
|
2009-04-24 23:53:10 +02:00
|
|
|
echo $tree
|
|
|
|
break
|
2021-04-27 23:17:31 +02:00
|
|
|
done || exit $?
|
2009-04-24 23:53:10 +02:00
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:41 +02:00
|
|
|
# Usage: tree_changed TREE [PARENTS...]
|
2016-07-28 02:16:50 +02:00
|
|
|
tree_changed () {
|
2021-04-27 23:17:41 +02:00
|
|
|
assert test $# -gt 0
|
2009-04-24 23:53:10 +02:00
|
|
|
tree=$1
|
|
|
|
shift
|
2016-07-28 02:16:49 +02:00
|
|
|
if test $# -ne 1
|
|
|
|
then
|
2009-04-24 23:53:10 +02:00
|
|
|
return 0 # weird parents, consider it changed
|
|
|
|
else
|
2021-04-27 23:17:31 +02:00
|
|
|
ptree=$(toptree_for_commit $1) || exit $?
|
2016-07-28 02:16:49 +02:00
|
|
|
if test "$ptree" != "$tree"
|
|
|
|
then
|
2009-04-24 23:53:10 +02:00
|
|
|
return 0 # changed
|
|
|
|
else
|
|
|
|
return 1 # not changed
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:41 +02:00
|
|
|
# Usage: new_squash_commit OLD_SQUASHED_COMMIT OLD_NONSQUASHED_COMMIT NEW_NONSQUASHED_COMMIT
|
2016-07-28 02:16:50 +02:00
|
|
|
new_squash_commit () {
|
2021-04-27 23:17:41 +02:00
|
|
|
assert test $# = 3
|
2009-05-30 09:18:27 +02:00
|
|
|
old="$1"
|
|
|
|
oldsub="$2"
|
|
|
|
newsub="$3"
|
|
|
|
tree=$(toptree_for_commit $newsub) || exit $?
|
2016-07-28 02:16:49 +02:00
|
|
|
if test -n "$old"
|
|
|
|
then
|
|
|
|
squash_msg "$dir" "$oldsub" "$newsub" |
|
|
|
|
git commit-tree "$tree" -p "$old" || exit $?
|
2009-05-30 10:11:43 +02:00
|
|
|
else
|
|
|
|
squash_msg "$dir" "" "$newsub" |
|
2016-07-28 02:16:49 +02:00
|
|
|
git commit-tree "$tree" || exit $?
|
2009-05-30 10:11:43 +02:00
|
|
|
fi
|
2009-05-30 09:18:27 +02:00
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:41 +02:00
|
|
|
# Usage: copy_or_skip REV TREE NEWPARENTS
|
2016-07-28 02:16:50 +02:00
|
|
|
copy_or_skip () {
|
2021-04-27 23:17:41 +02:00
|
|
|
assert test $# = 3
|
2009-04-25 04:05:30 +02:00
|
|
|
rev="$1"
|
|
|
|
tree="$2"
|
|
|
|
newparents="$3"
|
2016-07-28 02:16:49 +02:00
|
|
|
assert test -n "$tree"
|
2009-04-25 04:05:30 +02:00
|
|
|
|
2009-04-25 04:36:06 +02:00
|
|
|
identical=
|
2009-04-26 23:07:16 +02:00
|
|
|
nonidentical=
|
2009-04-25 04:36:06 +02:00
|
|
|
p=
|
2009-04-26 22:53:57 +02:00
|
|
|
gotparents=
|
2018-09-28 20:35:40 +02:00
|
|
|
copycommit=
|
2016-07-28 02:16:49 +02:00
|
|
|
for parent in $newparents
|
|
|
|
do
|
2009-04-25 04:05:30 +02:00
|
|
|
ptree=$(toptree_for_commit $parent) || exit $?
|
2016-07-28 02:16:49 +02:00
|
|
|
test -z "$ptree" && continue
|
|
|
|
if test "$ptree" = "$tree"
|
|
|
|
then
|
2009-04-25 04:36:06 +02:00
|
|
|
# an identical parent could be used in place of this rev.
|
2018-09-28 20:35:40 +02:00
|
|
|
if test -n "$identical"
|
|
|
|
then
|
|
|
|
# if a previous identical parent was found, check whether
|
|
|
|
# one is already an ancestor of the other
|
|
|
|
mergebase=$(git merge-base $identical $parent)
|
|
|
|
if test "$identical" = "$mergebase"
|
|
|
|
then
|
|
|
|
# current identical commit is an ancestor of parent
|
|
|
|
identical="$parent"
|
|
|
|
elif test "$parent" != "$mergebase"
|
|
|
|
then
|
|
|
|
# no common history; commit must be copied
|
|
|
|
copycommit=1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
# first identical parent detected
|
|
|
|
identical="$parent"
|
|
|
|
fi
|
2009-04-26 23:07:16 +02:00
|
|
|
else
|
|
|
|
nonidentical="$parent"
|
2009-04-25 04:36:06 +02:00
|
|
|
fi
|
2016-07-28 02:16:49 +02:00
|
|
|
|
2009-04-26 22:53:57 +02:00
|
|
|
# sometimes both old parents map to the same newparent;
|
|
|
|
# eliminate duplicates
|
|
|
|
is_new=1
|
2016-07-28 02:16:49 +02:00
|
|
|
for gp in $gotparents
|
|
|
|
do
|
|
|
|
if test "$gp" = "$parent"
|
|
|
|
then
|
2009-04-26 22:53:57 +02:00
|
|
|
is_new=
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2016-07-28 02:16:49 +02:00
|
|
|
if test -n "$is_new"
|
|
|
|
then
|
2009-04-26 22:53:57 +02:00
|
|
|
gotparents="$gotparents $parent"
|
2009-04-25 04:05:30 +02:00
|
|
|
p="$p -p $parent"
|
|
|
|
fi
|
|
|
|
done
|
2016-01-15 01:41:43 +01:00
|
|
|
|
2016-07-28 02:16:49 +02:00
|
|
|
if test -n "$identical" && test -n "$nonidentical"
|
|
|
|
then
|
2016-01-15 01:41:43 +01:00
|
|
|
extras=$(git rev-list --count $identical..$nonidentical)
|
2016-07-28 02:16:49 +02:00
|
|
|
if test "$extras" -ne 0
|
|
|
|
then
|
2016-01-15 01:41:43 +01:00
|
|
|
# we need to preserve history along the other branch
|
|
|
|
copycommit=1
|
|
|
|
fi
|
|
|
|
fi
|
2016-07-28 02:16:49 +02:00
|
|
|
if test -n "$identical" && test -z "$copycommit"
|
|
|
|
then
|
2009-04-25 04:36:06 +02:00
|
|
|
echo $identical
|
|
|
|
else
|
2016-07-28 02:16:49 +02:00
|
|
|
copy_commit "$rev" "$tree" "$p" || exit $?
|
2009-04-25 04:36:06 +02:00
|
|
|
fi
|
2009-04-25 04:05:30 +02:00
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:41 +02:00
|
|
|
# Usage: ensure_clean
|
2016-07-28 02:16:50 +02:00
|
|
|
ensure_clean () {
|
2021-04-27 23:17:41 +02:00
|
|
|
assert test $# = 0
|
2016-07-28 02:16:49 +02:00
|
|
|
if ! git diff-index HEAD --exit-code --quiet 2>&1
|
|
|
|
then
|
2009-04-25 05:28:30 +02:00
|
|
|
die "Working tree has modifications. Cannot add."
|
|
|
|
fi
|
2016-07-28 02:16:49 +02:00
|
|
|
if ! git diff-index --cached HEAD --exit-code --quiet 2>&1
|
|
|
|
then
|
2009-04-25 05:28:30 +02:00
|
|
|
die "Index has modifications. Cannot add."
|
|
|
|
fi
|
2009-04-25 05:41:19 +02:00
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:41 +02:00
|
|
|
# Usage: ensure_valid_ref_format REF
|
2016-07-28 02:16:50 +02:00
|
|
|
ensure_valid_ref_format () {
|
2021-04-27 23:17:41 +02:00
|
|
|
assert test $# = 1
|
2013-11-27 19:34:09 +01:00
|
|
|
git check-ref-format "refs/heads/$1" ||
|
2016-07-28 02:16:49 +02:00
|
|
|
die "'$1' does not look like a ref"
|
2013-11-27 19:34:09 +01:00
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:43 +02:00
|
|
|
# Usage: process_split_commit REV PARENTS
|
2018-09-28 20:35:37 +02:00
|
|
|
process_split_commit () {
|
2021-04-27 23:17:43 +02:00
|
|
|
assert test $# = 2
|
2018-09-28 20:35:37 +02:00
|
|
|
local rev="$1"
|
|
|
|
local parents="$2"
|
2018-09-28 20:35:39 +02:00
|
|
|
|
|
|
|
if test $indent -eq 0
|
|
|
|
then
|
|
|
|
revcount=$(($revcount + 1))
|
|
|
|
else
|
|
|
|
# processing commit without normal parent information;
|
|
|
|
# fetch from repo
|
2018-10-12 15:52:18 +02:00
|
|
|
parents=$(git rev-parse "$rev^@")
|
2018-09-28 20:35:39 +02:00
|
|
|
extracount=$(($extracount + 1))
|
|
|
|
fi
|
|
|
|
|
|
|
|
progress "$revcount/$revmax ($createcount) [$extracount]"
|
|
|
|
|
2018-09-28 20:35:37 +02:00
|
|
|
debug "Processing commit: $rev"
|
2021-04-27 23:17:43 +02:00
|
|
|
local indent=$(($indent + 1))
|
2021-04-27 23:17:31 +02:00
|
|
|
exists=$(cache_get "$rev") || exit $?
|
2018-09-28 20:35:37 +02:00
|
|
|
if test -n "$exists"
|
|
|
|
then
|
2021-04-27 23:17:43 +02:00
|
|
|
debug "prior: $exists"
|
2018-09-28 20:35:37 +02:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
createcount=$(($createcount + 1))
|
2021-04-27 23:17:43 +02:00
|
|
|
debug "parents: $parents"
|
2021-12-08 03:11:58 +01:00
|
|
|
check_parents $parents
|
2021-04-27 23:17:31 +02:00
|
|
|
newparents=$(cache_get $parents) || exit $?
|
2021-04-27 23:17:43 +02:00
|
|
|
debug "newparents: $newparents"
|
2018-09-28 20:35:37 +02:00
|
|
|
|
2021-04-27 23:17:31 +02:00
|
|
|
tree=$(subtree_for_commit "$rev" "$dir") || exit $?
|
2021-04-27 23:17:43 +02:00
|
|
|
debug "tree is: $tree"
|
2018-09-28 20:35:37 +02:00
|
|
|
|
|
|
|
# ugly. is there no better way to tell if this is a subtree
|
|
|
|
# vs. a mainline commit? Does it matter?
|
|
|
|
if test -z "$tree"
|
|
|
|
then
|
|
|
|
set_notree "$rev"
|
|
|
|
if test -n "$newparents"
|
|
|
|
then
|
|
|
|
cache_set "$rev" "$rev"
|
|
|
|
fi
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
newrev=$(copy_or_skip "$rev" "$tree" "$newparents") || exit $?
|
2021-04-27 23:17:43 +02:00
|
|
|
debug "newrev is: $newrev"
|
2018-09-28 20:35:37 +02:00
|
|
|
cache_set "$rev" "$newrev"
|
|
|
|
cache_set latest_new "$newrev"
|
|
|
|
cache_set latest_old "$rev"
|
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:41 +02:00
|
|
|
# Usage: cmd_add REV
|
|
|
|
# Or: cmd_add REPOSITORY REF
|
2016-07-28 02:16:50 +02:00
|
|
|
cmd_add () {
|
2010-02-13 20:32:21 +01:00
|
|
|
|
2009-04-25 05:41:19 +02:00
|
|
|
ensure_clean
|
2016-07-28 02:16:49 +02:00
|
|
|
|
|
|
|
if test $# -eq 1
|
|
|
|
then
|
|
|
|
git rev-parse -q --verify "$1^{commit}" >/dev/null ||
|
|
|
|
die "'$1' does not refer to a commit"
|
|
|
|
|
|
|
|
cmd_add_commit "$@"
|
|
|
|
|
|
|
|
elif test $# -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.
|
|
|
|
ensure_valid_ref_format "$2"
|
|
|
|
|
|
|
|
cmd_add_repository "$@"
|
2010-02-13 20:32:21 +01:00
|
|
|
else
|
2021-04-27 23:17:36 +02:00
|
|
|
say >&2 "error: parameters were '$*'"
|
2016-07-28 02:16:49 +02:00
|
|
|
die "Provide either a commit or a repository and commit."
|
2009-04-25 05:28:30 +02:00
|
|
|
fi
|
2010-02-13 20:32:21 +01:00
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:41 +02:00
|
|
|
# Usage: cmd_add_repository REPOSITORY REFSPEC
|
2016-07-28 02:16:50 +02:00
|
|
|
cmd_add_repository () {
|
2021-04-27 23:17:41 +02:00
|
|
|
assert test $# = 2
|
2010-02-13 20:32:21 +01:00
|
|
|
echo "git fetch" "$@"
|
|
|
|
repository=$1
|
|
|
|
refspec=$2
|
|
|
|
git fetch "$@" || exit $?
|
2021-04-27 23:17:39 +02:00
|
|
|
cmd_add_commit FETCH_HEAD
|
2010-02-13 20:32:21 +01:00
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:41 +02:00
|
|
|
# Usage: cmd_add_commit REV
|
2016-07-28 02:16:50 +02:00
|
|
|
cmd_add_commit () {
|
2021-04-27 23:17:39 +02:00
|
|
|
# The rev has already been validated by cmd_add(), we just
|
|
|
|
# need to normalize it.
|
2021-04-27 23:17:41 +02:00
|
|
|
assert test $# = 1
|
2021-04-27 23:17:39 +02:00
|
|
|
rev=$(git rev-parse --verify "$1^{commit}") || exit $?
|
2016-07-28 02:16:49 +02:00
|
|
|
|
2009-04-25 05:28:30 +02:00
|
|
|
debug "Adding $dir as '$rev'..."
|
2021-04-27 23:17:45 +02:00
|
|
|
if test -z "$arg_split_rejoin"
|
|
|
|
then
|
|
|
|
# Only bother doing this if this is a genuine 'add',
|
|
|
|
# not a synthetic 'add' from '--rejoin'.
|
|
|
|
git read-tree --prefix="$dir" $rev || exit $?
|
|
|
|
fi
|
2009-08-26 16:43:43 +02:00
|
|
|
git checkout -- "$dir" || exit $?
|
2009-04-25 05:28:30 +02:00
|
|
|
tree=$(git write-tree) || exit $?
|
2016-07-28 02:16:49 +02:00
|
|
|
|
2009-04-25 05:28:30 +02:00
|
|
|
headrev=$(git rev-parse HEAD) || exit $?
|
2016-07-28 02:16:49 +02:00
|
|
|
if test -n "$headrev" && test "$headrev" != "$rev"
|
|
|
|
then
|
2009-04-25 05:28:30 +02:00
|
|
|
headp="-p $headrev"
|
|
|
|
else
|
|
|
|
headp=
|
|
|
|
fi
|
2016-07-28 02:16:49 +02:00
|
|
|
|
2021-04-27 23:17:35 +02:00
|
|
|
if test -n "$arg_addmerge_squash"
|
2016-07-28 02:16:49 +02:00
|
|
|
then
|
2009-05-30 10:11:43 +02:00
|
|
|
rev=$(new_squash_commit "" "" "$rev") || exit $?
|
2010-01-09 19:55:35 +01:00
|
|
|
commit=$(add_squashed_msg "$rev" "$dir" |
|
2016-07-28 02:16:49 +02:00
|
|
|
git commit-tree "$tree" $headp -p "$rev") || exit $?
|
2009-05-30 10:11:43 +02:00
|
|
|
else
|
2021-04-27 23:17:31 +02:00
|
|
|
revp=$(peel_committish "$rev") || exit $?
|
2016-07-28 02:16:49 +02:00
|
|
|
commit=$(add_msg "$dir" $headrev "$rev" |
|
|
|
|
git commit-tree "$tree" $headp -p "$revp") || exit $?
|
2009-05-30 10:11:43 +02:00
|
|
|
fi
|
2009-04-25 05:28:30 +02:00
|
|
|
git reset "$commit" || exit $?
|
2016-07-28 02:16:49 +02:00
|
|
|
|
2021-04-27 23:17:34 +02:00
|
|
|
say >&2 "Added dir '$dir'"
|
2009-04-25 05:28:30 +02:00
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:41 +02:00
|
|
|
# Usage: cmd_split [REV]
|
2016-07-28 02:16:50 +02:00
|
|
|
cmd_split () {
|
2021-04-27 23:17:39 +02:00
|
|
|
if test $# -eq 0
|
|
|
|
then
|
|
|
|
rev=$(git rev-parse HEAD)
|
|
|
|
elif test $# -eq 1
|
|
|
|
then
|
|
|
|
rev=$(git rev-parse -q --verify "$1^{commit}") ||
|
|
|
|
die "'$1' does not refer to a commit"
|
|
|
|
else
|
|
|
|
die "You must provide exactly one revision. Got: '$*'"
|
|
|
|
fi
|
|
|
|
|
2021-04-27 23:17:45 +02:00
|
|
|
if test -n "$arg_split_rejoin"
|
|
|
|
then
|
|
|
|
ensure_clean
|
|
|
|
fi
|
|
|
|
|
2009-04-24 20:13:34 +02:00
|
|
|
debug "Splitting $dir..."
|
|
|
|
cache_setup || exit $?
|
2016-07-28 02:16:49 +02:00
|
|
|
|
2021-04-27 23:17:35 +02:00
|
|
|
if test -n "$arg_split_onto"
|
2016-07-28 02:16:49 +02:00
|
|
|
then
|
2021-04-27 23:17:35 +02:00
|
|
|
debug "Reading history for --onto=$arg_split_onto..."
|
|
|
|
git rev-list $arg_split_onto |
|
2016-07-28 02:16:49 +02:00
|
|
|
while read rev
|
|
|
|
do
|
2009-04-24 23:05:14 +02:00
|
|
|
# the 'onto' history is already just the subdir, so
|
|
|
|
# any parent we find there can be used verbatim
|
2021-04-27 23:17:43 +02:00
|
|
|
debug "cache: $rev"
|
2016-07-28 02:16:49 +02:00
|
|
|
cache_set "$rev" "$rev"
|
2021-04-27 23:17:31 +02:00
|
|
|
done || exit $?
|
2009-04-24 23:05:14 +02:00
|
|
|
fi
|
2016-07-28 02:16:49 +02:00
|
|
|
|
2021-04-27 23:17:39 +02:00
|
|
|
unrevs="$(find_existing_splits "$dir" "$rev")" || exit $?
|
2016-07-28 02:16:49 +02:00
|
|
|
|
2009-04-26 21:54:42 +02:00
|
|
|
# We can't restrict rev-list to only $dir here, because some of our
|
|
|
|
# parents have the $dir contents the root, and those won't match.
|
|
|
|
# (and rev-list --follow doesn't seem to solve this)
|
2021-04-27 23:17:39 +02:00
|
|
|
grl='git rev-list --topo-order --reverse --parents $rev $unrevs'
|
2009-04-27 00:06:08 +02:00
|
|
|
revmax=$(eval "$grl" | wc -l)
|
|
|
|
revcount=0
|
|
|
|
createcount=0
|
2018-09-28 20:35:39 +02:00
|
|
|
extracount=0
|
2009-04-27 00:06:08 +02:00
|
|
|
eval "$grl" |
|
2016-07-28 02:16:49 +02:00
|
|
|
while read rev parents
|
|
|
|
do
|
2021-04-27 23:17:43 +02:00
|
|
|
process_split_commit "$rev" "$parents"
|
2009-04-24 20:24:38 +02:00
|
|
|
done || exit $?
|
2016-07-28 02:16:49 +02:00
|
|
|
|
2021-04-27 23:17:31 +02:00
|
|
|
latest_new=$(cache_get latest_new) || exit $?
|
2016-07-28 02:16:49 +02:00
|
|
|
if test -z "$latest_new"
|
|
|
|
then
|
2009-04-24 20:52:27 +02:00
|
|
|
die "No new revisions were found"
|
|
|
|
fi
|
2016-07-28 02:16:49 +02:00
|
|
|
|
2021-04-27 23:17:35 +02:00
|
|
|
if test -n "$arg_split_rejoin"
|
2016-07-28 02:16:49 +02:00
|
|
|
then
|
2009-04-24 21:48:41 +02:00
|
|
|
debug "Merging split branch into HEAD..."
|
2021-04-27 23:17:31 +02:00
|
|
|
latest_old=$(cache_get latest_old) || exit $?
|
2021-04-27 23:17:45 +02:00
|
|
|
arg_addmerge_message="$(rejoin_msg "$dir" "$latest_old" "$latest_new")" || exit $?
|
|
|
|
if test -z "$(find_latest_squash "$dir")"
|
|
|
|
then
|
|
|
|
cmd_add "$latest_new" >&2 || exit $?
|
|
|
|
else
|
|
|
|
cmd_merge "$latest_new" >&2 || exit $?
|
|
|
|
fi
|
2016-07-28 02:16:49 +02:00
|
|
|
fi
|
2021-04-27 23:17:35 +02:00
|
|
|
if test -n "$arg_split_branch"
|
2016-07-28 02:16:49 +02:00
|
|
|
then
|
2021-04-27 23:17:35 +02:00
|
|
|
if rev_exists "refs/heads/$arg_split_branch"
|
2016-07-28 02:16:49 +02:00
|
|
|
then
|
2021-04-27 23:17:35 +02:00
|
|
|
if ! git merge-base --is-ancestor "$arg_split_branch" "$latest_new"
|
2016-07-28 02:16:49 +02:00
|
|
|
then
|
2021-04-27 23:17:35 +02:00
|
|
|
die "Branch '$arg_split_branch' is not an ancestor of commit '$latest_new'."
|
2010-01-09 19:56:05 +01:00
|
|
|
fi
|
|
|
|
action='Updated'
|
|
|
|
else
|
|
|
|
action='Created'
|
|
|
|
fi
|
2016-07-28 02:16:49 +02:00
|
|
|
git update-ref -m 'subtree split' \
|
2021-04-27 23:17:35 +02:00
|
|
|
"refs/heads/$arg_split_branch" "$latest_new" || exit $?
|
|
|
|
say >&2 "$action branch '$arg_split_branch'"
|
2009-05-30 07:05:43 +02:00
|
|
|
fi
|
2016-07-28 02:16:49 +02:00
|
|
|
echo "$latest_new"
|
2009-04-24 20:13:34 +02:00
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:41 +02:00
|
|
|
# Usage: cmd_merge REV
|
2016-07-28 02:16:50 +02:00
|
|
|
cmd_merge () {
|
2021-04-27 23:17:39 +02:00
|
|
|
test $# -eq 1 ||
|
|
|
|
die "You must provide exactly one revision. Got: '$*'"
|
|
|
|
rev=$(git rev-parse -q --verify "$1^{commit}") ||
|
|
|
|
die "'$1' does not refer to a commit"
|
2009-04-25 05:41:19 +02:00
|
|
|
ensure_clean
|
2016-07-28 02:16:49 +02:00
|
|
|
|
2021-04-27 23:17:35 +02:00
|
|
|
if test -n "$arg_addmerge_squash"
|
2016-07-28 02:16:49 +02:00
|
|
|
then
|
2021-04-27 23:17:31 +02:00
|
|
|
first_split="$(find_latest_squash "$dir")" || exit $?
|
2016-07-28 02:16:49 +02:00
|
|
|
if test -z "$first_split"
|
|
|
|
then
|
2009-05-30 09:18:27 +02:00
|
|
|
die "Can't squash-merge: '$dir' was never added."
|
|
|
|
fi
|
|
|
|
set $first_split
|
|
|
|
old=$1
|
|
|
|
sub=$2
|
2016-07-28 02:16:49 +02:00
|
|
|
if test "$sub" = "$rev"
|
|
|
|
then
|
2021-04-27 23:17:34 +02:00
|
|
|
say >&2 "Subtree is already at commit $rev."
|
2009-05-30 09:33:17 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
2009-05-30 09:18:27 +02:00
|
|
|
new=$(new_squash_commit "$old" "$sub" "$rev") || exit $?
|
|
|
|
debug "New squash commit: $new"
|
|
|
|
rev="$new"
|
|
|
|
fi
|
2010-05-07 21:21:25 +02:00
|
|
|
|
2021-04-27 23:17:35 +02:00
|
|
|
if test -n "$arg_addmerge_message"
|
2016-07-28 02:16:49 +02:00
|
|
|
then
|
2022-02-01 18:26:04 +01:00
|
|
|
git merge --no-ff -Xsubtree="$arg_prefix" \
|
2021-04-27 23:17:35 +02:00
|
|
|
--message="$arg_addmerge_message" "$rev"
|
2010-02-06 21:05:17 +01:00
|
|
|
else
|
2022-02-01 18:26:04 +01:00
|
|
|
git merge --no-ff -Xsubtree="$arg_prefix" $rev
|
2010-02-06 21:05:17 +01:00
|
|
|
fi
|
2009-04-25 05:41:19 +02:00
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:41 +02:00
|
|
|
# Usage: cmd_pull REPOSITORY REMOTEREF
|
2016-07-28 02:16:50 +02:00
|
|
|
cmd_pull () {
|
2016-07-28 02:16:49 +02:00
|
|
|
if test $# -ne 2
|
|
|
|
then
|
|
|
|
die "You must provide <repository> <ref>"
|
2013-11-27 19:34:09 +01:00
|
|
|
fi
|
2009-04-25 05:41:19 +02:00
|
|
|
ensure_clean
|
2013-11-27 19:34:09 +01:00
|
|
|
ensure_valid_ref_format "$2"
|
2009-10-03 00:23:54 +02:00
|
|
|
git fetch "$@" || exit $?
|
2021-04-27 23:17:39 +02:00
|
|
|
cmd_merge FETCH_HEAD
|
2010-02-13 20:32:21 +01:00
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:47 +02:00
|
|
|
# Usage: cmd_push REPOSITORY [+][LOCALREV:]REMOTEREF
|
2016-07-28 02:16:50 +02:00
|
|
|
cmd_push () {
|
2016-07-28 02:16:49 +02:00
|
|
|
if test $# -ne 2
|
|
|
|
then
|
2021-04-27 23:17:47 +02:00
|
|
|
die "You must provide <repository> <refspec>"
|
2010-02-13 20:32:21 +01:00
|
|
|
fi
|
2016-07-28 02:16:49 +02:00
|
|
|
if test -e "$dir"
|
|
|
|
then
|
|
|
|
repository=$1
|
2021-04-27 23:17:47 +02:00
|
|
|
refspec=${2#+}
|
|
|
|
remoteref=${refspec#*:}
|
|
|
|
if test "$remoteref" = "$refspec"
|
|
|
|
then
|
|
|
|
localrevname_presplit=HEAD
|
|
|
|
else
|
|
|
|
localrevname_presplit=${refspec%%:*}
|
|
|
|
fi
|
|
|
|
ensure_valid_ref_format "$remoteref"
|
|
|
|
localrev_presplit=$(git rev-parse -q --verify "$localrevname_presplit^{commit}") ||
|
|
|
|
die "'$localrevname_presplit' does not refer to a commit"
|
|
|
|
|
2016-07-28 02:16:49 +02:00
|
|
|
echo "git push using: " "$repository" "$refspec"
|
2021-04-27 23:17:47 +02:00
|
|
|
localrev=$(cmd_split "$localrev_presplit") || die
|
|
|
|
git push "$repository" "$localrev":"refs/heads/$remoteref"
|
2010-02-13 20:32:21 +01:00
|
|
|
else
|
2016-07-28 02:16:49 +02:00
|
|
|
die "'$dir' must already exist. Try 'git subtree add'."
|
2010-02-13 20:32:21 +01:00
|
|
|
fi
|
2009-04-24 20:13:34 +02:00
|
|
|
}
|
|
|
|
|
2021-04-27 23:17:30 +02:00
|
|
|
main "$@"
|