Skip to content

Commit

Permalink
fix: create new upstream branch
Browse files Browse the repository at this point in the history
close #808
  • Loading branch information
Vinzent03 committed Nov 24, 2024
1 parent f8464e6 commit c5a95c1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
9 changes: 8 additions & 1 deletion src/gitManager/isomorphicGit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -824,11 +824,18 @@ export class IsomorphicGit extends GitManager {
const [remote, branch] = splitRemoteBranch(remoteBranch);
const branchInfo = await this.branchInfo();

await this.wrapFS(
git.push({
...this.getRepo(),
remote: remote,
remoteRef: branch,
})
);

await this.setConfig(
`branch.${branchInfo.current}.merge`,
`refs/heads/${branch}`
);
await this.setConfig(`branch.${branch}.remote`, remote);
}

updateGitPath(_: string): Promise<void> {
Expand Down
8 changes: 3 additions & 5 deletions src/gitManager/simpleGit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -829,14 +829,12 @@ export class SimpleGit extends GitManager {
try {
// git 1.8+
await this.git.branch(["--set-upstream-to", remoteBranch]);
} catch (e) {
console.error(e);
} catch {
try {
// git 1.7 - 1.8
await this.git.branch(["--set-upstream", remoteBranch]);
} catch (e) {
console.error(e);
// fallback
} catch {
// fallback for when setting upstream branch to a branch that does not exist on the remote yet. Setting it with push instead.
await this.git.push(
// @ts-expect-error A type error occurs here because the third element could be undefined.
// However, it is unlikely to be undefined due to the `remoteBranch`'s format, and error handling is in place.
Expand Down
9 changes: 4 additions & 5 deletions src/ui/modals/generalModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ export class GeneralModal extends SuggestModal<string> {
}

openAndGetResult(): Promise<string> {
if (this.config.initialValue != undefined) {
this.inputEl.value = this.config.initialValue;
this.inputEl.dispatchEvent(new Event("input"));
}

return new Promise((resolve) => {
this.resolve = resolve;
this.open();
if (this.config.initialValue != undefined) {
this.inputEl.value = this.config.initialValue;
this.inputEl.dispatchEvent(new Event("input"));
}
});
}

Expand Down

0 comments on commit c5a95c1

Please sign in to comment.