git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / Atom feed
* push.recurseSubmodules=check doesn't consider tags
@ 2019-06-12  2:04 Scott Johnson
  2019-06-12 17:26 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Scott Johnson @ 2019-06-12  2:04 UTC (permalink / raw)
  To: git

I occasionally rebase my submodules. I realize the danger (historical submodule pointers could point to commits that get garbage-collected away) so I always create and push a tag before the rebase, to make sure the old commits will never get purged. I believe this is safe, based on some experiments I’ve run.

The issue: I set the config var push.recurseSubmodules=check, and it seems to insist on having a branch and not merely a tag. When I push the parent repo’s commits, I get failures: "The following submodule paths contain changes that can not be found on any remote”. This is overly pessimistic: the commits are there on the remote, and the tag demonstrates that.

Expected behavior: when the submodule remote has a branch or a tag with the submodule pointer as ancestor, the push.recurseSubmodules=check should succeed.

Actual behavior: the push.recurseSubmodules=check fails when only a tag, and not any branch, contains the specific commit hash.

I’m using Git 2.18.0, but I’ve checked newer Release Notes and didn’t see anything.

Below is a Makefile that demonstrates the unexpected failure. The “pre-rebase” tag should be sufficient to allow the check to succeed. Run this in an empty directory.
----
.PHONY: all clean

# Make sure no config settings, either /etc/gitconfig or ~/.gitconfig,
# affect this experiment. We will create our own ./.gitconfig.
GIT := GIT_CONFIG_NOSYSTEM=1 HOME=$(PWD) XDG_CONFIG_HOME= git

all:
        # Configure globally (into ./.gitconfig)
        $(GIT) config --global user.email "you@example.com"
        $(GIT) config --global user.name "Your Name"
        $(GIT) config --global push.recurseSubmodules check
        # Create upstream repos
        mkdir sub.git && cd sub.git && $(GIT) init --bare
        mkdir repo.git && cd repo.git && $(GIT) init --bare
        # Create local repos
        $(GIT) clone repo.git repo
        $(GIT) clone sub.git sub
        # Populate submodule
        cd sub && echo "foo" > foo && $(GIT) add foo && $(GIT) commit -m 'rev 1 of foo' && $(GIT) push
        # Add submodule to parent repo
        cd repo && $(GIT) submodule add ../sub.git && $(GIT) commit -m 'Add submodule' && $(GIT) push
        # Track a new branch in the submodule
        cd repo/sub && $(GIT) checkout -b aril && $(GIT) push -u origin aril
        # Add commits to sub repo
        cd repo/sub && echo "bar" > bar && $(GIT) add bar && $(GIT) commit -m 'Add bar' && $(GIT) push
        cd repo/sub && echo "foo2" >> foo && $(GIT) commit -am 'Add more to foo' && $(GIT) push
        # Update parent with new submodule commits. Note: no push
        cd repo && $(GIT) add sub && $(GIT) commit -m 'Update sub'
        # Sub's master branch diverges
        cd sub && echo "three" > three && $(GIT) add three && $(GIT) commit -m 'Add three' && $(GIT) push
        # Rebase submodule: this tag is enough to keep the old commits from being garbage collected
        cd repo/sub && $(GIT) tag pre-rebase && $(GIT) push --tags origin
        cd repo/sub && $(GIT) checkout master && $(GIT) pull --ff-only
        cd repo/sub && $(GIT) checkout aril
        cd repo/sub && $(GIT) rebase master && $(GIT) push --force-with-lease
        # Update parent repo with newly rebased sub: this will FAIL due to push.recurseSubmodules=check unable to find HEAD^'s submodule pointer in any pushed branch in repo/sub
        cd repo && $(GIT) add sub && $(GIT) commit -m 'Add rebased submodule' && $(GIT) push

clean:
        rm -rf repo repo2 repo.git sub sub.git .gitconfig


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: push.recurseSubmodules=check doesn't consider tags
  2019-06-12  2:04 push.recurseSubmodules=check doesn't consider tags Scott Johnson
@ 2019-06-12 17:26 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2019-06-12 17:26 UTC (permalink / raw)
  To: Scott Johnson; +Cc: git

Scott Johnson <scott.johnson@arilinc.com> writes:

> I occasionally rebase my submodules. I realize the danger (historical submodule pointers could point to commits that get garbage-collected away) so I always create and push a tag before the rebase, to make sure the old commits will never get purged. I believe this is safe, based on some experiments I’ve run.
>
> The issue: I set the config var push.recurseSubmodules=check, and
> it seems to insist on having a branch and not merely a tag.

I suspect that this is pretty much by design.

When deciding if it needs a push in a submodule repository,
submodule.c::submodule_needs_pushing() gets called and asked to
check what is available at the remote without actually making a
connection to the other side.  It is done by looking at the
remote-tracking branches in the copy of the submodule repository we
have locally.  As there is no "remote-tracking tags" (iow, you
cannot tell from the output of "git -C submodule tag -l" if each of
the tags you have locally in your copy of the submodule exists in
another repository you push to and fetch from), this process does
not look at refs/tags/ hierarchy of your copy of the submodule
repository and that is quite deliberate, I would think.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-12  2:04 push.recurseSubmodules=check doesn't consider tags Scott Johnson
2019-06-12 17:26 ` Junio C Hamano

git@vger.kernel.org list mirror (unofficial, one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.org/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox