Skip to content

Commit 2e76a77

Browse files
committed
feat: allow running tool in offline mode by setting --fetch-remote=false
1 parent 4fa46bf commit 2e76a77

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

src/command-line-arguments.ts

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export type CommandLineArguments = {
77
reset: boolean;
88
backport: boolean;
99
defaultBranch: string;
10+
fetchRemote: boolean;
1011
};
1112

1213
/**
@@ -51,6 +52,12 @@ export async function readCommandLineArguments(
5152
default: 'main',
5253
type: 'string',
5354
})
55+
.option('fetch-remote', {
56+
alias: 'f',
57+
describe: 'Syncronizes local git references with remote',
58+
default: true,
59+
type: 'boolean',
60+
})
5461
.help()
5562
.strict()
5663
.parse();

src/initial-parameters.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ export async function determineInitialParameters({
4545
const args = await readCommandLineArguments(argv);
4646

4747
const projectDirectoryPath = path.resolve(cwd, args.projectDirectory);
48-
const project = await readProject(projectDirectoryPath, { stderr });
48+
const project = await readProject(projectDirectoryPath, {
49+
stderr,
50+
fetchRemote: args.fetchRemote,
51+
});
4952
const tempDirectoryPath =
5053
args.tempDirectory === undefined
5154
? path.join(

src/project.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,18 @@ function examineReleaseVersion(packageVersion: SemVer): ReleaseVersion {
7474
* @param projectDirectoryPath - The path to the project.
7575
* @param args - Additional arguments.
7676
* @param args.stderr - A stream that can be used to write to standard error.
77+
* @param args.fetchRemote - Whether to synchronize local tags with remote.
7778
* @returns An object that represents information about the project.
7879
* @throws if the project does not contain a root `package.json` (polyrepo and
7980
* monorepo) or if any of the workspaces specified in the root `package.json` do
8081
* not have `package.json`s (monorepo only).
8182
*/
8283
export async function readProject(
8384
projectDirectoryPath: string,
84-
{ stderr }: { stderr: WriteStreamLike },
85+
{ fetchRemote, stderr }: { fetchRemote?: boolean; stderr: WriteStreamLike },
8586
): Promise<Project> {
8687
const repositoryUrl = await getRepositoryHttpsUrl(projectDirectoryPath);
87-
const tagNames = await getTagNames(projectDirectoryPath);
88+
const tagNames = await getTagNames(projectDirectoryPath, fetchRemote);
8889
const rootPackage = await readMonorepoRootPackage({
8990
packageDirectoryPath: projectDirectoryPath,
9091
projectDirectoryPath,

src/repo.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,17 @@ export async function branchExists(
256256
* advised to only run this once.
257257
*
258258
* @param repositoryDirectoryPath - The path to the repository directory.
259+
* @param fetchRemote - Whether to synchronize local tags with remote.
259260
* @returns The names of the tags.
260261
* @throws If no tags are found and the local git history is incomplete.
261262
*/
262263
export async function getTagNames(
263264
repositoryDirectoryPath: string,
265+
fetchRemote?: boolean,
264266
): Promise<string[]> {
265-
await runGitCommandWithin(repositoryDirectoryPath, 'fetch', ['--tags']);
267+
if (typeof fetchRemote !== 'boolean' || fetchRemote) {
268+
await runGitCommandWithin(repositoryDirectoryPath, 'fetch', ['--tags']);
269+
}
266270

267271
const tagNames = await getLinesFromGitCommandWithin(
268272
repositoryDirectoryPath,

0 commit comments

Comments
 (0)