Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Commit

Permalink
Add command to open all changed files
Browse files Browse the repository at this point in the history
  • Loading branch information
flexoid committed Jun 5, 2016
1 parent 2c08021 commit f97cfdc
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,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 @@ -84,6 +85,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 @@ -130,6 +131,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
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)
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,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 f97cfdc

Please sign in to comment.