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

Commit e8355b3

Browse files
committed
address feedback
1 parent 3ca706f commit e8355b3

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

src/commands/link/index.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export default class LinkIndex extends Command {
116116
try {
117117
currentBranch = execSync("git symbolic-ref --short HEAD", { encoding: "utf-8" }).trim();
118118
} catch (error) {
119-
this.log(chalk.red("Unable to determine the current branch. Are you inside a Git repository?"));
119+
this.log(chalk.red("Unable to determine the current branch."));
120120
throw error;
121121
}
122122

@@ -129,9 +129,9 @@ export default class LinkIndex extends Command {
129129
this.exit(1);
130130
}
131131

132-
const hasRemoteOrigin = await hasGitRemoteUrl(gitConfigFilePath);
132+
const remoteUrl = await getGitRemoteUrl(gitConfigFilePath);
133133

134-
if (!hasRemoteOrigin) {
134+
if (!remoteUrl) {
135135
this.log(chalk.red("`hyp link` requires a git remote to work"));
136136
const gitRoot = execSync("git rev-parse --show-toplevel", { encoding: "utf-8" }).trim();
137137
const projectName = path.basename(gitRoot);
@@ -143,8 +143,6 @@ export default class LinkIndex extends Command {
143143
this.exit(1);
144144
}
145145

146-
const gitUrl = await getGitRemoteUrl(gitConfigFilePath);
147-
148146
// check the .hypermode/settings.json and see if there is a installationId with a key for the github owner. if there is,
149147
// continue, if not send them to github app installation page, and then go to callback server, and add installation id to settings.json
150148

@@ -161,7 +159,7 @@ export default class LinkIndex extends Command {
161159
return;
162160
}
163161

164-
const { gitOwner, repoName } = parseGitUrl(gitUrl);
162+
const { gitOwner, repoName } = parseGitUrl(remoteUrl);
165163

166164
const repoFullName = `${gitOwner}/${repoName}`;
167165

@@ -175,7 +173,7 @@ export default class LinkIndex extends Command {
175173
}
176174

177175
// call hypermode getRepoId with the installationId and the git url, if it returns a repoId, continue, if not, throw an error
178-
const repoId = await sendGetRepoIdReq(settings.jwt, installationId, gitUrl);
176+
const repoId = await sendGetRepoIdReq(settings.jwt, installationId, remoteUrl);
179177

180178
if (!repoId) {
181179
throw new Error("No repoId found for the given installationId and gitUrl");

src/util/index.ts

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

128-
export async function hasGitRemoteUrl(filePath: string): Promise<boolean> {
128+
export async function getGitRemoteUrl(filePath: string): Promise<string | null> {
129129
const content = await fs.readFile(filePath, "utf8");
130130
const remoteMatch = content.match(/\[remote "origin"]\n\s+url = (.*)/);
131-
if (!remoteMatch) {
132-
return false;
133-
}
134131

135-
return true;
136-
}
137-
export async function getGitRemoteUrl(filePath: string): Promise<string> {
138-
const content = await fs.readFile(filePath, "utf8");
139-
const remoteMatch = content.match(/\[remote "origin"]\n\s+url = (.*)/);
140132
if (!remoteMatch) {
141-
throw new Error(chalk.red("No remote origin found in .git/config, please set up a remote origin with `git remote add origin <url>`."));
133+
return null;
142134
}
143135

144136
return remoteMatch[1];

0 commit comments

Comments
 (0)