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

Fix subfolder git detection #31

Merged
merged 1 commit into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions lib/helpers.coffee
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
fs = require "fs-plus"
path = require "path"
{Directory} = require "atom"

module.exports =
repositoryForPath: (goalPath) ->
for directory, i in atom.project.getDirectories()
if goalPath is directory.getPath() or directory.contains(goalPath)
return atom.project.getRepositories()[i]
null
if goalPath
directory = new Directory goalPath
return atom.project.repositoryForDirectory directory
Promise.resolve(null)
28 changes: 14 additions & 14 deletions lib/minimap-git-diff-binding.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ class MinimapGitDiffBinding

@subscriptions.add @minimap.onDidDestroy @destroy

if repository = @getRepo()
@subscriptions.add @editor.getBuffer().onDidStopChanging @updateDiffs
@subscriptions.add repository.onDidChangeStatuses =>
@scheduleUpdate()
@subscriptions.add repository.onDidChangeStatus (changedPath) =>
@scheduleUpdate() if changedPath is @editor.getPath()
@subscriptions.add repository.onDidDestroy =>
@destroy()
@subscriptions.add atom.config.observe 'minimap-git-diff.useGutterDecoration', (@useGutterDecoration) =>
@scheduleUpdate()
@getRepo().then (repo) =>
@repository = repo
if repo
@subscriptions.add @editor.getBuffer().onDidStopChanging @updateDiffs
@subscriptions.add @repository.onDidChangeStatuses =>
@scheduleUpdate()
@subscriptions.add @repository.onDidChangeStatus (changedPath) =>
@scheduleUpdate() if changedPath is @editor.getPath()
@subscriptions.add @repository.onDidDestroy =>
@destroy()
@subscriptions.add atom.config.observe 'minimap-git-diff.useGutterDecoration', (@useGutterDecoration) =>
@scheduleUpdate()

@scheduleUpdate()

Expand Down Expand Up @@ -75,12 +77,10 @@ class MinimapGitDiffBinding

getPath: -> @editor.getBuffer()?.getPath()

getRepositories: -> atom.project.getRepositories().filter (repo) -> repo?

getRepo: -> @repository ?= repositoryForPath(@editor.getPath())
getRepo: -> repositoryForPath(@editor.getPath())

getDiffs: ->
try
return @getRepo()?.getLineDiffs(@getPath(), @editor.getBuffer().getText())
return @repository?.getLineDiffs(@getPath(), @editor.getBuffer()?.getText())
catch e
return null
16 changes: 2 additions & 14 deletions lib/minimap-git-diff.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ class MinimapGitDiff
return if @pluginActive

try
@activateBinding()
@createBindings()
@pluginActive = true

@subscriptions.add @minimap.onDidActivate @activateBinding
@subscriptions.add @minimap.onDidActivate @createBindings
@subscriptions.add @minimap.onDidDeactivate @destroyBindings
catch e
console.log e
Expand All @@ -45,16 +45,6 @@ class MinimapGitDiff
@subscriptions.dispose()
@destroyBindings()

activateBinding: =>
@createBindings() if @getRepositories().length > 0

@subscriptions.add atom.project.onDidChangePaths =>

if @getRepositories().length > 0
@createBindings()
else
@destroyBindings()

createBindings: =>
MinimapGitDiffBinding ||= require './minimap-git-diff-binding'

Expand All @@ -67,8 +57,6 @@ class MinimapGitDiff
binding = new MinimapGitDiffBinding minimap
@bindings.set(minimap, binding)

getRepositories: -> atom.project.getRepositories().filter (repo) -> repo?

destroyBindings: =>
return unless @minimap? and @minimap.editorsMinimaps?
@minimap.editorsMinimaps.forEach (minimap) =>
Expand Down
4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,5 @@
"1.0.0": "consumeMinimapServiceV1"
}
}
},
"dependencies": {
"mixto": "1.x",
"fs-plus": "^2.0.0"
}
}