Read-only mirror — the public repositories of the Forgejo instance, refreshed every 10 minutes. The live instance (fg.dieschoenewolke.de) is reachable only over the VPN; clone here with https://git.dieschoenewolke.de/git/<owner>/<repo>.git.
summaryrefslogtreecommitdiff
path: root/__test__/git-directory-helper.test.ts
diff options
context:
space:
mode:
authoreric sciple <ericsciple@users.noreply.github.com>2020-05-27 09:54:28 -0400
committerGitHub <noreply@github.com>2020-05-27 09:54:28 -0400
commit1af3b46e902378dcbdf104a32ddae1644c64c366 (patch)
treeeb40b22d94abbd6860bb2ec1eac5b1ca62ea542a /__test__/git-directory-helper.test.ts
parent31d9f35c90667154e76ccca096898caab3e5bba7 (diff)
Fetch all history for all tags and branches when fetch-depth=0 (#258)
Diffstat (limited to '__test__/git-directory-helper.test.ts')
-rw-r--r--__test__/git-directory-helper.test.ts90
1 files changed, 72 insertions, 18 deletions
diff --git a/__test__/git-directory-helper.test.ts b/__test__/git-directory-helper.test.ts
index c39a2a5..7283102 100644
--- a/__test__/git-directory-helper.test.ts
+++ b/__test__/git-directory-helper.test.ts
@@ -9,6 +9,7 @@ const testWorkspace = path.join(__dirname, '_temp', 'git-directory-helper')
let repositoryPath: string
let repositoryUrl: string
let clean: boolean
+let ref: string
let git: IGitCommandManager
describe('git-directory-helper tests', () => {
@@ -41,7 +42,8 @@ describe('git-directory-helper tests', () => {
git,
repositoryPath,
repositoryUrl,
- clean
+ clean,
+ ref
)
// Assert
@@ -63,7 +65,8 @@ describe('git-directory-helper tests', () => {
git,
repositoryPath,
repositoryUrl,
- clean
+ clean,
+ ref
)
// Assert
@@ -88,7 +91,8 @@ describe('git-directory-helper tests', () => {
git,
repositoryPath,
repositoryUrl,
- clean
+ clean,
+ ref
)
// Assert
@@ -109,7 +113,8 @@ describe('git-directory-helper tests', () => {
git,
repositoryPath,
repositoryUrl,
- clean
+ clean,
+ ref
)
// Assert
@@ -137,7 +142,8 @@ describe('git-directory-helper tests', () => {
git,
repositoryPath,
repositoryUrl,
- clean
+ clean,
+ ref
)
// Assert
@@ -163,7 +169,8 @@ describe('git-directory-helper tests', () => {
git,
repositoryPath,
differentRepositoryUrl,
- clean
+ clean,
+ ref
)
// Assert
@@ -187,7 +194,8 @@ describe('git-directory-helper tests', () => {
git,
repositoryPath,
repositoryUrl,
- clean
+ clean,
+ ref
)
// Assert
@@ -212,7 +220,8 @@ describe('git-directory-helper tests', () => {
git,
repositoryPath,
repositoryUrl,
- clean
+ clean,
+ ref
)
// Assert
@@ -236,7 +245,8 @@ describe('git-directory-helper tests', () => {
undefined,
repositoryPath,
repositoryUrl,
- clean
+ clean,
+ ref
)
// Assert
@@ -260,7 +270,8 @@ describe('git-directory-helper tests', () => {
git,
repositoryPath,
repositoryUrl,
- clean
+ clean,
+ ref
)
// Assert
@@ -290,7 +301,8 @@ describe('git-directory-helper tests', () => {
git,
repositoryPath,
repositoryUrl,
- clean
+ clean,
+ ref
)
// Assert
@@ -305,29 +317,66 @@ describe('git-directory-helper tests', () => {
expect(git.tryReset).not.toHaveBeenCalled()
})
- const removesRemoteBranches = 'removes local branches'
- it(removesRemoteBranches, async () => {
+ const removesAncestorRemoteBranch = 'removes ancestor remote branch'
+ it(removesAncestorRemoteBranch, async () => {
// Arrange
- await setup(removesRemoteBranches)
+ await setup(removesAncestorRemoteBranch)
await fs.promises.writeFile(path.join(repositoryPath, 'my-file'), '')
const mockBranchList = git.branchList as jest.Mock<any, any>
mockBranchList.mockImplementation(async (remote: boolean) => {
- return remote ? ['remote-branch-1', 'remote-branch-2'] : []
+ return remote ? ['origin/remote-branch-1', 'origin/remote-branch-2'] : []
})
+ ref = 'remote-branch-1/conflict'
// Act
await gitDirectoryHelper.prepareExistingDirectory(
git,
repositoryPath,
repositoryUrl,
- clean
+ clean,
+ ref
)
// Assert
const files = await fs.promises.readdir(repositoryPath)
expect(files.sort()).toEqual(['.git', 'my-file'])
- expect(git.branchDelete).toHaveBeenCalledWith(true, 'remote-branch-1')
- expect(git.branchDelete).toHaveBeenCalledWith(true, 'remote-branch-2')
+ expect(git.branchDelete).toHaveBeenCalledTimes(1)
+ expect(git.branchDelete).toHaveBeenCalledWith(
+ true,
+ 'origin/remote-branch-1'
+ )
+ })
+
+ const removesDescendantRemoteBranches = 'removes descendant remote branch'
+ it(removesDescendantRemoteBranches, async () => {
+ // Arrange
+ await setup(removesDescendantRemoteBranches)
+ await fs.promises.writeFile(path.join(repositoryPath, 'my-file'), '')
+ const mockBranchList = git.branchList as jest.Mock<any, any>
+ mockBranchList.mockImplementation(async (remote: boolean) => {
+ return remote
+ ? ['origin/remote-branch-1/conflict', 'origin/remote-branch-2']
+ : []
+ })
+ ref = 'remote-branch-1'
+
+ // Act
+ await gitDirectoryHelper.prepareExistingDirectory(
+ git,
+ repositoryPath,
+ repositoryUrl,
+ clean,
+ ref
+ )
+
+ // Assert
+ const files = await fs.promises.readdir(repositoryPath)
+ expect(files.sort()).toEqual(['.git', 'my-file'])
+ expect(git.branchDelete).toHaveBeenCalledTimes(1)
+ expect(git.branchDelete).toHaveBeenCalledWith(
+ true,
+ 'origin/remote-branch-1/conflict'
+ )
})
})
@@ -344,6 +393,9 @@ async function setup(testName: string): Promise<void> {
// Clean
clean = true
+ // Ref
+ ref = ''
+
// Git command manager
git = {
branchDelete: jest.fn(),
@@ -364,7 +416,9 @@ async function setup(testName: string): Promise<void> {
log1: jest.fn(),
remoteAdd: jest.fn(),
removeEnvironmentVariable: jest.fn(),
+ revParse: jest.fn(),
setEnvironmentVariable: jest.fn(),
+ shaExists: jest.fn(),
submoduleForeach: jest.fn(),
submoduleSync: jest.fn(),
submoduleUpdate: jest.fn(),