Skip to content
This repository was archived by the owner on Aug 21, 2025. It is now read-only.

Commit 822fd0f

Browse files
committed
HYP-2624: hyp link should guide the user to create remote origin
1 parent 942cd77 commit 822fd0f

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/commands/link/index.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ import * as fs from "../../util/fs.js";
1313
import * as http from "node:http";
1414
import { URL } from "node:url";
1515
import open from "open";
16+
import { execSync } from "child_process";
17+
import path from "path";
1618

1719
import { ciStr } from "../../util/ci.js";
1820
import { getProjectsByOrgReq, sendMapRepoAndFinishProjectCreationReq, sendCreateProjectReq, sendGetRepoIdReq } from "../../util/graphql.js";
19-
import { confirmExistingProjectLink, confirmOverwriteCiHypFile, fileExists, getCiHypFilePath, getSettingsFilePath, getGitConfigFilePath, getGitRemoteUrl, getGithubWorkflowDir, promptProjectLinkSelection, promptProjectName, readSettingsJson, writeGithubInstallationIdToSettingsFile } from "../../util/index.js";
21+
import { confirmExistingProjectLink, confirmOverwriteCiHypFile, fileExists, getCiHypFilePath, getSettingsFilePath, getGitConfigFilePath, getGitRemoteUrl, getGithubWorkflowDir, promptProjectLinkSelection, promptProjectName, readSettingsJson, writeGithubInstallationIdToSettingsFile, hasGitRemoteUrl } from "../../util/index.js";
2022

2123
export default class LinkIndex extends Command {
2224
static override args = {};
@@ -109,6 +111,20 @@ export default class LinkIndex extends Command {
109111
throw new Error(chalk.red("No .git found in this directory. Please initialize a git repository with `git init`."));
110112
}
111113

114+
const hasRemoteOrigin = await hasGitRemoteUrl(gitConfigFilePath);
115+
116+
if (!hasRemoteOrigin) {
117+
this.log(chalk.red("`hyp link` requires a git remote to work"));
118+
const gitRoot = execSync("git rev-parse --show-toplevel", { encoding: "utf-8" }).trim();
119+
const projectName = path.basename(gitRoot);
120+
this.log(`Please create a GitHub repository: https://github.com/new?name=${projectName}`);
121+
this.log(`And push your code:`);
122+
this.log(`> git remote add origin <GIT_URL>`);
123+
this.log(`> git push -u origin main`);
124+
125+
return;
126+
}
127+
112128
const gitUrl = await getGitRemoteUrl(gitConfigFilePath);
113129

114130
// check the .hypermode/settings.json and see if there is a installationId with a key for the github owner. if there is,

src/util/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,15 @@ export function getGitConfigFilePath(): string {
125125
return path.join(getGitDir(), "config");
126126
}
127127

128+
export async function hasGitRemoteUrl(filePath: string): Promise<boolean> {
129+
const content = await fs.readFile(filePath, "utf8");
130+
const remoteMatch = content.match(/\[remote "origin"]\n\s+url = (.*)/);
131+
if (!remoteMatch) {
132+
return false;
133+
}
134+
135+
return true;
136+
}
128137
export async function getGitRemoteUrl(filePath: string): Promise<string> {
129138
const content = await fs.readFile(filePath, "utf8");
130139
const remoteMatch = content.match(/\[remote "origin"]\n\s+url = (.*)/);

0 commit comments

Comments
 (0)