Re: [PATCH v2 02/23] contrib/subtree: Add command from-submodule

2013-03-10 Thread Junio C Hamano
Paul Campbell  writes:

> @@ -721,4 +722,31 @@ cmd_push()
>   fi
>  }
>  
> +cmd_from-submodule()
> +{

I know contrib/subtree does not work with anything other than bash,
and bash may accept this as a valid function name, but if you can
avoid it easily I would prefer not to see a non-POSIX construct like
this in my tree, even in contrib/ part:

  
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_230

because people often reference random parts of the tree and mimick
what existing code does.

> + ensure_clean
> +
> + local submodule_sha=$(git submodule status $prefix | cut -d ' ' -f 2)

Is $prefix guaranteed not to have any $IFS whitespaces?

> + # 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.X)"

Doesn't "git subtree" honor TMPDIR?  Not complaining, but being
curious.

> + rm -r $tmp_repo
> + mv $prefix $tmp_repo
> + git rm $prefix

Is $prefix guaranteed not to have any $IFS whitespaces?

> +
> + # 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" "$@"
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 02/23] contrib/subtree: Add command from-submodule

2013-03-10 Thread Paul Campbell
From: Peter Jaros 

Converts a git-submodule into a git-subtree.

Signed-off-by: Paul Campbell 

Conflicts:
.gitignore
contrib/subtree/git-subtree.sh
test.sh
---
 contrib/subtree/git-subtree.sh | 30 +-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 8a23f58..caf4988 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -14,6 +14,7 @@ git subtree merge --prefix= 
 git subtree pull  --prefix=  
 git subtree push  --prefix=  
 git subtree split --prefix= 
+git subtree from-submodule --prefix=
 --
 h,helpshow the help
 q quiet
@@ -101,7 +102,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
@@ -721,4 +722,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.X)"
+   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" "$@"
-- 
1.8.2.rc1

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html