As the 'list' command finds commit ids for subtrees injected into the checked out branch the --resolve flag tries to look up the repositories at 'git-subtree-repo' and retrive the symbolic refs associated with the commit ids found. Example: $ git-subtree.sh list --resolve vim-airline https://repo/bling/vim-airline.git 4fa37e5e[...] vim-airline https://repo/bling/vim-airline.git HEAD vim-airline https://repo/bling/vim-airline.git refs/heads/master Signed-off-by: Nicola Paolucci <npaolucci@xxxxxxxxxxxxx> --- contrib/subtree/git-subtree.sh | 21 +++++++++++++++++---- contrib/subtree/git-subtree.txt | 31 +++++++++++++++++++++++++++++++ contrib/subtree/t/t7900-subtree.sh | 26 ++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 4 deletions(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index 82f3fce..fe62151 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -14,7 +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 +git subtree list [--resolve] -- h,help show the help q quiet @@ -29,6 +29,7 @@ onto= try connecting new tree to an existing one rejoin merge the new branch back into HEAD options for 'add', 'merge', and 'pull' squash merge subtree changes as a single commit +resolve resolves ids to refs when possible " eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)" @@ -48,6 +49,7 @@ annotate= squash= message= prefix= +resolve= debug() { @@ -102,6 +104,8 @@ while [ $# -gt 0 ]; do --no-ignore-joins) ignore_joins= ;; --squash) squash=1 ;; --no-squash) squash= ;; + --resolve) resolve=1 ;; + --no-resolve) resolve= ;; --) break ;; *) die "Unexpected option: $opt" ;; esac @@ -254,12 +258,21 @@ find_subtree_repos() 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" + # Strip potential space at the end in repo + repo=$(echo $repo) + if [ -n "$resolve" ] && [ -n "$repo" ]; then + echo "$dir" "$repo" "$sub" + # Retrieve remote refs if repo is available + resolved_refs=$(git ls-remote "$repo" | grep "$sub" | cut -c 42- | xargs) + for r in $resolved_refs; do + echo "$dir" "$repo" "$r" + done + else + echo "$dir" "$repo" "$sub" + fi fi sq= main= diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt index 60d76cd..ab36951 100644 --- a/contrib/subtree/git-subtree.txt +++ b/contrib/subtree/git-subtree.txt @@ -15,6 +15,7 @@ SYNOPSIS 'git subtree' push -P <prefix> <repository> <ref> 'git subtree' merge -P <prefix> <commit> 'git subtree' split -P <prefix> [OPTIONS] [<commit>] +'git subtree' list [--resolve] DESCRIPTION @@ -106,6 +107,12 @@ split:: contents of <prefix> at the root of the project instead of in a subdirectory. Thus, the newly created history is suitable for export as a separate git repository. + +list:: + List all subtrees injected in checked out branch. Run + with optional `--resolve` to retrieve remote symbolic refs + associated with the subtree. Address of subtree repo is stored + in commits as `git-subtree-repo` at the time of `git subtree add`. + After splitting successfully, a single commit id is printed to stdout. This corresponds to the HEAD of the newly created tree, which you can @@ -240,6 +247,13 @@ split, because you don't want the subproject's history to be part of your project anyway. +OPTIONS FOR list +---------------------------------- +--resolve:: + Resolves 'git-subtree-split' refs by looking up symbolic refs at + 'git-subtree-repo'. + + EXAMPLE 1. Add command ---------------------- Let's assume that you have a local repository that you would like @@ -341,6 +355,23 @@ Then push the new branch onto the new empty repository: $ git push <new-repo> split:master +EXAMPLE 3. List subtrees +----------------------------------------- +Suppose you add a subtree with: + + $ git subtree add --prefix dependency https://host/repo.git master --squash + +You can list all subtrees in the current branch resolving the refs with: + + $ git subtree list --resolve + +Which would output something like: + + depenency https://host/repo.git 4fa37e5e20b5ae9b[...] + depenency https://host/repo.git HEAD + depenency https://host/repo.git refs/heads/master + + AUTHOR ------ Written by Avery Pennarun <apenwarr@xxxxxxxxx> diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh index ce97446..d100001 100755 --- a/contrib/subtree/t/t7900-subtree.sh +++ b/contrib/subtree/t/t7900-subtree.sh @@ -81,6 +81,19 @@ test_create_commit() ( git commit -m "$commit" || error "Could not commit" ) +test_create_commit_and_tag() ( + repo=$1 + commit=$2 + tag=$3 + cd "$repo" + mkdir -p $(dirname "$commit") \ + || error "Could not create directory for commit" + echo "$commit" >"$commit" + git add "$commit" || error "Could not add commit" + git commit -m "$commit" || error "Could not commit" + git tag -m "$commit tag: $tag" $tag || error "Could not tag" +) + last_commit_message() { git log --pretty=format:%s -1 @@ -212,6 +225,19 @@ test_expect_success 'list outputs list of subtrees' ' check_equal "$(git subtree list | cut -c -19)" "sub dir ./sub proj " ) ' +next_test +test_expect_success 'list --resolve resolves refs' ' + subtree_test_create_repo "$subtree_test_count" && + subtree_test_create_repo "$subtree_test_count/sub proj" && + test_create_commit_and_tag "$subtree_test_count/sub proj" sub1 test-v0.1 && + test_create_commit "$subtree_test_count" main1 && + ( + cd "$subtree_test_count" && + git fetch ./"sub proj" master && + git subtree add --prefix="sub dir" "./sub proj" HEAD --squash && + check_equal "$(git subtree -d list --resolve | grep HEAD)" "sub dir ./sub proj HEAD" + ) +' # # Tests for 'git subtree merge' -- 2.7.1 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html