Git submodule fetches an incorrect commit hash

569 Views Asked by At

I'm running the following commands

export GIT_TRACE=1
$ git clone [email protected]:org/project.git
$ cd project
$ git fetch --force --no-tags --no-recurse-submodules origin refs/heads/project-3.4
$ git checkout -B project-3.4 origin/project-3.4
$ git -C . submodule update --init --remote project-buildscripts
$ cd project-buildscripts
$ git checkout 4i790d3
$ cd ..

Everything seems to be doing good until now... Then I run

$ git fetch origin
18:10:08.504581 git.c:444               trace: built-in: git fetch origin
18:10:08.510629 run-command.c:663       trace: run_command: unset GIT_PREFIX; ssh [email protected] 'git-upload-pack '\''pie/project.git'\'''
remote: Enumerating objects: 3160, done.
remote: Counting objects: 100% (3160/3160), done.
remote: Compressing objects: 100% (27/27), done.
18:10:09.373335 run-command.c:663       trace: run_command: git index-pack --stdin -v --fix-thin '--keep=fetch-pack 85369 on Machine.local' --pack_header=2,8661
18:10:09.380636 git.c:444               trace: built-in: git index-pack --stdin -v --fix-thin '--keep=fetch-pack 85369 on Machine.local' --pack_header=2,8661
remote: Total 8661 (delta 3136), reused 3143 (delta 3133), pack-reused 5501
Receiving objects: 100% (8661/8661), 4.72 MiB | 3.25 MiB/s, done.
Resolving deltas: 100% (5230/5230), completed with 598 local objects.
18:10:11.429321 run-command.c:663       trace: run_command: git rev-list --objects --stdin --not --all --quiet --alternate-refs
18:10:11.435057 git.c:444               trace: built-in: git rev-list --objects --stdin --not --all --quiet --alternate-refs
From github.org.com:pie/project
 + 09aa5f74...4fe45193 project-3.4                       -> origin/project-3.4  (forced update)
 * [new branch]        app-logging                       -> origin/app-logging
... [bunch of other branches]
18:10:11.618055 run-command.c:1617      run_processes_parallel: preparing to run up to 1 tasks
18:10:11.618710 run-command.c:663       trace: run_command: cd /Users/local/junkyard/submod/project/.git/modules/project-buildscripts; unset GIT_PREFIX; GIT_DIR=. git fetch --no-prune --no-prune-tags --recurse-submodules-default on-demand --submodule-prefix project-buildscripts/
Fetching submodule project-buildscripts
18:10:11.625640 git.c:444               trace: built-in: git fetch --no-prune --no-prune-tags --recurse-submodules-default on-demand --submodule-prefix project-buildscripts/
18:10:11.627202 run-command.c:663       trace: run_command: unset GIT_DIR GIT_PREFIX; ssh [email protected] 'git-upload-pack '\''pie/project-buildscripts.git'\'''
18:10:12.085406 run-command.c:663       trace: run_command: git rev-list --objects --stdin --not --all --quiet --alternate-refs
18:10:12.094694 run-command.c:663       trace: run_command: git rev-list --objects --stdin --not --all --quiet --alternate-refs
18:10:12.100317 git.c:444               trace: built-in: git rev-list --objects --stdin --not --all --quiet --alternate-refs
18:10:12.126601 run-command.c:1617      run_processes_parallel: preparing to run up to 1 tasks
18:10:12.126624 run-command.c:1649      run_processes_parallel: done
18:10:12.126647 run-command.c:663       trace: run_command: git gc --auto
18:10:12.133044 git.c:444               trace: built-in: git gc --auto
18:10:12.135664 run-command.c:663       trace: run_command: cd /Users/local/junkyard/submod/project/.git/modules/project-buildscripts; unset GIT_PREFIX; GIT_DIR=. git fetch --no-prune --no-prune-tags --recurse-submodules-default on-demand --submodule-prefix project-buildscripts/ origin 54eb8df72c5bd87a93407354ca1e16394c58e15f
18:10:12.142435 git.c:444               trace: built-in: git fetch --no-prune --no-prune-tags --recurse-submodules-default on-demand --submodule-prefix project-buildscripts/ origin 58ff9df72c5bd87a93407354ca1e16394c58e15f
18:10:12.144087 run-command.c:663       trace: run_command: unset GIT_DIR GIT_PREFIX; ssh [email protected] 'git-upload-pack '\''pie/project-buildscripts.git'\'''
error: Server does not allow request for unadvertised object 58ff9df72c5bd87a93407354ca1e16394c58e15f
18:10:12.783758 run-command.c:663       trace: run_command: git gc --auto
18:10:12.791054 git.c:444               trace: built-in: git gc --auto
18:10:12.792972 run-command.c:1649      run_processes_parallel: done
Errors during submodule fetch:
    project-buildscripts
18:10:12.793291 run-command.c:663       trace: run_command: git gc --auto
18:10:12.799263 git.c:444               trace: built-in: git gc --auto

I've made sure that I go the submodule and checkout the latest commit but somehow it still references a commit that does not exist now (force-push in the submodule dir).

4i790d3 - New Commit

58ff9df72c5bd87a93407354ca1e16394c58e15f - Old commit that is lost due to a force push in the past

How do I get around this issue and actually fix this? Thank you.

GitHub Enterprise Server 2.19.17

Github Client - 2.28.0

1

There are 1 best solutions below

5
bk2204 On

This message means that the server doesn't let you fetch an object that isn't the head of a reference. This is the default behavior of Git, so this isn't surprising.

You can try to turn on protocol v2, since the Git core server side implementation doesn't perform this restriction with protocol v2. You can do that by running git config --global protocol.version 2. It is possible, however, that the version of GitHub Enterprise Server you're running is too old to support that, in which case there isn't an easy solution.

If the commit is reachable from any existing ref, then you can probably just clone the submodule manually and Git will update it, but if the object is truly unreferenced, then you're out of luck if the above doesn't work.

Note that a newer version of GitHub Enterprise Server may also help here, since the server side option must be disabled for partial clone. Therefore, if your version of GHES has partial clone support, this should just work whether you're using protocol v2 or not.