Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions src/core/git/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,26 @@ export function getRepositoryName(directory: string): string | null {

function extractRepoNameFromConfig(content: string): string | null {
const lines = content.split('\n');
let inRemoteSection = false;

for (const line of lines) {
const trimmed = line.trim();

// Look for URL lines
const urlMatch = trimmed.match(/url\s*=\s*(.+)/);
if (urlMatch) {
const url = urlMatch[1].trim();
const repoName = extractRepoNameFromURL(url);
if (repoName) {
return repoName;
// Track section headers — only extract URLs from [remote "..."] sections,
// not [submodule "..."] sections whose URLs point to unrelated repos.
if (trimmed.startsWith('[')) {
inRemoteSection = /^\[remote\s+"/.test(trimmed);
continue;
}

if (inRemoteSection) {
const urlMatch = trimmed.match(/url\s*=\s*(.+)/);
if (urlMatch) {
const url = urlMatch[1].trim();
const repoName = extractRepoNameFromURL(url);
if (repoName) {
return repoName;
}
}
}
}
Expand Down
23 changes: 9 additions & 14 deletions src/core/parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ function getCachedRepositoryName(directory: string): string {
return repoName;
}

// Find parent repository by walking up the directory tree
// Find parent repository by walking up the directory tree.
// Only checks for actual .git/config with remotes — never uses the
// repositoryCache to avoid cross-project name pollution (e.g. a cached
// parent "/home/user" → "user" would incorrectly rename unrelated child projects).
function findParentRepository(directory: string): string | null {
let currentDir = directory;

Expand All @@ -44,19 +47,11 @@ function findParentRepository(directory: string): string | null {
break;
}

if (repositoryCache.has(parentDir)) {
const repoName = repositoryCache.get(parentDir)!;
if (repoName) {
repositoryCache.set(directory, repoName);
return repoName;
}
} else {
const repoName = getRepositoryName(parentDir);
if (repoName) {
repositoryCache.set(parentDir, repoName);
repositoryCache.set(directory, repoName);
return repoName;
}
const repoName = getRepositoryName(parentDir);
if (repoName) {
repositoryCache.set(parentDir, repoName);
repositoryCache.set(directory, repoName);
return repoName;
}

currentDir = parentDir;
Expand Down