From mboxrd@z Thu Jan 1 00:00:00 1970 From: Petr Baudis Subject: [PATCH 3/7] git submodule add: Fix naming clash handling Date: Wed, 16 Jul 2008 21:11:18 +0200 Message-ID: <20080716191118.19772.96984.stgit@localhost> References: <20080716190753.19772.93357.stgit@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Wed Jul 16 21:13:24 2008 Return-path: Envelope-to: gcvg-git-2@gmane.org Received: from vger.kernel.org ([209.132.176.167]) by lo.gmane.org with esmtp (Exim 4.50) id 1KJCQH-0000ru-Qj for gcvg-git-2@gmane.org; Wed, 16 Jul 2008 21:12:22 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753920AbYGPTLZ (ORCPT ); Wed, 16 Jul 2008 15:11:25 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754166AbYGPTLZ (ORCPT ); Wed, 16 Jul 2008 15:11:25 -0400 Received: from 159-162.104-92.cust.bluewin.ch ([92.104.162.159]:64265 "EHLO pixie.suse.cz" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753611AbYGPTLY (ORCPT ); Wed, 16 Jul 2008 15:11:24 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) by pixie.suse.cz (Postfix) with ESMTP id C93F72ACC76 for ; Wed, 16 Jul 2008 21:11:18 +0200 (CEST) In-Reply-To: <20080716190753.19772.93357.stgit@localhost> User-Agent: StGIT/0.14.2 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: This patch fixes git submodule add behaviour when we add submodule living at a same path as logical name of existing submodule. This can happen e.g. in case the user git mv's the previous submodule away and then git submodule add's another under the same name. A test-case is obviously included. This is not completely satisfactory since .git/config cross-commit conflicts can still occur. A question is whether this is worth handling, maybe it would be worth adding some kind of randomization of the autogenerated submodule name, e.g. appending $$ or a timestamp. Signed-off-by: Petr Baudis --- git-submodule.sh | 15 ++++++++++++--- t/t7400-submodule-basic.sh | 11 +++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/git-submodule.sh b/git-submodule.sh index 9228f56..a93547b 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -192,10 +192,19 @@ cmd_add() git add "$path" || die "Failed to add submodule '$path'" - git config -f .gitmodules submodule."$path".path "$path" && - git config -f .gitmodules submodule."$path".url "$repo" && + name="$path" + if git config -f .gitmodules submodule."$name".path; then + name="$path~"; i=1; + while git config -f .gitmodules submodule."$name".path; do + name="$path~$i" + i=$((i+1)) + done + fi + + git config -f .gitmodules submodule."$name".path "$path" && + git config -f .gitmodules submodule."$name".url "$repo" && git add .gitmodules || - die "Failed to register submodule '$path'" + die "Failed to register submodule '$path' (name '$name')" } # diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index ab5eb1e..092dffc 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -235,4 +235,15 @@ test_expect_success 'submodule add -b' ' ' +test_expect_success 'submodule add auto-naming clash' ' + + git submodule add "$(pwd)/init2/.git" example && + test -d example/.git && + [ "$(git config -f .gitmodules submodule.example.url)" = "$(pwd)/init2" ] && + [ "$(git config -f .gitmodules submodule.example.path)" = "init" ] + [ "$(git config -f .gitmodules submodule.example~.url)" = "$(pwd)/init2/.git" ] && + [ "$(git config -f .gitmodules submodule.example~.path)" = "example" ] + +' + test_done