Coverage Report - com.aragost.javahg.commands.IncomingCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
IncomingCommand
90%
18/20
75%
6/8
1.667
 
 1  
 /*
 2  
  * #%L
 3  
  * JavaHg
 4  
  * %%
 5  
  * Copyright (C) 2011 aragost Trifork ag
 6  
  * %%
 7  
  * Permission is hereby granted, free of charge, to any person obtaining a copy
 8  
  * of this software and associated documentation files (the "Software"), to deal
 9  
  * in the Software without restriction, including without limitation the rights
 10  
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 11  
  * copies of the Software, and to permit persons to whom the Software is
 12  
  * furnished to do so, subject to the following conditions:
 13  
  * 
 14  
  * The above copyright notice and this permission notice shall be included in
 15  
  * all copies or substantial portions of the Software.
 16  
  * 
 17  
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 18  
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 19  
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 20  
  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 21  
  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 22  
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 23  
  * THE SOFTWARE.
 24  
  * #L%
 25  
  */
 26  
 package com.aragost.javahg.commands;
 27  
 
 28  
 import java.io.File;
 29  
 import java.util.List;
 30  
 
 31  
 import com.aragost.javahg.Bundle;
 32  
 import com.aragost.javahg.Changeset;
 33  
 import com.aragost.javahg.Repository;
 34  
 import com.aragost.javahg.commands.flags.IncomingCommandFlags;
 35  
 import com.aragost.javahg.internals.HgInputStream;
 36  
 import com.aragost.javahg.internals.Utils;
 37  
 
 38  
 /**
 39  
  * Command class for executing <tt>hg incoming</tt>. Set flags from
 40  
  * {@link IncomingCommandFlags} and call the {@link #execute} method.
 41  
  */
 42  
 public class IncomingCommand extends IncomingCommandFlags {
 43  
 
 44  
     private File bundleFile;
 45  
 
 46  
     /**
 47  
      * @param repository
 48  
      *            the repository associated with this command.
 49  
      */
 50  
     public IncomingCommand(Repository repository) {
 51  6
         super(repository);
 52  6
         withDebugAndChangesetStyle();
 53  6
         cmdAppend("-y");
 54  6
     }
 55  
 
 56  
     @Override
 57  
     public IncomingCommand bundle(String file) {
 58  0
         this.bundleFile = new File(file);
 59  0
         return this;
 60  
     }
 61  
 
 62  
     /**
 63  
      * @param src
 64  
      *            the source repository.
 65  
      * @return bundle with incoming changesets
 66  
      */
 67  
     public Bundle execute(String src) {
 68  6
         if (this.bundleFile == null) {
 69  6
             this.bundleFile = Utils.createTempFile(".bundle");
 70  6
             cmdAppend("--bundle", this.bundleFile.getPath());
 71  
         }
 72  6
         HgInputStream stream = launchStream(src);
 73  6
         Bundle bundle = new Bundle(getRepository().getBaseRepository(), this.bundleFile, true);
 74  6
         List<Changeset> changesets = Changeset.readListFromStream(bundle.getOverlayRepository(), stream);
 75  6
         if (changesets.isEmpty()) {
 76  1
             bundle.close();
 77  1
             return null;
 78  
         }
 79  5
         bundle.init(changesets);
 80  5
         return bundle;
 81  
     }
 82  
 
 83  
     public Bundle execute(File directory) {
 84  5
         return execute(directory.getPath());
 85  
     }
 86  
 
 87  
     public Bundle execute(Repository repository) {
 88  5
         return execute(repository.getDirectory());
 89  
     }
 90  
 
 91  
     @Override
 92  
     public boolean isSuccessful() {
 93  6
         return super.isSuccessful() || getReturnCode() == 1;
 94  
     }
 95  
 }