|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +import { default as assert } from 'assert'; |
| 7 | +import * as vscode from 'vscode'; |
| 8 | +import { Repository, Submodule } from '../api/api'; |
| 9 | +import { GitApiImpl } from '../api/api1'; |
| 10 | +import { isSubmodule } from '../common/gitUtils' |
| 11 | + |
| 12 | +describe('isSubmodule Tests', function () { |
| 13 | + it('should return false for repositories with no submodules', () => { |
| 14 | + const mockRepo: Repository = { |
| 15 | + rootUri: vscode.Uri.file('/home/user/repo1'), |
| 16 | + state: { |
| 17 | + submodules: [], |
| 18 | + remotes: [], |
| 19 | + HEAD: undefined, |
| 20 | + rebaseCommit: undefined, |
| 21 | + mergeChanges: [], |
| 22 | + indexChanges: [], |
| 23 | + workingTreeChanges: [], |
| 24 | + onDidChange: new vscode.EventEmitter<void>().event, |
| 25 | + }, |
| 26 | + } as Partial<Repository> as Repository; |
| 27 | + |
| 28 | + const mockGit: GitApiImpl = { |
| 29 | + repositories: [mockRepo], |
| 30 | + } as GitApiImpl; |
| 31 | + |
| 32 | + const result = isSubmodule(mockRepo, mockGit); |
| 33 | + assert.strictEqual(result, false); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should return true when repository is listed as submodule in another repo', () => { |
| 37 | + const submoduleRepo: Repository = { |
| 38 | + rootUri: vscode.Uri.file('/home/user/parent/submodule'), |
| 39 | + state: { |
| 40 | + submodules: [], |
| 41 | + remotes: [], |
| 42 | + HEAD: undefined, |
| 43 | + rebaseCommit: undefined, |
| 44 | + mergeChanges: [], |
| 45 | + indexChanges: [], |
| 46 | + workingTreeChanges: [], |
| 47 | + onDidChange: new vscode.EventEmitter<void>().event, |
| 48 | + }, |
| 49 | + } as Partial<Repository> as Repository; |
| 50 | + |
| 51 | + const parentRepo: Repository = { |
| 52 | + rootUri: vscode.Uri.file('/home/user/parent'), |
| 53 | + state: { |
| 54 | + submodules: [ |
| 55 | + { |
| 56 | + name: 'submodule', |
| 57 | + path: 'submodule', |
| 58 | + url: 'https://github.com/example/submodule.git' |
| 59 | + } as Submodule |
| 60 | + ], |
| 61 | + remotes: [], |
| 62 | + HEAD: undefined, |
| 63 | + rebaseCommit: undefined, |
| 64 | + mergeChanges: [], |
| 65 | + indexChanges: [], |
| 66 | + workingTreeChanges: [], |
| 67 | + onDidChange: new vscode.EventEmitter<void>().event, |
| 68 | + }, |
| 69 | + } as Partial<Repository> as Repository; |
| 70 | + |
| 71 | + const mockGit: GitApiImpl = { |
| 72 | + repositories: [parentRepo, submoduleRepo], |
| 73 | + } as GitApiImpl; |
| 74 | + |
| 75 | + const result = isSubmodule(submoduleRepo, mockGit); |
| 76 | + assert.strictEqual(result, true); |
| 77 | + }); |
| 78 | + |
| 79 | + it('should return false when repository is not listed as submodule', () => { |
| 80 | + const repo1: Repository = { |
| 81 | + rootUri: vscode.Uri.file('/home/user/repo1'), |
| 82 | + state: { |
| 83 | + submodules: [], |
| 84 | + remotes: [], |
| 85 | + HEAD: undefined, |
| 86 | + rebaseCommit: undefined, |
| 87 | + mergeChanges: [], |
| 88 | + indexChanges: [], |
| 89 | + workingTreeChanges: [], |
| 90 | + onDidChange: new vscode.EventEmitter<void>().event, |
| 91 | + }, |
| 92 | + } as Partial<Repository> as Repository; |
| 93 | + |
| 94 | + const repo2: Repository = { |
| 95 | + rootUri: vscode.Uri.file('/home/user/repo2'), |
| 96 | + state: { |
| 97 | + submodules: [ |
| 98 | + { |
| 99 | + name: 'different-submodule', |
| 100 | + path: 'different-submodule', |
| 101 | + url: 'https://github.com/example/different.git' |
| 102 | + } as Submodule |
| 103 | + ], |
| 104 | + remotes: [], |
| 105 | + HEAD: undefined, |
| 106 | + rebaseCommit: undefined, |
| 107 | + mergeChanges: [], |
| 108 | + indexChanges: [], |
| 109 | + workingTreeChanges: [], |
| 110 | + onDidChange: new vscode.EventEmitter<void>().event, |
| 111 | + }, |
| 112 | + } as Partial<Repository> as Repository; |
| 113 | + |
| 114 | + const mockGit: GitApiImpl = { |
| 115 | + repositories: [repo1, repo2], |
| 116 | + } as GitApiImpl; |
| 117 | + |
| 118 | + const result = isSubmodule(repo1, mockGit); |
| 119 | + assert.strictEqual(result, false); |
| 120 | + }); |
| 121 | +}); |
0 commit comments