From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.3 required=3.0 tests=BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,
	RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id D4ECA207B9
	for <e@80x24.org>; Tue, 18 Apr 2017 21:37:42 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1753440AbdDRVhk (ORCPT <rfc822;e@80x24.org>);
        Tue, 18 Apr 2017 17:37:40 -0400
Received: from mail-pg0-f54.google.com ([74.125.83.54]:34152 "EHLO
        mail-pg0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1751691AbdDRVhj (ORCPT <rfc822;git@vger.kernel.org>);
        Tue, 18 Apr 2017 17:37:39 -0400
Received: by mail-pg0-f54.google.com with SMTP id s64so2403995pgb.1
        for <git@vger.kernel.org>; Tue, 18 Apr 2017 14:37:37 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=google.com; s=20161025;
        h=from:to:cc:subject:date:message-id;
        bh=f+6aEBb+ifFFPzzSSvX6mie9dqzBLfB/46kwU9CHvA4=;
        b=qjt620ubHVAbU5ey0JMjmtn3VpBT1SR21WMM9v4rH6hQrZKgTJTZnALlO5Yl3HsXI0
         cvLjiOS3by0YQNBmZ029rJNXdrAx22qn0IDcU/ncwPh9xRvqnG67upZzBBZccDRbfiJf
         Ba7STCQdRCdYxNSynrg87GQmyQ8VooeBr6JOMk/FX6kHdeSFKJQPciSEMIVDg1r0Xyu9
         N33+nCPpZrzn115tL69+qTEDHr3VukH/2/VlAEjn4ldFGgk4vzZOMbWUBzguQXPIZRaD
         rSTFBJV6p/HUxg555Qklifxs98R2hlHHgOyomc3GyRPJpHWcMnjL+h3agkIqD5LWO2pG
         eV/Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id;
        bh=f+6aEBb+ifFFPzzSSvX6mie9dqzBLfB/46kwU9CHvA4=;
        b=mG2Cds2CtKWn64j8mS5Ze1yqTG9GgFhndigt+rWOpEtzQuztavXQN8REkON3n8YvJJ
         7zAtUufldO/imRfzt8WIXhAGmMJhFMuF+VPIE4UZKQN5M20uuYnLdpsMFgrJPyEK4glT
         eyMwn8Qj7eQlxAarKZyMSEU84jgxVex8ioNu4uilIZBtjZhgp01vn1p4HoXRQs/cbcbW
         jBgmA/wUH0HvCIIh4qsdmOZjGjzQfTAl218W+LexNqAT2gFECHnZsb4sqqPdpLzT0I0k
         mT9UnQoqBgdhhogwPjWhhSuUojCCgGRc+sScEWFaeL8ihMyqw2a20Tjfgp3o9w5hf3ma
         g9BA==
X-Gm-Message-State: AN3rC/7vspPPKgbJWL9XEgiHxfbEe31SSeJJesbBG1F5jykdsa/awiW8
        w7C8bu3liyZzSpXyfk0Sbg==
X-Received: by 10.84.230.131 with SMTP id e3mr26652127plk.100.1492551457219;
        Tue, 18 Apr 2017 14:37:37 -0700 (PDT)
Received: from localhost ([2620:0:100e:422:c47b:4f4d:6233:ff9f])
        by smtp.gmail.com with ESMTPSA id f6sm333512pfe.57.2017.04.18.14.37.36
        (version=TLS1_2 cipher=AES128-SHA bits=128/128);
        Tue, 18 Apr 2017 14:37:36 -0700 (PDT)
From:   Stefan Beller <sbeller@google.com>
To:     bmwill@google.com
Cc:     git@vger.kernel.org, jrnieder@gmail.com, gitster@pobox.com,
        jonathantanmy@google.com, philipoakley@iee.org,
        Stefan Beller <sbeller@google.com>
Subject: [PATCHv2 0/4] recursive submodules: git-reset!
Date:   Tue, 18 Apr 2017 14:37:21 -0700
Message-Id: <20170418213725.7901-1-sbeller@google.com>
X-Mailer: git-send-email 2.12.2.642.g1b8cc69eee.dirty
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

v2:
* improved commit message to be proper English (Thanks, Philip!)
* clarified why the patch 2 is so short (i.e. it doesn't matter if the submodule
  is initialized in the preparation repo, we care about the actual testing repo!
  Thanks, Brandon)
* reworded patch 1 (Thanks Jonathan)

Thanks,
Stefan

v1: https://public-inbox.org/git/20170411234923.1860-1-sbeller@google.com/

Now that the BIG one has landed, e394fa01d6 (Merge branch
'sb/checkout-recurse-submodules', 2017-03-28), you would expect that
teaching to recurse into submodules is easy for all the remaining 
working tree manipulations?

It turns out it is. See the last patch how we teach git-reset to recurse
into submodules.

However when thinking more about what git-reset is expected to do,
I added tests and some fixes for them (patch 2+3).

patch 1 is a correctness thing, required for patch 3.

Thanks,
Stefan

Stefan Beller (4):
  entry.c: submodule recursing: respect force flag correctly
  submodule.c: uninitialized submodules are ignored in recursive
    commands
  submodule.c: submodule_move_head works with broken submodules
  builtin/reset: add --recurse-submodules switch

 builtin/reset.c            | 30 ++++++++++++++++++++++++++++++
 entry.c                    |  8 ++++----
 submodule.c                | 31 +++++++++++++++++++++++++++----
 t/lib-submodule-update.sh  | 24 +++++++++++++++++++++---
 t/t7112-reset-submodule.sh |  8 ++++++++
 unpack-trees.c             |  7 ++++++-
 6 files changed, 96 insertions(+), 12 deletions(-)



From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.3 required=3.0 tests=BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,
	RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id BFF7A207B9
	for <e@80x24.org>; Tue, 18 Apr 2017 21:37:43 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1754377AbdDRVhl (ORCPT <rfc822;e@80x24.org>);
        Tue, 18 Apr 2017 17:37:41 -0400
Received: from mail-pg0-f44.google.com ([74.125.83.44]:34157 "EHLO
        mail-pg0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1752146AbdDRVhj (ORCPT <rfc822;git@vger.kernel.org>);
        Tue, 18 Apr 2017 17:37:39 -0400
Received: by mail-pg0-f44.google.com with SMTP id s64so2404183pgb.1
        for <git@vger.kernel.org>; Tue, 18 Apr 2017 14:37:39 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=google.com; s=20161025;
        h=from:to:cc:subject:date:message-id:in-reply-to:references;
        bh=l/by+mbPVn9yxye8Ba0XhXgA4URfBfcG/mJbLimPAgE=;
        b=raBchVLLEUX6qI9/xI62gcLLVtR1Ui7OKvh7ALyaT6ECH/CleqT9fRG+3rLlmUW3sx
         QmCxqW99djYWyBtBNsmRYWDl0BmSHzCVB3BY7s0ffSvZe4TsChuuhNHuYvx8VenJmTLR
         WD5ICKgE8gCbX+2wcRRRuGsCtXYiWTm2pELknGEjoSTd/zJjNlWO7wQeWxTlus0f7oqB
         SZNgKCIIirRQfi4tuTCocdBYlrc5gQz4AN3WwUcSv/Lp6M0n29JN5EM9AS8CmfIizeSk
         SiakFFelT5xERLoZqu9KG851r4EFU6fGTCuLWMZwhW5S+WR6TnecHyZ1OLWDEmqnofhQ
         IyaQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
         :references;
        bh=l/by+mbPVn9yxye8Ba0XhXgA4URfBfcG/mJbLimPAgE=;
        b=ID/4KG8a3XBwUf8YijmWC7DyWjAz2F7kqA510E2VABfeisbP3Mckb3jDEm7w5TRwA7
         ofFzXmSU7lE1mlROOiGv+XsBfIl5Ng4RNy53NYaxGh6B4ZIseh63ih0YqY8a/436+Lxl
         MXiJDtDNQuYkJh02NWUsCDIqwp0PM8A/T3ObWGeVLLStkHXWSa4o3Z6SE5Q0+6UYzTj6
         xG2hDMuW6v/uA5XDo72Bgr93BKyMBP+DB3wDS9jKwYuA7U6lgU0kvWkuKvrwtFA2Ff1u
         ehCBk4kjZYkxNiCmZFBXW53tO5fYmQp24mIB44bwlWsSWMyKaanqjyUoz8Vr+zC3lO1k
         amUw==
X-Gm-Message-State: AN3rC/6vX/BSvNtsE45WzMTRdJTjjVQzJmdiN3ziprDuEr/qn/Pvvq41
        XaGZZVbhBAhK2wpV
X-Received: by 10.99.129.194 with SMTP id t185mr20001779pgd.57.1492551458431;
        Tue, 18 Apr 2017 14:37:38 -0700 (PDT)
Received: from localhost ([2620:0:100e:422:c47b:4f4d:6233:ff9f])
        by smtp.gmail.com with ESMTPSA id a184sm313370pfb.118.2017.04.18.14.37.37
        (version=TLS1_2 cipher=AES128-SHA bits=128/128);
        Tue, 18 Apr 2017 14:37:37 -0700 (PDT)
From:   Stefan Beller <sbeller@google.com>
To:     bmwill@google.com
Cc:     git@vger.kernel.org, jrnieder@gmail.com, gitster@pobox.com,
        jonathantanmy@google.com, philipoakley@iee.org,
        Stefan Beller <sbeller@google.com>
Subject: [PATCHv2 1/4] entry.c: submodule recursing: respect force flag correctly
Date:   Tue, 18 Apr 2017 14:37:22 -0700
Message-Id: <20170418213725.7901-2-sbeller@google.com>
X-Mailer: git-send-email 2.12.2.642.g1b8cc69eee.dirty
In-Reply-To: <20170418213725.7901-1-sbeller@google.com>
References: <20170418213725.7901-1-sbeller@google.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

In case of a non-forced worktree update, the submodule movement is tested
in a dry run first, such that it doesn't matter if the actual update is
done via the force flag. However for correctness, we want to give the
flag as specified by the user. All callers have been inspected and updated
if needed.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 entry.c        | 8 ++++----
 unpack-trees.c | 7 ++++++-
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/entry.c b/entry.c
index d2b512da90..d6b263f78e 100644
--- a/entry.c
+++ b/entry.c
@@ -208,7 +208,8 @@ static int write_entry(struct cache_entry *ce,
 		sub = submodule_from_ce(ce);
 		if (sub)
 			return submodule_move_head(ce->name,
-				NULL, oid_to_hex(&ce->oid), SUBMODULE_MOVE_HEAD_FORCE);
+				NULL, oid_to_hex(&ce->oid),
+				state->force ? SUBMODULE_MOVE_HEAD_FORCE : 0);
 		break;
 	default:
 		return error("unknown file mode for %s in index", path);
@@ -282,12 +283,11 @@ int checkout_entry(struct cache_entry *ce,
 					unlink_or_warn(ce->name);
 
 				return submodule_move_head(ce->name,
-					NULL, oid_to_hex(&ce->oid),
-					SUBMODULE_MOVE_HEAD_FORCE);
+					NULL, oid_to_hex(&ce->oid), 0);
 			} else
 				return submodule_move_head(ce->name,
 					"HEAD", oid_to_hex(&ce->oid),
-					SUBMODULE_MOVE_HEAD_FORCE);
+					state->force ? SUBMODULE_MOVE_HEAD_FORCE : 0);
 		}
 
 		if (!changed)
diff --git a/unpack-trees.c b/unpack-trees.c
index 6b7356dab2..4b3f9518e5 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -252,14 +252,18 @@ static int check_submodule_move_head(const struct cache_entry *ce,
 				     const char *new_id,
 				     struct unpack_trees_options *o)
 {
+	unsigned flags = SUBMODULE_MOVE_HEAD_DRY_RUN;
 	const struct submodule *sub = submodule_from_ce(ce);
 	if (!sub)
 		return 0;
 
+	if (o->reset)
+		flags |= SUBMODULE_MOVE_HEAD_FORCE;
+
 	switch (sub->update_strategy.type) {
 	case SM_UPDATE_UNSPECIFIED:
 	case SM_UPDATE_CHECKOUT:
-		if (submodule_move_head(ce->name, old_id, new_id, SUBMODULE_MOVE_HEAD_DRY_RUN))
+		if (submodule_move_head(ce->name, old_id, new_id, flags))
 			return o->gently ? -1 :
 				add_rejected_path(o, ERROR_WOULD_LOSE_SUBMODULE, ce->name);
 		return 0;
@@ -308,6 +312,7 @@ static void unlink_entry(const struct cache_entry *ce)
 		case SM_UPDATE_CHECKOUT:
 		case SM_UPDATE_REBASE:
 		case SM_UPDATE_MERGE:
+			/* state.force is set at the caller. */
 			submodule_move_head(ce->name, "HEAD", NULL,
 					    SUBMODULE_MOVE_HEAD_FORCE);
 			break;
-- 
2.12.2.642.g1b8cc69eee.dirty


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.3 required=3.0 tests=BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,
	RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id CE0B9207B9
	for <e@80x24.org>; Tue, 18 Apr 2017 21:37:47 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1754922AbdDRVhp (ORCPT <rfc822;e@80x24.org>);
        Tue, 18 Apr 2017 17:37:45 -0400
Received: from mail-pf0-f177.google.com ([209.85.192.177]:35090 "EHLO
        mail-pf0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1753784AbdDRVhl (ORCPT <rfc822;git@vger.kernel.org>);
        Tue, 18 Apr 2017 17:37:41 -0400
Received: by mail-pf0-f177.google.com with SMTP id i5so2483020pfc.2
        for <git@vger.kernel.org>; Tue, 18 Apr 2017 14:37:40 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=google.com; s=20161025;
        h=from:to:cc:subject:date:message-id:in-reply-to:references;
        bh=egnwUX7uiqEyGwdSL6G8FciAWPpsSKgq7IMc7smcnpg=;
        b=Uh+TI02rH+cyEvPojiHuaKlWkT+wtmPeJKe10ywOZsxx4irzeZuOpnjEM9ELA3Ha6A
         9aV4x0gkrbPlcF/dRfUL1uTzwFgWcACvd0FZSDyD7IDzk/d5PFPs7kH1QTfcd6pr6URP
         L8wPx0MNgk0u/NPwMnU3M8rXci0L7pPCXQDjWsBFUkNP04GSnHwlaaPQDn4e2CI0IpJM
         Nh4WsJ26H53C4ZtCzVQkyeu4iiYMS207aeAhcllo43gDE6vRBL/dQi/pVewb/hEJl8cX
         1/OOTxFlhkkQnHYvt7lpaFqPl3GeD2i5Z7pUHsZP61K8axpuevYhzuMhywud8wMLrFbE
         oAkw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
         :references;
        bh=egnwUX7uiqEyGwdSL6G8FciAWPpsSKgq7IMc7smcnpg=;
        b=VRLv54P0cg+0Jft9lfxSVp4zCzKdonQ7Nlq873UYvawLaNQ9vGlhDgoB4eOudfJdVm
         WtcOfLK1Oi6s2wlr+2+BalYstVxj2JQI5LE1xBzebTZuVqUYkiWzi7k3shYiOaD555ZN
         ncMGgfOnZZNjkJmtGenz/uI8yYWodcuLAtqzVds34irb8jUZs4OhLIN0kAh0Y7QbmE+K
         dIWr/vqbUzi5+jK5vUodHXS4NkxSzq9A8APlpJu48D1Pks5yFS8uGS7SB6wLoOwiMY8k
         DpJloEXpWx5dmfCflifSPIl5WnWRI4/ni/XnASpBoyCc3GlCxamgsGeUhmMbYjmaGZmv
         FeTQ==
X-Gm-Message-State: AN3rC/4U/wJjzOfnyij1oOa5MBE5CFlgl0YhsDVN/QYoh3caxfvO2OmR
        ItqvfScHlCTyt2Gj
X-Received: by 10.99.3.8 with SMTP id 8mr7092698pgd.208.1492551459694;
        Tue, 18 Apr 2017 14:37:39 -0700 (PDT)
Received: from localhost ([2620:0:100e:422:c47b:4f4d:6233:ff9f])
        by smtp.gmail.com with ESMTPSA id 128sm317882pgi.49.2017.04.18.14.37.38
        (version=TLS1_2 cipher=AES128-SHA bits=128/128);
        Tue, 18 Apr 2017 14:37:39 -0700 (PDT)
From:   Stefan Beller <sbeller@google.com>
To:     bmwill@google.com
Cc:     git@vger.kernel.org, jrnieder@gmail.com, gitster@pobox.com,
        jonathantanmy@google.com, philipoakley@iee.org,
        Stefan Beller <sbeller@google.com>
Subject: [PATCHv2 2/4] submodule.c: uninitialized submodules are ignored in recursive commands
Date:   Tue, 18 Apr 2017 14:37:23 -0700
Message-Id: <20170418213725.7901-3-sbeller@google.com>
X-Mailer: git-send-email 2.12.2.642.g1b8cc69eee.dirty
In-Reply-To: <20170418213725.7901-1-sbeller@google.com>
References: <20170418213725.7901-1-sbeller@google.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

This was an oversight when working on the working tree modifying commands
recursing into submodules.

To test for uninitialized submodules, introduce another submodule
"uninitialized_sub". Adding it via `submodule add` will activate the
submodule in the preparation area (in create_lib_submodule_repo we
setup all the things in submodule_update_repo), but the later tests
will use a new testing repo that clones the preparation repo
in which the new submodule is not initialized.

By adding it to the branch "add_sub1", which is the starting point of
all other branches, we have wide coverage.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 submodule.c               | 3 +++
 t/lib-submodule-update.sh | 1 +
 2 files changed, 4 insertions(+)

diff --git a/submodule.c b/submodule.c
index 7c3c4b17fb..ccf8932731 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1333,6 +1333,9 @@ int submodule_move_head(const char *path,
 	struct child_process cp = CHILD_PROCESS_INIT;
 	const struct submodule *sub;
 
+	if (!is_submodule_initialized(path))
+		return 0;
+
 	sub = submodule_from_path(null_sha1, path);
 
 	if (!sub)
diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh
index fb4f7b014e..22dd9e060c 100755
--- a/t/lib-submodule-update.sh
+++ b/t/lib-submodule-update.sh
@@ -73,6 +73,7 @@ create_lib_submodule_repo () {
 
 		git checkout -b "add_sub1" &&
 		git submodule add ../submodule_update_sub1 sub1 &&
+		git submodule add ../submodule_update_sub1 uninitialized_sub &&
 		git config -f .gitmodules submodule.sub1.ignore all &&
 		git config submodule.sub1.ignore all &&
 		git add .gitmodules &&
-- 
2.12.2.642.g1b8cc69eee.dirty


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.3 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,
	RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 6DDAB207B9
	for <e@80x24.org>; Tue, 18 Apr 2017 21:37:49 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1755140AbdDRVhq (ORCPT <rfc822;e@80x24.org>);
        Tue, 18 Apr 2017 17:37:46 -0400
Received: from mail-pg0-f44.google.com ([74.125.83.44]:33650 "EHLO
        mail-pg0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1752146AbdDRVhl (ORCPT <rfc822;git@vger.kernel.org>);
        Tue, 18 Apr 2017 17:37:41 -0400
Received: by mail-pg0-f44.google.com with SMTP id 63so2661096pgh.0
        for <git@vger.kernel.org>; Tue, 18 Apr 2017 14:37:41 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=google.com; s=20161025;
        h=from:to:cc:subject:date:message-id:in-reply-to:references;
        bh=8TDHQcQ1LpoA/Mg53UhCUNZHjW1R1qBUqtAHkQ8dV+E=;
        b=OeU3yUDeiIfEgSI0JIjwDjuBCPl7RnEGcGcSqUxKeRtK7YdA4OkfVLtNPUkGn2wSRc
         sFdQy3i34CFgdwkl68x0PIWWEqgKFsI8EKipPQ+nBGNOUlboUndfk0X6rS7+FYbY+qTU
         8DSqTxYOfA3ATjt368/YHxSZUfRl5SObSGx7XWmU9HAc7T2EGK1IYBujY4ubo10Vb/R4
         3OctlVYsuc+3P+7FkH9aRWqFfaW93el5EPfFCJRNFyDGP1Jm/BjP+KoqNo1V2ep7r2tu
         1w3jzXoRzl3o/Utg4wX6kyJ4J31t1WIcVU6dI2epJhmR5vC0+0AqBfTrcKAO5OT96a8q
         Wf9g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
         :references;
        bh=8TDHQcQ1LpoA/Mg53UhCUNZHjW1R1qBUqtAHkQ8dV+E=;
        b=JnweblKOydXjvAJmoG70kZLU9rW4VAc4Ejr6n/WCu18hwseI4u2JBxWPXY2LZesc3r
         kWq7Ip9cQqBTTcGheR1rUfsq6Ca5CIk5e+RGxTNwgFKDkpjrMO+hA1eJzjfbPskMqu+d
         YguLkm88ZrfolxWt8KFH5hFLt77ChiQZMMQARXCzC/ffVbvSrW6EADtoDxHqlpyThXW7
         tmHGXjEfLaHyZN6DJdxjftWGbmP2lG2OylFbMXc9KWQmAI9PhGb3saJg+SwONVrXwJRl
         akMVppe2giL9rFj24xylofl/S6RAbRp5rVt0tbPEC0K0OHA8VCWepZjZf1OuCbKgmqz2
         K2tg==
X-Gm-Message-State: AN3rC/5g4wkbNJYgREwNEtXDyh2UweSWCyF5/UbzmZwJkhtWVL0vtwH3
        0rSG0lkhv3xtQ+zM
X-Received: by 10.99.64.69 with SMTP id n66mr20317479pga.197.1492551461011;
        Tue, 18 Apr 2017 14:37:41 -0700 (PDT)
Received: from localhost ([2620:0:100e:422:c47b:4f4d:6233:ff9f])
        by smtp.gmail.com with ESMTPSA id o7sm326146pga.36.2017.04.18.14.37.40
        (version=TLS1_2 cipher=AES128-SHA bits=128/128);
        Tue, 18 Apr 2017 14:37:40 -0700 (PDT)
From:   Stefan Beller <sbeller@google.com>
To:     bmwill@google.com
Cc:     git@vger.kernel.org, jrnieder@gmail.com, gitster@pobox.com,
        jonathantanmy@google.com, philipoakley@iee.org,
        Stefan Beller <sbeller@google.com>
Subject: [PATCHv2 3/4] submodule.c: submodule_move_head works with broken submodules
Date:   Tue, 18 Apr 2017 14:37:24 -0700
Message-Id: <20170418213725.7901-4-sbeller@google.com>
X-Mailer: git-send-email 2.12.2.642.g1b8cc69eee.dirty
In-Reply-To: <20170418213725.7901-1-sbeller@google.com>
References: <20170418213725.7901-1-sbeller@google.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

Early on in submodule_move_head just after the check if the submodule is
initialized, we need to check if the submodule is populated correctly.

If the submodule is initialized but doesn't look like it is populated,
this is a red flag and can indicate multiple sorts of failures:
(1) The submodule may be recorded at an object name, that is missing.
(2) The submodule '.git' file link may be broken and it is not pointing
    at a repository.

In both cases we want to complain to the user in the non-forced mode,
and in the forced mode ignoring the old state and just moving the
submodule into its new state with a fixed '.git' file link.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 submodule.c               | 28 ++++++++++++++++++++++++----
 t/lib-submodule-update.sh | 23 ++++++++++++++++++++---
 2 files changed, 44 insertions(+), 7 deletions(-)

diff --git a/submodule.c b/submodule.c
index ccf8932731..20ed5b5681 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1332,10 +1332,24 @@ int submodule_move_head(const char *path,
 	int ret = 0;
 	struct child_process cp = CHILD_PROCESS_INIT;
 	const struct submodule *sub;
+	int *error_code_ptr, error_code;
 
 	if (!is_submodule_initialized(path))
 		return 0;
 
+	if (flags & SUBMODULE_MOVE_HEAD_FORCE)
+		/*
+		 * Pass non NULL pointer to is_submodule_populated_gently
+		 * to prevent die()-ing. We'll use connect_work_tree_and_git_dir
+		 * to fixup the submodule in the force case later.
+		 */
+		error_code_ptr = &error_code;
+	else
+		error_code_ptr = NULL;
+
+	if (old && !is_submodule_populated_gently(path, error_code_ptr))
+		return 0;
+
 	sub = submodule_from_path(null_sha1, path);
 
 	if (!sub)
@@ -1353,15 +1367,21 @@ int submodule_move_head(const char *path,
 				absorb_git_dir_into_superproject("", path,
 					ABSORB_GITDIR_RECURSE_SUBMODULES);
 		} else {
-			struct strbuf sb = STRBUF_INIT;
-			strbuf_addf(&sb, "%s/modules/%s",
+			char *gitdir = xstrfmt("%s/modules/%s",
 				    get_git_common_dir(), sub->name);
-			connect_work_tree_and_git_dir(path, sb.buf);
-			strbuf_release(&sb);
+			connect_work_tree_and_git_dir(path, gitdir);
+			free(gitdir);
 
 			/* make sure the index is clean as well */
 			submodule_reset_index(path);
 		}
+
+		if (old && (flags & SUBMODULE_MOVE_HEAD_FORCE)) {
+			char *gitdir = xstrfmt("%s/modules/%s",
+				    get_git_common_dir(), sub->name);
+			connect_work_tree_and_git_dir(path, gitdir);
+			free(gitdir);
+		}
 	}
 
 	prepare_submodule_repo_env_no_git_dir(&cp.env_array);
diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh
index 22dd9e060c..f0b1b18206 100755
--- a/t/lib-submodule-update.sh
+++ b/t/lib-submodule-update.sh
@@ -1213,14 +1213,31 @@ test_submodule_forced_switch_recursing () {
 		)
 	'
 	# Updating a submodule from an invalid sha1 updates
-	test_expect_success "$command: modified submodule does not update submodule work tree from invalid commit" '
+	test_expect_success "$command: modified submodule does update submodule work tree from invalid commit" '
 		prolog &&
 		reset_work_tree_to_interested invalid_sub1 &&
 		(
 			cd submodule_update &&
 			git branch -t valid_sub1 origin/valid_sub1 &&
-			test_must_fail $command valid_sub1 &&
-			test_superproject_content origin/invalid_sub1
+			$command valid_sub1 &&
+			test_superproject_content origin/valid_sub1 &&
+			test_submodule_content sub1 origin/valid_sub1
+		)
+	'
+
+	# Old versions of Git were buggy writing the .git link file
+	# (e.g. before f8eaa0ba98b and then moving the superproject repo
+	# whose submodules contained absolute paths)
+	test_expect_success "$command: updating submodules fixes .git links" '
+		prolog &&
+		reset_work_tree_to_interested add_sub1 &&
+		(
+			cd submodule_update &&
+			git branch -t modify_sub1 origin/modify_sub1 &&
+			echo "gitdir: bogus/path" >sub1/.git &&
+			$command modify_sub1 &&
+			test_superproject_content origin/modify_sub1 &&
+			test_submodule_content sub1 origin/modify_sub1
 		)
 	'
 }
-- 
2.12.2.642.g1b8cc69eee.dirty


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.3 required=3.0 tests=BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,
	RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 33C0F207B9
	for <e@80x24.org>; Tue, 18 Apr 2017 21:37:55 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1755918AbdDRVhx (ORCPT <rfc822;e@80x24.org>);
        Tue, 18 Apr 2017 17:37:53 -0400
Received: from mail-pg0-f42.google.com ([74.125.83.42]:33656 "EHLO
        mail-pg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1755365AbdDRVhs (ORCPT <rfc822;git@vger.kernel.org>);
        Tue, 18 Apr 2017 17:37:48 -0400
Received: by mail-pg0-f42.google.com with SMTP id 63so2661306pgh.0
        for <git@vger.kernel.org>; Tue, 18 Apr 2017 14:37:48 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=google.com; s=20161025;
        h=from:to:cc:subject:date:message-id:in-reply-to:references;
        bh=xl1wbmNxDht3PYdm5YeE1ZBCFH4EkZkg/dtFmXQtdcA=;
        b=byL5Oqf3efFun9hVlqWvFCUyDDy8igwhV0AQIlHCsOndWYPa/QewJNIAhDPNBPzCs3
         UXkP0CyInEPShf6SoZS16OLkOY7xUWOzWDp9ktEqWFb5bS9M27Loh2bvzSZXuNOC8KxC
         d5lZKUzGAqefhbrZjssy393YFx6MgARWXZt7DQEklbjf/j4a1sf7/03NjRW0dOoBW62J
         Tjyi+iSiluLcM7ve1P1mnbWwBko0CVuxLJwCVW4Ij3h+dwg38HF4awtMiky4ZM04hxA/
         81hZsHWX8tZLyf32AEY+GVsp9A+Bt3HbOFSfVi/aEPTSrRuo2z7Y7r3c79thvk0h4Zgs
         wJFg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
         :references;
        bh=xl1wbmNxDht3PYdm5YeE1ZBCFH4EkZkg/dtFmXQtdcA=;
        b=K/YnHRxJMhGNxoh5W6Qi1/aSMAysV2fj/dc0fAOOYVgbMhF2iLYM0qNoNe2kFD6QKE
         yVWLnAZdivNSSPhkYJzBpuPhj2BBYtsKAoHRHtEsRONrcr/2NOUXwKLipfZnn2anNy4e
         kGSh5rhaNcawltOabm7EYUrRB+dRw+lbSUcOHLMkRncHPUbQJarn6THHo+N0OWCJk5AO
         1pm5wWHXLzMaSL3H8a8NPY3xZKuGjM49RsFxOTeZGjyluafK3Q56Z58IRv40ADlogLGq
         1asGWERoHbIJIMeRIxQv4q5RD/Ncul33K7mBq8loiDQL70CIzBoZH1sWhxexKSGVzKb4
         0PNQ==
X-Gm-Message-State: AN3rC/5MIyS4g68uRaDBiAjRXsOth8evVIqIPnDhPNwsbmwhu5EckuRq
        dbOb3ImA8pIvDsFG
X-Received: by 10.99.151.18 with SMTP id n18mr20664359pge.199.1492551462378;
        Tue, 18 Apr 2017 14:37:42 -0700 (PDT)
Received: from localhost ([2620:0:100e:422:c47b:4f4d:6233:ff9f])
        by smtp.gmail.com with ESMTPSA id u45sm348961pgn.7.2017.04.18.14.37.41
        (version=TLS1_2 cipher=AES128-SHA bits=128/128);
        Tue, 18 Apr 2017 14:37:41 -0700 (PDT)
From:   Stefan Beller <sbeller@google.com>
To:     bmwill@google.com
Cc:     git@vger.kernel.org, jrnieder@gmail.com, gitster@pobox.com,
        jonathantanmy@google.com, philipoakley@iee.org,
        Stefan Beller <sbeller@google.com>
Subject: [PATCHv2 4/4] builtin/reset: add --recurse-submodules switch
Date:   Tue, 18 Apr 2017 14:37:25 -0700
Message-Id: <20170418213725.7901-5-sbeller@google.com>
X-Mailer: git-send-email 2.12.2.642.g1b8cc69eee.dirty
In-Reply-To: <20170418213725.7901-1-sbeller@google.com>
References: <20170418213725.7901-1-sbeller@google.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

git-reset is yet another working tree manipulator, which should
be taught about submodules.

One use case of "git-reset" is to reset to a known good state,
and dropping commits that did not work as expected.
In that case one of the expected outcomes from a hard reset
would be to have broken submodules reset to a known good
state as well.  A test for this was added in a prior patch.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/reset.c            | 30 ++++++++++++++++++++++++++++++
 t/t7112-reset-submodule.sh |  8 ++++++++
 2 files changed, 38 insertions(+)

diff --git a/builtin/reset.c b/builtin/reset.c
index fc3b906c47..5ce27fcaed 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -21,6 +21,27 @@
 #include "parse-options.h"
 #include "unpack-trees.h"
 #include "cache-tree.h"
+#include "submodule.h"
+#include "submodule-config.h"
+
+static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
+
+static int option_parse_recurse_submodules(const struct option *opt,
+					   const char *arg, int unset)
+{
+	if (unset) {
+		recurse_submodules = RECURSE_SUBMODULES_OFF;
+		return 0;
+	}
+	if (arg)
+		recurse_submodules =
+			parse_update_recurse_submodules_arg(opt->long_name,
+							    arg);
+	else
+		recurse_submodules = RECURSE_SUBMODULES_ON;
+
+	return 0;
+}
 
 static const char * const git_reset_usage[] = {
 	N_("git reset [--mixed | --soft | --hard | --merge | --keep] [-q] [<commit>]"),
@@ -283,6 +304,9 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
 				N_("reset HEAD, index and working tree"), MERGE),
 		OPT_SET_INT(0, "keep", &reset_type,
 				N_("reset HEAD but keep local changes"), KEEP),
+		{ OPTION_CALLBACK, 0, "recurse-submodules", &recurse_submodules,
+			    "reset", "control recursive updating of submodules",
+			    PARSE_OPT_OPTARG, option_parse_recurse_submodules },
 		OPT_BOOL('p', "patch", &patch_mode, N_("select hunks interactively")),
 		OPT_BOOL('N', "intent-to-add", &intent_to_add,
 				N_("record only the fact that removed paths will be added later")),
@@ -295,6 +319,12 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
 						PARSE_OPT_KEEP_DASHDASH);
 	parse_args(&pathspec, argv, prefix, patch_mode, &rev);
 
+	if (recurse_submodules != RECURSE_SUBMODULES_DEFAULT) {
+		gitmodules_config();
+		git_config(submodule_config, NULL);
+		set_config_update_recurse_submodules(RECURSE_SUBMODULES_ON);
+	}
+
 	unborn = !strcmp(rev, "HEAD") && get_sha1("HEAD", oid.hash);
 	if (unborn) {
 		/* reset on unborn branch: treat as reset to empty tree */
diff --git a/t/t7112-reset-submodule.sh b/t/t7112-reset-submodule.sh
index 2eda6adeb1..f86ccdf215 100755
--- a/t/t7112-reset-submodule.sh
+++ b/t/t7112-reset-submodule.sh
@@ -5,6 +5,14 @@ test_description='reset can handle submodules'
 . ./test-lib.sh
 . "$TEST_DIRECTORY"/lib-submodule-update.sh
 
+KNOWN_FAILURE_SUBMODULE_RECURSIVE_NESTED=1
+KNOWN_FAILURE_DIRECTORY_SUBMODULE_CONFLICTS=1
+KNOWN_FAILURE_SUBMODULE_OVERWRITE_IGNORED_UNTRACKED=1
+
+test_submodule_switch_recursing "git reset --recurse-submodules --keep"
+
+test_submodule_forced_switch_recursing "git reset --hard --recurse-submodules"
+
 test_submodule_switch "git reset --keep"
 
 test_submodule_switch "git reset --merge"
-- 
2.12.2.642.g1b8cc69eee.dirty


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-4.1 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,
	RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 05630207BC
	for <e@80x24.org>; Wed, 19 Apr 2017 04:18:09 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1750891AbdDSESF (ORCPT <rfc822;e@80x24.org>);
        Wed, 19 Apr 2017 00:18:05 -0400
Received: from pb-smtp2.pobox.com ([64.147.108.71]:54116 "EHLO
        sasl.smtp.pobox.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org
        with ESMTP id S1750827AbdDSESE (ORCPT <rfc822;git@vger.kernel.org>);
        Wed, 19 Apr 2017 00:18:04 -0400
Received: from sasl.smtp.pobox.com (unknown [127.0.0.1])
        by pb-smtp2.pobox.com (Postfix) with ESMTP id D360484965;
        Wed, 19 Apr 2017 00:18:02 -0400 (EDT)
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc
        :subject:references:date:in-reply-to:message-id:mime-version
        :content-type; s=sasl; bh=Raz2dVjfrNKf5QXz2ZlX93aRHnY=; b=TvvtHv
        99cKQiTNKpEeEXCRGjn1/HsvCT9g7BCkFexoa9frUFJPMQikvlYIF4WJC6OmE1e7
        CIzXqCER5Nz4A472FY/2cDe4tV+bvr95ZqOrsL7y6ORMgryCh0cBi6cCzAvsSF0T
        hvtboKhTosaruNZQnqyX7h47yuZCZU9mwRZUw=
DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc
        :subject:references:date:in-reply-to:message-id:mime-version
        :content-type; q=dns; s=sasl; b=ODd6u4OtIT+8+gDMHEfwj3GYEWyQJBbI
        lvSSB8u3Scwz9RXXcHpLMG1P/6h4808R3UdjWx+0PBUG+Q9i8QohDTAgUnOnQwTW
        jzS+XyKyHk/YeKwS8fPO4C7XXyQX1hTrcKzhZwawGpHARFt/yFwnSZ7blOOsKoji
        l9FfSEb0RXM=
Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1])
        by pb-smtp2.pobox.com (Postfix) with ESMTP id CAD0184963;
        Wed, 19 Apr 2017 00:18:02 -0400 (EDT)
Received: from pobox.com (unknown [104.132.0.95])
        (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits))
        (No client certificate requested)
        by pb-smtp2.pobox.com (Postfix) with ESMTPSA id 296EB84962;
        Wed, 19 Apr 2017 00:18:02 -0400 (EDT)
From:   Junio C Hamano <gitster@pobox.com>
To:     Stefan Beller <sbeller@google.com>
Cc:     bmwill@google.com, git@vger.kernel.org, jrnieder@gmail.com,
        jonathantanmy@google.com, philipoakley@iee.org
Subject: Re: [PATCHv2 4/4] builtin/reset: add --recurse-submodules switch
References: <20170418213725.7901-1-sbeller@google.com>
        <20170418213725.7901-5-sbeller@google.com>
Date:   Tue, 18 Apr 2017 21:18:00 -0700
In-Reply-To: <20170418213725.7901-5-sbeller@google.com> (Stefan Beller's
        message of "Tue, 18 Apr 2017 14:37:25 -0700")
Message-ID: <xmqqfuh5av47.fsf@gitster.mtv.corp.google.com>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.91 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Pobox-Relay-ID: 2DB3B752-24B7-11E7-9DC1-C260AE2156B6-77302942!pb-smtp2.pobox.com
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

Stefan Beller <sbeller@google.com> writes:

> git-reset is yet another working tree manipulator, which should
> be taught about submodules.
>
> One use case of "git-reset" is to reset to a known good state,
> and dropping commits that did not work as expected.
>
> In that case one of the expected outcomes from a hard reset
> would be to have broken submodules reset to a known good
> state as well.  A test for this was added in a prior patch.

When "git reset --hard" at the top-level superproject updates a
gitlink in the index to a commit that was different from what was
checked out in the working tree of the submodule, what should
happen?  Do we reset the tip of the current branch in the submodule
to point at the commit the index of the top-level records?  Do we
detach the HEAD in the submodule to point at the commit?  Something
else that is configurable?  Or do we just run "git reset --hard"
in each submodule (which may leave submodule's HEAD different from
what is recorded in the index of the superproject)?

"... to a known good state as well" does not help answering the above.


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,
	RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id EF3581FE90
	for <e@80x24.org>; Wed, 19 Apr 2017 19:08:29 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S969179AbdDSTI2 (ORCPT <rfc822;e@80x24.org>);
        Wed, 19 Apr 2017 15:08:28 -0400
Received: from mail-yb0-f174.google.com ([209.85.213.174]:33071 "EHLO
        mail-yb0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S965850AbdDSTI0 (ORCPT <rfc822;git@vger.kernel.org>);
        Wed, 19 Apr 2017 15:08:26 -0400
Received: by mail-yb0-f174.google.com with SMTP id 81so13295252ybp.0
        for <git@vger.kernel.org>; Wed, 19 Apr 2017 12:08:26 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=google.com; s=20161025;
        h=mime-version:in-reply-to:references:from:date:message-id:subject:to
         :cc;
        bh=wD0RUMAZX08OQLK3HzbJh04v7Gp4EnzB+c6vv1gCsg8=;
        b=YBuSymenVG5hltlJz1ShSgQPDhdi4KbLyXDJp3gBQQX+opAnr4vhp8iz4/LAWLarvJ
         cYdaFCj8preEMDAixHbpNQvQ8S6IMV6EmUO9OO4y4+HGM9+ReAsSuzBfrP/mzWcFBZsu
         a63Xo2P3u2ab814Y2EYaTj+SRscbhDYOAF7JkjTKKq6tTRNJABgYVsPbfZKjkY8XngGX
         gRV3sgZG188q5H96vbFsu5MOl9TQAtS4tSiIWBpx5uI5vo1LntIXUZ/gZuHBysxoH5PV
         /GCPKPLM3kwan56Qx79ehQ2kKq4jWV6MOyJDYXqVdlL9gbcdkQj6S4WDG8LjiH3R9Ugw
         GNKA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:in-reply-to:references:from:date
         :message-id:subject:to:cc;
        bh=wD0RUMAZX08OQLK3HzbJh04v7Gp4EnzB+c6vv1gCsg8=;
        b=tak/aqa6ThKpHUg6CR6SBr7Ozvmt7wLWKvGwaTzvYHaSN0VpLt/aEtQh8dbFdGsFqA
         8SZ6BVd6C6bqqTwKHf5a+60yHXun/EeGSBd8cl3M4DzTD2jvpIvwt2tiM3zgzKtDvKpv
         7GH1Zipne7Nb0FgW+xjB/YuB68VPmkCmOkNx2P2v86PFgkOMiaMdKt1tg7E4ihaOibna
         5pUck7NJ5tWRlSWptwq3Ehkzvy21KBiUL9LhWXZ1/0OGN4L0AbOuTm00TT/ek1kgDYhY
         zRjLUl2m1bDi2xAN0DUOD6rdyX1GXtJlFE18a80cibq8hVmCntP9kXHYzvm2Dt2rMmNW
         NImQ==
X-Gm-Message-State: AN3rC/6Ph854FNlDyiu6aGGQbVIv7iMvbjqlqTGOc9Xf/flKwvsk+dFe
        ZfNM7Qpbj890vysK92tolSQD6Kk0XYkREL8=
X-Received: by 10.84.222.134 with SMTP id x6mr5681735pls.52.1492628905371;
 Wed, 19 Apr 2017 12:08:25 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.100.153.156 with HTTP; Wed, 19 Apr 2017 12:08:24 -0700 (PDT)
In-Reply-To: <xmqqfuh5av47.fsf@gitster.mtv.corp.google.com>
References: <20170418213725.7901-1-sbeller@google.com> <20170418213725.7901-5-sbeller@google.com>
 <xmqqfuh5av47.fsf@gitster.mtv.corp.google.com>
From:   Stefan Beller <sbeller@google.com>
Date:   Wed, 19 Apr 2017 12:08:24 -0700
Message-ID: <CAGZ79kZ4oJcCD5QttcSzkfTVotust8vnBmSbp0sh5PrpqMQgJw@mail.gmail.com>
Subject: Re: [PATCHv2 4/4] builtin/reset: add --recurse-submodules switch
To:     Junio C Hamano <gitster@pobox.com>
Cc:     Brandon Williams <bmwill@google.com>,
        "git@vger.kernel.org" <git@vger.kernel.org>,
        Jonathan Nieder <jrnieder@gmail.com>,
        Jonathan Tan <jonathantanmy@google.com>,
        Philip Oakley <philipoakley@iee.org>
Content-Type: text/plain; charset=UTF-8
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

On Tue, Apr 18, 2017 at 9:18 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Stefan Beller <sbeller@google.com> writes:
>
>> git-reset is yet another working tree manipulator, which should
>> be taught about submodules.
>>
>> One use case of "git-reset" is to reset to a known good state,
>> and dropping commits that did not work as expected.
>>
>> In that case one of the expected outcomes from a hard reset
>> would be to have broken submodules reset to a known good
>> state as well.  A test for this was added in a prior patch.
>
> When "git reset --hard" at the top-level superproject updates a
> gitlink in the index to a commit that was different from what was
> checked out in the working tree of the submodule, what should
> happen?

We reset the submodule to the commit as recorded in the superproject,
detaching its HEAD.


>  Do we reset the tip of the current branch in the submodule
> to point at the commit the index of the top-level records?  Do we
> detach the HEAD in the submodule to point at the commit?  Something
> else that is configurable?  Or do we just run "git reset --hard"
> in each submodule (which may leave submodule's HEAD different from
> what is recorded in the index of the superproject)?
>
> "... to a known good state as well" does not help answering the above.

I agree.

>

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-2.9 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,
	RCVD_IN_SORBS_SPAM,RP_MATCHES_RCVD shortcircuit=no autolearn=no
	autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 2C95A1FA26
	for <e@80x24.org>; Thu, 20 Apr 2017 19:41:43 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S947136AbdDTTlg (ORCPT <rfc822;e@80x24.org>);
        Thu, 20 Apr 2017 15:41:36 -0400
Received: from mail-yb0-f171.google.com ([209.85.213.171]:32871 "EHLO
        mail-yb0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S947119AbdDTTle (ORCPT <rfc822;git@vger.kernel.org>);
        Thu, 20 Apr 2017 15:41:34 -0400
Received: by mail-yb0-f171.google.com with SMTP id 81so36169477ybp.0
        for <git@vger.kernel.org>; Thu, 20 Apr 2017 12:41:33 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=google.com; s=20161025;
        h=date:from:to:cc:subject:message-id:references:mime-version
         :content-disposition:in-reply-to:user-agent;
        bh=OI5QHIpOQj6IPIsGYPXPNiqCWxU2hH2EqIpeL8lsLmI=;
        b=KM5dG/2LEV9FH+DY2A7WCHusPNlZVEstE1bHyA3ln52UkUQHyHMHFlxCjalXVs5M9L
         JMwCZ5J1GW3ZuS3yzI/w9mbYe5BEhdPhLhn3I0O2LtAn1EUxfnDiZ3NAY9cbOoJcSdwh
         FqFShQdXnyHf7L8wpPrPsg4Lj165q2PT0dLhl5lyH8M9RQ7hORjCktuVmOSS8nzXwHB/
         cxLGFeM/tmWQfWpHuKAOpN+3uPiDazY5c94bKEQp8GKs2S1tHl49XygM7PDGuuDhxxoP
         CywDR5C1uMGpJi/+swH8xG37S8V4ZIiv4MjwdxEzLqlU4VZD+HWxTlBgnKjzwnzJOUra
         nWYA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:date:from:to:cc:subject:message-id:references
         :mime-version:content-disposition:in-reply-to:user-agent;
        bh=OI5QHIpOQj6IPIsGYPXPNiqCWxU2hH2EqIpeL8lsLmI=;
        b=DuFY2kwt0RNR1/02j6w2OXvpbyRNqobtlp57V0n2NAaO/D/cPb4gNsIuMOPu5NC2a0
         x8xXkeRVPPZbdWOWDmIFwpHSch/ZRN2MLIT5xThMpiyYt8VtkSVqsHXzCPXQ38n7dNK5
         lvsXf/SsFdG3iWSosbmJHOCxM7DMgJ5/dDA4l3886OQzg5MkxNx7vMUd5LX8lksIN3kf
         A34g/ENg0e5zymuo0EbxbI6PJcYA11Np72viwyZo/3Cky4FQHMUbkw4HxInw9kigVab1
         TbbWUfBltYroJIw49acRyt2Et4kvSMKg/dEysqUv2A/zXwNapqnxmWeIC5kEC4MmCNhM
         tDEw==
X-Gm-Message-State: AN3rC/5qVKiZdKkUMxFTjTTH1wACHXK21GI+yJJz63uDt7nmtR6Th88U
        S7Voss2r2vsX92q0
X-Received: by 10.98.16.6 with SMTP id y6mr9320332pfi.210.1492717293126;
        Thu, 20 Apr 2017 12:41:33 -0700 (PDT)
Received: from google.com ([2620:0:100e:422:90d3:adf:57a8:ebdc])
        by smtp.gmail.com with ESMTPSA id q1sm11954765pfl.89.2017.04.20.12.41.31
        (version=TLS1_2 cipher=AES128-SHA bits=128/128);
        Thu, 20 Apr 2017 12:41:31 -0700 (PDT)
Date:   Thu, 20 Apr 2017 12:41:30 -0700
From:   Brandon Williams <bmwill@google.com>
To:     Stefan Beller <sbeller@google.com>
Cc:     git@vger.kernel.org, jrnieder@gmail.com, gitster@pobox.com,
        jonathantanmy@google.com, philipoakley@iee.org
Subject: Re: [PATCHv2 0/4] recursive submodules: git-reset!
Message-ID: <20170420194130.GF142567@google.com>
References: <20170418213725.7901-1-sbeller@google.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20170418213725.7901-1-sbeller@google.com>
User-Agent: Mutt/1.5.21 (2010-09-15)
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

On 04/18, Stefan Beller wrote:
> v2:
> * improved commit message to be proper English (Thanks, Philip!)
> * clarified why the patch 2 is so short (i.e. it doesn't matter if the submodule
>   is initialized in the preparation repo, we care about the actual testing repo!
>   Thanks, Brandon)

That was the only thing I was unsure about in v1. v2 lgtm.

> * reworded patch 1 (Thanks Jonathan)
> 
> Thanks,
> Stefan
> 
> v1: https://public-inbox.org/git/20170411234923.1860-1-sbeller@google.com/
> 
> Now that the BIG one has landed, e394fa01d6 (Merge branch
> 'sb/checkout-recurse-submodules', 2017-03-28), you would expect that
> teaching to recurse into submodules is easy for all the remaining 
> working tree manipulations?
> 
> It turns out it is. See the last patch how we teach git-reset to recurse
> into submodules.
> 
> However when thinking more about what git-reset is expected to do,
> I added tests and some fixes for them (patch 2+3).
> 
> patch 1 is a correctness thing, required for patch 3.
> 
> Thanks,
> Stefan
> 
> Stefan Beller (4):
>   entry.c: submodule recursing: respect force flag correctly
>   submodule.c: uninitialized submodules are ignored in recursive
>     commands
>   submodule.c: submodule_move_head works with broken submodules
>   builtin/reset: add --recurse-submodules switch
> 
>  builtin/reset.c            | 30 ++++++++++++++++++++++++++++++
>  entry.c                    |  8 ++++----
>  submodule.c                | 31 +++++++++++++++++++++++++++----
>  t/lib-submodule-update.sh  | 24 +++++++++++++++++++++---
>  t/t7112-reset-submodule.sh |  8 ++++++++
>  unpack-trees.c             |  7 ++++++-
>  6 files changed, 96 insertions(+), 12 deletions(-)
> 
> 

-- 
Brandon Williams

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,
	RCVD_IN_SORBS_SPAM,RP_MATCHES_RCVD shortcircuit=no autolearn=no
	autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 7BF43207BD
	for <e@80x24.org>; Thu, 20 Apr 2017 20:01:01 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S947282AbdDTUA7 (ORCPT <rfc822;e@80x24.org>);
        Thu, 20 Apr 2017 16:00:59 -0400
Received: from mail-oi0-f50.google.com ([209.85.218.50]:36154 "EHLO
        mail-oi0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1031995AbdDTUAL (ORCPT <rfc822;git@vger.kernel.org>);
        Thu, 20 Apr 2017 16:00:11 -0400
Received: by mail-oi0-f50.google.com with SMTP id r203so65195963oib.3
        for <git@vger.kernel.org>; Thu, 20 Apr 2017 13:00:10 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=google.com; s=20161025;
        h=mime-version:in-reply-to:references:from:date:message-id:subject:to
         :cc;
        bh=bUGmjvZg0XrKp+Yk2H68RLuhZAf0QwniXXP5d4Ngbic=;
        b=LqwTQQbR8Qw743R/x1c1fmAKcCE+Vt8u1bxtfr+jpIqEeYBgSFfzM+l2PQDj76hguE
         zON5ZXfUuz9c7K1vYIMsvaUhPYmMSKfzak4Bvl3zryKDINNGpDTekYNPlkuvLKzXzl27
         znYAcTgiLLkE+zzK1gklHRLKuj5fWyc+jzZFbLhmH8epXFNRh5h7Dprc/zhJBr6yErGY
         2J55SZVMAbs7gyCPkd+yNRODrv2rB4GFIPJ1IFLSYcrJbCYt1P0NnLdTt/OYje9NyoEK
         RhnQM2QfqQbu5wqywelzjCOVQV+yn1VRNWU1Rbx+1ZbNJ0vrNO6YeJGS5LHfR7pxnV2P
         v/vQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:in-reply-to:references:from:date
         :message-id:subject:to:cc;
        bh=bUGmjvZg0XrKp+Yk2H68RLuhZAf0QwniXXP5d4Ngbic=;
        b=RyF3ZM4t1qeutJLsRi7gz2E8qc/65MvXGSQtU8w9J9vCuBR0OrkmwVQdCd2NHJ19sX
         bVpL6qQEw00YjgVeWCPRmindvGml0kpjM3TMc4z9RhNU/oS7HJS0UoHU7MjZ1sb5e63q
         6Em5mut9Ihri2v+zr2FWkIjasnt5rCMY3yPKQ2RgIAeuDi3LXAaQLr+pyXVduOCLTZqU
         Iw29ytvRqvLYJEZhgqYQSrPMqZQ2DQGoDjFzfUpIqTtRLtPbA0wuJK9J246jGV3lW76m
         xhGsGvMzIPweueWV11Pi758+6+j6PFoj1r10RNGYa14KpiD5zQdIeqQy10RVtWcgyowf
         vzqw==
X-Gm-Message-State: AN3rC/6X1KMvxB9gQ1nLignTjP6onLk3huCZY8bCH02ozMMVGEYlmdfr
        VJ5iE39XrvjESa0tXkELDDbIJ0yZdBFq
X-Received: by 10.99.44.140 with SMTP id s134mr9220005pgs.178.1492718409004;
 Thu, 20 Apr 2017 13:00:09 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.100.153.156 with HTTP; Thu, 20 Apr 2017 13:00:08 -0700 (PDT)
In-Reply-To: <20170420194130.GF142567@google.com>
References: <20170418213725.7901-1-sbeller@google.com> <20170420194130.GF142567@google.com>
From:   Stefan Beller <sbeller@google.com>
Date:   Thu, 20 Apr 2017 13:00:08 -0700
Message-ID: <CAGZ79kZxfAJDQ96QngOCSp1q6kepgcByv7zSkRn_aFL3CLcznQ@mail.gmail.com>
Subject: Re: [PATCHv2 0/4] recursive submodules: git-reset!
To:     Brandon Williams <bmwill@google.com>
Cc:     "git@vger.kernel.org" <git@vger.kernel.org>,
        Jonathan Nieder <jrnieder@gmail.com>,
        Junio C Hamano <gitster@pobox.com>,
        Jonathan Tan <jonathantanmy@google.com>,
        Philip Oakley <philipoakley@iee.org>
Content-Type: text/plain; charset=UTF-8
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

On Thu, Apr 20, 2017 at 12:41 PM, Brandon Williams <bmwill@google.com> wrote:
> On 04/18, Stefan Beller wrote:
>> v2:
>> * improved commit message to be proper English (Thanks, Philip!)
>> * clarified why the patch 2 is so short (i.e. it doesn't matter if the submodule
>>   is initialized in the preparation repo, we care about the actual testing repo!
>>   Thanks, Brandon)
>
> That was the only thing I was unsure about in v1. v2 lgtm.

Thanks for the review.

Well the last commit still needs a better commit message as Junio
pointed out, so might just resend the last patch with better wording.

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <git-owner@vger.kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net
X-Spam-Level: 
X-Spam-ASN: AS31976 209.132.180.0/23
X-Spam-Status: No, score=-3.0 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,
	RCVD_IN_SORBS_SPAM,RP_MATCHES_RCVD shortcircuit=no autolearn=no
	autolearn_force=no version=3.4.0
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by dcvr.yhbt.net (Postfix) with ESMTP id 0E375207BC
	for <e@80x24.org>; Fri, 21 Apr 2017 18:06:49 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1041560AbdDURlc (ORCPT <rfc822;e@80x24.org>);
        Fri, 21 Apr 2017 13:41:32 -0400
Received: from mail-io0-f176.google.com ([209.85.223.176]:36555 "EHLO
        mail-io0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1041565AbdDURlM (ORCPT <rfc822;git@vger.kernel.org>);
        Fri, 21 Apr 2017 13:41:12 -0400
Received: by mail-io0-f176.google.com with SMTP id p80so9419859iop.3
        for <git@vger.kernel.org>; Fri, 21 Apr 2017 10:41:12 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=google.com; s=20161025;
        h=from:to:cc:subject:date:message-id:in-reply-to:references;
        bh=u60SZkERupozcX0oZXrcBHm3SGNC7B9XKy8VQfEDszo=;
        b=AK8mxgu+2t5Ea8A5qlYtPvkW/j8nombWC4ILly+GzcSjVRSHUhKykDh1pJ5qDi6Buw
         gPMfaw/+2ESVkD4UWXzzY20p38O8qQ0Czoj6fneA2q/Oa4lBokp0RVwFWvIGnXXfEnfJ
         83E8FhL9R7hHVoX919u3WyMBUBQwzUcUkaSWdDHJqXNTaKHOOFes7z8DjUHMwQuSPuwg
         FEwLCksP60jdGLEuhlYRhai1nI1EQ1jNLcm40XAWOlPx4iHjowupBmf4ZqA6PewCoF5f
         4ugYYBRF/34aXn+HfNTL3nRcdHtw7zQM5CA9TugGFsKbKRgqnQbeUM+glWdRwW7HVubK
         t5ew==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
         :references;
        bh=u60SZkERupozcX0oZXrcBHm3SGNC7B9XKy8VQfEDszo=;
        b=mvuc37CW5v/5NqYDaCq1hg7Lx24GcoTO+7AeJ9uh1IM9ldXo7LFU65aUlJt4u+i123
         mugYMkF4959zIZums5K46Vz2rMeQk4/Xcbk8fA5sD9jE2zv7VRqBGmEjqVeI9YJpTifS
         auM5IRdv9o8nsXI48grGOrccQgq6HDbimoQEXmuWgxHJB8RGx7O21YjQNzhM8xVRgXop
         +hOsyWqBu7DmNm+dksQEvb5Hde6FYGGPjcRYD9VHZyg/AGP2C66BriH9/S5aVgeQje7P
         cAPhwk3yfoT3lVfXpNvLUf3sdGiWuDx3aIH/p1mZrnk2BSs5k1PR+g4K4WhctSbTP4RJ
         b1cg==
X-Gm-Message-State: AN3rC/7hynInZvf7jW4XbEbZOyBxZ6kYzXoqSToXgWWfoEZDG77IXp7H
        ytqY1bNe55KHam1h
X-Received: by 10.99.107.198 with SMTP id g189mr13273502pgc.162.1492796397693;
        Fri, 21 Apr 2017 10:39:57 -0700 (PDT)
Received: from localhost ([2620:0:100e:422:20c0:fec:9e95:adb1])
        by smtp.gmail.com with ESMTPSA id x1sm7356500pfx.133.2017.04.21.10.39.56
        (version=TLS1_2 cipher=AES128-SHA bits=128/128);
        Fri, 21 Apr 2017 10:39:56 -0700 (PDT)
From:   Stefan Beller <sbeller@google.com>
To:     gitster@pobox.com
Cc:     git@vger.kernel.org, bmwill@google.com, jrnieder@gmail.com,
        jonathantanmy@google.com, philipoakley@iee.org,
        Stefan Beller <sbeller@google.com>
Subject: [PATCHv3 4/4] builtin/reset: add --recurse-submodules switch
Date:   Fri, 21 Apr 2017 10:39:53 -0700
Message-Id: <20170421173953.16433-1-sbeller@google.com>
X-Mailer: git-send-email 2.13.0.rc0.2.g0d1ae48b0e
In-Reply-To: <CAGZ79kZ4oJcCD5QttcSzkfTVotust8vnBmSbp0sh5PrpqMQgJw@mail.gmail.com>
References: <CAGZ79kZ4oJcCD5QttcSzkfTVotust8vnBmSbp0sh5PrpqMQgJw@mail.gmail.com>
Sender: git-owner@vger.kernel.org
Precedence: bulk
List-ID: <git.vger.kernel.org>
X-Mailing-List: git@vger.kernel.org

git-reset is yet another working tree manipulator, which should
be taught about submodules.

When a user uses git-reset and requests to recurse into submodules,
this will reset the submodules to the object name as recorded in the
superproject, detaching the HEADs.

Signed-off-by: Stefan Beller <sbeller@google.com>
---

  This replaces the topmost patch in sb/reset-recurse-submodules.
  The only difference is the rewording of the commit message.
  
  Thanks,
  Stefan

 builtin/reset.c            | 30 ++++++++++++++++++++++++++++++
 t/t7112-reset-submodule.sh |  8 ++++++++
 2 files changed, 38 insertions(+)

diff --git a/builtin/reset.c b/builtin/reset.c
index fc3b906c47..5ce27fcaed 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -21,6 +21,27 @@
 #include "parse-options.h"
 #include "unpack-trees.h"
 #include "cache-tree.h"
+#include "submodule.h"
+#include "submodule-config.h"
+
+static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
+
+static int option_parse_recurse_submodules(const struct option *opt,
+					   const char *arg, int unset)
+{
+	if (unset) {
+		recurse_submodules = RECURSE_SUBMODULES_OFF;
+		return 0;
+	}
+	if (arg)
+		recurse_submodules =
+			parse_update_recurse_submodules_arg(opt->long_name,
+							    arg);
+	else
+		recurse_submodules = RECURSE_SUBMODULES_ON;
+
+	return 0;
+}
 
 static const char * const git_reset_usage[] = {
 	N_("git reset [--mixed | --soft | --hard | --merge | --keep] [-q] [<commit>]"),
@@ -283,6 +304,9 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
 				N_("reset HEAD, index and working tree"), MERGE),
 		OPT_SET_INT(0, "keep", &reset_type,
 				N_("reset HEAD but keep local changes"), KEEP),
+		{ OPTION_CALLBACK, 0, "recurse-submodules", &recurse_submodules,
+			    "reset", "control recursive updating of submodules",
+			    PARSE_OPT_OPTARG, option_parse_recurse_submodules },
 		OPT_BOOL('p', "patch", &patch_mode, N_("select hunks interactively")),
 		OPT_BOOL('N', "intent-to-add", &intent_to_add,
 				N_("record only the fact that removed paths will be added later")),
@@ -295,6 +319,12 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
 						PARSE_OPT_KEEP_DASHDASH);
 	parse_args(&pathspec, argv, prefix, patch_mode, &rev);
 
+	if (recurse_submodules != RECURSE_SUBMODULES_DEFAULT) {
+		gitmodules_config();
+		git_config(submodule_config, NULL);
+		set_config_update_recurse_submodules(RECURSE_SUBMODULES_ON);
+	}
+
 	unborn = !strcmp(rev, "HEAD") && get_sha1("HEAD", oid.hash);
 	if (unborn) {
 		/* reset on unborn branch: treat as reset to empty tree */
diff --git a/t/t7112-reset-submodule.sh b/t/t7112-reset-submodule.sh
index 2eda6adeb1..f86ccdf215 100755
--- a/t/t7112-reset-submodule.sh
+++ b/t/t7112-reset-submodule.sh
@@ -5,6 +5,14 @@ test_description='reset can handle submodules'
 . ./test-lib.sh
 . "$TEST_DIRECTORY"/lib-submodule-update.sh
 
+KNOWN_FAILURE_SUBMODULE_RECURSIVE_NESTED=1
+KNOWN_FAILURE_DIRECTORY_SUBMODULE_CONFLICTS=1
+KNOWN_FAILURE_SUBMODULE_OVERWRITE_IGNORED_UNTRACKED=1
+
+test_submodule_switch_recursing "git reset --recurse-submodules --keep"
+
+test_submodule_forced_switch_recursing "git reset --hard --recurse-submodules"
+
 test_submodule_switch "git reset --keep"
 
 test_submodule_switch "git reset --merge"
-- 
2.13.0.rc0.2.g0d1ae48b0e


