@changesets/git
Advanced tools
Comparing version 1.4.1 to 1.5.0
# @changesets/git | ||
## 1.5.0 | ||
### Minor Changes | ||
- [#662](https://github.com/changesets/changesets/pull/662) [`8c08469`](https://github.com/changesets/changesets/commit/8c0846977597ddaf51aaeb35f1f0f9428bf8ba14) Thanks [@JakeGinnivan](https://github.com/JakeGinnivan)! - Add `tagExists` & `remoteTagExists` git helpers | ||
### Patch Changes | ||
- Updated dependencies [[`8c08469`](https://github.com/changesets/changesets/commit/8c0846977597ddaf51aaeb35f1f0f9428bf8ba14)]: | ||
- @changesets/types@5.2.0 | ||
## 1.4.1 | ||
@@ -4,0 +15,0 @@ |
@@ -22,3 +22,3 @@ import { Package } from "@manypkg/get-packages"; | ||
}): Promise<void>; | ||
export declare function getChangedFilesSince({ cwd, ref, fullPath }: { | ||
export declare function getChangedFilesSince({ cwd, ref, fullPath, }: { | ||
cwd: string; | ||
@@ -28,12 +28,14 @@ ref: string; | ||
}): Promise<Array<string>>; | ||
export declare function getChangedChangesetFilesSinceRef({ cwd, ref }: { | ||
export declare function getChangedChangesetFilesSinceRef({ cwd, ref, }: { | ||
cwd: string; | ||
ref: string; | ||
}): Promise<Array<string>>; | ||
export declare function getChangedPackagesSinceRef({ cwd, ref }: { | ||
export declare function getChangedPackagesSinceRef({ cwd, ref, }: { | ||
cwd: string; | ||
ref: string; | ||
}): Promise<Package[]>; | ||
export declare function getCurrentCommitId({ cwd }: { | ||
export declare function tagExists(tagStr: string, cwd: string): Promise<boolean>; | ||
export declare function getCurrentCommitId({ cwd, }: { | ||
cwd: string; | ||
}): Promise<string>; | ||
export declare function remoteTagExists(tagStr: string): Promise<boolean>; |
@@ -255,2 +255,10 @@ 'use strict'; | ||
} | ||
async function tagExists(tagStr, cwd) { | ||
const gitCmd = await spawn__default['default']("git", ["tag", "-l", tagStr], { | ||
cwd | ||
}); | ||
const output = gitCmd.stdout.toString().trim(); | ||
const tagExists = !!output; | ||
return tagExists; | ||
} | ||
async function getCurrentCommitId({ | ||
@@ -263,2 +271,8 @@ cwd | ||
} | ||
async function remoteTagExists(tagStr) { | ||
const gitCmd = await spawn__default['default']("git", ["ls-remote", "--tags", "origin", "-l", tagStr]); | ||
const output = gitCmd.stdout.toString().trim(); | ||
const tagExists = !!output; | ||
return tagExists; | ||
} | ||
@@ -277,2 +291,4 @@ exports.add = add; | ||
exports.isRepoShallow = isRepoShallow; | ||
exports.remoteTagExists = remoteTagExists; | ||
exports.tag = tag; | ||
exports.tagExists = tagExists; |
@@ -160,2 +160,8 @@ "use strict"; | ||
async function tagExists(tagStr, cwd) { | ||
return !!(await spawn__default.default("git", [ "tag", "-l", tagStr ], { | ||
cwd: cwd | ||
})).stdout.toString().trim(); | ||
} | ||
async function getCurrentCommitId({cwd: cwd}) { | ||
@@ -167,2 +173,6 @@ return (await spawn__default.default("git", [ "rev-parse", "--short", "HEAD" ], { | ||
async function remoteTagExists(tagStr) { | ||
return !!(await spawn__default.default("git", [ "ls-remote", "--tags", "origin", "-l", tagStr ])).stdout.toString().trim(); | ||
} | ||
exports.add = add, exports.commit = commit, exports.deepenCloneBy = deepenCloneBy, | ||
@@ -173,2 +183,3 @@ exports.getAllTags = getAllTags, exports.getChangedChangesetFilesSinceRef = getChangedChangesetFilesSinceRef, | ||
exports.getCurrentCommitId = getCurrentCommitId, exports.getDivergedCommit = getDivergedCommit, | ||
exports.isRepoShallow = isRepoShallow, exports.tag = tag; | ||
exports.isRepoShallow = isRepoShallow, exports.remoteTagExists = remoteTagExists, | ||
exports.tag = tag, exports.tagExists = tagExists; |
@@ -244,2 +244,10 @@ import spawn from 'spawndamnit'; | ||
} | ||
async function tagExists(tagStr, cwd) { | ||
const gitCmd = await spawn("git", ["tag", "-l", tagStr], { | ||
cwd | ||
}); | ||
const output = gitCmd.stdout.toString().trim(); | ||
const tagExists = !!output; | ||
return tagExists; | ||
} | ||
async function getCurrentCommitId({ | ||
@@ -252,3 +260,9 @@ cwd | ||
} | ||
async function remoteTagExists(tagStr) { | ||
const gitCmd = await spawn("git", ["ls-remote", "--tags", "origin", "-l", tagStr]); | ||
const output = gitCmd.stdout.toString().trim(); | ||
const tagExists = !!output; | ||
return tagExists; | ||
} | ||
export { add, commit, deepenCloneBy, getAllTags, getChangedChangesetFilesSinceRef, getChangedFilesSince, getChangedPackagesSinceRef, getCommitThatAddsFile, getCommitsThatAddFiles, getCurrentCommitId, getDivergedCommit, isRepoShallow, tag }; | ||
export { add, commit, deepenCloneBy, getAllTags, getChangedChangesetFilesSinceRef, getChangedFilesSince, getChangedPackagesSinceRef, getCommitThatAddsFile, getCommitsThatAddFiles, getCurrentCommitId, getDivergedCommit, isRepoShallow, remoteTagExists, tag, tagExists }; |
{ | ||
"name": "@changesets/git", | ||
"version": "1.4.1", | ||
"version": "1.5.0", | ||
"description": "Some git helpers that changesets use to get information", | ||
@@ -12,3 +12,3 @@ "main": "dist/git.cjs.js", | ||
"@changesets/errors": "^0.1.4", | ||
"@changesets/types": "^5.1.0", | ||
"@changesets/types": "^5.2.0", | ||
"@manypkg/get-packages": "^1.1.3", | ||
@@ -15,0 +15,0 @@ "is-subdir": "^1.1.1", |
@@ -15,3 +15,4 @@ import path from "path"; | ||
getChangedChangesetFilesSinceRef, | ||
getAllTags | ||
getAllTags, | ||
tagExists, | ||
} from "./"; | ||
@@ -57,3 +58,3 @@ | ||
await spawn("git", ["config", "tag.forceSignAnnotataled", "false"], { | ||
cwd | ||
cwd, | ||
}); | ||
@@ -105,3 +106,3 @@ }); | ||
const gitCmd = await spawn("git", ["diff", "--name-only", "--cached"], { | ||
cwd | ||
cwd, | ||
}); | ||
@@ -111,3 +112,3 @@ const stagedFiles = gitCmd.stdout | ||
.split("\n") | ||
.filter(a => a); | ||
.filter((a) => a); | ||
@@ -124,3 +125,3 @@ expect(stagedFiles).toHaveLength(1); | ||
const gitCmd = await spawn("git", ["diff", "--name-only", "--cached"], { | ||
cwd | ||
cwd, | ||
}); | ||
@@ -130,3 +131,3 @@ const stagedFiles = gitCmd.stdout | ||
.split("\n") | ||
.filter(a => a); | ||
.filter((a) => a); | ||
@@ -143,3 +144,3 @@ expect(stagedFiles).toHaveLength(3); | ||
const gitCmd = await spawn("git", ["diff", "--name-only", "--cached"], { | ||
cwd | ||
cwd, | ||
}); | ||
@@ -149,3 +150,3 @@ const stagedFiles = gitCmd.stdout | ||
.split("\n") | ||
.filter(a => a); | ||
.filter((a) => a); | ||
@@ -157,3 +158,3 @@ expect(stagedFiles).toEqual([ | ||
"packages/pkg-b/index.js", | ||
"packages/pkg-b/package.json" | ||
"packages/pkg-b/package.json", | ||
]); | ||
@@ -169,3 +170,3 @@ }); | ||
const gitCmd = await spawn("git", ["log", "-1", "--pretty=%B"], { | ||
cwd | ||
cwd, | ||
}); | ||
@@ -214,3 +215,3 @@ const commitMessage = gitCmd.stdout.toString().trim(); | ||
const initialHead = await spawn("git", ["rev-parse", "HEAD"], { | ||
cwd | ||
cwd, | ||
}); | ||
@@ -240,2 +241,19 @@ await tag("tag_message", cwd); | ||
describe("tagExists", () => { | ||
it("returns false when no tag exists", async () => { | ||
await add("packages/pkg-a/package.json", cwd); | ||
await commit("added packageA package.json", cwd); | ||
expect(await tagExists("tag_which_doesn't_exist", cwd)).toBe(false); | ||
}); | ||
it("returns true when tag exists", async () => { | ||
await add("packages/pkg-a/package.json", cwd); | ||
await commit("added packageA package.json", cwd); | ||
await tag("tag_message", cwd); | ||
expect(await tagExists("tag_message", cwd)).toBe(true); | ||
}); | ||
}); | ||
describe("getCommitsThatAddFiles", () => { | ||
@@ -295,3 +313,3 @@ it("should commit a file and get the hash of that commit", async () => { | ||
{ | ||
cwd: cloneDir | ||
cwd: cloneDir, | ||
} | ||
@@ -389,3 +407,3 @@ ); | ||
cwd, | ||
fullPath: false | ||
fullPath: false, | ||
}); | ||
@@ -400,3 +418,3 @@ expect(changedFiles).toHaveLength(0); | ||
cwd, | ||
fullPath: true | ||
fullPath: true, | ||
}); | ||
@@ -418,3 +436,3 @@ expect(changedFiles).toHaveLength(0); | ||
ref: firstRef.stdout.toString().trim(), | ||
cwd | ||
cwd, | ||
}); | ||
@@ -429,3 +447,3 @@ expect(filesChangedSinceFirstRef[0]).toEqual("packages/pkg-a/index.js"); | ||
ref: secondRef.stdout.toString().trim(), | ||
cwd | ||
cwd, | ||
}); | ||
@@ -449,3 +467,3 @@ expect(filesChangedSinceSecondRef[0]).toEqual("packages/pkg-b/index.js"); | ||
cwd, | ||
fullPath: true | ||
fullPath: true, | ||
}); | ||
@@ -462,3 +480,3 @@ expect(filesChangedSinceRef[0]).toBe( | ||
cwd: path.resolve(cwd, "packages"), | ||
fullPath: true | ||
fullPath: true, | ||
}); | ||
@@ -484,3 +502,3 @@ expect(filesChangedSinceRef2[0]).toBe( | ||
cwd, | ||
ref: "main" | ||
ref: "main", | ||
}); | ||
@@ -501,3 +519,3 @@ expect(changedPackages).toHaveLength(0); | ||
cwd, | ||
ref: "main" | ||
ref: "main", | ||
}); | ||
@@ -518,3 +536,3 @@ | ||
cwd, | ||
ref: "main" | ||
ref: "main", | ||
}); | ||
@@ -531,3 +549,3 @@ expect(files).toHaveLength(0); | ||
cwd, | ||
ref: "main" | ||
ref: "main", | ||
}); | ||
@@ -545,3 +563,3 @@ expect(files).toHaveLength(2); | ||
cwd, | ||
ref: "some-branch" | ||
ref: "some-branch", | ||
}); | ||
@@ -548,0 +566,0 @@ expect(files).toHaveLength(2); |
@@ -36,6 +36,3 @@ import spawn from "spawndamnit"; | ||
const tags = gitCmd.stdout | ||
.toString() | ||
.trim() | ||
.split("\n"); | ||
const tags = gitCmd.stdout.toString().trim().split("\n"); | ||
@@ -99,3 +96,3 @@ return new Set(tags); | ||
"--pretty=format:%h:%p", | ||
gitPath | ||
gitPath, | ||
], | ||
@@ -140,3 +137,3 @@ { cwd } | ||
await deepenCloneBy({ by: 50, cwd }); | ||
remaining = commitsWithMissingParents.map(p => p.path); | ||
remaining = commitsWithMissingParents.map((p) => p.path); | ||
} else { | ||
@@ -151,3 +148,3 @@ // It's not a shallow clone, so all the commit SHAs we have are legitimate. | ||
return gitPaths.map(p => map.get(p)); | ||
return gitPaths.map((p) => map.get(p)); | ||
} | ||
@@ -158,3 +155,3 @@ | ||
await spawn("git", ["rev-parse", "--is-shallow-repository"], { | ||
cwd | ||
cwd, | ||
}) | ||
@@ -201,6 +198,3 @@ ).stdout | ||
return stdout | ||
.toString() | ||
.trim() | ||
.replace(/\n|\r/g, ""); | ||
return stdout.toString().trim().replace(/\n|\r/g, ""); | ||
} | ||
@@ -211,3 +205,3 @@ | ||
ref, | ||
fullPath = false | ||
fullPath = false, | ||
}: { | ||
@@ -231,7 +225,7 @@ cwd: string; | ||
.split("\n") | ||
.filter(a => a); | ||
.filter((a) => a); | ||
if (!fullPath) return files; | ||
const repoRoot = await getRepoRoot({ cwd }); | ||
return files.map(file => path.resolve(repoRoot, file)); | ||
return files.map((file) => path.resolve(repoRoot, file)); | ||
} | ||
@@ -242,3 +236,3 @@ | ||
cwd, | ||
ref | ||
ref, | ||
}: { | ||
@@ -255,3 +249,3 @@ cwd: string; | ||
{ | ||
cwd | ||
cwd, | ||
} | ||
@@ -266,3 +260,3 @@ ); | ||
.split("\n") | ||
.filter(file => tester.test(file)); | ||
.filter((file) => tester.test(file)); | ||
return files; | ||
@@ -277,3 +271,3 @@ } catch (err) { | ||
cwd, | ||
ref | ||
ref, | ||
}: { | ||
@@ -288,4 +282,4 @@ cwd: string; | ||
packages.packages.forEach(pkg => | ||
changedFiles.filter(isInDir(pkg.dir)).forEach(fileName => { | ||
packages.packages.forEach((pkg) => | ||
changedFiles.filter(isInDir(pkg.dir)).forEach((fileName) => { | ||
const prevPkg = fileToPackage[fileName] || { dir: "" }; | ||
@@ -303,4 +297,11 @@ if (pkg.dir.length > prevPkg.dir.length) fileToPackage[fileName] = pkg; | ||
export async function tagExists(tagStr: string, cwd: string) { | ||
const gitCmd = await spawn("git", ["tag", "-l", tagStr], { cwd }); | ||
const output = gitCmd.stdout.toString().trim(); | ||
const tagExists = !!output; | ||
return tagExists; | ||
} | ||
export async function getCurrentCommitId({ | ||
cwd | ||
cwd, | ||
}: { | ||
@@ -313,1 +314,14 @@ cwd: string; | ||
} | ||
export async function remoteTagExists(tagStr: string) { | ||
const gitCmd = await spawn("git", [ | ||
"ls-remote", | ||
"--tags", | ||
"origin", | ||
"-l", | ||
tagStr, | ||
]); | ||
const output = gitCmd.stdout.toString().trim(); | ||
const tagExists = !!output; | ||
return tagExists; | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
68209
1427
Updated@changesets/types@^5.2.0