Skip to content
Navigation Menu
{{ message }}
forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-package.test.js
More file actions
685 lines (530 loc) · 26.7 KB
/
Copy pathgithub-package.test.js
File metadata and controls
685 lines (530 loc) · 26.7 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
import fs from 'fs-extra';
import path from 'path';
import temp from 'temp';
import until from 'test-until';
import {cloneRepository, disableFilesystemWatchers} from './helpers';
import {fileExists, getTempDir} from '../lib/helpers';
import GithubPackage from '../lib/github-package';
describe('GithubPackage', function() {
let atomEnv, workspace, project, commandRegistry, notificationManager, grammars, config, confirm, tooltips, styles;
let getLoadSettings, configDirPath, deserializers;
let githubPackage, contextPool;
beforeEach(async function() {
atomEnv = global.buildAtomEnvironment();
await disableFilesystemWatchers(atomEnv);
workspace = atomEnv.workspace;
project = atomEnv.project;
commandRegistry = atomEnv.commands;
deserializers = atomEnv.deserializers;
notificationManager = atomEnv.notifications;
tooltips = atomEnv.tooltips;
config = atomEnv.config;
confirm = atomEnv.confirm.bind(atomEnv);
styles = atomEnv.styles;
grammars = atomEnv.grammars;
getLoadSettings = atomEnv.getLoadSettings.bind(atomEnv);
configDirPath = path.join(__dirname, 'fixtures', 'atomenv-config');
githubPackage = new GithubPackage(
workspace, project, commandRegistry, notificationManager, tooltips, styles, grammars, confirm, config,
deserializers, configDirPath, getLoadSettings,
);
sinon.stub(githubPackage, 'rerender').callsFake(callback => {
if (callback) {
process.nextTick(callback);
}
});
contextPool = githubPackage.getContextPool();
});
afterEach(async function() {
await githubPackage.deactivate();
atomEnv.destroy();
});
async function contextUpdateAfter(chunk) {
const updatePromise = githubPackage.getSwitchboard().getFinishActiveContextUpdatePromise();
await chunk();
return updatePromise;
}
describe('construction', function() {
let githubPackage1;
afterEach(async function() {
if (githubPackage1) {
await githubPackage1.deactivate();
}
});
async function constructWith(projectPaths, initialPaths) {
const realProjectPaths = await Promise.all(
projectPaths.map(projectPath => getTempDir({prefix: projectPath})),
);
project.setPaths(realProjectPaths);
const getLoadSettings1 = () => ({initialPaths});
githubPackage1 = new GithubPackage(
workspace, project, commandRegistry, notificationManager, tooltips, styles, grammars, confirm, config,
deserializers, configDirPath, getLoadSettings1,
);
}
function assertAbsentLike() {
const repository = githubPackage1.getActiveRepository();
assert.isTrue(repository.isUndetermined());
assert.isFalse(repository.showGitTabLoading());
assert.isTrue(repository.showGitTabInit());
}
function assertLoadingLike() {
const repository = githubPackage1.getActiveRepository();
assert.isTrue(repository.isUndetermined());
assert.isTrue(repository.showGitTabLoading());
assert.isFalse(repository.showGitTabInit());
}
it('with no projects or initial paths begins with an absent-like undetermined context', async function() {
await constructWith([], []);
assertAbsentLike();
});
it('with one existing project begins with a loading-like undetermined context', async function() {
await constructWith(['one'], []);
assertLoadingLike();
});
it('with several existing projects begins with an absent-like undetermined context', async function() {
await constructWith(['one', 'two'], []);
assertAbsentLike();
});
it('with no projects but one initial path begins with a loading-like undetermined context', async function() {
await constructWith([], ['one']);
assertLoadingLike();
});
it('with no projects and several initial paths begins with an absent-like undetermined context', async function() {
await constructWith([], ['one', 'two']);
assertAbsentLike();
});
it('with one project and initial paths begins with a loading-like undetermined context', async function() {
await constructWith(['one'], ['two', 'three']);
assertLoadingLike();
});
it('with several projects and an initial path begins with an absent-like undetermined context', async function() {
await constructWith(['one', 'two'], ['three']);
assertAbsentLike();
});
});
describe('activate()', function() {
it('begins with an undetermined repository context', async function() {
await contextUpdateAfter(() => githubPackage.activate());
assert.isTrue(githubPackage.getActiveRepository().isUndetermined());
});
it('uses models from preexisting projects', async function() {
const [workdirPath1, workdirPath2, nonRepositoryPath] = await Promise.all([
cloneRepository('three-files'),
cloneRepository('three-files'),
getTempDir(),
]);
project.setPaths([workdirPath1, workdirPath2, nonRepositoryPath]);
await contextUpdateAfter(() => githubPackage.activate());
assert.isTrue(contextPool.getContext(workdirPath1).isPresent());
assert.isTrue(contextPool.getContext(workdirPath2).isPresent());
assert.isTrue(contextPool.getContext(nonRepositoryPath).isPresent());
assert.isTrue(githubPackage.getActiveRepository().isUndetermined());
});
it('uses an active model from a single preexisting project', async function() {
const workdirPath = await cloneRepository('three-files');
project.setPaths([workdirPath]);
await contextUpdateAfter(() => githubPackage.activate());
const context = contextPool.getContext(workdirPath);
assert.isTrue(context.isPresent());
assert.strictEqual(context.getRepository(), githubPackage.getActiveRepository());
assert.strictEqual(context.getResolutionProgress(), githubPackage.getActiveResolutionProgress());
assert.equal(githubPackage.getActiveWorkdir(), workdirPath);
});
it('uses an active model from a preexisting active pane item', async function() {
const [workdirPath1, workdirPath2] = await Promise.all([
cloneRepository('three-files'),
cloneRepository('three-files'),
]);
project.setPaths([workdirPath1, workdirPath2]);
await workspace.open(path.join(workdirPath2, 'a.txt'));
await contextUpdateAfter(() => githubPackage.activate());
const context = contextPool.getContext(workdirPath2);
assert.isTrue(context.isPresent());
assert.strictEqual(context.getRepository(), githubPackage.getActiveRepository());
assert.strictEqual(context.getResolutionProgress(), githubPackage.getActiveResolutionProgress());
assert.equal(githubPackage.getActiveWorkdir(), workdirPath2);
});
it('uses an active model from serialized state', async function() {
const [workdirPath1, workdirPath2, workdirPath3] = await Promise.all([
cloneRepository('three-files'),
cloneRepository('three-files'),
cloneRepository('three-files'),
]);
project.setPaths([workdirPath1, workdirPath2, workdirPath3]);
await contextUpdateAfter(() => githubPackage.activate({
activeRepositoryPath: workdirPath2,
}));
const context = contextPool.getContext(workdirPath2);
assert.isTrue(context.isPresent());
assert.strictEqual(context.getRepository(), githubPackage.getActiveRepository());
assert.strictEqual(context.getResolutionProgress(), githubPackage.getActiveResolutionProgress());
assert.equal(githubPackage.getActiveWorkdir(), workdirPath2);
});
it('prefers the active model from an active pane item to serialized state', async function() {
const [workdirPath1, workdirPath2] = await Promise.all([
cloneRepository('three-files'),
cloneRepository('three-files'),
]);
project.setPaths([workdirPath1, workdirPath2]);
await workspace.open(path.join(workdirPath2, 'b.txt'));
await contextUpdateAfter(() => githubPackage.activate({
activeRepositoryPath: workdirPath1,
}));
const context = contextPool.getContext(workdirPath2);
assert.isTrue(context.isPresent());
assert.strictEqual(context.getRepository(), githubPackage.getActiveRepository());
assert.strictEqual(context.getResolutionProgress(), githubPackage.getActiveResolutionProgress());
assert.equal(githubPackage.getActiveWorkdir(), workdirPath2);
});
it('prefers the active model from a single project to serialized state', async function() {
const [workdirPath1, workdirPath2] = await Promise.all([
cloneRepository('three-files'),
cloneRepository('three-files'),
]);
project.setPaths([workdirPath1]);
await contextUpdateAfter(() => githubPackage.activate({
activeRepositoryPath: workdirPath2,
}));
const context = contextPool.getContext(workdirPath1);
assert.isTrue(context.isPresent());
assert.strictEqual(context.getRepository(), githubPackage.getActiveRepository());
assert.strictEqual(context.getResolutionProgress(), githubPackage.getActiveResolutionProgress());
assert.equal(githubPackage.getActiveWorkdir(), workdirPath1);
});
it('restores the active resolution progress', async function() {
// Repository with a merge conflict, repository without a merge conflict, path without a repository
const workdirMergeConflict = await cloneRepository('merge-conflict');
const workdirNoConflict = await cloneRepository('three-files');
const nonRepositoryPath = await fs.realpath(temp.mkdirSync());
fs.writeFileSync(path.join(nonRepositoryPath, 'c.txt'));
project.setPaths([workdirMergeConflict, workdirNoConflict, nonRepositoryPath]);
await contextUpdateAfter(() => githubPackage.activate());
// Open a file in the merge conflict repository.
await workspace.open(path.join(workdirMergeConflict, 'modified-on-both-ours.txt'));
await githubPackage.scheduleActiveContextUpdate();
const resolutionMergeConflict = contextPool.getContext(workdirMergeConflict).getResolutionProgress();
await assert.strictEqual(githubPackage.getActiveResolutionProgress(), resolutionMergeConflict);
// Record some resolution progress to recall later
resolutionMergeConflict.reportMarkerCount('modified-on-both-ours.txt', 3);
// Open a file in the non-merge conflict repository.
await workspace.open(path.join(workdirNoConflict, 'b.txt'));
await githubPackage.scheduleActiveContextUpdate();
const resolutionNoConflict = contextPool.getContext(workdirNoConflict).getResolutionProgress();
assert.strictEqual(githubPackage.getActiveResolutionProgress(), resolutionNoConflict);
assert.isTrue(githubPackage.getActiveResolutionProgress().isEmpty());
// Open a file in the workdir with no repository.
await workspace.open(path.join(nonRepositoryPath, 'c.txt'));
await githubPackage.scheduleActiveContextUpdate();
assert.isTrue(githubPackage.getActiveResolutionProgress().isEmpty());
// Re-open a file in the merge conflict repository.
await workspace.open(path.join(workdirMergeConflict, 'modified-on-both-theirs.txt'));
await githubPackage.scheduleActiveContextUpdate();
assert.strictEqual(githubPackage.getActiveResolutionProgress(), resolutionMergeConflict);
assert.isFalse(githubPackage.getActiveResolutionProgress().isEmpty());
assert.equal(githubPackage.getActiveResolutionProgress().getRemaining('modified-on-both-ours.txt'), 3);
});
describe('startOpen', function() {
let confFile;
beforeEach(async function() {
confFile = path.join(configDirPath, 'github.cson');
await fs.remove(confFile);
});
it('renders with startOpen on the first run', async function() {
config.set('welcome.showOnStartup', false);
await githubPackage.activate();
assert.isTrue(githubPackage.startOpen);
assert.isTrue(await fileExists(confFile));
});
it('renders without startOpen on non-first runs', async function() {
await fs.writeFile(confFile, '', {encoding: 'utf8'});
await githubPackage.activate();
assert.isFalse(githubPackage.startOpen);
assert.isTrue(await fileExists(confFile));
});
it('renders without startOpen on the first run if the welcome pane is shown', async function() {
config.set('welcome.showOnStartup', true);
await githubPackage.activate();
assert.isFalse(githubPackage.startOpen);
assert.isTrue(await fileExists(confFile));
});
});
});
describe('when the project paths change', function() {
it('adds new workdirs to the pool', async function() {
const [workdirPath1, workdirPath2, workdirPath3] = await Promise.all([
cloneRepository('three-files'),
cloneRepository('three-files'),
cloneRepository('three-files'),
]);
project.setPaths([workdirPath1, workdirPath2]);
await contextUpdateAfter(() => githubPackage.activate());
assert.isTrue(contextPool.getContext(workdirPath1).isPresent());
assert.isTrue(contextPool.getContext(workdirPath2).isPresent());
assert.isFalse(contextPool.getContext(workdirPath3).isPresent());
await contextUpdateAfter(() => project.setPaths([workdirPath1, workdirPath2, workdirPath3]));
assert.isTrue(contextPool.getContext(workdirPath1).isPresent());
assert.isTrue(contextPool.getContext(workdirPath2).isPresent());
assert.isTrue(contextPool.getContext(workdirPath3).isPresent());
});
it('destroys contexts associated with the removed project folders', async function() {
const [workdirPath1, workdirPath2, workdirPath3] = await Promise.all([
cloneRepository('three-files'),
cloneRepository('three-files'),
cloneRepository('three-files'),
]);
project.setPaths([workdirPath1, workdirPath2, workdirPath3]);
await contextUpdateAfter(() => githubPackage.activate());
const [repository1, repository2, repository3] = [workdirPath1, workdirPath2, workdirPath3].map(workdir => {
return contextPool.getContext(workdir).getRepository();
});
sinon.stub(repository1, 'destroy');
sinon.stub(repository2, 'destroy');
sinon.stub(repository3, 'destroy');
await contextUpdateAfter(() => project.removePath(workdirPath1));
await contextUpdateAfter(() => project.removePath(workdirPath3));
assert.equal(repository1.destroy.callCount, 1);
assert.equal(repository3.destroy.callCount, 1);
assert.isFalse(repository2.destroy.called);
assert.isFalse(contextPool.getContext(workdirPath1).isPresent());
assert.isFalse(contextPool.getContext(workdirPath3).isPresent());
assert.isTrue(contextPool.getContext(workdirPath2).isPresent());
});
it('returns to an absent context when the last project folder is removed', async function() {
const workdirPath = await cloneRepository('three-files');
project.setPaths([workdirPath]);
await contextUpdateAfter(() => githubPackage.activate());
assert.isTrue(githubPackage.getActiveRepository().isLoading() || githubPackage.getActiveRepository().isPresent());
await contextUpdateAfter(() => project.setPaths([]));
assert.isTrue(githubPackage.getActiveRepository().isAbsent());
});
it('does not transition away from an absent guess when no project folders are present', async function() {
await contextUpdateAfter(() => githubPackage.activate());
assert.isTrue(githubPackage.getActiveRepository().isAbsentGuess());
});
});
describe('when the active pane item changes', function() {
it('becomes the active context', async function() {
const [workdirPath1, workdirPath2] = await Promise.all([
cloneRepository('three-files'),
cloneRepository('three-files'),
]);
project.setPaths([workdirPath1, workdirPath2]);
await contextUpdateAfter(() => githubPackage.activate());
const repository2 = contextPool.getContext(workdirPath2).getRepository();
assert.isTrue(githubPackage.getActiveRepository().isUndetermined());
await contextUpdateAfter(() => workspace.open(path.join(workdirPath2, 'b.txt')));
assert.strictEqual(githubPackage.getActiveRepository(), repository2);
});
it('adds a new context if not in a project', async function() {
const [workdirPath1, workdirPath2] = await Promise.all([
cloneRepository('three-files'),
cloneRepository('three-files'),
]);
project.setPaths([workdirPath1]);
await contextUpdateAfter(() => githubPackage.activate());
assert.isFalse(contextPool.getContext(workdirPath2).isPresent());
await contextUpdateAfter(() => workspace.open(path.join(workdirPath2, 'c.txt')));
assert.equal(githubPackage.getActiveWorkdir(), workdirPath2);
assert.isTrue(contextPool.getContext(workdirPath2).isPresent());
});
it('removes a context if not in a project', async function() {
const [workdirPath1, workdirPath2] = await Promise.all([
cloneRepository('three-files'),
cloneRepository('three-files'),
]);
project.setPaths([workdirPath1]);
await contextUpdateAfter(() => githubPackage.activate());
await contextUpdateAfter(() => workspace.open(path.join(workdirPath2, 'c.txt')));
assert.isTrue(contextPool.getContext(workdirPath2).isPresent());
await contextUpdateAfter(() => workspace.getActivePane().destroyActiveItem());
assert.isFalse(contextPool.getContext(workdirPath2).isPresent());
});
});
describe('scheduleActiveContextUpdate()', function() {
beforeEach(function() {
// Necessary since we skip activate()
githubPackage.savedState = {};
githubPackage.useLegacyPanels = !workspace.getLeftDock;
});
it('prefers the context of the active pane item', async function() {
const [workdirPath1, workdirPath2, workdirPath3] = await Promise.all([
cloneRepository('three-files'),
cloneRepository('three-files'),
cloneRepository('three-files'),
]);
project.setPaths([workdirPath1]);
await workspace.open(path.join(workdirPath2, 'a.txt'));
await githubPackage.scheduleActiveContextUpdate({
activeRepositoryPath: workdirPath3,
});
assert.equal(githubPackage.getActiveWorkdir(), workdirPath2);
});
it('uses an absent context when the active item is not in a git repository', async function() {
const nonRepositoryPath = await fs.realpath(temp.mkdirSync());
const workdir = await cloneRepository('three-files');
project.setPaths([nonRepositoryPath, workdir]);
await fs.writeFile(path.join(nonRepositoryPath, 'a.txt'), 'stuff', {encoding: 'utf8'});
await workspace.open(path.join(nonRepositoryPath, 'a.txt'));
await githubPackage.scheduleActiveContextUpdate();
assert.isTrue(githubPackage.getActiveRepository().isAbsent());
});
it('uses the context of the PaneItem active in the workspace center', async function() {
if (!workspace.getLeftDock) {
this.skip();
}
const [workdir0, workdir1] = await Promise.all([
cloneRepository('three-files'),
cloneRepository('three-files'),
]);
project.setPaths([workdir1]);
await workspace.open(path.join(workdir0, 'a.txt'));
commandRegistry.dispatch(atomEnv.views.getView(workspace), 'tree-view:toggle-focus');
workspace.getLeftDock().activate();
await githubPackage.scheduleActiveContextUpdate();
assert.equal(githubPackage.getActiveWorkdir(), workdir0);
});
it('uses the context of a single open project', async function() {
const [workdirPath1, workdirPath2] = await Promise.all([
cloneRepository('three-files'),
cloneRepository('three-files'),
]);
project.setPaths([workdirPath1]);
await githubPackage.scheduleActiveContextUpdate({
activeRepositoryPath: workdirPath2,
});
assert.equal(githubPackage.getActiveWorkdir(), workdirPath1);
});
it('uses an empty context with a single open project without a git workdir', async function() {
const nonRepositoryPath = await getTempDir();
project.setPaths([nonRepositoryPath]);
await githubPackage.scheduleActiveContextUpdate();
await githubPackage.getActiveRepository().getLoadPromise();
assert.isTrue(contextPool.getContext(nonRepositoryPath).isPresent());
assert.isTrue(githubPackage.getActiveRepository().isEmpty());
assert.isFalse(githubPackage.getActiveRepository().isAbsent());
});
it('activates a saved context state', async function() {
const [workdirPath1, workdirPath2] = await Promise.all([
cloneRepository('three-files'),
cloneRepository('three-files'),
]);
project.setPaths([workdirPath1, workdirPath2]);
await githubPackage.scheduleActiveContextUpdate({
activeRepositoryPath: workdirPath2,
});
assert.equal(githubPackage.getActiveWorkdir(), workdirPath2);
});
it('falls back to keeping the context the same', async function() {
const [workdirPath1, workdirPath2] = await Promise.all([
cloneRepository('three-files'),
cloneRepository('three-files'),
]);
project.setPaths([workdirPath1, workdirPath2]);
contextPool.set([workdirPath1, workdirPath2]);
githubPackage.setActiveContext(contextPool.getContext(workdirPath1));
await githubPackage.scheduleActiveContextUpdate();
assert.equal(githubPackage.getActiveWorkdir(), workdirPath1);
});
it('discovers a context from an open subdirectory', async function() {
const workdirPath = await cloneRepository('three-files');
const projectPath = path.join(workdirPath, 'subdir-1');
project.setPaths([projectPath]);
await githubPackage.scheduleActiveContextUpdate();
assert.equal(githubPackage.getActiveWorkdir(), workdirPath);
});
it('reverts to an empty context if the active repository is destroyed', async function() {
const workdirPath = await cloneRepository('three-files');
project.setPaths([workdirPath]);
await githubPackage.scheduleActiveContextUpdate();
assert.isTrue(contextPool.getContext(workdirPath).isPresent());
const repository = contextPool.getContext(workdirPath).getRepository();
repository.destroy();
assert.isTrue(githubPackage.getActiveRepository().isAbsent());
});
// Don't worry about this on Windows as it's not a common op
if (process.platform !== 'win32') {
it('handles symlinked project paths', async function() {
const workdirPath = await cloneRepository('three-files');
const symlinkPath = (await fs.realpath(temp.mkdirSync())) + '-symlink';
fs.symlinkSync(workdirPath, symlinkPath);
project.setPaths([symlinkPath]);
await workspace.open(path.join(symlinkPath, 'a.txt'));
await githubPackage.scheduleActiveContextUpdate();
await assert.async.isOk(githubPackage.getActiveRepository());
});
}
});
describe('when there is a change in the repository', function() {
let workdirPath1, atomGitRepository1, repository1;
let workdirPath2, atomGitRepository2, repository2;
beforeEach(async function() {
[workdirPath1, workdirPath2] = await Promise.all([
cloneRepository('three-files'),
cloneRepository('three-files'),
]);
fs.writeFileSync(path.join(workdirPath1, 'c.txt'), 'ch-ch-ch-changes', 'utf8');
fs.writeFileSync(path.join(workdirPath2, 'c.txt'), 'ch-ch-ch-changes', 'utf8');
project.setPaths([workdirPath1, workdirPath2]);
await githubPackage.activate();
const watcherPromises = [
until(() => contextPool.getContext(workdirPath1).getChangeObserver().isStarted()),
until(() => contextPool.getContext(workdirPath2).getChangeObserver().isStarted()),
];
if (project.getWatcherPromise) {
watcherPromises.push(project.getWatcherPromise(workdirPath1));
watcherPromises.push(project.getWatcherPromise(workdirPath2));
}
await Promise.all(watcherPromises);
[atomGitRepository1, atomGitRepository2] = githubPackage.project.getRepositories();
sinon.stub(atomGitRepository1, 'refreshStatus');
sinon.stub(atomGitRepository2, 'refreshStatus');
repository1 = contextPool.getContext(workdirPath1).getRepository();
repository2 = contextPool.getContext(workdirPath2).getRepository();
sinon.stub(repository1, 'observeFilesystemChange');
sinon.stub(repository2, 'observeFilesystemChange');
});
it('refreshes the appropriate Repository and Atom GitRepository when a file is changed in workspace 1', async function() {
if (process.platform === 'linux') {
this.skip();
}
fs.writeFileSync(path.join(workdirPath1, 'a.txt'), 'some changes', 'utf8');
await assert.async.isTrue(repository1.observeFilesystemChange.called);
await assert.async.isTrue(atomGitRepository1.refreshStatus.called);
});
it('refreshes the appropriate Repository and Atom GitRepository when a file is changed in workspace 2', async function() {
if (process.platform === 'linux') {
this.skip();
}
fs.writeFileSync(path.join(workdirPath2, 'b.txt'), 'other changes', 'utf8');
await assert.async.isTrue(repository2.observeFilesystemChange.called);
await assert.async.isTrue(atomGitRepository2.refreshStatus.called);
});
it('refreshes the appropriate Repository and Atom GitRepository when a commit is made in workspace 1', async function() {
await repository1.git.exec(['commit', '-am', 'commit in repository1']);
await assert.async.isTrue(repository1.observeFilesystemChange.called);
await assert.async.isTrue(atomGitRepository1.refreshStatus.called);
});
it('refreshes the appropriate Repository and Atom GitRepository when a commit is made in workspace 2', async function() {
await repository2.git.exec(['commit', '-am', 'commit in repository2']);
await assert.async.isTrue(repository2.observeFilesystemChange.called);
await assert.async.isTrue(atomGitRepository2.refreshStatus.called);
});
});
describe('createRepositoryForProjectPath()', function() {
it('creates and sets a repository for the given project path', async function() {
const nonRepositoryPath = await getTempDir();
project.setPaths([nonRepositoryPath]);
await contextUpdateAfter(() => githubPackage.activate());
await githubPackage.getActiveRepository().getLoadPromise();
assert.isTrue(githubPackage.getActiveRepository().isEmpty());
assert.isFalse(githubPackage.getActiveRepository().isAbsent());
await githubPackage.createRepositoryForProjectPath(nonRepositoryPath);
assert.isTrue(githubPackage.getActiveRepository().isPresent());
assert.strictEqual(
githubPackage.getActiveRepository(),
await contextPool.getContext(nonRepositoryPath).getRepository(),
);
});
});
});
You can’t perform that action at this time.
