Skip to content

Commit 81338b4

Browse files
committed
Merge branch 'node-pty'
2 parents 9d5396f + bb905dc commit 81338b4

20 files changed

+372
-282
lines changed

.yarnrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
child-concurrency 1
2+
runtime "electron"
3+
target "1.6.11"
4+
target_arch "x64"
5+
disturl "https://atom.io/download/atom-shell"
6+
progress "true"

package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@
5151
"prompt": "^1.0.0"
5252
},
5353
"dependencies": {
54+
"default-shell": "^1.0.1",
5455
"fs-extra": "^3.0.1",
5556
"ignore": "^3.3.3",
56-
"ramda": "^0.24.1"
57-
},
58-
"optionalDependencies": {
59-
"pty.js": "0.3.1"
57+
"node-pty": "^0.6.10",
58+
"promisify-node": "^0.4.0",
59+
"ramda": "^0.24.1",
60+
"tmp": "^0.0.33"
6061
}
6162
}

src/callbacks/apply.js

+59-37
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,73 @@
11
import fse from 'fs-extra';
22
import path from 'path';
33
import { Error } from '../constants';
4+
import { spawnShell, winSpawn } from '../utils/spawnHelper';
45
import exec from '../utils/execHelper';
56

6-
const clean = (to, from, source) => {
7-
const ticks = process.platform === 'win32' ? '"' : '\'';
8-
const workdir = source.repo().workdir();
9-
const filePath = path.join(workdir, source.path());
10-
const command = `git lfs clean ${ticks}${source.path()}${ticks}`;
11-
12-
return fse.readFile(filePath)
13-
.then(buf => exec(command, buf, { cwd: workdir }))
14-
.then(({ stdout }) => {
15-
const sha = new Buffer(stdout);
16-
return to.set(sha, sha.length).then(() => Error.CODE.OK);
17-
});
7+
const IS_WINDOWS = process.platform === 'win32';
8+
const ticks = IS_WINDOWS ? '"' : '\'';
9+
10+
const parseSize = (ptr) => {
11+
const idx = ptr.indexOf('size ') + 5;
12+
return Number(ptr.substring(idx).trim());
1813
};
1914

20-
const smudge = (to, from, source) => {
21-
const workdir = source.repo().workdir();
15+
export default (crednetialsCallback) => {
16+
const clean = (to, from, source) => {
17+
const workdir = source.repo().workdir();
18+
const filePath = path.join(workdir, source.path());
19+
const command = `git lfs clean ${ticks}${source.path()}${ticks}`;
2220

23-
return exec('git lfs smudge', from.ptr(), { cwd: workdir })
24-
.then(({ stdout }) => {
25-
const sha = new Buffer(stdout);
26-
return to.set(sha, sha.length).then(() => Error.CODE.OK);
27-
});
28-
};
21+
return fse.readFile(filePath)
22+
.then(buf => exec(command, buf, { cwd: workdir }))
23+
.then(({ stdout }) => {
24+
const sha = new Buffer(stdout);
25+
return to.set(sha, sha.length).then(() => Error.CODE.OK);
26+
});
27+
};
28+
29+
const smudge = (to, from, source) => {
30+
const workdir = source.repo().workdir();
31+
const parts = source.path().split('/');
32+
const filepath = parts[parts.length - 1];
33+
const ptr = from.ptr();
34+
const size = parseSize(ptr);
35+
const echo = IS_WINDOWS ? `echo|set /p="${ptr}"` : `echo -ne "${ptr}"`;
36+
37+
const promise = IS_WINDOWS
38+
? winSpawn(`git lfs smudge ${ticks}${filepath}${ticks}`, ptr, { cwd: workdir })
39+
: spawnShell(
40+
`${echo} | git lfs smudge ${ticks}${filepath}${ticks}`,
41+
{ cwd: workdir },
42+
size,
43+
crednetialsCallback
44+
);
45+
46+
return promise
47+
.then(({ stdout }) => to.set(stdout, stdout.length)
48+
.then(() => Error.CODE.OK));
49+
};
2950

30-
let previousFilterPromise = Promise.resolve();
51+
let previousFilterPromise = Promise.resolve();
3152

32-
export const apply = (to, from, source) => {
33-
const mode = source.mode();
53+
return (to, from, source) => {
54+
const mode = source.mode();
3455

35-
const runNextFilter = () => Promise.resolve()
36-
.then(() => {
37-
if (mode === 1) {
38-
return clean(to, from, source);
39-
}
40-
return smudge(to, from, source);
41-
})
42-
.then(
43-
() => Error.CODE.OK,
44-
() => Error.CODE.PASSTHROUGH
45-
);
56+
const runNextFilter = () => Promise.resolve()
57+
.then(() => {
58+
if (mode === 1) {
59+
return clean(to, from, source);
60+
}
61+
return smudge(to, from, source);
62+
})
63+
.then(
64+
() => Error.CODE.OK,
65+
() => Error.CODE.PASSTHROUGH
66+
);
4667

47-
previousFilterPromise = previousFilterPromise
48-
.then(runNextFilter, runNextFilter);
68+
previousFilterPromise = previousFilterPromise
69+
.then(runNextFilter, runNextFilter);
4970

50-
return previousFilterPromise;
71+
return previousFilterPromise;
72+
};
5173
};

src/callbacks/check.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Error } from '../constants';
33

44
import { loadGitattributeFiltersFromRepo } from '../helpers';
55

6-
export const check = src => loadGitattributeFiltersFromRepo(src.repo())
6+
export default src => loadGitattributeFiltersFromRepo(src.repo())
77
.then((filters) => {
88
const file = src.path();
99
const filterIgnore = ignore().add(filters);

src/callbacks/initialize.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import { Error } from '../constants';
22

3-
export const initialize = () => Error.CODE.OK;
3+
export default () => Error.CODE.OK;

src/commands/checkout.js

+2-33
Original file line numberDiff line numberDiff line change
@@ -55,42 +55,11 @@ const generateCheckoutStats = (raw) => {
5555
return {};
5656
};
5757

58-
function checkout(repo, options) {
58+
function checkout(repo) {
5959
const response = generateResponse();
6060
const repoPath = repo.workdir();
6161

62-
const {
63-
remoteName,
64-
branchName,
65-
callback,
66-
} = (options || {});
67-
68-
let branch = branchName;
69-
let remote = remoteName;
70-
let getRemoteAndBranchPromise = Promise.resolve();
71-
72-
if (!remote || !branch) {
73-
let remoteRef;
74-
getRemoteAndBranchPromise = repo.getCurrentBranch()
75-
.then((Reference) => {
76-
const promises = [];
77-
promises.push(this.NodeGit.Branch.upstream(Reference));
78-
promises.push(this.NodeGit.Branch.name(Reference));
79-
return Promise.all(promises);
80-
})
81-
.then((results) => {
82-
remoteRef = results[0];
83-
branch = branch || results[1];
84-
return this.NodeGit.Branch.remoteName(repo, remoteRef.name());
85-
})
86-
.then((name) => {
87-
remote = remote || name;
88-
return Promise.resolve();
89-
});
90-
}
91-
92-
return getRemoteAndBranchPromise
93-
.then(() => core.checkout(`${remote} ${branch}`, { cwd: repoPath }, callback))
62+
return core.checkout('', { cwd: repoPath })
9463
.then(({ stdout, stderr }) => {
9564
response.raw = stdout;
9665

src/commands/clone.js

+8-12
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import R from 'ramda';
22
import { core } from './lfsCommands';
33
import {
44
regex,
5-
BAD_CORE_RESPONSE,
65
BAD_REGEX_PARSE_RESULT,
76
} from '../constants';
87
import generateResponse from '../utils/generateResponse';
9-
import { regexResult } from '../helpers';
8+
import {
9+
regexResult,
10+
errorCatchHandler,
11+
verifyOutput } from '../helpers';
1012

1113
const isValidLine = str => str !== '';
1214

@@ -45,6 +47,8 @@ const generateCloneStats = (raw) => {
4547
skippedFileResults !== null ?
4648
skippedFileResults[0].trim() : BAD_REGEX_PARSE_RESULT;
4749

50+
verifyOutput(stats, raw);
51+
4852
if (statLine.includes('error:')) {
4953
stats.clone_error = statLine.split('error:')[1].trim();
5054
}
@@ -67,19 +71,11 @@ function clone(url, cwd, options) {
6771

6872
const response = generateResponse();
6973
return core.clone(`${url} ${args}`, { cwd }, callback)
70-
.then(({ stdout, stderr }) => {
74+
.then(({ stdout }) => {
7175
response.raw = stdout;
72-
73-
if (stderr) {
74-
response.stderr = stderr;
75-
response.success = false;
76-
response.errno = BAD_CORE_RESPONSE;
77-
return response;
78-
}
79-
8076
response.clone = generateCloneStats(stdout);
8177
return response;
82-
});
78+
}, errorCatchHandler(response));
8379
}
8480

8581
export default clone;

src/commands/fetch.js

+8-12
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import {
55
BAD_REGEX_PARSE_RESULT,
66
} from '../constants';
77
import generateResponse from '../utils/generateResponse';
8-
import { regexResult } from '../helpers';
8+
import {
9+
regexResult,
10+
errorCatchHandler,
11+
verifyOutput } from '../helpers';
912

1013
const isValidLine = str => str !== '';
1114

@@ -44,6 +47,8 @@ const generateFetchStats = (raw) => {
4447
skippedFileResults !== null ?
4548
skippedFileResults[0].trim() : BAD_REGEX_PARSE_RESULT;
4649

50+
verifyOutput(stats, raw);
51+
4752
if (statLine.includes('error:')) {
4853
stats.fetch_error = statLine.split('error:')[1].trim();
4954
}
@@ -74,20 +79,11 @@ function fetch(repo, options) {
7479

7580
const argsString = R.join(' ', args);
7681
return core.fetch(argsString, { cwd: repoPath, shell: true }, callback)
77-
.then(({ stdout, stderr }) => {
82+
.then(({ stdout }) => {
7883
response.raw = stdout;
79-
response.stderr = stderr;
80-
81-
if (stderr > '') {
82-
response.success = false;
83-
response.raw = stderr;
84-
response.stderr = stderr;
85-
return response;
86-
}
87-
8884
response.fetch = generateFetchStats(stdout);
8985
return response;
90-
});
86+
}, errorCatchHandler(response));
9187
}
9288

9389
export default fetch;

src/commands/lfsCommands.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import spawn from '../utils/spawnHelper';
2+
import exec from '../utils/execHelper';
23

34
export const core = {
4-
checkout: (args = '', options, callback) => spawn(`git lfs checkout ${args}`, options, callback),
5+
checkout: (args = '', options) => exec(`git lfs checkout ${args}`, null, options),
56
clone: (args = '', options, callback) => spawn(`git lfs clone ${args}`, options, callback),
67
fetch: (args = '', options, callback) => spawn(`git lfs fetch ${args}`, options, callback),
7-
fsck: options => spawn('git lfs fsck', options),
8+
fsck: options => exec('git lfs fsck', null, options),
89
git: (args = '', options) => spawn(`git ${args}`, options),
9-
install: (args = '', options) => spawn(`git lfs install ${args}`, options),
10-
logs: (args = '', options) => spawn(`git lfs logs ${args}`, options),
11-
ls: (args = '', options) => spawn(`git lfs ls-files ${args}`, options),
12-
pointer: (args = '', options) => spawn(`git lfs pointer ${args}`, options),
13-
prune: (args = '', options) => spawn(`git lfs prune ${args}`, options),
10+
install: (args = '', options) => exec(`git lfs install ${args}`, null, options),
11+
logs: (args = '', options) => exec(`git lfs logs ${args}`, null, options),
12+
ls: (args = '', options) => exec(`git lfs ls-files ${args}`, null, options),
13+
pointer: (args = '', options) => exec(`git lfs pointer ${args}`, null, options),
14+
prune: (args = '', options) => exec(`git lfs prune ${args}`, null, options),
1415
pull: (args = '', options, callback) => spawn(`git lfs pull ${args}`, options, callback),
1516
push: (args = '', options, callback) => spawn(`git lfs push ${args}`, options, callback),
16-
status: (args = '', options) => spawn(`git lfs status ${args}`, options),
17-
track: (args = '', options) => spawn(`git lfs track ${args}`, options),
18-
untrack: (args = '', options) => spawn(`git lfs untrack ${args}`, options),
19-
update: (args = '', options) => spawn(`git lfs update ${args}`, options),
20-
version: options => spawn('git lfs version', options),
17+
status: (args = '', options) => exec(`git lfs status ${args}`, null, options),
18+
track: (args = '', options) => exec(`git lfs track ${args}`, null, options),
19+
untrack: (args = '', options) => exec(`git lfs untrack ${args}`, null, options),
20+
update: (args = '', options) => exec(`git lfs update ${args}`, null, options),
21+
version: options => exec('git lfs version', null, options),
2122
};

src/commands/pull.js

+8-12
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import R from 'ramda';
22
import { core } from './lfsCommands';
33
import {
44
regex,
5-
BAD_CORE_RESPONSE,
65
BAD_REGEX_PARSE_RESULT,
76
} from '../constants';
87
import generateResponse from '../utils/generateResponse';
9-
import { regexResult } from '../helpers';
8+
import {
9+
regexResult,
10+
verifyOutput,
11+
errorCatchHandler } from '../helpers';
1012

1113
const isValidLine = str => str !== '';
1214

@@ -45,6 +47,8 @@ const generatePullStats = (raw) => {
4547
skippedFileResults !== null ?
4648
skippedFileResults[0].trim() : BAD_REGEX_PARSE_RESULT;
4749

50+
verifyOutput(stats, raw);
51+
4852
if (statLine.includes('error:')) {
4953
stats.pull_error = statLine.split('error:')[1].trim();
5054
}
@@ -74,19 +78,11 @@ function pull(repo, options) {
7478
const argsString = R.join(' ', args);
7579

7680
return core.pull(argsString, { cwd: repoPath, shell: true }, callback)
77-
.then(({ stdout, stderr }) => {
81+
.then(({ stdout }) => {
7882
response.raw = stdout;
79-
80-
if (stderr) {
81-
response.stderr = stderr;
82-
response.success = false;
83-
response.errno = BAD_CORE_RESPONSE;
84-
return response;
85-
}
86-
8783
response.pull = generatePullStats(stdout);
8884
return response;
89-
});
85+
}, errorCatchHandler(response));
9086
}
9187

9288
export default pull;

0 commit comments

Comments
 (0)