Skip to content

Commit

Permalink
Merge branch 'git-open-changed-files' of git://github.com/flexoid/git…
Browse files Browse the repository at this point in the history
…-plus into pr-463
  • Loading branch information
akonwi committed Jun 11, 2016
2 parents 4a6be5d + f97cfdc commit 33ee05d
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ _Commands are accessible for keybindings by dasherizing the command title._
| `Git rm [current file]` | `git rm` the current file or open an selector to select the files to remove. You can select multiple files at once. | |
| `Git Log [Current File]` | Show the commit history [for the current file] and show display the selected commit. | |
| `Git Show` | Show the specified object, for example `HEAD`, `HEAD~2`,`3925a0d`, `origin/master` or `v2.7.3`. | |
| `Git Open Changed Files` | Open tabs with all added, modified or renamed files. | |

### Commit window
To change where the commit window appears go to settings and find
Expand Down
2 changes: 2 additions & 0 deletions lib/git-plus-commands.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ getCommands = ->
GitRun = require './models/git-run'
GitMerge = require './models/git-merge'
GitRebase = require './models/git-rebase'
GitOpenChangedFiles = require './models/git-open-changed-files'

git.getRepo()
.then (repo) ->
Expand Down Expand Up @@ -85,6 +86,7 @@ getCommands = ->
commands.push ['git-plus:merge', 'Merge', -> GitMerge(repo)]
commands.push ['git-plus:merge-remote', 'Merge Remote', -> GitMerge(repo, remote: true)]
commands.push ['git-plus:rebase', 'Rebase', -> GitRebase(repo)]
commands.push ['git-plus:git-open-changed-files', 'Open Changed Files', -> GitOpenChangedFiles(repo)]

return commands

Expand Down
2 changes: 2 additions & 0 deletions lib/git-plus.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ GitUnstageFiles = require './models/git-unstage-files'
GitRun = require './models/git-run'
GitMerge = require './models/git-merge'
GitRebase = require './models/git-rebase'
GitOpenChangedFiles = require './models/git-open-changed-files'

currentFile = (repo) ->
repo.relativize(atom.workspace.getActiveTextEditor()?.getPath())
Expand Down Expand Up @@ -131,6 +132,7 @@ module.exports =
@subscriptions.add atom.commands.add 'atom-workspace', 'git-plus:merge', -> git.getRepo().then((repo) -> GitMerge(repo))
@subscriptions.add atom.commands.add 'atom-workspace', 'git-plus:merge-remote', -> git.getRepo().then((repo) -> GitMerge(repo, remote: true))
@subscriptions.add atom.commands.add 'atom-workspace', 'git-plus:rebase', -> git.getRepo().then((repo) -> GitRebase(repo))
@subscriptions.add atom.commands.add 'atom-workspace', 'git-plus:git-open-changed-files', -> git.getRepo().then((repo) -> GitOpenChangedFiles(repo))

deactivate: ->
@subscriptions.dispose()
Expand Down
2 changes: 1 addition & 1 deletion lib/git.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ module.exports = git =

status: (repo) ->
git.cmd(['status', '--porcelain', '-z'], cwd: repo.getWorkingDirectory())
.then (data) -> if data.length > 2 then data.split('\0') else []
.then (data) -> if data.length > 2 then data.split('\0')[...-1] else []

refresh: () ->
atom.project.getRepositories().forEach (repo) ->
Expand Down
13 changes: 13 additions & 0 deletions lib/models/git-open-changed-files.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
git = require '../git'

filesFromData = (statusData) ->
files = []
for line in statusData
lineMatch = line.match /^([ MARCU?!]{2})\s{1}(.*)/
files.push lineMatch[2] if lineMatch
files

module.exports = (repo) ->
git.status(repo).then (statusData) ->
for file in filesFromData(statusData)
atom.workspace.open(file)
2 changes: 1 addition & 1 deletion lib/views/status-list-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class StatusListView extends SelectListView
initialize: (@repo, @data) ->
super
@show()
@setItems @parseData @data[...-1]
@setItems @parseData @data
@focusFilterEditor()

parseData: (files) ->
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"git-plus:run",
"git-plus:merge",
"git-plus:merge-remote",
"git-plus:rebase"
"git-plus:rebase",
"git-plus:open-changed-files"
]
},
"consumedServices": {
Expand Down
31 changes: 31 additions & 0 deletions spec/models/git-open-changed-files-spec.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
git = require '../../lib/git'
{repo} = require '../fixtures'
GitOpenChangedFiles = require '../../lib/models/git-open-changed-files'

describe "GitOpenChangedFiles", ->
beforeEach ->
spyOn(atom.workspace, 'open')

describe "when file is modified", ->
beforeEach ->
spyOn(git, 'status').andReturn Promise.resolve [' M file1.txt']
waitsForPromise -> GitOpenChangedFiles(repo)

it "opens changed file", ->
expect(atom.workspace.open).toHaveBeenCalledWith("file1.txt")

describe "when file is added", ->
beforeEach ->
spyOn(git, 'status').andReturn Promise.resolve ['?? file2.txt']
waitsForPromise -> GitOpenChangedFiles(repo)

it "opens added file", ->
expect(atom.workspace.open).toHaveBeenCalledWith("file2.txt")

describe "when file is renamed", ->
beforeEach ->
spyOn(git, 'status').andReturn Promise.resolve ['R file3.txt']
waitsForPromise -> GitOpenChangedFiles(repo)

it "opens renamed file", ->
expect(atom.workspace.open).toHaveBeenCalledWith("file3.txt")

0 comments on commit 33ee05d

Please sign in to comment.