0

First off, I am not using command line git at all. I am only using SourceTree's gui interface. I would prefer to solve my problem this way; if possible.

Somehow, my submodule has become corrupted. Attempting to fetch or pull gives me the following error: enter image description here

I haven't found any answers for this particular problem. I am fortunate in that my remote master is ok, 100% up to date, and I have no local changes. So, I think the easiest way will be to just fully reset my local submodule.

However, I can't figure out how to do so.

I considered trying to remove my submodule and then re add it. However, I have had problems with that in the past, and so am gun shy.

I found handfuls of posts about resetting to a specific commit. However, the SourceTree gui is failing to populate my history because of this error.

Any help would be appreciated

Thank you

FunnerSoft
  • 77
  • 8

3 Answers3

0

You can try this

  • Right click at your conflicted branch at BRANCHES and delete it.
  • Double click at your remote branch at REMOTES to re-download and switch to that branch.

Easy, good luck.

BlackLotus
  • 318
  • 4
  • 12
  • thank you for the suggestion. Unfortunately, I get an error when trying to delete master. It looks the same as the error I posted in my original question "fatal: failed to read object 666168c0bacade2e719e0054c11d6903719f13f5: Invalid argument" – FunnerSoft Dec 03 '21 at 16:50
  • I was able to delete it by using the "Force Delete" option. However, trying to re-add master causes the same error message to display. That seems to imply that something is wrong with my remote branch, but I am quite certain that is not the case. I can pull this remote branch in multiple other projects' submodules just fine. I think the issue is that I still have 1 corrupted, local branch within this problem submodule. I can't delete that because Sourcetree says you can't delete your current branch. So, that route seems sort of stuck. – FunnerSoft Dec 03 '21 at 17:00
  • I was able to delete all local branches from my submodule. However, attempting to re-add the master branch to this submodule continues to fail with the above error. I can still pull and update this same master branch in other, different submodules with no issue. – FunnerSoft Dec 03 '21 at 17:39
  • Did you try to delete entire folder and then clone it again? – BlackLotus Dec 04 '21 at 04:02
  • Hi BlackLotus. I did finally get this working. See my answer if you are curious. I just wanted to say thank you for your assistance with this issue. Cheers – FunnerSoft Dec 06 '21 at 17:40
0

I finally did get this fixed. I had to give up and use the command line.

I found this page (git fatal: failed to read object xxx: Invalid argument). That pointed me to using the "git fsck --full" command.

That pointed me to a very specific folder in the .git hierarchy that was corrupted.

I needed to delete this folder, but doing so wasn't easy. Windows would let me delete it. Not in safe mode. Not with cmd del or rmdir. I had to run a scan disk from windows on my entire drive. That ended up detecting the folder and removing it.

Finally, from there, I was able to fetch and pull master again.

FunnerSoft
  • 77
  • 8
0

From all the solutions I was able to find to perform an actually hard reset with proper cleanup and reinitialization of submodules nothing worked. So I ended up creating a custom script. Following will perform a full cleanup of your submodules and will recreate them as if you were cloning the parent repo.

#!/bin/bash

echo "Backing up current .gitmodules"
cp -f .gitmodules .gitmodules.bkp
has_submodules=$(echo "$(git submodule)")
if [ "$has_submodules" != "" ]; then
    git submodule deinit --force .
    rm -rf .git/modules
    git submodule | cut -c43- | while read -r line; do (git rm -f "$line"); done
fi

cp -f .gitmodules.bkp .gitmodules
PARAMS=("path" "url" "branch")
CHUNKS=${#PARAMS[@]}
PARAMS_STR=$(IFS='|'; echo "${PARAMS[*]}")

readarray -t SUBMODULES_INFO_ARRAY < <(git config -f .gitmodules --get-regexp '^submodule\..*\.('"$PARAMS_STR"')$')
SUBMODULES_INFO_ARRAY_STR=$(IFS='|'; echo "${SUBMODULES_INFO_ARRAY[*]}")

function process_submodules_parsed_array()
{
    name=${SUBMODULES_PARSED_ARRAY[0]}
    path=${SUBMODULES_PARSED_ARRAY[1]}
    repo_url=${SUBMODULES_PARSED_ARRAY[2]}
    branch=${SUBMODULES_PARSED_ARRAY[3]}
    echo "Running: git submodule add --force -b "$branch" --depth 1 --name "$name" -- "$repo_url" "$path""
    git submodule add --force -b "$branch" --depth 1 --name "$name" -- "$repo_url" "$path"
}
echo "Parsing current .gitmodules"
for((chunk=0; chunk<${#SUBMODULES_INFO_ARRAY[@]}; chunk+=CHUNKS))
do
    section_name="$(sed -nE 's/^submodule\.(.*?)\.'${PARAMS[0]}'\s(.*?)$/\1/p' <<< "${SUBMODULES_INFO_ARRAY[chunk]}")"
    SUBMODULES_PARSED_ARRAY=("$section_name")
    for ((param_i=0; param_i<CHUNKS; param_i+=1))
    do
    param_unparsed="${SUBMODULES_INFO_ARRAY[chunk+param_i]}"
    param_parsed="$(sed -nE 's/^submodule.*?\.'${PARAMS[param_i]}'\s(.*?)$/\1/p' <<< "$param_unparsed")"
    SUBMODULES_PARSED_ARRAY+=($param_parsed)
    done
    process_submodules_parsed_array
done
echo "Restoring .gitmodules"
mv -f .gitmodules.bkp .gitmodules
echo "Initializing submodules"
git submodule init
git submodule update
mmtechslv
  • 126
  • 1
  • 3