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

Commit

Permalink
Merge pull request #1671 from phyllisstein/master
Browse files Browse the repository at this point in the history
Sort staged and unstaged files by path.
  • Loading branch information
smashwilson authored Aug 29, 2018
2 parents 7f89ab7 + ce32420 commit 5cefdf0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/models/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,16 @@ export default class Repository {

async getUnstagedChanges() {
const {unstagedFiles} = await this.getStatusBundle();
return Object.keys(unstagedFiles).map(filePath => { return {filePath, status: unstagedFiles[filePath]}; });
return Object.keys(unstagedFiles)
.sort()
.map(filePath => { return {filePath, status: unstagedFiles[filePath]}; });
}

async getStagedChanges() {
const {stagedFiles} = await this.getStatusBundle();
return Object.keys(stagedFiles).map(filePath => { return {filePath, status: stagedFiles[filePath]}; });
return Object.keys(stagedFiles)
.sort()
.map(filePath => { return {filePath, status: stagedFiles[filePath]}; });
}

async getMergeConflicts() {
Expand Down
24 changes: 24 additions & 0 deletions test/models/repository.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,30 @@ describe('Repository', function() {
`);
});

it('sorts staged and unstaged files', async function() {
const workingDirPath = await cloneRepository('three-files');
const repo = new Repository(workingDirPath);
await repo.getLoadPromise();

const zShortPath = path.join('z-dir', 'a.txt');
const zFilePath = path.join(workingDirPath, zShortPath);
const wFilePath = path.join(workingDirPath, 'w.txt');
fs.mkdirSync(path.join(workingDirPath, 'z-dir'));
fs.renameSync(path.join(workingDirPath, 'a.txt'), zFilePath);
fs.renameSync(path.join(workingDirPath, 'b.txt'), wFilePath);
const unstagedChanges = await repo.getUnstagedChanges();
const unstagedPaths = unstagedChanges.map(change => change.filePath);

assert.deepStrictEqual(unstagedPaths, ['a.txt', 'b.txt', 'w.txt', zShortPath]);

await repo.stageFiles([zFilePath]);
await repo.stageFiles([wFilePath]);
const stagedChanges = await repo.getStagedChanges();
const stagedPaths = stagedChanges.map(change => change.filePath);

assert.deepStrictEqual(stagedPaths, ['w.txt', zShortPath]);
});
});

describe('getFilePatchForPath', function() {
Expand Down

0 comments on commit 5cefdf0

Please sign in to comment.