1
1
mirror of https://github.com/kahole/edamagit.git synced 2024-09-11 07:15:31 +03:00

adds stash worktree command

This commit is contained in:
kahole 2020-03-27 17:11:37 +01:00
parent 0e30aa67ab
commit a0e48a890e
2 changed files with 24 additions and 3 deletions

View File

@ -24,6 +24,7 @@
"quotes": [2, "single", { "avoidEscape": true, "allowTemplateLiterals": true }],
"curly": "warn",
"no-empty": "off",
"no-unused-vars": "off"
"no-unused-vars": "off",
"semi": "warn"
}
}

View File

@ -11,8 +11,8 @@ const stashingMenu = {
{ label: 'p', description: 'Pop', action: popStash },
{ label: 'a', description: 'Apply', action: applyStash },
{ label: 'k', description: 'Drop', action: dropStash },
// { label: 'i', description: 'Save index', action: (menuState: MenuState) => stash(menuState, ['--']) },
// { label: 'w', description: 'Save worktree', action: (menuState: MenuState) => stash(menuState, ['--']) },
// { label: 'i', description: 'Save index', action: stashIndex },
{ label: 'w', description: 'Save worktree', action: stashWorktree },
{ label: 'x', description: 'Save keeping index', action: (menuState: MenuState) => stash(menuState, ['--keep-index']) },
]
};
@ -44,6 +44,26 @@ async function stash({ repository, switches }: MenuState, stashArgs: string[] =
}
}
async function stashWorktree({ repository, switches }: MenuState) {
if (repository.magitState?.HEAD?.commit) {
const intermediaryCommitArgs = ['commit', '--message', 'intermediary stash commit'];
const resetCommitArgs = ['reset', '--soft', repository.magitState?.HEAD?.commit];
try {
try {
await gitRun(repository, intermediaryCommitArgs);
} catch { }
await stash({ repository, switches });
return gitRun(repository, resetCommitArgs);
} catch (error) {
await gitRun(repository, resetCommitArgs);
throw error;
}
}
}
function applyStash() {
return commands.executeCommand('git.stashApply');
}