View Javadoc

1   package com.aragost.javahg.merge;
2   
3   import java.util.List;
4   
5   import com.aragost.javahg.Changeset;
6   import com.aragost.javahg.commands.RemoveCommand;
7   import com.aragost.javahg.commands.RevertCommand;
8   
9   public class KeepDeleteConflict extends MergeFile {
10  
11      private State state = State.KEEP;
12  
13      /**
14       * Is the local parent the parent where the file is kept
15       */
16      private boolean localKeep;
17  
18      public enum State {
19          KEEP, DELETE
20      };
21  
22      public KeepDeleteConflict(ConflictResolvingContext mergeState, String fileName, State localState) {
23          super(mergeState, fileName);
24          this.localKeep = localState.equals(State.KEEP);
25      }
26  
27      public State getState() {
28          return state;
29      }
30  
31      public void update(State state) {
32          if (this.state.equals(state)) {
33              return;
34          }
35          String fn = getFilename();
36          switch (state) {
37          case KEEP:
38              RevertCommand.on(getRepository()).rev(getKeepParent().getNode()).noBackup().execute(fn);
39              break;
40          case DELETE:
41              List<String> removed = RemoveCommand.on(getRepository()).force().execute(fn);
42              if (removed.size() != 1 || !removed.get(0).equals(fn)) {
43                  throw new RuntimeException("remove failed to removed file: " + fn);
44              }
45              break;
46          default:
47              throw new IllegalStateException("Unhandled state");
48          }
49          this.state = state;
50      }
51  
52      public void keep() {
53          update(State.KEEP);
54      }
55  
56      public void delete() {
57          update(State.DELETE);
58      }
59  
60      public Changeset getKeepParent() {
61          if (this.localKeep) {
62              return getMergeCtx().getLocal();
63          } else {
64              return getMergeCtx().getRemote();
65          }
66      }
67  }