From mboxrd@z Thu Jan 1 00:00:00 1970 From: Petr Baudis Subject: [PATCH 6/6] git submodule add: Fix naming clash handling Date: Fri, 12 Sep 2008 23:09:24 +0200 Message-ID: <20080912210924.31628.61593.stgit@localhost> References: <20080912210817.31628.69014.stgit@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Cc: gitster@pobox.com To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Fri Sep 12 23:10:53 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 1KeFuj-0006Ow-VA for gcvg-git-2@gmane.org; Fri, 12 Sep 2008 23:10:50 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758081AbYILVJ3 (ORCPT ); Fri, 12 Sep 2008 17:09:29 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1758007AbYILVJ3 (ORCPT ); Fri, 12 Sep 2008 17:09:29 -0400 Received: from 132-201.104-92.cust.bluewin.ch ([92.104.201.132]:53680 "EHLO pixie.suse.cz" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1758002AbYILVJ2 (ORCPT ); Fri, 12 Sep 2008 17:09:28 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) by pixie.suse.cz (Postfix) with ESMTP id 7D1DB2AC89F; Fri, 12 Sep 2008 23:09:24 +0200 (CEST) In-Reply-To: <20080912210817.31628.69014.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 1c39b59..3e4d839 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -201,10 +201,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 8a002bc..0d12a37 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