diff --git a/forcePush.ts b/forcePush.ts index 86fb0e83..c8d6b0e1 100644 --- a/forcePush.ts +++ b/forcePush.ts @@ -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(); @@ -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,