mirror of
https://github.com/kahole/edamagit.git
synced 2024-10-26 09:00:54 +03:00
improve magit-branch-spinoff
implementation
This commit is contained in:
parent
0fd309db0a
commit
dc5cd8ddf7
@ -207,13 +207,49 @@ async function createNewSpinoff({ repository }: MenuState) {
|
|||||||
prompt: 'Name for new branch',
|
prompt: 'Name for new branch',
|
||||||
});
|
});
|
||||||
|
|
||||||
if (newBranchName && newBranchName.length > 0) {
|
if (!newBranchName || newBranchName.length < 1) {
|
||||||
const args = ['checkout', '-B', newBranchName];
|
return window.setStatusBarMessage(
|
||||||
return gitRun(repository.gitRepository, args);
|
|
||||||
} else {
|
|
||||||
window.setStatusBarMessage(
|
|
||||||
'No name given for new branch',
|
'No name given for new branch',
|
||||||
Constants.StatusMessageDisplayTimeout
|
Constants.StatusMessageDisplayTimeout
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (repository.branches.find(b => b.name === newBranchName)) {
|
||||||
|
return window.setStatusBarMessage(
|
||||||
|
`Cannot spin off ${newBranchName}. It already exists`,
|
||||||
|
Constants.StatusMessageDisplayTimeout
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const base = repository.HEAD?.name;
|
||||||
|
|
||||||
|
if (!base) {
|
||||||
|
return window.setStatusBarMessage(
|
||||||
|
'No branch checked out',
|
||||||
|
Constants.StatusMessageDisplayTimeout
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save current commit hash of base branch for later reference
|
||||||
|
const baseCommit = repository.HEAD?.commit;
|
||||||
|
|
||||||
|
// Get upsteam branch commit hash of base branch
|
||||||
|
const upstreamBranchCommit = repository.HEAD.upstreamRemote?.commit?.hash;
|
||||||
|
|
||||||
|
// Checkout new branch
|
||||||
|
await gitRun(repository.gitRepository, ['checkout', '-b', newBranchName]);
|
||||||
|
|
||||||
|
if (upstreamBranchCommit && baseCommit !== upstreamBranchCommit) {
|
||||||
|
await gitRun(repository.gitRepository, ['branch', '-f', base, upstreamBranchCommit]);
|
||||||
|
|
||||||
|
window.setStatusBarMessage(
|
||||||
|
`Branch ${base} was reset to upstream`,
|
||||||
|
Constants.StatusMessageDisplayTimeout
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
window.setStatusBarMessage(
|
||||||
|
`Branch ${base} not changed`,
|
||||||
|
Constants.StatusMessageDisplayTimeout
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user