项目:WebIDE-Backend
文件:RewordActionHandler.java
@Override
public RebaseResponse extractMessage(Repository repository) throws IOException {
List<RebasetodoLine> rebasetodoLines = repository.readRebasetodo(getRebasePath(repository,DONE),false);
// the last rebase_todo_line
RebasetodoLine line = rebasetodoLines.get(rebasetodoLines.size() - 1);
try (RevWalk walk = new RevWalk(repository)) {
ObjectReader or = repository.newObjectReader();
RevCommit commitToPick = walk.parseCommit(or.resolve(line.getCommit()).iterator().next());
String oldMessage = commitToPick.getFullMessage();
RebaseResponse response = new RebaseResponse(false,RebaseResponse.Status.INteraCTIVE_EDIT);
response.setMessage(oldMessage);
return response;
}
}
项目:github-merge
文件:GitUtil.java
public static void updatetodoLog(NotificationService notification,PullRequestKey request,Map<AbbreviatedobjectId,Commit> mappedCommits,List<RebasetodoLine> steps) {
for(int i = 0; i < steps.size(); i++) {
RebasetodoLine step = steps.get(i);
if(!mappedCommits.containsKey(step.getCommit())) {
notification.sendMessage(request,"Perform " + step.getCommit().toString() + " Action[remove]");
steps.remove(i);
i--;
continue;
}
Commit commit = mappedCommits.get(step.getCommit());
if(commit.getState() == State.DELETE) {
notification.sendMessage(request,"Perform " + step.getCommit().toString() + " " + " Action[remove]");
steps.remove(i);
i--;
continue;
}
try {
step.setAction(Action.parse(commit.getState().name().toLowerCase()));
} catch (Exception e) {
e.printstacktrace();
}
notification.sendMessage(request,"Perform " + step.getCommit().toString() + " " + step.getAction());
}
}
项目:incubator-netbeans
文件:CherryPickCommand.java
private void writetodoFile (Repository repository,List<RebasetodoLine> steps) throws IOException {
File f = new File(repository.getDirectory(),SEQUENCER);
if (f.canWrite()) {
RebasetodoFile todoFile = new RebasetodoFile(repository);
todoFile.writeRebasetodoFile(SEQUENCER + File.separator + SEQUENCER_Todo,steps,false);
}
}
项目:incubator-netbeans
文件:CherryPickCommand.java
private List<RebasetodoLine> readTodoFile (Repository repository) throws IOException {
String path = SEQUENCER + File.separator + SEQUENCER_Todo;
File f = new File(repository.getDirectory(),path);
if (f.canRead()) {
RebasetodoFile todoFile = new RebasetodoFile(repository);
return todoFile.readRebasetodo(SEQUENCER + File.separator + SEQUENCER_Todo,true);
}
return Collections.<RebasetodoLine>emptyList();
}
public static List<RebaseResponse.RebasetodoLine> loadFrom(List<RebasetodoLine> lines) {
List<RebaseResponse.RebasetodoLine> rebasetodoLines = new ArrayList<>();
for (RebasetodoLine line : lines) {
RebaseResponse.RebasetodoLine rebasetodoLine = new RebaseResponse.RebasetodoLine(
line.getAction().name(),line.getCommit().name(),line.getShortMessage());
rebasetodoLines.add(rebasetodoLine);
}
return rebasetodoLines;
}
public static List<RebasetodoLine> parseLines(List<RebaseResponse.RebasetodoLine> lines) {
List<RebasetodoLine> rebasetodoLines = new ArrayList<>();
for (RebaseResponse.RebasetodoLine line : lines) {
RebasetodoLine rebasetodoLine = new RebasetodoLine(
RebasetodoLine.Action.valueOf(line.getAction().name()),AbbreviatedobjectId.fromString(line.getCommit()),line.getShortMessage());
rebasetodoLines.add(rebasetodoLine);
}
return rebasetodoLines;
}
项目:incubator-netbeans
文件:CherryPickCommand.java
@Override
protected void run () throws GitException {
Repository repository = getRepository();
ObjectId originalCommit = getoriginalCommit();
ObjectId head = getHead();
List<RebasetodoLine> steps;
try {
switch (operation) {
case BEGIN:
// initialize sequencer and cherry-pick steps if there are
// more commits to cherry-pick
steps = prepareCommand(head);
// apply the selected steps
applySteps(steps,false);
break;
case ABORT:
// delete the sequencer and reset to the original head
if (repository.getRepositoryState() == RepositoryState.CHERRY_PICKING
|| repository.getRepositoryState() == RepositoryState.CHERRY_PICKING_RESOLVED) {
if (originalCommit == null) {
// maybe the sequencer is not created in that case simply reset to HEAD
originalCommit = head;
}
}
Utils.deleteRecursively(getSequencerFolder());
if (originalCommit != null) {
ResetCommand reset = new ResetCommand(repository,getClassFactory(),originalCommit.name(),GitClient.ResetType.HARD,new DelegatingGitProgressMonitor(monitor),listener);
reset.execute();
}
result = createCustomresult(GitCherryPickResult.CherryPickStatus.ABORTED);
break;
case QUIT:
// used to reset the sequencer only
Utils.deleteRecursively(getSequencerFolder());
switch (repository.getRepositoryState()) {
case CHERRY_PICKING:
// unresolved conflicts
result = createResult(CherryPickResult.CONFLICT);
break;
case CHERRY_PICKING_RESOLVED:
result = createCustomresult(GitCherryPickResult.CherryPickStatus.UNCOMMITTED);
break;
default:
result = createCustomresult(GitCherryPickResult.CherryPickStatus.OK);
break;
}
break;
case CONTINUE:
switch (repository.getRepositoryState()) {
case CHERRY_PICKING:
// unresolved conflicts,cannot continue
result = createResult(CherryPickResult.CONFLICT);
break;
case CHERRY_PICKING_RESOLVED:
// cannot continue without manual commit
result = createCustomresult(GitCherryPickResult.CherryPickStatus.UNCOMMITTED);
break;
default:
// read steps from sequencer and apply them
// if sequencer is empty this will be a noop
steps = readTodoFile(repository);
applySteps(steps,true);
break;
}
break;
default:
throw new IllegalStateException("Unexpected operation " + operation.name());
}
} catch (GitAPIException | IOException ex) {
throw new GitException(ex);
}
}
项目:incubator-netbeans
文件:CherryPickCommand.java
private void applySteps (List<RebasetodoLine> steps,boolean skipFirstStep) throws GitAPIException,IOException {
Repository repository = getRepository();
ObjectReader or = repository.newObjectReader();
CherryPickResult res = null;
boolean skipped = false;
List<Ref> cherryPickedRefs = new ArrayList<>();
for (Iterator<RebasetodoLine> it = steps.iterator(); it.hasNext();) {
RebasetodoLine step = it.next();
if (step.getAction() == RebasetodoLine.Action.PICK) {
if (skipFirstStep && !skipped) {
it.remove();
writetodoFile(repository,steps);
skipped = true;
continue;
}
Collection<ObjectId> ids = or.resolve(step.getCommit());
if (ids.size() != 1) {
throw new JGitInternalException("Could not resolve uniquely the abbreviated object ID");
}
org.eclipse.jgit.api.CherryPickCommand command = new Git(repository).cherryPick();
command.include(ids.iterator().next());
if (workAroundStrategyIssue) {
command.setStrategy(new FailuresDetectRecurciveStrategy());
}
res = command.call();
if (res.getStatus() == CherryPickResult.CherryPickStatus.OK) {
it.remove();
writetodoFile(repository,steps);
cherryPickedRefs.addAll(res.getCherryPickedRefs());
} else {
break;
}
} else {
it.remove();
}
}
if (res == null) {
result = createCustomresult(GitCherryPickResult.CherryPickStatus.OK,cherryPickedRefs);
} else {
result = createResult(res,cherryPickedRefs);
}
if (steps.isEmpty()) {
// sequencer no longer needed
Utils.deleteRecursively(getSequencerFolder());
}
}
项目:WebIDE-Backend
文件:SquashActionHandler.java
项目:WebIDE-Backend
文件:RebaseActionHandler.java
@Override
public RebasetodoLine.Action getAction() {
return EDIT;
}
项目:WebIDE-Backend
文件:RewordActionHandler.java
项目:github-merge
文件:GitUtil.java
public static void main(String[] args) throws IOException,GitAPIException {
try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
// all refs
try (Git git = new Git(repository)) {
InteractiveHandler handler = new InteractiveHandler() {
@Override
public void prepareSteps(List<RebasetodoLine> steps) {
// the handler receives the list of commits that are rebased,i.e. the ones on the local branch
for(RebasetodoLine step : steps) {
// for each step,you can decide which action should be taken
// default is PICK
try {
// by selecting "EDIT",the rebase will stop and ask you to edit the commit-contents
step.setAction(Action.EDIT);
} catch (IllegalTodoFileModification e) {
throw new IllegalStateException(e);
}
}
}
@Override
public String modifyCommitMessage(String oldMessage) {
return oldMessage;
}
};
RebaseResult result = git.rebase().setUpstream("origin/master").runInteractively(handler).call();
System.out.println("Rebase had state: " + result.getStatus() + ": " + result.getConflicts());
// because of the "EDIT" in the InteractiveHandler,the rebase was stopped in-between
// Now you can adjust the commit and continue rebasing with setoperation(RebaseCommand.Operation.CONTINUE)
// to use the local changes for the commit or setoperation(RebaseCommand.Operation.SKIP) to skip this
// commit (i.e. remove it from the branch!)
if(!result.getStatus().isSuccessful()) {
// if rebasing stopped or Failed,you can get back to the original state by running it with setoperation(RebaseCommand.Operation.ABORT)
result = git.rebase().setUpstream("origin/master").runInteractively(handler).setoperation(RebaseCommand.Operation.ABORT).call();
System.out.println("Aborted reabse with state: " + result.getStatus() + ": " + result.getConflicts());
}
}
}
}
项目:WebIDE-Backend
文件:RebaseActionHandler.java
RebasetodoLine.Action getAction();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。