-
Notifications
You must be signed in to change notification settings - Fork 0
/
stash-apply.js
42 lines (34 loc) · 1.3 KB
/
stash-apply.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// use isomorphic-git API to clone a github repository
import * as isogit from 'isomorphic-git';
import fs from 'fs';
import {getAndApplyFileStateChanges} from './git-util.js';
const dir = './sandbox';
export async function stash_apply() {
try {
// get the stash commit SHA-1 from the stash ref
const stashCommitSHA = await isogit.resolveRef({
fs,
dir,
ref: 'stash' });
// get the stash commit object
const stashCommit = await isogit.readCommit({
fs,
dir,
oid: stashCommitSHA });
const { parent: stashParents } = stashCommit.commit;
// compare the stash commit tree with it's parent commit
for (let i = 0; i < stashParents.length - 1; i++) {
const applyingCommit = await isogit.readCommit({
fs,
dir,
oid: stashParents[i+1] });
const wasStaged = applyingCommit.commit.message.startsWith('stash-Index');
const fileChanges = await getAndApplyFileStateChanges(dir, stashParents[i+1], stashParents[i], wasStaged);
console.info(`fileChanges:${stashParents[i]}`, fileChanges);
}
return stashCommitSHA;
} catch (e) {
console.error(e);
}
}
// stash_apply();