All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sylvain Joyeux <sylvain.joyeux@dfki.de>
To: git@vger.kernel.org
Subject: [PATCH] fix "git-submodule add a/b/c/repository"
Date: Tue, 1 Jul 2008 17:00:25 +0200	[thread overview]
Message-ID: <20080701150025.GD5852@joyeux> (raw)

The 'master' version of git-submodule.sh fails to see that
a/b/c/repository is an already existing repository and messes up the
whole thing. The following patch fixes that.
-- 
Sylvain

>From 2bca2e17a01cd81ce30f81750583ab943ab57ff0 Mon Sep 17 00:00:00 2001
From: Sylvain Joyeux <sylvain.joyeux@dfki.de>
Date: Tue, 1 Jul 2008 16:45:04 +0200
Subject: [PATCH] fix submodule add for non-toplevel in-project directories

This patch fixes git-submodule add for submodules that
already exist in the current package tree, in a folder
which is not at toplevel, i.e.:

  git submodule add a/b/c/repository

Signed-off-by: Sylvain Joyeux <sylvain.joyeux@dfki.de>
---
 git-submodule.sh           |    6 +++++-
 t/t7400-submodule-basic.sh |    9 +++++++++
 2 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index e2b91f6..3fa8ff3 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -156,7 +156,11 @@ cmd_add()
 
 	# Guess path from repo if not specified or strip trailing slashes
 	if test -z "$path"; then
-		path=$(echo "$repo" | sed -e 's|/*$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
+                if echo "$repo" | grep -q "^\(\.\.\|\/\)"; then
+                        path=$(echo "$repo" | sed -e 's|/*$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
+                else
+                        path=$(echo "$repo" | sed -e 's|/*$||')
+                fi
 	else
 		path=$(echo "$path" | sed -e 's|/*$||')
 	fi
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index ffaa932..84ea6e9 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -215,4 +215,13 @@ test_expect_success 'update --init' '
 
 '
 
+test_expect_success 'adding an already-existing repository deep in the directory hierarchy' '
+
+        mkdir dir0 &&
+        mkdir dir0/dir1 &&
+        git clone init dir0/dir1/init &&
+        git-submodule add dir0/dir1/init &&
+        git-submodule status | grep "dir0/dir1/init"
+'
+
 test_done
-- 
1.5.6

             reply	other threads:[~2008-07-01 15:08 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-01 15:00 Sylvain Joyeux [this message]
2008-07-06  6:27 ` [PATCH] fix "git-submodule add a/b/c/repository" Junio C Hamano
2008-07-06 16:11   ` Sylvain Joyeux
2008-07-06 19:05     ` Mark Levedahl
2008-07-07  6:34       ` Sylvain Joyeux
2008-07-08  2:23         ` Mark Levedahl
2008-07-08  2:42           ` Junio C Hamano
2008-07-08  3:26             ` Mark Levedahl
2008-07-08  6:02               ` Junio C Hamano
2008-07-08 23:57                 ` Mark Levedahl
2008-07-09  3:59                 ` [PATCH] git-submodule - make "submodule add" more strict, and document it Mark Levedahl
2008-07-09  6:04                   ` Junio C Hamano
2008-07-10  1:05                     ` Mark Levedahl
2008-07-10  1:05                       ` [PATCH] git-submodule - register submodule URL if adding in place Mark Levedahl
2008-07-08  8:08               ` [PATCH] fix "git-submodule add a/b/c/repository" Sylvain Joyeux

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080701150025.GD5852@joyeux \
    --to=sylvain.joyeux@dfki.de \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.