Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error "fatal: Not a valid object name: ''." #498

Conversation

DanielBauten
Copy link
Contributor

Problem

In case there are no (relevant) commits (e.g. directly after git subrepo push) which cause subrepo:branch() (i.e. on git subrepo pull <subrepo>) to fail with an git error message

git-subrepo: Command failed: 'git branch subrepo/<subrepo> '.
fatal: Not a valid object name: ''.

See issues #348, #350 and #424.

Cause

This is because second parameter to git branch is an empty string as variable prev_commit has not been set. Thus, branch creation fails in that case.

Solution

To create the subrepo branch, nevertheless, it can be created on the cloned/pulled commit from .gitrepo file (per variable subrepo_commit) as there have not been any relevant changes.
Furthermore – to avoid unnecessary large range on the subsequent call of git filter-branch – variable first_gitrepo_commit should be neutralized with subrepo_commit as well, so that variable filter results in an empty revision range.

@admorgan
Copy link
Collaborator

Would you be willing to add some tests for this?

@admorgan
Copy link
Collaborator

If this blindly "fixes" the issues you linked I think that could be a problem. Your example of a pull after a push is desirable, but when the ancestry has changed I feel we should acknowledge that there is a potential for your code not being what you expect. I have to dive deeper, but I believe it would not effect the included issues because we would fail before we reach this code due to the SHA not existing. @ingydotnet I would like you to look at this one if you have some time.

Overall thank you, this has been a thorn in my side. I have another favor to ask. We are currently working on the release/0.4.2 branch would you mind applying these patches there instead?

@DanielBauten DanielBauten changed the base branch from master to release/0.4.2 August 27, 2020 16:04
@DanielBauten
Copy link
Contributor Author

Would you be willing to add some tests for this?

We were able to recreate the problem very well during the corrections to #497 and therefore believe that it was not just blindly fixed the issue linked. However, we have only been working with sub-repo for a few weeks and therefore have no experience in how to write suitable tests.

So – if @ingydotnet sees the need for this – it would be great if a more experienced developer could write some suitable tests.

@blaggacao
Copy link

I think I hit this after a sqash merge of a feature branch where I did git subrepo on the feature branch. Does that sound plausible?

@DanielBauten
Copy link
Contributor Author

I think I hit this after a sqash merge of a feature branch where I did git subrepo on the feature branch. Does that sound plausible?

Sounds plausible. If it reproducable in your case, perhaps you can check wether our fix is applicable on your situation.

@natew
Copy link

natew commented Oct 18, 2020

Is there a way to fix this manually for now?

@admorgan
Copy link
Collaborator

Modify the parent sha in your .gitrepo file to be the previous commit in your repo.

@ingydotnet ingydotnet force-pushed the release/0.4.2 branch 4 times, most recently from b3b0754 to fc7486e Compare November 16, 2020 14:30
@natew
Copy link

natew commented Dec 4, 2020

Unfortunately that seems to "squash" all the changes across a bunch of commits into one... We work on branches that rebase off master, then merge, but it seems every time i have to update the SHA to the latest, so all intermediate messages are being removed.

Editing for others: you need to set the SHA to be much further back, to wherever you want it to check for changes (just after last synced SHA I believe).

@dwettstein
Copy link

Probably this PR refers to #503 and #532 as well.

@jameswalmsley
Copy link

Can we merge this PR?

@jcalfee
Copy link

jcalfee commented Jun 16, 2023

What SHA do I use for the parent? Is SHA easier to get from the client or the server? Maybe I should git log on the subrepo folder to find this? I new sha parent hash that matched the server (no pushes since I pulled), committed, and still get the error.

@admorgan
Copy link
Collaborator

I have been working with this patch, and have found a number of paths that cause issues with regenerating the branch. I am addressing this through UI improvements and better error messaging instead of automatic regeneration for these reasons.

@admorgan admorgan closed this Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants