Constant for repo url
This commit is contained in:
@@ -3,7 +3,9 @@ import { existsSync } from "node:fs";
|
||||
import { dirname, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const UPDATE_REMOTE = "origin";
|
||||
export const UPDATE_REMOTE_URL =
|
||||
"https://git.harvmaster.com/Harvmaster/xo-cli.git";
|
||||
const UPDATE_REF_NAMESPACE = "xo-updater";
|
||||
const COMMAND_TIMEOUT_MS = 10_000;
|
||||
|
||||
export interface CommandResult {
|
||||
@@ -99,8 +101,8 @@ export class GitUpdateService {
|
||||
const fetchResult = await this.git([
|
||||
"fetch",
|
||||
"--quiet",
|
||||
UPDATE_REMOTE,
|
||||
`+refs/heads/${branch}:refs/remotes/${UPDATE_REMOTE}/${branch}`,
|
||||
UPDATE_REMOTE_URL,
|
||||
`+refs/heads/${branch}:refs/remotes/${UPDATE_REF_NAMESPACE}/${branch}`,
|
||||
]);
|
||||
if (fetchResult.code !== 0) {
|
||||
return {
|
||||
@@ -111,13 +113,13 @@ export class GitUpdateService {
|
||||
|
||||
const [headResult, targetResult, dirtyResult] = await Promise.all([
|
||||
this.git(["rev-parse", "HEAD"]),
|
||||
this.git(["rev-parse", `refs/remotes/${UPDATE_REMOTE}/${branch}`]),
|
||||
this.git(["rev-parse", `refs/remotes/${UPDATE_REF_NAMESPACE}/${branch}`]),
|
||||
this.git(["status", "--porcelain"]),
|
||||
]);
|
||||
if (headResult.code !== 0 || targetResult.code !== 0) {
|
||||
return {
|
||||
status: "unavailable",
|
||||
reason: `The branch ${branch} is not available on ${UPDATE_REMOTE}.`,
|
||||
reason: `The branch ${branch} is not available at the update repository.`,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -145,7 +147,7 @@ export class GitUpdateService {
|
||||
}
|
||||
return {
|
||||
status: "unavailable",
|
||||
reason: `Local branch ${branch} has diverged from ${UPDATE_REMOTE}/${branch}; update it manually.`,
|
||||
reason: `Local branch ${branch} has diverged from the update repository; update it manually.`,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -191,6 +193,8 @@ export class GitUpdateService {
|
||||
request.currentCommit,
|
||||
"--to",
|
||||
request.targetCommit,
|
||||
"--target-ref",
|
||||
`refs/remotes/${UPDATE_REF_NAMESPACE}/${request.branch}`,
|
||||
"--parent",
|
||||
String(process.pid),
|
||||
];
|
||||
|
||||
@@ -9,6 +9,7 @@ interface HelperOptions {
|
||||
branch: string;
|
||||
from: string;
|
||||
to: string;
|
||||
targetRef: string;
|
||||
parent: number;
|
||||
restart: boolean;
|
||||
}
|
||||
@@ -34,14 +35,25 @@ function parseOptions(args: string[]): HelperOptions {
|
||||
const branch = values.get("--branch");
|
||||
const from = values.get("--from");
|
||||
const to = values.get("--to");
|
||||
const targetRef = values.get("--target-ref");
|
||||
const parent = Number(values.get("--parent"));
|
||||
if (!repo || !branch || !from || !to || !Number.isInteger(parent)) {
|
||||
if (
|
||||
!repo ||
|
||||
!branch ||
|
||||
!from ||
|
||||
!to ||
|
||||
!targetRef ||
|
||||
!Number.isInteger(parent)
|
||||
) {
|
||||
throw new Error("Missing updater helper arguments.");
|
||||
}
|
||||
if (!/^[0-9a-f]{40,64}$/u.test(from) || !/^[0-9a-f]{40,64}$/u.test(to)) {
|
||||
throw new Error("Invalid updater commit identifiers.");
|
||||
}
|
||||
return { repo, branch, from, to, parent, restart };
|
||||
if (targetRef !== `refs/remotes/xo-updater/${branch}`) {
|
||||
throw new Error("Invalid updater target reference.");
|
||||
}
|
||||
return { repo, branch, from, to, targetRef, parent, restart };
|
||||
}
|
||||
|
||||
function run(command: string, args: string[], cwd: string): Promise<void> {
|
||||
@@ -129,11 +141,7 @@ async function main(): Promise<void> {
|
||||
const [branch, head, target, status] = await Promise.all([
|
||||
capture("git", ["branch", "--show-current"], options.repo),
|
||||
capture("git", ["rev-parse", "HEAD"], options.repo),
|
||||
capture(
|
||||
"git",
|
||||
["rev-parse", `refs/remotes/origin/${options.branch}`],
|
||||
options.repo,
|
||||
),
|
||||
capture("git", ["rev-parse", options.targetRef], options.repo),
|
||||
capture("git", ["status", "--porcelain"], options.repo),
|
||||
]);
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user