Skip to content

Commit c5a95c1

Browse files
committed
fix: create new upstream branch
close #808
1 parent f8464e6 commit c5a95c1

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

src/gitManager/isomorphicGit.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,11 +824,18 @@ export class IsomorphicGit extends GitManager {
824824
const [remote, branch] = splitRemoteBranch(remoteBranch);
825825
const branchInfo = await this.branchInfo();
826826

827+
await this.wrapFS(
828+
git.push({
829+
...this.getRepo(),
830+
remote: remote,
831+
remoteRef: branch,
832+
})
833+
);
834+
827835
await this.setConfig(
828836
`branch.${branchInfo.current}.merge`,
829837
`refs/heads/${branch}`
830838
);
831-
await this.setConfig(`branch.${branch}.remote`, remote);
832839
}
833840

834841
updateGitPath(_: string): Promise<void> {

src/gitManager/simpleGit.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -829,14 +829,12 @@ export class SimpleGit extends GitManager {
829829
try {
830830
// git 1.8+
831831
await this.git.branch(["--set-upstream-to", remoteBranch]);
832-
} catch (e) {
833-
console.error(e);
832+
} catch {
834833
try {
835834
// git 1.7 - 1.8
836835
await this.git.branch(["--set-upstream", remoteBranch]);
837-
} catch (e) {
838-
console.error(e);
839-
// fallback
836+
} catch {
837+
// fallback for when setting upstream branch to a branch that does not exist on the remote yet. Setting it with push instead.
840838
await this.git.push(
841839
// @ts-expect-error A type error occurs here because the third element could be undefined.
842840
// However, it is unlikely to be undefined due to the `remoteBranch`'s format, and error handling is in place.

src/ui/modals/generalModal.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,13 @@ export class GeneralModal extends SuggestModal<string> {
3737
}
3838

3939
openAndGetResult(): Promise<string> {
40-
if (this.config.initialValue != undefined) {
41-
this.inputEl.value = this.config.initialValue;
42-
this.inputEl.dispatchEvent(new Event("input"));
43-
}
44-
4540
return new Promise((resolve) => {
4641
this.resolve = resolve;
4742
this.open();
43+
if (this.config.initialValue != undefined) {
44+
this.inputEl.value = this.config.initialValue;
45+
this.inputEl.dispatchEvent(new Event("input"));
46+
}
4847
});
4948
}
5049

0 commit comments

Comments
 (0)