VCS API

Hi,

 

Is there a VCS/Git API allowing to easily manipulate VCS (in particular Git) ?

Currently, it's not easy and really messy to push code or get VCS URLs. In another topic, I read that it was on board.

So I would like to know if the OpenAPI is available for VCS or else, if you have an idea about when it'll be available.

Sincerely,

3 comments
Comment actions Permalink

It might stop feeling "messy" once you understand all different use cases with multiple remotes, multiple URLs for each remote, and even mixed-VCS projects. 

What kind of task would you like to solve exactly? (e.g. something like "push current branch to origin, just like git push origin <current-branch> does"). Can you give an example of the API you'd be happy to use (e.g. you can write a wrapper over IntelliJ API)? 

0
Comment actions Permalink

Hi,

In my plugin, a project can be associated with one or more "application" (corresponding to an application on Clever Cloud and its associated repository).

When the user call my deploy action, I want to push the current branch to the master branch of the remote repository.

Currently, I can detect all applications without problem and push but I don't really like how it's done : I read all remotes urls to find if there match with Clever Cloud. If yes, I get the parent of the ".git" directory (using GitRepository#gitDir which is deprecated, I don't like this way to do things) that I associate with my application. 

When I need to push, I get the Repository from its path (ugly again), I get the remote from the url of the application repository on Clever Cloud, the corresponding branch.

There, I need to get an AbstractVcs (so no longer playing directly with Git), prepare the push and push everything.

As I'm converting the plugin to Kotlin (and use this occasion to simplify the code), I would like to find another way, simpler, to do that. Also, I'm trying to avoid explicit references to Git stuff (instead, use interfaces or abstract class when possible).

Ideally, it would be nice to have an API which simplify this steps and make them more abstracts. I know my code is not the best way to do (it's why I'm trying to improve it).

Personally, I would have imagined an API which offer to manipulate VCS (clone, push, commit, etc ...) regardless to the type of the VCS. A part which could be simplified is the push part :

GitPushSupport pushSupport = (GitPushSupport)DvcsUtil.getPushSupport(abstractVcs);
assert pushSupport != null;
GitPushSource source = pushSupport.getSource(repository);
GitPushTarget target = new GitPushTarget(branch, false);

PushSpec<GitPushSource, GitPushTarget> pushSourceGitPushTargetPushSpec = new PushSpec<>(source, target);
Map<GitRepository, PushSpec<GitPushSource, GitPushTarget>> pushSpecs =
Collections.singletonMap(repository, pushSourceGitPushTargetPushSpec);

pushSupport.getPusher().push(pushSpecs, null, false);

We could imagine a call like "AbstractVcs.getPushSupport.push(source, target).

An existing method which is a good example is the git4idea.checkout.GitCheckoutProvider#clone method, which is easy to call and does coffee.

Maybe it's not possible as VCS don't necessarily work the same, but it would be nice to have.

0
Comment actions Permalink

> `VirtualFile gitRoot = LocalFileSystem.getInstance().findFileByIoFile(new File(application.deployment.repository));`

Well, you have a number of Cloud applications, they correspond to some folders on the hard drive. There are Git repositories there. What's wrong here? If you wish, you can keep a map between Cloud applications and Git repositories, and update the map on adding/removing an application. 

> We could imagine a call like "AbstractVcs.getPushSupport.push(source, target).

1. We could do AbstractVcs.getPushSupport, but we decided not to do it, because the implementation will return null for all VCSs, except Git and Hg. However, I don't see any serious inconvenicences in a single call to DvcsUtil.getPushSupport(vcs).

2. PushSupport.push(source, target): nice, but what to do in multi-repository case? That's why there is a map. That's why there is the PushSpec: to avoid Pairs in Map<GitRepository, Pair<PushSource, PushTarget>>.

> Personally, I would have imagined an API which offer to manipulate VCS (clone, push, commit, etc ...) regardless to the type of the VCS.

As already said, "regardless to the type of the VCS" doesn't play well here, since only two of about 10 VCS know how to push. Git is most popular VCS indeed, but still only one of them.

Summarizing: the given API for push is far from ideal and has its flaws, however I don't see any serious problems in the code samples you provided. If you don't need multi-repo stuff, if your Cloud application is just one repository and just one branch, for example, go on and write a wrapper for this special case.

0

Please sign in to leave a comment.