[git] allow to call "Rebase..." action when the HEAD is detached

IDEA-195601

GitOrigin-RevId: b53f5adfc6a1bc7375a0e09d68313e6c98673ccb
This commit is contained in:
Julia Beliaeva
2024-03-12 11:11:41 +00:00
committed by intellij-monorepo-bot
parent 34760d0f55
commit 269a7a6ce7
4 changed files with 7 additions and 11 deletions
@@ -299,8 +299,6 @@ rebase.notification.failed.stash.text=Could not stash local uncommitted changes:
rebase.notification.no.rebase.in.progress.abort.title=Cannot abort rebase
rebase.notification.no.rebase.in.progress.continue.title=Cannot continue rebase
rebase.notification.no.rebase.in.progress.message=No rebase in progress
rebase.notification.not.allowed.detached.message.first=You are in the detached HEAD state in {0}.
rebase.notification.not.allowed.detached.message.second=Rebase is not possible.
rebase.notification.not.allowed.empty.repository.message=Repository {0} is empty.
rebase.notification.not.allowed.grafting.message.first=There is an unfinished cherry-pick process in {0}.
rebase.notification.not.allowed.grafting.message.second=You should finish it before starting a rebase.
@@ -39,7 +39,7 @@ public class GitRebase extends DumbAwareAction {
if (project == null || !hasGitRepositories(project) || !getRebasingRepositories(project).isEmpty()) {
presentation.setEnabledAndVisible(false);
}
else if (getRepositoriesInStates(project, Repository.State.NORMAL).isEmpty()) {
else if (getRepositoriesInStates(project, Repository.State.NORMAL, Repository.State.DETACHED).isEmpty()) {
presentation.setEnabled(false);
}
else {
@@ -54,6 +54,7 @@ import java.util.regex.Pattern;
import static com.intellij.dvcs.DvcsUtil.getShortRepositoryName;
import static com.intellij.openapi.ui.Messages.getWarningIcon;
import static com.intellij.openapi.vcs.VcsNotifier.IMPORTANT_ERROR_NOTIFICATION;
import static com.intellij.util.ObjectUtils.chooseNotNull;
import static com.intellij.util.ObjectUtils.notNull;
import static com.intellij.util.containers.ContainerUtil.*;
import static git4idea.GitActionIdsHolder.Id.*;
@@ -492,11 +493,12 @@ public class GitRebaseProcess {
String upstream = myRebaseSpec.getParams().getUpstream();
for (GitRepository repository : myRebaseSpec.getAllRepositories()) {
if (repository.getCurrentBranchName() == null) {
LOG.error("No current branch in " + repository);
String currentBranchName = chooseNotNull(repository.getCurrentBranchName(), repository.getCurrentRevision());
if (currentBranchName == null) {
LOG.error("No current branch or revision in " + repository);
return true;
}
String rebasingBranch = notNull(myRebaseSpec.getParams().getBranch(), repository.getCurrentBranchName());
String rebasingBranch = notNull(myRebaseSpec.getParams().getBranch(), currentBranchName);
if (isRebasingPublishedCommit(repository, upstream, rebasingBranch)) {
return askIfShouldRebasePublishedCommit();
}
@@ -132,7 +132,7 @@ public final class GitRebaseUtils {
Repository.State state = repository.getState();
String repositoryName = getShortRepositoryName(repository);
String message = switch (state) {
case NORMAL -> {
case NORMAL, DETACHED -> {
if (repository.isFresh()) {
yield GitBundle.message("rebase.notification.not.allowed.empty.repository.message", repositoryName);
}
@@ -154,10 +154,6 @@ public final class GitRebaseUtils {
.append(GitBundle.message("rebase.notification.not.allowed.reverting.message.first", repositoryName)).br()
.append(GitBundle.message("rebase.notification.not.allowed.reverting.message.second"))
.toString();
case DETACHED -> new HtmlBuilder()
.append(GitBundle.message("rebase.notification.not.allowed.detached.message.first", repositoryName)).br()
.append(GitBundle.message("rebase.notification.not.allowed.detached.message.second"))
.toString();
};
if (message != null) {
VcsNotifier.getInstance(project).notifyError(