[prev in list] [next in list] [prev in thread] [next in thread]
List: git
Subject: [PATCH 2/2] contrib/subtree: List subcmd and modify push/pull to use .gittrees
From: Keval Patel <patel.keval88 () gmail ! com>
Date: 2014-05-30 17:45:15
Message-ID: 1401471915-47195-2-git-send-email-kapatel () lutron ! com
[Download RAW message or body]
- Add subtree list sub-command
- git subtree list - Lists the subtrees in current project
- Changes taken from helmo's repository from following URL:
https://github.com/helmo/git-subtree/blob/master/git-subtree.sh
- Add tests for subtree list and subtree push/pull using .gittrees
- Files changed in this commit:
1. git/contrib/subtree/git-subtree.sh
2. git/contrib/subtree/t/t7900-subtree.sh
Signed-off-by: Keval Patel <kapatel@lutron.com>
---
A selection of updates to git-subtree were offered to the list by couple of people
($gmane/196667) by Herman van Rink and ($gmane/217820) by Paul Campbell
For various reasons the work stalled and I would like to pick it up from there
The following patches take a selection of these commits and rebase them
against the tip of master.
The make test works and I have added more tests to cover the new commands and
use of .gittrees file for storing the subtree metadata
Thanks-to and Based-on-patch-by:
- Herman van Rink
- Matt Hoffman
- Michael Hart
- Nate Jones
- Paul Campbell
- Paul Cartwright
- Peter Jaros
- bibendi
contrib/subtree/git-subtree.sh | 25 ++++++++++--
contrib/subtree/t/t7900-subtree.sh | 72 ++++++++++++++++++++++++++++++++++++
2 files changed, 93 insertions(+), 4 deletions(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 7d01b4b..1151884 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -10,9 +10,10 @@ fi
OPTS_SPEC="\
git subtree add --prefix=<prefix> <repository> <refspec>
git subtree merge --prefix=<prefix> <commit>
-git subtree pull --prefix=<prefix> <repository> <ref>
-git subtree push --prefix=<prefix> <repository> <ref>
+git subtree pull --prefix=<prefix> [<repository> [<refspec>...]]
+git subtree push --prefix=<prefix> [<repository> [<refspec>...]]
git subtree split --prefix=<prefix> <commit...>
+git subtree list
--
h,help show the help
q quiet
@@ -102,15 +103,16 @@ command="$1"
shift
case "$command" in
add|merge|pull) default= ;;
- split|push) default="--default HEAD" ;;
+ split|push|list) default="--default HEAD" ;;
*) die "Unknown command '$command'" ;;
esac
-if [ -z "$prefix" ]; then
+if [ -z "$prefix" -a "$command" != "list" ]; then
die "You must provide the --prefix option."
fi
case "$command" in
+ list);;
add) [ -e "$prefix" ] &&
die "prefix '$prefix' already exists." ;;
*) [ -e "$prefix" ] ||
@@ -759,4 +761,19 @@ cmd_push()
fi
}
+subtree_list()
+{
+ git config -f .gittrees -l | grep subtree | grep path | grep -o '=.*' | grep -o '[^=].*' |
+ while read path; do
+ repository=$(git config -f .gittrees subtree.$path.url)
+ refspec=$(git config -f .gittrees subtree.$path.branch)
+ echo " $path (merged from $repository branch $refspec) "
+ done
+}
+
+cmd_list()
+{
+ subtree_list
+}
+
"cmd_$command" "$@"
diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index 05110f7..c29993e 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -571,4 +571,76 @@ test_expect_success 'add another subtree with master branch' '
check_equal ''"$(last_commit_message)"'' "Add sub2 subtree"
'
+# Lets commit the changes we made to .gittrees file
+test_expect_success 'Commit chages to .gittrees for sub1 and sub2 in repo' '
+ git add .gittrees &&
+ git commit -m "Add .gittrees file"
+'
+# Tests for subtree list
+# Hardcode expected output to a file
+cat >expect <<-\EOF
+ sub1 (merged from ../shared_projects/subtree1 branch master)
+ sub2 (merged from ../shared_projects/subtree2 branch master)
+EOF
+
+test_expect_success 'check subtree list gives correct output' '
+ git subtree list>output &&
+ test_cmp expect output
+'
+# Lets commit the changes to parent1 before proceeding
+test_expect_success 'Commit changes to the repository' '
+ git add --all &&
+ git commit -m "Commit expect and output file additions"
+'
+
+# Tests for individual subtree pull using information in .gittrees
+# Go to subtree1 and make a change
+cd ../shared_projects/subtree1
+
+subtree1_change1="Add_line_to_Sub1_File2"
+
+echo $subtree1_change1>>sub1_file2
+
+# Lets commit the changes to subtree1 before proceeding
+test_expect_success 'Commit changes to the subtree1' '
+ git add --all &&
+ git commit -m "Commit change to sub1_file2"
+'
+
+# Switch to develop branch for a future test to push changes to master
+test_expect_success 'Switch to branch develop' '
+ git checkout -b develop
+'
+
+# Back to parent1
+cd ../../parent1
+
+test_expect_success 'check git subtree pull <prefix> works' '
+ git subtree pull -P sub1 master &&
+ test_cmp sub1/sub1_file1 ../shared_projects/subtree1/sub1_file1 &&
+ test_cmp sub1/sub1_file2 ../shared_projects/subtree1/sub1_file2
+'
+
+# Now lets make local change on subtree and push it to subtree remote
+cd sub1
+
+local_change="Local addition of line to sub1 file 2"
+echo $local_change1>>sub1_file2
+
+# Back to parent1
+cd ..
+
+# Lets commit the changes to parent1 before proceeding
+test_expect_success 'Commit changes to parent repository' '
+ git add --all &&
+ git commit -m "Commit local changes to sub1/sub1 file2"
+'
+
+test_expect_success 'check git subtree push <prefix> works' '
+ git subtree push -P sub1 &&
+ cd ../shared_projects/subtree1 &&
+ git checkout master &&
+ test_cmp ../../parent1/sub1/sub1_file1 sub1_file1 &&
+ test_cmp ../../parent1/sub1/sub1_file2 sub1_file2
+'
test_done
--
1.7.9
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic