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

Add a git extensions api to check for unsynced changes #93779

Closed
wangjaso opened this issue Mar 30, 2020 · 10 comments
Closed

Add a git extensions api to check for unsynced changes #93779

wangjaso opened this issue Mar 30, 2020 · 10 comments
Assignees
Labels
feature-request Request for new features or functionality git GIT issues verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@wangjaso
Copy link
Contributor

Currently the git extensions api does not have a method to check if the user has unsynced changes. To achieve that I am doing a check like such

    git.onDidOpenRepository(async function(repo: Repository) {
        updateGitChanges(repo.state);

        repo.state.onDidChange(async function(this: any) {
            const repo: any = this;
            updateGitChanges(repo.state);
        }, repo);
    });

async function updateGitChanges(repoState: RepositoryState) {
    const hasChanges = !!(
        repoState.indexChanges.length !== 0 ||
        repoState.mergeChanges.length !== 0 ||
        repoState.workingTreeChanges.length !== 0 ||
        repoState.rebaseCommit !== undefined ||
        (repoState.HEAD?.ahead && repoState.HEAD?.ahead !== 0)
    );

    ...
}

Would be nice to have a api method that does this.
Thanks,
Jason

@jkeech
Copy link
Member

jkeech commented Mar 30, 2020

Specifically, this would need to be a command so that we can execute it over a local -> remote connection.

@joaomoreno
Copy link
Member

@wangjaso Your snippet shows that the git extension already exposes this information. What other information do you need?

Would be nice to have a api method that does this.

That would be a utility function, not exactly API. We don't really expose utility functions in our API.


@jkeech I don't understand what you mean by this. Given that the Git extension exposes this information via its API, you can just use the API.

@joaomoreno joaomoreno added the info-needed Issue requires more information from poster label Mar 31, 2020
@joaomoreno
Copy link
Member

From @kieferrm:

Git runs as a workspace extension. They need this information on the UI side. Since we cannot call API across extension host boundaries, we could however expose a command that provides this functionality.

Got it. We could expose an internal command which returns a snapshot of RepositoryState, given a file path of a repo or inside a repo. @wangjaso @jkeech would that be enough?

@jkeech
Copy link
Member

jkeech commented Mar 31, 2020

@joaomoreno, the Visual Studio Online Extension is a UI extension since it includes a remote resolver. In VS Code desktop, it runs on the local side, while the Git extension is a workspace extension that runs on the remote side. In this scenario, the Git extension is not visible to the VSO extension. Extension APIs are not remoted, but commands are. So we need the Git extension to also expose this functionality via commands.

@joaomoreno joaomoreno added feature-request Request for new features or functionality git GIT issues and removed info-needed Issue requires more information from poster labels Mar 31, 2020
@joaomoreno joaomoreno added this to the April 2020 milestone Mar 31, 2020
@jkeech
Copy link
Member

jkeech commented Mar 31, 2020

@wangjaso, do you think it would make sense to have two commands?

  1. List all known/tracked repositories that VS Code is aware of, or at least the currently tracked one in the workspace
  2. For a given repository, return the state snapshot.

I think we don’t know all of the interesting repos up front, so we’re relying on VS Code to provide that information, hence the need for the first command. Jason can confirm.

@wangjaso
Copy link
Contributor Author

@joaomoreno @jkeech

That would make sense, since right now we can only know about #1 if user actively worked on it.

@joaomoreno
Copy link
Member

joaomoreno commented Apr 9, 2020

OK, just pushed this. Here are the commands:

  • git.api.getRepositories returns an array of string uris
  • git.api.getRepositoryState returns the state of a repository, given a string uri. returns null if the repository is not found

Please give it a try in tomorrow's insiders. Let me know how it goes and if you need more data in the methods.

@joaomoreno
Copy link
Member

joaomoreno commented Apr 27, 2020

Verification: please see comment above

@joaomoreno joaomoreno added the verification-needed Verification of issue is requested label Apr 27, 2020
@wangjaso
Copy link
Contributor Author

wangjaso commented Apr 27, 2020

@joaomoreno I verified that these 2 are working correctly. Thanks!

With these 2 apis I'm able to detect existing repo changes. But is there a way to know when a repo has been initialized? For example below:

git.onDidOpenRepository(async function (repo: Repository) {
        await updateGitChanges(repo.state);
}

@joaomoreno joaomoreno added the verified Verification succeeded label Apr 28, 2020
@joaomoreno
Copy link
Member

joaomoreno commented Apr 28, 2020

Thanks! No, there is currently no way to do that. Remember that the current solution is a hack: it just passes a JSON representation of the git model between the barrier... it doesn't really reproduce the model on the other side.

@github-actions github-actions bot locked and limited conversation to collaborators May 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality git GIT issues verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

3 participants