summaryrefslogtreecommitdiff
path: root/contrib/subtree
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/subtree')
-rw-r--r--contrib/subtree/Makefile48
-rwxr-xr-xcontrib/subtree/git-subtree.sh33
-rw-r--r--contrib/subtree/git-subtree.txt16
-rwxr-xr-xcontrib/subtree/t/t7900-subtree.sh13
4 files changed, 72 insertions, 38 deletions
diff --git a/contrib/subtree/Makefile b/contrib/subtree/Makefile
index b507505..d9a0ce2 100644
--- a/contrib/subtree/Makefile
+++ b/contrib/subtree/Makefile
@@ -3,17 +3,28 @@
prefix ?= /usr/local
mandir ?= $(prefix)/share/man
-libexecdir ?= $(prefix)/libexec/git-core
-gitdir ?= $(shell git --exec-path)
+gitexecdir ?= $(prefix)/libexec/git-core
man1dir ?= $(mandir)/man1
-gitver ?= $(word 3,$(shell git --version))
+../../GIT-VERSION-FILE: FORCE
+ $(MAKE) -C ../../ GIT-VERSION-FILE
+
+-include ../../GIT-VERSION-FILE
# this should be set to a 'standard' bsd-type install program
-INSTALL ?= install
+INSTALL ?= install
+RM ?= rm -f
+
+ASCIIDOC = asciidoc
+XMLTO = xmlto
+
+ifndef SHELL_PATH
+ SHELL_PATH = /bin/sh
+endif
+SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
-ASCIIDOC_CONF = ../../Documentation/asciidoc.conf
-MANPAGE_NORMAL_XSL = ../../Documentation/manpage-normal.xsl
+ASCIIDOC_CONF = ../../Documentation/asciidoc.conf
+MANPAGE_XSL = ../../Documentation/manpage-normal.xsl
GIT_SUBTREE_SH := git-subtree.sh
GIT_SUBTREE := git-subtree
@@ -21,16 +32,19 @@ GIT_SUBTREE := git-subtree
GIT_SUBTREE_DOC := git-subtree.1
GIT_SUBTREE_XML := git-subtree.xml
GIT_SUBTREE_TXT := git-subtree.txt
+GIT_SUBTREE_HTML := git-subtree.html
all: $(GIT_SUBTREE)
$(GIT_SUBTREE): $(GIT_SUBTREE_SH)
- cp $< $@ && chmod +x $@
+ sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' $< >$@
+ chmod +x $@
-doc: $(GIT_SUBTREE_DOC)
+doc: $(GIT_SUBTREE_DOC) $(GIT_SUBTREE_HTML)
install: $(GIT_SUBTREE)
- $(INSTALL) -m 755 $(GIT_SUBTREE) $(DESTDIR)$(libexecdir)
+ $(INSTALL) -d -m 755 $(DESTDIR)$(gitexecdir)
+ $(INSTALL) -m 755 $(GIT_SUBTREE) $(DESTDIR)$(gitexecdir)
install-doc: install-man
@@ -39,15 +53,21 @@ install-man: $(GIT_SUBTREE_DOC)
$(INSTALL) -m 644 $^ $(DESTDIR)$(man1dir)
$(GIT_SUBTREE_DOC): $(GIT_SUBTREE_XML)
- xmlto -m $(MANPAGE_NORMAL_XSL) man $^
+ $(XMLTO) -m $(MANPAGE_XSL) man $^
$(GIT_SUBTREE_XML): $(GIT_SUBTREE_TXT)
- asciidoc -b docbook -d manpage -f $(ASCIIDOC_CONF) \
- -agit_version=$(gitver) $^
+ $(ASCIIDOC) -b docbook -d manpage -f $(ASCIIDOC_CONF) \
+ -agit_version=$(GIT_VERSION) $^
+
+$(GIT_SUBTREE_HTML): $(GIT_SUBTREE_TXT)
+ $(ASCIIDOC) -b xhtml11 -d manpage -f $(ASCIIDOC_CONF) \
+ -agit_version=$(GIT_VERSION) $^
test:
$(MAKE) -C t/ test
clean:
- rm -f *~ *.xml *.html *.1
- rm -rf subproj mainline
+ $(RM) $(GIT_SUBTREE)
+ $(RM) *.xml *.html *.1
+
+.PHONY: FORCE
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 8a23f58..fa1a583 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
#
# git-subtree.sh: split/join git repositories in subdirectories of this one
#
@@ -9,10 +9,10 @@ if [ $# -eq 0 ]; then
fi
OPTS_SPEC="\
git subtree add --prefix=<prefix> <commit>
-git subtree add --prefix=<prefix> <repository> <commit>
+git subtree add --prefix=<prefix> <repository> <ref>
git subtree merge --prefix=<prefix> <commit>
-git subtree pull --prefix=<prefix> <repository> <refspec...>
-git subtree push --prefix=<prefix> <repository> <refspec...>
+git subtree pull --prefix=<prefix> <repository> <ref>
+git subtree push --prefix=<prefix> <repository> <ref>
git subtree split --prefix=<prefix> <commit...>
--
h,help show the help
@@ -46,6 +46,7 @@ ignore_joins=
annotate=
squash=
message=
+prefix=
debug()
{
@@ -311,7 +312,7 @@ copy_commit()
GIT_COMMITTER_NAME \
GIT_COMMITTER_EMAIL \
GIT_COMMITTER_DATE
- (echo -n "$annotate"; cat ) |
+ (printf "%s" "$annotate"; cat ) |
git commit-tree "$2" $3 # reads the rest of stdin
) || die "Can't copy commit $1"
}
@@ -489,6 +490,12 @@ ensure_clean()
fi
}
+ensure_valid_ref_format()
+{
+ git check-ref-format "refs/heads/$1" ||
+ die "'$1' does not look like a ref"
+}
+
cmd_add()
{
if [ -e "$dir" ]; then
@@ -508,8 +515,7 @@ cmd_add()
# 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"
+ ensure_valid_ref_format "$2"
"cmd_add_repository" "$@"
else
@@ -552,8 +558,9 @@ cmd_add_commit()
commit=$(add_squashed_msg "$rev" "$dir" |
git commit-tree $tree $headp -p "$rev") || exit $?
else
+ revp=$(peel_committish "$rev") &&
commit=$(add_msg "$dir" "$headrev" "$rev" |
- git commit-tree $tree $headp -p "$rev") || exit $?
+ git commit-tree $tree $headp -p "$revp") || exit $?
fi
git reset "$commit" || exit $?
@@ -699,7 +706,11 @@ cmd_merge()
cmd_pull()
{
+ if [ $# -ne 2 ]; then
+ die "You must provide <repository> <ref>"
+ fi
ensure_clean
+ ensure_valid_ref_format "$2"
git fetch "$@" || exit $?
revs=FETCH_HEAD
set -- $revs
@@ -709,13 +720,15 @@ cmd_pull()
cmd_push()
{
if [ $# -ne 2 ]; then
- die "You must provide <repository> <refspec>"
+ die "You must provide <repository> <ref>"
fi
+ ensure_valid_ref_format "$2"
if [ -e "$dir" ]; then
repository=$1
refspec=$2
echo "git push using: " $repository $refspec
- git push $repository $(git subtree split --prefix=$prefix):refs/heads/$refspec
+ localrev=$(git subtree split --prefix="$prefix") || die
+ git push $repository $localrev:refs/heads/$refspec
else
die "'$dir' must already exist. Try 'git subtree add'."
fi
diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
index 7ba853e..02669b1 100644
--- a/contrib/subtree/git-subtree.txt
+++ b/contrib/subtree/git-subtree.txt
@@ -9,10 +9,10 @@ git-subtree - Merge subtrees together and split repository into subtrees
SYNOPSIS
--------
[verse]
-'git subtree' add -P <prefix> <refspec>
-'git subtree' add -P <prefix> <repository> <refspec>
-'git subtree' pull -P <prefix> <repository> <refspec...>
-'git subtree' push -P <prefix> <repository> <refspec...>
+'git subtree' add -P <prefix> <commit>
+'git subtree' add -P <prefix> <repository> <ref>
+'git subtree' pull -P <prefix> <repository> <ref>
+'git subtree' push -P <prefix> <repository> <ref>
'git subtree' merge -P <prefix> <commit>
'git subtree' split -P <prefix> [OPTIONS] [<commit>]
@@ -68,7 +68,7 @@ COMMANDS
--------
add::
Create the <prefix> subtree by importing its contents
- from the given <refspec> or <repository> and remote <refspec>.
+ from the given <commit> or <repository> and remote <ref>.
A new commit is created automatically, joining the imported
project's history with your own. With '--squash', imports
only a single commit from the subproject, rather than its
@@ -90,13 +90,13 @@ merge::
pull::
Exactly like 'merge', but parallels 'git pull' in that
- it fetches the given commit from the specified remote
+ it fetches the given ref from the specified remote
repository.
push::
Does a 'split' (see below) using the <prefix> supplied
and then does a 'git push' to push the result to the
- repository and refspec. This can be used to push your
+ repository and ref. This can be used to push your
subtree to different branches of the remote repository.
split::
@@ -270,7 +270,7 @@ git-extensions repository in ~/git-extensions/:
name
You can omit the --squash flag, but doing so will increase the number
-of commits that are incldued in your local repository.
+of commits that are included in your local repository.
We now have a ~/git-extensions/git-subtree directory containing code
from the master branch of git://github.com/apenwarr/git-subtree.git
diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index b0f8536..6309d12 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -8,7 +8,8 @@ This test verifies the basic operation of the merge, pull, add
and split subcommands of git subtree.
'
-export TEST_DIRECTORY=$(pwd)/../../../t
+TEST_DIRECTORY=$(pwd)/../../../t
+export TEST_DIRECTORY
. ../../../t/test-lib.sh
@@ -76,7 +77,7 @@ test_expect_success 'add sub1' '
# Save this hash for testing later.
-subdir_hash=`git rev-parse HEAD`
+subdir_hash=$(git rev-parse HEAD)
test_expect_success 'add sub2' '
create sub2 &&
@@ -182,9 +183,9 @@ test_expect_success 'merge new subproj history into subdir' '
test_expect_success 'Check that prefix argument is required for split' '
echo "You must provide the --prefix option." > expected &&
test_must_fail git subtree split > actual 2>&1 &&
- test_debug "echo -n expected: " &&
+ test_debug "printf '"'"'expected: '"'"'" &&
test_debug "cat expected" &&
- test_debug "echo -n actual: " &&
+ test_debug "printf '"'"'actual: '"'"'" &&
test_debug "cat actual" &&
test_cmp expected actual &&
rm -f expected actual
@@ -193,9 +194,9 @@ test_expect_success 'Check that prefix argument is required for split' '
test_expect_success 'Check that the <prefix> exists for a split' '
echo "'"'"'non-existent-directory'"'"'" does not exist\; use "'"'"'git subtree add'"'"'" > expected &&
test_must_fail git subtree split --prefix=non-existent-directory > actual 2>&1 &&
- test_debug "echo -n expected: " &&
+ test_debug "printf '"'"'expected: '"'"'" &&
test_debug "cat expected" &&
- test_debug "echo -n actual: " &&
+ test_debug "printf '"'"'actual: '"'"'" &&
test_debug "cat actual" &&
test_cmp expected actual
# rm -f expected actual