From: Nicola Paolucci <npaolucci@atlassian.com>
To: git@vger.kernel.org
Cc: Dave <davidw@realtimegenomics.com>,
"David A . Greene" <greened@obbligato.org>,
Mathias Nyman <mathias.nyman@iki.fi>,
Nicola Paolucci <npaolucci@atlassian.com>
Subject: [PATCH 2/3] contrib/subtree: new list command to list subtrees
Date: Thu, 10 Mar 2016 10:44:11 +0100 [thread overview]
Message-ID: <1457603052-53963-3-git-send-email-npaolucci@atlassian.com> (raw)
In-Reply-To: <1457603052-53963-1-git-send-email-npaolucci@atlassian.com>
Example output:
$ git subtree list
.vim/bundle/fireplace https://github.com/tpope/vim-fireplace.git b999b0
Signed-off-by: Nicola Paolucci <npaolucci@atlassian.com>
---
contrib/subtree/git-subtree.sh | 54 ++++++++++++++++++++++++++++++++++----
contrib/subtree/t/t7900-subtree.sh | 18 +++++++++++++
2 files changed, 67 insertions(+), 5 deletions(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 278699b..82f3fce 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -14,6 +14,7 @@ git subtree merge --prefix=<prefix> <commit>
git subtree pull --prefix=<prefix> <repository> <ref>
git subtree push --prefix=<prefix> <repository> <ref>
git subtree split --prefix=<prefix> <commit...>
+git subtree list
--
h,help show the help
q quiet
@@ -109,19 +110,22 @@ done
command="$1"
shift
case "$command" in
- add|merge|pull) default= ;;
+ add|merge|pull|list) default= ;;
split|push) default="--default HEAD" ;;
*) die "Unknown command '$command'" ;;
esac
-if [ -z "$prefix" ]; then
- die "You must provide the --prefix option."
+if [ "$command" != "list" ]; then
+ if [ -z "$prefix" ]; then
+ die "You must provide the --prefix option."
+ fi
fi
case "$command" in
- add) [ -e "$prefix" ] &&
+ add) [ -e "$prefix" ] &&
die "prefix '$prefix' already exists." ;;
- *) [ -e "$prefix" ] ||
+ list) ;;
+ *) [ -e "$prefix" ] ||
die "'$prefix' does not exist; use 'git subtree add'" ;;
esac
@@ -230,6 +234,41 @@ try_remove_previous()
fi
}
+find_subtree_repos()
+{
+ debug "Looking for subtree repos..."
+ sq=
+ main=
+ sub=
+ git log --grep="^git-subtree-dir:" \
+ --pretty=format:'START %H%n%s%n%n%b%nEND%n' HEAD |
+ while read a b c; do
+ debug "$a $b $c"
+ debug "{{$sq/$main/$sub}}"
+ case "$a" in
+ START) sq="$b" ;;
+ git-subtree-dir:) dir="$b $c" ;;
+ git-subtree-mainline:) main="$b" ;;
+ git-subtree-split:) sub="$b" ;;
+ git-subtree-repo:) repo="$b $c" ;;
+ END)
+ if [ -n "$sub" ]; then
+ if [ -n "$main" ]; then
+ # a rejoin commit?
+ # Pretend its sub was a squash.
+ sq="$sub"
+ fi
+ debug "Subtree found: $dir $repo $sub"
+ echo "$dir" "$repo" "$sub"
+ fi
+ sq=
+ main=
+ sub=
+ ;;
+ esac
+ done
+}
+
find_latest_squash()
{
debug "Looking for latest squash ($dir)..."
@@ -536,6 +575,11 @@ get_repository_url()
echo $repo_url
}
+cmd_list()
+{
+ find_subtree_repos "$@"
+}
+
cmd_add()
{
if [ -e "$dir" ]; then
diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index ed40e73..ce97446 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -196,6 +196,24 @@ test_expect_success 'add --squash stores git-subtree-repo value' '
'
#
+# Tests for 'git subtree list'
+#
+
+next_test
+test_expect_success 'list outputs list of subtrees' '
+ subtree_test_create_repo "$subtree_test_count" &&
+ subtree_test_create_repo "$subtree_test_count/sub proj" &&
+ test_create_commit "$subtree_test_count" main1 &&
+ test_create_commit "$subtree_test_count/sub proj" sub1 &&
+ (
+ cd "$subtree_test_count" &&
+ git fetch ./"sub proj" master &&
+ git subtree add --prefix="sub dir" "./sub proj" HEAD --squash &&
+ check_equal "$(git subtree list | cut -c -19)" "sub dir ./sub proj "
+ )
+'
+
+#
# Tests for 'git subtree merge'
#
--
2.7.1
next prev parent reply other threads:[~2016-03-10 9:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-10 9:44 [PATCH 0/3] subtree: add 'git-subtree-repo' and list command Nicola Paolucci
2016-03-10 9:44 ` [PATCH v3 1/3] contrib/subtree: 'add' stores 'git-subtree-repo' Nicola Paolucci
2016-03-10 9:44 ` Nicola Paolucci [this message]
2016-03-10 9:44 ` [PATCH 3/3] contrib/subtree: list --resolve gets symbolic refs Nicola Paolucci
2016-05-21 22:59 ` [PATCH 0/3] subtree: add 'git-subtree-repo' and list command David A. Greene
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1457603052-53963-3-git-send-email-npaolucci@atlassian.com \
--to=npaolucci@atlassian.com \
--cc=davidw@realtimegenomics.com \
--cc=git@vger.kernel.org \
--cc=greened@obbligato.org \
--cc=mathias.nyman@iki.fi \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).