We All Live in a Broken Git Submodule

Posted on Dec 21, 2021
Submodule 'themes/archie' (https://github.com/athul/archie.git) registered for path 'themes/archie'
Cloning into '/home/vstsagent/agent/_work/1/s/themes/archie'...
fatal: remote error: upload-pack: not our ref 5053019cd84a81680f91eb1b8c48f147110cce18
fatal: the remote end hung up unexpectedly
Fetched in submodule path 'themes/archie', but it did not contain 5053019cd84a81680f91eb1b8c48f147110cce18. Direct fetching of that commit failed.
##[error]Git submodule update failed with exit code: 1

Yeah, not going great at the moment. I get the vibe that this may come from a .DS_Store issue and wow… yeah. Apple. C’mon. What a complete pain in the ass. Ok so what now. I’m going to try to just remove the submodule and add it again. This is the second time I’ve had to do that. It’s unpleasant and doesn’t feel particularly continuous and doesn’t give off the impression of improvement or delivery.

I take that back, it’s a submodule, which means it isn’t mine, and I still want it there. I’m going to hit it with the hard reset. In my current office there was, or still is, a hammer labeled “Hard Reset”. I’m hitting this with the git hammer.

cd themes/archie
$ git reset --hard
HEAD is now at 5053019 gitignore
$ git add -A

OK that feels promising. I may have added .DS_store to the .gitignore by accident.

Submodule 'themes/archie' (https://github.com/athul/archie.git) registered for path 'themes/archie'
Cloning into '/home/vstsagent/agent/_work/1/s/themes/archie'...
fatal: remote error: upload-pack: not our ref 5053019cd84a81680f91eb1b8c48f147110cce18
fatal: the remote end hung up unexpectedly
Fetched in submodule path 'themes/archie', but it did not contain 5053019cd84a81680f91eb1b8c48f147110cce18. Direct fetching of that commit failed.
##[error]Git submodule update failed with exit code: 1

Nope, still bad.

$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

So I’m slowly understanding what the problem is but the “how to solve it” isn’t fully there just yet.

$ git reset --hard origin/main
fatal: ambiguous argument 'origin/main': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

This worked when I messed up my directory structure a little while ago.

$ git reset --hard
HEAD is now at 5053019 gitignore

Yes, reset is good. Perhaps I’m misunderstanding exactly what a reset does. Indeed, a reset reverts back to the last commit. I’m, allegedly, 1 commit ahead. I can’t push because it’s not mine. Maybe I’m missing some really innocuous detail.

$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

Wait a second! Branch “master”? I didn’t even notice it. Everything I’ve been touching lately has been “main” and I understand that there was some effort to adjust that terminology. I just didn’t even stop to realize that it was “master” and not “main”. Assumptions were made. Text was ignored.

$ git reset --hard origin/master
HEAD is now at ddcd4cd Merge pull request #36 from hsand/master
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	assets/.DS_Store

nothing added to commit but untracked files present (use "git add" to track)
$ git clean -f
Removing assets/.DS_Store
$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

Still not working. Ok. Something in my repo must be off.

$ cd ../..
$ git status
On branch vale-info
Your branch is up to date with 'origin/vale-info'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   ../content/posts/we-all-live-in-a-broken-git-submodule.md
	modified:   archie (new commits)

no changes added to commit (use "git add" and/or "git commit -a")

That’s right. The pending changes are this file and a submodule? Ok. I guess. It’s fine. Let’s try this.

$ git commit -a -m "I didn't eat dinner today. Very hungry"
[vale-info e48d22a] I didn't eat dinner today. Very hungry
 2 files changed, 62 insertions(+), 3 deletions(-)
 $ git push
 Enumerating objects: 11, done.
Counting objects: 100% (11/11), done.
Delta compression using up to 8 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 2.11 KiB | 2.11 MiB/s, done.
Total 6 (delta 3), reused 0 (delta 0), pack-reused 0
remote: Analyzing objects... (6/6) (27 ms)
remote: Storing packfile... done (87 ms)
remote: Storing index... done (48 ms)
To https://dev.azure.com/markad/marktoso-site/_git/marktoso-site
   9261b8e..e48d22a  vale-info -> vale-info

That was it. So, to summarize:

  1. macOS decides to make a .DS_store file because I had the gall to actually browse the submodule with finder (it was an accident, I swear).
  2. Visual Studio Code dutifully shows me that there is now untracked changes.
  3. I’m busy and just add it to .gitignore so it can just stop bothering me. I see it in the sidebar. It drives me nuts.
  4. I keep working. Commits and all that. No problems.
  5. Pushed it to the limit already. Hulk bash.
  6. Finally gearing up to do the pipeline work after messing around in bash and now the checkout step won’t succeed. Complains about looking for a commit on the remote that doesn’t exist. I completely miss the implication that it would mean that the commit is on my local.
  7. Tried a git reset --hard. It sounds like it’ll really work but it won’t. It resets to the last commit which would be local. It tells me that because I’m the literary titan that would put in “gitignore” as a commit message but this feedback also goes unheeded.
  8. git status is telling me that I’m 1 check-in ahead of the remote but, again, that information goes unrecognized as being useful.
  9. No progress gets made until I realize the branch is origin/master and, only then, does git reset --hard origin/master have any real efficacy.
  10. git clean -f will then figure out what’s wrong and get rid of it. In this case it was, indeed, a .DS_Store file.
  11. Then I had to go back up to the main Hugo site repo because that repo keeps information on the submodules. I can only assume that it’s meant to keep the submodule at the same version consistently up until such a time that it’s updated “properly”. I haven’t looked into this exact process but I assume that something like that will happen. git status tells us that we have untracked changes and one of them is the submodule itself.
  12. git commit -a -m "should have had dinner" gets everything in the local.
  13. git push gets it up into the repo.
  14. Pipeline is able to check out the code and build the staging site.

I try to learn something new every day.

Hi, this post was checked with vale which is a content-aware linter. It was checked using the Microsoft style as well as some rules that I made. A summary of those results is below. More details as to how this was put together check out this post. This post had: 4 errors, 47 warnings and 0 suggestions For details on the linting of this post
 ./content/posts/we-all-live-in-a-broken-git-submodule.md
 18:37    warning  Use first person (such as ' I   Microsoft.FirstPerson  
                   ') sparingly.                                          
 18:102   warning  In general, don't use an        Microsoft.Ellipses     
                   ellipsis.                                              
 18:175   warning  Use first person (such as       Microsoft.FirstPerson  
                   'I'm') sparingly.                                      
 20:1     warning  Use first person (such as 'I    Microsoft.FirstPerson  
                   ') sparingly.                                          
 20:58    warning  Use first person (such as       Microsoft.FirstPerson  
                   'mine') sparingly.                                     
 20:67    warning  Use first person (such as ' I   Microsoft.FirstPerson  
                   ') sparingly.                                          
 20:91    warning  Use first person (such as       Microsoft.FirstPerson  
                   'I'm') sparingly.                                      
 20:135   warning  Use first person (such as       Microsoft.FirstPerson  
                   'my') sparingly.                                       
 20:194   error    Punctuation should be inside    Microsoft.Quotes       
                   the quotes.                                            
 20:208   warning  Use first person (such as       Microsoft.FirstPerson  
                   'I'm') sparingly.                                      
 27:25    warning  Use first person (such as ' I   Microsoft.FirstPerson  
                   ') sparingly.                                          
 43:4     warning  Use first person (such as       Microsoft.FirstPerson  
                   'I'm') sparingly.                                      
 43:8     warning  Consider removing 'slowly'.     Microsoft.Adverbs      
 50:17    warning  Use first person (such as ' I   Microsoft.FirstPerson  
                   ') sparingly.                                          
 50:30    warning  Use first person (such as       Microsoft.FirstPerson  
                   'my') sparingly.                                       
 55:29    warning  Use first person (such as       Microsoft.FirstPerson  
                   'I'm') sparingly.                                      
 55:126   warning  Use first person (such as       Microsoft.FirstPerson  
                   'I'm') sparingly.                                      
 55:157   warning  Use first person (such as ' I   Microsoft.FirstPerson  
                   ') sparingly.                                          
 55:188   warning  Use first person (such as       Microsoft.FirstPerson  
                   'mine') sparingly.                                     
 55:200   warning  Use first person (such as       Microsoft.FirstPerson  
                   'I'm') sparingly.                                      
 55:217   warning  Consider removing 'really'.     Microsoft.Adverbs      
 64:116   warning  Use first person (such as ' I   Microsoft.FirstPerson  
                   ') sparingly.                                          
 64:184   warning  Use first person (such as ' I   Microsoft.FirstPerson  
                   ') sparingly.                                          
 64:249   error    Punctuation should be inside    Microsoft.Quotes       
                   the quotes.                                            
 85:38    warning  Use first person (such as       Microsoft.FirstPerson  
                   'my') sparingly.                                       
 100:69   warning  Use first person (such as ' I   Microsoft.FirstPerson  
                   ') sparingly.                                          
 100:90   warning  Try to avoid using              Microsoft.We           
                   first-person plural like                               
                   'Let's'.                                               
 120:50   warning  Use first person (such as ' I   Microsoft.FirstPerson  
                   ') sparingly.                                          
 120:131  warning  Use first person (such as ' I   Microsoft.FirstPerson  
                   ') sparingly.                                          
 121:39   warning  Use first person (such as       Microsoft.FirstPerson  
                   'me') sparingly.                                       
 122:4    warning  Use first person (such as       Microsoft.FirstPerson  
                   'I'm') sparingly.                                      
 122:73   warning  Use first person (such as       Microsoft.FirstPerson  
                   'me') sparingly.                                       
 122:76   warning  Use first person (such as ' I   Microsoft.FirstPerson  
                   ') sparingly.                                          
 122:112  warning  Use first person (such as       Microsoft.FirstPerson  
                   'me') sparingly.                                       
 123:4    warning  Use first person (such as 'I    Microsoft.FirstPerson  
                   ') sparingly.                                          
 125:187  warning  Use first person (such as ' I   Microsoft.FirstPerson  
                   ') sparingly.                                          
 125:263  warning  Use first person (such as       Microsoft.FirstPerson  
                   'my') sparingly.                                       
 126:53   warning  Consider removing 'really'.     Microsoft.Adverbs      
 126:141  warning  Use first person (such as       Microsoft.FirstPerson  
                   'me') sparingly.                                       
 126:157  warning  Use first person (such as       Microsoft.FirstPerson  
                   'I'm') sparingly.                                      
 127:28   warning  Use first person (such as       Microsoft.FirstPerson  
                   'me') sparingly.                                       
 127:36   warning  Use first person (such as       Microsoft.FirstPerson  
                   'I'm') sparingly.                                      
 128:31   warning  Use first person (such as ' I   Microsoft.FirstPerson  
                   ') sparingly.                                          
 130:9    warning  Use first person (such as ' I   Microsoft.FirstPerson  
                   ') sparingly.                                          
 130:242  error    Punctuation should be inside    Microsoft.Quotes       
                   the quotes.                                            
 130:243  warning  Consider removing 'properly'.   Microsoft.Adverbs      
 130:298  warning  Use first person (such as ' I   Microsoft.FirstPerson  
                   ') sparingly.                                          
 130:365  warning  Try to avoid using              Microsoft.We           
                   first-person plural like 'us'.                         
 130:373  warning  Try to avoid using              Microsoft.We           
                   first-person plural like 'we'.                         
 130:373  error    Use 'we've' instead of 'we      Microsoft.Contractions 
                   have'.                                                 
 135:1    warning  Use first person (such as 'I    Microsoft.FirstPerson  
                   ') sparingly.                                          
 137:210  warning  Use first person (such as ' I   Microsoft.FirstPerson  
                   ') sparingly.                                          

4 errors, 48 warnings and 0 suggestions in 1 file.