threads / discuss / 51293

push.recurseSubmodules=check doesn't consider tags

Subject: push.recurseSubmodules=check doesn't consider tags

## tl;dr

2 messages between Jun 12, 2019 and Jun 12, 2019.

replies: 1people: 2as markdown or json

Scott Johnson· Jun 12, 2019, 02:04 UTC · lore
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
Junio C Hamano· Jun 12, 2019, 17:26 UTC · re: Scott Johnson · lore

Re: push.recurseSubmodules=check doesn't consider tags

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.

← back to recent threads