vscode icon indicating copy to clipboard operation
vscode copied to clipboard

useGitApi() missing repository resource after updating to latest version

Open FloppyDisco opened this issue 9 months ago • 10 comments

Does this issue occur when all extensions are disabled?: Yes/No

  • VS Code Version:
  • OS Version:

i wrote an extension that allows you to run some git commands using the keyboard. https://github.com/Bluesteel-Software/git-stage-file

i was previously using repository.onDidRunOperation() for adding an event listener.

upon updating to the latest version.

it seems onDidRunOperation is no longer available? it is not so much that onDidRunOperation is not available but the actual repository resource is completely gone. i am unable to locate the repository resource that was previously available from the git extension api that is returned from useGitApi()

Is there at least somewhere i can find the changes that were made so i can get my extension going again? the documentation surrounding the git extension API is abismal. I'm NOT the first to complain about it's lack of support!

thank you for any help anyone might provide.

FloppyDisco avatar Mar 04 '25 05:03 FloppyDisco

here are two screen shots of the useGitApi() running VSCode 1.95 a call to useGitApi().repositories returns an array of resources which have a repository available.

Image

now in version 1.97 a call to useGitApi().repositories still returns an array, but the resources do not have the repository property anymore...

Image

this extension API needs MORE features not less...

FloppyDisco avatar Mar 04 '25 05:03 FloppyDisco

Can you please try to use the ApiRepositoryState.onDidChange event that is fired after every "write" git operation. If that event does not suit your needs please let me know what exactly are you trying to detect in your extension. Thanks!

lszomoru avatar Mar 04 '25 14:03 lszomoru

@lszomoru thank you i will try using that. could you tell me if there is a difference between repository.state.onDidChange and repository.ui.onDidChange if so when is the UI event triggered? that may actually be better for my purposes. thank you

FloppyDisco avatar Mar 04 '25 18:03 FloppyDisco

repository.ui.onDidChange is fired when the "selected" state of the repository changes. I don't think that is useful for you.

lszomoru avatar Mar 04 '25 20:03 lszomoru

@lszomoru "selected" as in if the user interacts with the staged/unstaged files displayed in the scm view?

FloppyDisco avatar Mar 04 '25 21:03 FloppyDisco

@FloppyDisco, "selected" as in it is the active repository that is currently being shown in the status bar. The "selected" repository can change as you click around the Changes view when there are multiple repositories visible.

lszomoru avatar Mar 05 '25 08:03 lszomoru

@lszomoru thank you for the help. i have not been able to confirm if that listener will work or not yet. this update also broke my extension's ability to stage and unstage files. vscode.commands.executeCommand("git.stage",selection.resource) I am not able to find the resource that the "git.stage" command accepts

I have never been able to find any docs on the git extension or its API? is there not something that should show what is available? i've tried reading the source code. but it seems that the git API does not expose all of the properties on these objects and i have been unable to find where it actually says what it does expose. thanks again for your help

FloppyDisco avatar Mar 22 '25 18:03 FloppyDisco

@FloppyDisco, if you would like to stage a file I would suggest that you use the repository.add() method.

lszomoru avatar Apr 09 '25 10:04 lszomoru

@FloppyDisco, if you would like to stage a file I would suggest that you use the repository.add() method.

@floppydisco can you confirm whether this works for you?

dannypernik avatar May 16 '25 00:05 dannypernik

@lszomoru

as far as i can tell. there is no repository.onDidChange() at least not available in the gitApi() Image

i was able to find repository.add() however it does not work. probably because the resources that are being provided are no longer adequate.

here you can see that the in the previous version the resources returned from repository.state.workingTreeChanges() included the actual resource, which held all the resource data like leftUri and rightUri which made diffing files and the like possible.

Image Image

in the current version of vscode, repository.state.workingTreeChanges() only includes the base URI fields and not the resource data

Image

passing a resource uri to repository.add() does not stage the resource. as in, the following does not work:

repository.add([resource.uri])

i can understand it's not your job to trouble shoot my extension. i just think it's a little silly that this would change so much without a heads up or anything

FloppyDisco avatar May 22 '25 22:05 FloppyDisco

@FloppyDisco, could you please share the exact URI that you are passing to repository.add()? The VS Code itself is using the same call when staging a resource so I would like to understand the difference.

lszomoru avatar May 29 '25 12:05 lszomoru

This issue has been closed automatically because it needs more information and has not had recent activity. See also our issue reporting guidelines.

Happy Coding!

@FloppyDisco, could you please share the exact URI that you are passing to repository.add()? The VS Code itself is using the same call when staging a resource so I would like to understand the difference.

@FloppyDisco can you comment here?

dannypernik avatar Jun 06 '25 15:06 dannypernik