Skip to content

Commit 2aca7c8

Browse files
committed
feat: append .git to https remote url if not present
close #867
1 parent 0754fd8 commit 2aca7c8

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/main.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import { BranchModal } from "./ui/modals/branchModal";
4949
import { GeneralModal } from "./ui/modals/generalModal";
5050
import GitView from "./ui/sourceControl/sourceControl";
5151
import { BranchStatusBar } from "./ui/statusBar/branchStatusBar";
52-
import { splitRemoteBranch } from "./utils";
52+
import { formatRemoteUrl, splitRemoteBranch } from "./utils";
5353
import Tools from "./tools";
5454
import SplitDiffView from "./ui/diff/splitDiffView";
5555

@@ -671,7 +671,11 @@ export default class ObsidianGit extends Plugin {
671671
this.settings.basePath = dir;
672672
}
673673
try {
674-
await this.gitManager.clone(url, dir, depthInt);
674+
await this.gitManager.clone(
675+
formatRemoteUrl(url),
676+
dir,
677+
depthInt
678+
);
675679
new Notice("Cloned new repo.");
676680
new Notice("Please restart Obsidian");
677681

@@ -1246,7 +1250,10 @@ I strongly recommend to use "Source mode" for viewing the conflicted files. For
12461250
// urlModal.inputEl.setText(oldUrl ?? "");
12471251
const remoteURL = await urlModal.openAndGetResult();
12481252
if (remoteURL) {
1249-
await this.gitManager.setRemote(remoteName, remoteURL);
1253+
await this.gitManager.setRemote(
1254+
remoteName,
1255+
formatRemoteUrl(remoteURL)
1256+
);
12501257
return remoteName;
12511258
}
12521259
}

src/utils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,15 @@ export function fileIsBinary(path: string): boolean {
174174

175175
return BINARY_EXTENSIONS.includes(ext);
176176
}
177+
178+
export function formatRemoteUrl(url: string): string {
179+
if (
180+
url.startsWith("https://github.com/") ||
181+
url.startsWith("https://gitlab.com/")
182+
) {
183+
if (!url.endsWith(".git")) {
184+
url = url + ".git";
185+
}
186+
}
187+
return url;
188+
}

0 commit comments

Comments
 (0)