Coverage Report - com.aragost.javahg.merge.BackoutConflictResolvingContext
 
Classes in this File Line Coverage Branch Coverage Complexity
BackoutConflictResolvingContext
88%
22/25
81%
13/16
6
 
 1  
 package com.aragost.javahg.merge;
 2  
 
 3  
 import java.io.IOException;
 4  
 
 5  
 import com.aragost.javahg.internals.AbstractCommand;
 6  
 import com.aragost.javahg.internals.HgInputStream;
 7  
 import com.aragost.javahg.internals.UnexpectedCommandOutputException;
 8  
 
 9  
 public class BackoutConflictResolvingContext extends ConflictResolvingContext {
 10  
 
 11  1
     private static final byte[] MERGING_WITH_CHANGESET = "merging with changeset ".getBytes();
 12  1
     private static final byte[] BACKS_OUT_CHANGESET = " backs out changeset ".getBytes();
 13  1
     private static final byte[] CHANGESET = "changeset".getBytes();
 14  1
     private static final byte[] REVERTING = "reverting".getBytes();
 15  1
     private static final byte[] CREATED_NEW_HEAD = "created new head".getBytes();
 16  
 
 17  
     private final boolean merge;
 18  
 
 19  
     public BackoutConflictResolvingContext(AbstractCommand command, boolean merge) {
 20  6
         super(command);
 21  
         
 22  6
         this.merge = merge;
 23  6
     }
 24  
 
 25  
     /**
 26  
      * Example:
 27  
      * <pre>
 28  
      * $ hg backout --merge 7:7
 29  
      * reverting foo.txt
 30  
      * created new head
 31  
      * changeset 9:664c3e4cbb2b backs out changeset 7:3f5bacea93aa
 32  
      * merging with changeset 9:664c3e4cbb2b
 33  
      * merging foo.txt
 34  
      * warning: conflicts during merge.
 35  
      * merging foo.txt incomplete! (edit conflicts, then use 'hg resolve --mark')
 36  
      * 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
 37  
      * use 'hg resolve' to retry unresolved file merges or 'hg update -C .' to abandon
 38  
      * </pre>
 39  
      * 
 40  
      * @see com.aragost.javahg.merge.ConflictResolvingContext#processStream(com.aragost.javahg.internals.HgInputStream,
 41  
      *      boolean)
 42  
      */
 43  
     @Override
 44  
     public void processStream(HgInputStream in, boolean whenUnknowReturn)
 45  
             throws IOException {
 46  6
         String createdChangeset = null;
 47  
         
 48  22
         while (!in.isEof()) {
 49  20
             if (in.match(REVERTING)) {
 50  8
                 in.upTo('\n');
 51  12
             } else if (in.match(CREATED_NEW_HEAD)) {
 52  2
                 in.upTo('\n');
 53  10
             } else if (in.match(CHANGESET)) {
 54  4
                 createdChangeset = in.textUpTo(BACKS_OUT_CHANGESET);
 55  4
                 in.upTo('\n');
 56  6
             } else if (in.match(MERGING_WITH_CHANGESET)) {
 57  2
                 in.upTo('\n');
 58  
             } else {
 59  
                 break;
 60  
             }
 61  
         }
 62  
 
 63  6
         if (createdChangeset == null && merge) {
 64  0
             if (whenUnknowReturn) {
 65  0
                 return;
 66  
             }
 67  0
             throw new UnexpectedCommandOutputException(this.getCommand(), null);
 68  
         }
 69  
 
 70  6
         super.processStream(in, whenUnknowReturn);
 71  6
     }
 72  
 
 73  
 }