#! /bin/bash # This script demonstrates a bug in git where it reports # # The following submodule paths contain changes that can # not be found on any remote: # # for a submodule that is clean and pushed. # # Create an empty directory, put this script in it # and run the script. # # Carlo Wood, 2017/01/29 # Clean a possible previous run: rm -rf parent remote.parent remote.subm REMOTE_BASE="$(pwd)" # Create a 'remote' for the submodule 'subm'. mkdir remote.subm pushd remote.subm git init --bare popd # Create a 'remote' for the 'parent' repository. mkdir remote.parent pushd remote.parent git init --bare popd # Create initial parent/subm directory structore. mkdir -p parent/subm # Create an initial subm git repository. pushd parent/subm git init git remote add local "$REMOTE_BASE/remote.subm" touch s ; git add s git commit -m 'Initial commit.' git push --set-upstream local master popd # Create an initial parent git repository with subm as submodule # and push.recurseSubmodules = on-demand. pushd parent git init git config push.recurseSubmodules on-demand git remote add local "$REMOTE_BASE/remote.parent" touch p ; git add p git submodule add "$REMOTE_BASE/remote.subm subm" git add .gitmodules subm git commit -m 'Initial commit.' git push --set-upstream local master popd # Do some commit in subm, but do not push it to the remote. pushd parent/subm echo "My frist commit." > s git commit -a -m 'Change s' popd # Add the subm hash to the parent. pushd parent git add subm git commit -m 'Updated subm.' popd # Amend the commit in subm (and optionally push it). pushd parent/subm echo "My first commit." > s git commit -a --amend -m 'Change s' popd # Correct that in the parent too: pushd parent git add subm git commit -m 'Updated subm.' popd # At this point nothing was published yes, so the # amend shouldn't have caused a problem. But it did. pushd parent git push popd echo "THE ABOVE ERROR CAN NOW BE REPRODUCED INDEFINITELY," echo "FOR EXAMPLE, DO:" echo "cd parent/subm" echo "git push" echo "cd .." echo "git push"