1
1
mirror of https://github.com/kahole/edamagit.git synced 2024-10-26 09:00:54 +03:00

adds 'push other' command (#105)

This commit is contained in:
kahole 2021-02-18 21:28:24 +01:00
parent 11dd43885b
commit 0780cde35a
2 changed files with 17 additions and 2 deletions

View File

@ -26,6 +26,7 @@ function generatePushingMenu(repository: MagitRepository) {
}
pushingMenuItems.push({ label: 'e', description: 'elsewhere', action: pushElsewhere });
pushingMenuItems.push({ label: 'o', description: 'another branch/commit', action: pushOther });
pushingMenuItems.push({ label: 'T', description: 'a tag', action: pushTag });
pushingMenuItems.push({ label: 't', description: 'all tags', action: pushAllTags });
@ -131,6 +132,20 @@ async function pushElsewhere() {
return commands.executeCommand('git.pushTo');
}
async function pushOther({ repository, switches }: MenuState) {
const ref = await MagitUtils.chooseRef(repository, 'Push', false, false, true);
const remote = await MagitUtils.chooseRef(repository, `Push ${ref} to`, false, false, true, true);
const [remoteName, ...remoteBranchNameParts] = remote.split('/');
const remoteBranchName = remoteBranchNameParts.join('/');
if (remote && ref) {
const args = ['push', ...MenuUtil.switchesToArgs(switches), remoteName, `${ref}:${remoteBranchName}`];
return gitRun(repository.gitRepository, args);
}
}
async function pushTag({ repository, switches }: MenuState) {
const remote = repository.HEAD?.upstreamRemote?.remote ?? repository.HEAD?.pushRemote?.remote;

View File

@ -143,7 +143,7 @@ export default class MagitUtils {
(repository.mergeChanges?.length ?? 0) > 0);
}
public static async chooseRef(repository: MagitRepository, prompt: string, showCurrent = false, showHEAD = false, allowFreeform = true): Promise<string> {
public static async chooseRef(repository: MagitRepository, prompt: string, showCurrent = false, showHEAD = false, allowFreeform = true, remoteOnly = false): Promise<string> {
const refs: PickMenuItem<string>[] = [];
@ -164,7 +164,7 @@ export default class MagitUtils {
}
refs.push(...repository.refs
.filter(ref => ref.name !== repository.HEAD?.name)
.filter(ref => ref.name !== repository.HEAD?.name && (!remoteOnly || ref.type === RefType.RemoteHead))
.sort((refA, refB) => refA.type - refB.type).map(r => ({
label: r.name!,
description: GitTextUtils.shortHash(r.commit),