/*
 * Copyright 2000-2013 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package hg4idea.test.history;

import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vcs.VcsTestUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.vcs.log.Hash;
import com.intellij.vcs.log.impl.HashImpl;
import hg4idea.test.HgPlatformTest;
import org.jetbrains.annotations.NotNull;
import org.zmlx.hg4idea.util.HgHistoryUtil;

import java.util.Arrays;
import java.util.Collection;

import static com.intellij.openapi.vcs.Executor.cd;
import static com.intellij.openapi.vcs.Executor.echo;
import static com.intellij.openapi.vcs.Executor.touch;
import static hg4idea.test.HgExecutor.hg;

/**
 * @author Nadya Zabrodina
 */
public class HgLogHistoryTest extends HgPlatformTest {

  @Override
  public void setUp() throws Exception {
    super.setUp();
    createBookmarksAndBranches(myRepository);
  }

  public void testContainedInBranchesInLogInfos() throws VcsException {
    Hash testHashForFirstCommit = HashImpl.build("0");
    Collection<String> branches = HgHistoryUtil.getDescendingHeadsOfBranches(myProject, myRepository, testHashForFirstCommit);
    //B_Bookmark should not be listed - it is inactive and not head//
    VcsTestUtil.assertEqualCollections(branches, Arrays.asList("default", "branchA", "branchB", "A_BookMark", "C_BookMark"));
  }

  private static void createBookmarksAndBranches(@NotNull VirtualFile repositoryRoot) {
    cd(repositoryRoot);
    hg("bookmark A_BookMark");
    hg("tag tag1");
    String aFile = "A.txt";
    touch(aFile, "base");
    hg("add " + aFile);
    hg("commit -m 'create file'");
    hg("branch branchA");
    hg("tag tag2");
    echo(aFile, " modify with a");
    hg("commit -m 'create branchA'");
    hg("bookmark B_BookMark --inactive");
    echo(aFile, " modify with AA");
    hg("commit -m 'modify branchA'");
    hg("up default");
    hg("branch branchB");
    hg("tag -l localTag");
    echo(aFile, " modify with b");
    hg("commit -m 'modify file in branchB'");
    hg("bookmark C_BookMark");
    hg("up branchA");
  }
}

@@ -1014,16 +1014,39 @@
 lection;
+%0Aimport java.util.List;
 %0A%0Aimport
@@ -1410,54 +1410,8 @@
 ();%0A
-    createBookmarksAndBranches(myRepository);%0A
   %7D%0A
@@ -1479,24 +1479,70 @@
 Exception %7B%0A
+    createBookmarksAndBranches(myRepository);%0A
     Hash tes
@@ -2059,28 +2059,8 @@
 %22);%0A
-    hg(%22tag tag1%22);%0A
     
@@ -2198,28 +2198,8 @@
 %22);%0A
-    hg(%22tag tag2%22);%0A
     
@@ -2401,24 +2401,24 @@
  default%22);%0A
+
     hg(%22bran
@@ -2435,35 +2435,8 @@
 %22);%0A
-    hg(%22tag -l localTag%22);%0A
     

test updated