dugite-extra
Advanced tools
Comparing version 0.0.1-alpha.8 to 0.0.1-alpha.9
@@ -61,2 +61,3 @@ "use strict"; | ||
var temp = require("temp"); | ||
var fs = require("fs"); | ||
var chai_1 = require("chai"); | ||
@@ -243,2 +244,30 @@ var stage_1 = require("./stage"); | ||
}); }); | ||
it('modifying a staged file should result in two changes', function () { return __awaiter(_this, void 0, void 0, function () { | ||
var repositoryPath, stagedFiles, status, changedFiles; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, test_helper_1.createTestRepository(track.mkdirSync('foo'))]; | ||
case 1: | ||
repositoryPath = _a.sent(); | ||
return [4 /*yield*/, stage_1.stage(repositoryPath, test_helper_1.modify(repositoryPath, { path: 'A.txt', data: 'new content' }))]; | ||
case 2: | ||
_a.sent(); | ||
return [4 /*yield*/, stage_1.getStagedFiles(repositoryPath)]; | ||
case 3: | ||
stagedFiles = _a.sent(); | ||
chai_1.expect(stagedFiles).to.be.lengthOf(1); | ||
chai_1.expect(stagedFiles.map(function (f) { return f.path; })).to.deep.equal(['A.txt']); | ||
fs.writeFileSync(path.join(repositoryPath, 'A.txt'), 'yet another new content', 'utf8'); | ||
chai_1.expect(fs.readFileSync(path.join(repositoryPath, 'A.txt'), 'utf8')).to.be.deep.equal('yet another new content'); | ||
return [4 /*yield*/, status_1.getStatus(repositoryPath)]; | ||
case 4: | ||
status = _a.sent(); | ||
changedFiles = status.workingDirectory.files; | ||
chai_1.expect(changedFiles).to.be.lengthOf(2); | ||
chai_1.expect(changedFiles.map(function (f) { return f.path; })).to.deep.equal(['A.txt', 'A.txt']); | ||
chai_1.expect(changedFiles.map(function (f) { return f.staged; }).sort()).to.deep.equal([false, true]); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
return [2 /*return*/]; | ||
@@ -245,0 +274,0 @@ }); |
@@ -37,2 +37,18 @@ "use strict"; | ||
}; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __values = (this && this.__values) || function (o) { | ||
@@ -78,7 +94,11 @@ var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; | ||
} | ||
function convertToStagedFlag(statusCode) { | ||
// For instance, when the status code is '?', or '.M', the the files are unstaged. | ||
// When the status code is one of the followings: 'A.', or 'M.', the it is staged. | ||
return statusCode.trim().endsWith('.'); | ||
// See: https://git-scm.com/docs/git-status#_short_format | ||
function isChangeInIndex(statusCode) { | ||
var index = statusCode.charAt(0); | ||
return index === 'M' || index === 'A' || index === 'D' || index === 'U' || index === 'R' || index === 'C'; | ||
} | ||
function isChangeInWorkTree(statusCode) { | ||
var _a = __read(statusCode, 2), workingTree = _a[1]; | ||
return workingTree === 'M' || workingTree === 'A' || workingTree === 'D' || workingTree === 'U'; | ||
} | ||
/** | ||
@@ -126,3 +146,14 @@ * Retrieve the status for a given repository, | ||
var selection = diff_1.DiffSelection.fromInitialSelection(diff_1.DiffSelectionType.All); | ||
files.push(new status_1.WorkingDirectoryFileChange(entry.path, summary, selection, entry.oldPath, convertToStagedFlag(entry.statusCode))); | ||
var changeInIndex = isChangeInIndex(entry.statusCode); | ||
var changeInWorkingTree = isChangeInWorkTree(entry.statusCode); | ||
if (changeInIndex) { | ||
files.push(new status_1.WorkingDirectoryFileChange(entry.path, summary, selection, entry.oldPath, true)); | ||
} | ||
if (changeInWorkingTree) { | ||
files.push(new status_1.WorkingDirectoryFileChange(entry.path, summary, selection, entry.oldPath, false)); | ||
} | ||
// Must be untracked | ||
if (!changeInIndex && !changeInWorkingTree) { | ||
files.push(new status_1.WorkingDirectoryFileChange(entry.path, summary, selection, entry.oldPath, false)); | ||
} | ||
} | ||
@@ -129,0 +160,0 @@ else if (entry.kind === 'header') { |
{ | ||
"name": "dugite-extra", | ||
"version": "0.0.1-alpha.8", | ||
"version": "0.0.1-alpha.9", | ||
"description": "High-level Git commands for dugite.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index", |
import * as path from 'path'; | ||
import * as temp from 'temp'; | ||
import * as fs from 'fs'; | ||
import { expect } from 'chai'; | ||
@@ -88,2 +89,3 @@ import { stage, unstage, getStagedFiles } from './stage'; | ||
}); | ||
}); | ||
@@ -123,2 +125,21 @@ | ||
it('modifying a staged file should result in two changes', async () => { | ||
const repositoryPath = await createTestRepository(track.mkdirSync('foo')); | ||
await stage(repositoryPath, modify(repositoryPath, { path: 'A.txt', data: 'new content' })); | ||
const stagedFiles = await getStagedFiles(repositoryPath); | ||
expect(stagedFiles).to.be.lengthOf(1); | ||
expect(stagedFiles.map(f => f.path)).to.deep.equal(['A.txt']); | ||
fs.writeFileSync(path.join(repositoryPath, 'A.txt'), 'yet another new content', 'utf8'); | ||
expect(fs.readFileSync(path.join(repositoryPath, 'A.txt'), 'utf8')).to.be.deep.equal('yet another new content'); | ||
const status = await getStatus(repositoryPath); | ||
const changedFiles = status.workingDirectory.files; | ||
expect(changedFiles).to.be.lengthOf(2); | ||
expect(changedFiles.map(f => f.path)).to.deep.equal(['A.txt', 'A.txt']); | ||
expect(changedFiles.map(f => f.staged).sort()).to.deep.equal([false, true]); | ||
}); | ||
}); | ||
@@ -125,0 +146,0 @@ |
@@ -29,8 +29,13 @@ import { git } from '../core/git'; | ||
function convertToStagedFlag(statusCode: string): boolean { | ||
// For instance, when the status code is '?', or '.M', the the files are unstaged. | ||
// When the status code is one of the followings: 'A.', or 'M.', the it is staged. | ||
return statusCode.trim().endsWith('.'); | ||
// See: https://git-scm.com/docs/git-status#_short_format | ||
function isChangeInIndex(statusCode: string): boolean { | ||
const index = statusCode.charAt(0); | ||
return index === 'M' || index === 'A' || index === 'D' || index === 'U' || index === 'R' || index === 'C'; | ||
} | ||
function isChangeInWorkTree(statusCode: string): boolean { | ||
const [, workingTree] = statusCode; | ||
return workingTree === 'M' || workingTree === 'A' || workingTree === 'D' || workingTree === 'U'; | ||
} | ||
/** | ||
@@ -87,11 +92,41 @@ * Retrieve the status for a given repository, | ||
files.push( | ||
new WorkingDirectoryFileChange( | ||
entry.path, | ||
summary, | ||
selection, | ||
entry.oldPath, | ||
convertToStagedFlag(entry.statusCode) | ||
) | ||
); | ||
const changeInIndex = isChangeInIndex(entry.statusCode); | ||
const changeInWorkingTree = isChangeInWorkTree(entry.statusCode); | ||
if (changeInIndex) { | ||
files.push( | ||
new WorkingDirectoryFileChange( | ||
entry.path, | ||
summary, | ||
selection, | ||
entry.oldPath, | ||
true | ||
) | ||
); | ||
} | ||
if (changeInWorkingTree) { | ||
files.push( | ||
new WorkingDirectoryFileChange( | ||
entry.path, | ||
summary, | ||
selection, | ||
entry.oldPath, | ||
false | ||
) | ||
); | ||
} | ||
// Must be untracked | ||
if (!changeInIndex && !changeInWorkingTree) { | ||
files.push( | ||
new WorkingDirectoryFileChange( | ||
entry.path, | ||
summary, | ||
selection, | ||
entry.oldPath, | ||
false | ||
) | ||
); | ||
} | ||
} else if (entry.kind === 'header') { | ||
@@ -98,0 +133,0 @@ let m: RegExpMatchArray | null; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
577819
10453
15