Skip to content
Draft
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
26 changes: 24 additions & 2 deletions forcePush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,28 @@ export const forcePush: BranchSequencerBase = (argsBase) =>
const branch: Git.Reference = await repo.getCurrentBranch();
const upstreamBranch: Git.Reference | null = await Git.Branch.upstream(branch).catch(() => null);

/**
* TODO work out a good solution because we don't want the user
* to get interrupted while in-between the "push" flow,
* or at least handle it ourselves / ask the user how to continue
*
* maybe need to have a `--push --continue`?
* ugh, starts to get mixed up w/ other commands, idk!
* or could `--continue` be used in any circumstance,
* i.e. both in a rebase setting, and in a push setting?
*
* could maybe utilize --dry-run? or analyze ourselves? idk
*
* needs to be further explored with our `--sync` (TBD)
*
*
* on --force-if-includes, see:
* - `man git-push`
* - https://stackoverflow.com/a/65839129/9285308
* - https://github.com/gitextensions/gitextensions/issues/8753#issuecomment-763390579
*/
const forceWithLeaseOrForce: string = "--force-with-lease --force-if-includes";

if (!upstreamBranch) {
const remotes: string[] = await repo.getRemoteNames();

Expand Down Expand Up @@ -85,11 +107,11 @@ export const forcePush: BranchSequencerBase = (argsBase) =>
remote = answer;
}

const cmd = `push -u ${remote} ${branch.name()} --force`;
const cmd = `push -u ${remote} ${branch.name()} ${forceWithLeaseOrForce}`;
console.log(`running ${cmd}`);
execSyncInRepo(`${argsBase.gitCmd} ${cmd}`);
} else {
execSyncInRepo(`${argsBase.gitCmd} push --force`);
execSyncInRepo(`${argsBase.gitCmd} push ${forceWithLeaseOrForce}`);
}
},
delayMsBetweenCheckouts: 0,
Expand Down