Skip to content
Browse files

Add from-submodule.

  • Loading branch information...
1 parent 9a40fcc commit d5ac1113ac67bb7bc47cf310a689ee59d60e4b16 Peter Jaros committed with Peter Jaros Nov 3, 2010
Showing with 75 additions and 7 deletions.
  1. +1 −0 .gitignore
  2. +36 −7 git-subtree.sh
  3. +38 −0 test.sh
View
1 .gitignore
@@ -3,3 +3,4 @@ git-subtree.xml
git-subtree.1
mainline
subproj
+submodule*
View
43 git-subtree.sh
@@ -8,11 +8,12 @@ if [ $# -eq 0 ]; then
set -- -h
fi
OPTS_SPEC="\
-git subtree add --prefix=<prefix> <commit>
-git subtree merge --prefix=<prefix> <commit>
-git subtree pull --prefix=<prefix> <repository> <refspec...>
-git subtree push --prefix=<prefix> <repository> <refspec...>
-git subtree split --prefix=<prefix> <commit...>
+git subtree add --prefix=<prefix> <commit>
+git subtree merge --prefix=<prefix> <commit>
+git subtree pull --prefix=<prefix> <repository> <refspec...>
+git subtree push --prefix=<prefix> <repository> <refspec...>
+git subtree split --prefix=<prefix> <commit...>
+git subtree from-submodule --prefix=<prefix>
--
h,help show the help
q quiet
@@ -100,7 +101,7 @@ done
command="$1"
shift
case "$command" in
- add|merge|pull) default= ;;
+ add|merge|pull|from-submodule) default= ;;
split|push) default="--default HEAD" ;;
*) die "Unknown command '$command'" ;;
esac
@@ -554,7 +555,8 @@ cmd_split()
eval "$grl" |
while read rev parents; do
revcount=$(($revcount + 1))
- say -n "$revcount/$revmax ($createcount)
+ say -n "$revcount/$revmax ($createcount)
+"
debug "Processing commit: $rev"
exists=$(cache_get $rev)
if [ -n "$exists" ]; then
@@ -680,4 +682,31 @@ cmd_push()
fi
}
+cmd_from-submodule()
+{
+ ensure_clean
+
+ local submodule_sha=$(git submodule status $prefix | cut -d ' ' -f 2)
+
+ # Remove references to submodule.
+ git config --remove-section submodule.$prefix
+ git config --file .gitmodules --remove-section submodule.$prefix
+ git add .gitmodules
+
+ # Move submodule aside.
+ local tmp_repo="$(mktemp -d /tmp/git-subtree.XXXXX)"
+ rm -r $tmp_repo
+ mv $prefix $tmp_repo
+ git rm $prefix
+
+ # Commit changes.
+ git commit -m "Remove '$prefix/' submodule"
+
+ # subtree add from submodule repo.
+ cmd_add_repository $tmp_repo HEAD
+
+ # Remove submodule repo.
+ rm -rf $tmp_repo
+}
+
"cmd_$command" "$@"
View
38 test.sh
@@ -338,5 +338,43 @@ git log --pretty=format:'commit: %H' | joincommits |
check_equal "$x" 1
) || exit 1
+# Return to mainline
+cd ../..
+
+
+# from-submodule
+
+make_submodule()
+{
+ cd ..
+ local prefix=$1
+
+ local submodule_path=$(mktemp -d submodule.XXX)
+ cd $submodule_path
+ local submodule_abs_path=$(pwd)
+
+ git init > /dev/null
+ create "sub-file"
+ git commit -m "sub-commit" > /dev/null
+ local submodule_sha=$(git rev-parse HEAD)
+ cd ../mainline
+
+ git submodule add $submodule_abs_path $prefix > /dev/null
+ git submodule update --init > /dev/null
+ git commit -m "Added $prefix." > /dev/null
+
+ echo $submodule_sha
+}
+
+subA_sha=$(make_submodule submodules/subA)
+
+git subtree from-submodule --prefix submodules/subA
+
+check_equal "$(last_commit_message)" "Add 'submodules/subA/' from commit '${subA_sha}'"
+# Submodule should be gone.
+check_equal "$(git submodule status)" ""
+
+rm -rf ../submodule.*
+
echo
echo 'ok'

0 comments on commit d5ac111

Please sign in to comment.
Something went wrong with that request. Please try again.