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

Switch from a detached head to a branch not working #995

Closed
fcollonval opened this issue Aug 3, 2021 · 4 comments
Closed

Switch from a detached head to a branch not working #995

fcollonval opened this issue Aug 3, 2021 · 4 comments
Labels
bug Good first issue Good first issue to be tackled by new contributors status:Help Wanted

Comments

@fcollonval
Copy link
Member

fcollonval commented Aug 3, 2021

If the repository is in detached head (for example after switching to a tag), then switching to a branch will fail.

Error message:

fatal: ambiguous argument '(HEAD detached at v0.20.0)': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git <command> [<revision>...] -- [<file>...]' 

Peek 2021-08-03 19-06

@fcollonval fcollonval added bug Good first issue Good first issue to be tackled by new contributors status:Help Wanted labels Aug 3, 2021
@Bl4ck-h00d
Copy link

Hi! I would like to work on this, can you help me how to get started?!

@fcollonval
Copy link
Member Author

Hey @Bl4ck-h00d

Thanks for kicking in.

The extension has two parts: a front-end in Typescript and a back-end in Python. Whenever you trigger an action from the front-end, it will call a git command in the back-end.

In this case, to switch branch, the command call is done there:

async def checkout_branch(self, branchname, path):

The action is triggered in the frontend with that callback:

async function onClick(): Promise<void> {

The workflow is the following:

  1. onClick is triggered with the branch name
  2. it calls the model.checkout method
    async checkout(options?: Git.ICheckoutOptions): Promise<Git.ICheckoutResult> {

The model is handling the repository state and the call to the backend

  1. That trigger a call to the backend
    const d = await requestAPI<Git.ICheckoutResult>(
  2. The call is catch by a Python handler:
    async def post(self, path: str = ""):
  3. That handler calls the git command mentioned above:
    body = await self.git.checkout_branch(data["branchname"], local_path)

The troubles is in the front-end because we want to deal with files that are different between two branches at

changes = await this._changedFiles(

This calls:
image

with

{"base":"(HEAD detached at v0.21.0)","remote":"master"}

base is not a valid ref; hence the error seen.

I'll update the description with an animation.

Let me know if you need more information and don't hesitate to open a PR early to discuss your fix.

@fcollonval
Copy link
Member Author

fcollonval commented Aug 3, 2021

Transforming the fake branch name (HEAD detached at #####) to ##### before calling model.checkout should solve this issue.

Transforming the fake branch name (HEAD detached at #####) to ##### before calling this._changedFiles at:

this._currentBranch.name,

should solve this issue.

@fcollonval
Copy link
Member Author

Fixed by #1218

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Good first issue Good first issue to be tackled by new contributors status:Help Wanted
Projects
None yet
Development

No branches or pull requests

2 participants