blob: 024266c7dd3d23db285578bed5b83a0e6fc48ff5 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
/*******************************************************************************
* Copyright (C) 2015, Max Hohenegger <eclipse@hohenegger.eu>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.egit.gitflow.ui.internal.actions;
import java.io.IOException;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.expressions.IEvaluationContext;
import org.eclipse.core.resources.IResource;
import org.eclipse.egit.gitflow.GitFlowRepository;
import org.eclipse.egit.ui.internal.selection.SelectionUtils;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jgit.annotations.Nullable;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.ui.handlers.HandlerUtil;
/**
*
*/
public class GitFlowHandlerUtil {
/**
* @param event
* @return Selected GitFlowRepository
*/
public static @Nullable GitFlowRepository getRepository(ExecutionEvent event) {
ISelection selection = HandlerUtil
.getCurrentSelection(event);
IStructuredSelection structuredSelection = SelectionUtils
.getStructuredSelection(selection);
Repository repository = SelectionUtils
.getRepository(structuredSelection);
if (repository == null) {
return null;
}
return new GitFlowRepository(repository);
}
static IResource[] gatherResourceToOperateOn(ExecutionEvent event) {
return getSelectedResources(event);
}
static IResource[] getSelectedResources(ExecutionEvent event) {
IStructuredSelection selection = getSelection(event);
return SelectionUtils.getSelectedResources(selection);
}
static IStructuredSelection getSelection(ExecutionEvent event) {
if (event == null) {
throw new IllegalArgumentException("event must not be NULL"); //$NON-NLS-1$
}
Object context = event.getApplicationContext();
if (context instanceof IEvaluationContext) {
return SelectionUtils.getSelection((IEvaluationContext) context);
}
return StructuredSelection.EMPTY;
}
static String gatherRevision(ExecutionEvent event) throws IOException {
final GitFlowRepository gfRepo = GitFlowHandlerUtil
.getRepository(event);
if (gfRepo == null) {
throw new IllegalStateException(
"Gitflow command called with no Gitflow repository present"); //$NON-NLS-1$
}
Ref develop = gfRepo.getRepository()
.exactRef(gfRepo.getConfig().getDevelopFull());
if (develop == null) {
throw new IllegalStateException(
"Gitflow command called on Gitflow repository with no develop branch. " //$NON-NLS-1$
+ "The Gitflow configuration is either corrupt or incomplete."); //$NON-NLS-1$
}
return develop.getName();
}
}
|