Permalink
Browse files

Fixing a bug where we did not respect the local name for a repo. For …

…example:

  git flow clone user@example.com:some_proj my_project
  # should clone into "my_project"
  # should not clone into "some_proj"
  • Loading branch information...
1 parent a5df4bd commit a710c563e8b1d10017e2f3987832a78692d65eca Arild Shirazi committed Oct 1, 2012
Showing with 28 additions and 16 deletions.
  1. +28 −16 git-flow-clone
View
@@ -7,19 +7,27 @@ USAGE='Clone a git repo with support for the gitflow branching model.
# Something went wrong
function fail { echo "$USAGE" >&2; exit 1; }
-# Extracts a DIR and REPO when given a URL
-function parse_url {
+# Extracts and creates the following from default git arguments:
+# DIR_STRUCTURE - intermediate directories to the repo
+# REPO - the name of the remote git repo
+# LOCAL_REPO (optional) - the name of the cloned git repo
+function parse_git_args {
web='https?://[^/]+/'
ssh='[^:]+:'
path=`echo "$1" | sed -E "s,($web|$ssh),,"`
- DIR=`dirname "$path"`
+ DIR_STRUCTURE=`dirname "$path"`
REPO=`basename "$path" | sed -E "s/.git$//"`
+ if [ -n "$2" ]; then
+ LOCAL_REPO=$2
+ else
+ LOCAL_REPO=$REPO
+ fi
}
# Clones a repo and performs Gitflow setup
-function clone_repo {
- git clone $1 -b master || fail
- cd "$REPO"
+function clone_as_gitflow_repo {
+ git clone $@ -b master || fail
+ cd "$LOCAL_REPO"
if (git checkout develop 2> /dev/null); then
git flow init -d
else
@@ -33,18 +41,22 @@ function clone_repo {
if [ $# -eq 0 ]; then fail; fi
if [ $1 = '-p' ]; then
- # Copy directory structre
- parse_url $2
- mkdir -p "$DIR" || fail
- cd "$DIR"
- clone_repo $2
- echo "Gitflow repo cloned to ${DIR}/${REPO}"
+ COPY_DIR_STRUCTURE=true
+ shift
+fi
+
+parse_git_args $@
+if [ "$COPY_DIR_STRUCTURE" = true ]; then
+ mkdir -p "$DIR_STRUCTURE" || fail
+ cd "$DIR_STRUCTURE"
+fi
+clone_as_gitflow_repo $@
+if [ "$COPY_DIR_STRUCTURE" = true ]; then
+ echo "Gitflow repo cloned to ${DIR_STRUCTURE}/${LOCAL_REPO}"
else
- # Clone in place
- parse_url $1
- clone_repo $1
- echo "Gitflow repo cloned to ${REPO}"
+ echo "Gitflow repo cloned to ${LOCAL_REPO}"
fi
+
# exit so we don't continue continue up the git call stack
exit 0

0 comments on commit a710c56

Please sign in to comment.