atom / git-diff

Diff markers in Atom's gutter
MIT License
102 stars 36 forks source link

Enable usecases where the git repo is not at top level of project #121

Closed LiyouZhou closed 6 years ago

LiyouZhou commented 7 years ago

use atom API repositoryForDirectory to get git repo associated with any open file. Replaces the old behaviour where it is assumed that the git repo is at top level of the project.

Requirements

Description of the Change

git-diff uses helper function repositoryForPath to get back a gitRepository object for each editor view.

The old implementation of repositoryForPath uses the getRepositories() API. Which only gives you repositories associated with project's directories. This means the git repo must exist in the projects's top level in order for it to be recognised.

However, there are situations where the git repo associated with a file under edit may not reside in the project's top level. For situations like the following:

toplevel/
├── repo_a/
│   ├── .git/
│   ├── file_under_version_control.c
├── repo_b/
│   ├── .git/

If you opened file_under_version_control.c, git-diff does not work.

The new implementation uses the new atom API repositoryForDirectory. The new API returns a promise and fulfils it asynchronously. Which means the caller of repositoryForPath need to be modified as well.

Alternate Designs

NA

Benefits

Enable usecases where the git repo is not at top level of project. Allow git-dff to be useful in more usecases. New API uses asynchronous API which allow UI to be more responsive. As getRepositories() is being deprecated in atom 2, this change allow the transition to happen.

Possible Drawbacks

NA

Applicable Issues

NA

LiyouZhou commented 7 years ago

Argh, anybody know how to debug test failures?

50Wliu commented 7 years ago

You can run specs locally using atom --test spec or by executing the "Window: Run Package Specs" command from within Atom.

ulrik59 commented 6 years ago

Hi, any news on this ? I'm currently in a project with this problem and this is kind of annoying... Thank you in advance !

LiyouZhou commented 6 years ago

lol, last update was from a year and half ago. I have forgot all the coffee script that I have learnt to fix this bug. It seems the atom team is not great at accepting contributions from the outside. maybe it would be better if you filed an issue instead and let the atom team fix it.

lee-dohm commented 6 years ago

We're going to see if we can solve this at a broader level via atom/atom#2203. Thanks @LiyouZhou for the work you did here and our apologies for not handling this better.