001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.maven.scm.provider.git.command.branch;
020
021import java.io.File;
022
023import org.apache.maven.scm.ScmFileSet;
024import org.apache.maven.scm.command.branch.BranchScmResult;
025import org.apache.maven.scm.command.checkout.CheckOutScmResult;
026import org.apache.maven.scm.provider.git.GitScmTestUtils;
027import org.apache.maven.scm.repository.ScmRepository;
028import org.apache.maven.scm.tck.command.branch.BranchCommandTckTest;
029import org.junit.Test;
030
031import static org.junit.Assert.assertFalse;
032
033/**
034 * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
035 */
036public abstract class GitBranchCommandTckTest extends BranchCommandTckTest {
037    /**
038     * {@inheritDoc}
039     */
040    public void initRepo() throws Exception {
041        GitScmTestUtils.initRepo("src/test/resources/repository/", getRepositoryRoot(), getWorkingDirectory());
042    }
043
044    @Override
045    protected CheckOutScmResult checkOut(File workingDirectory, ScmRepository repository) throws Exception {
046        try {
047            return super.checkOut(workingDirectory, repository);
048        } finally {
049            GitScmTestUtils.setDefaultGitConfig(workingDirectory);
050        }
051    }
052
053    @Test
054    public void testPushBranchRejected() throws Exception {
055        String branch = getBranch();
056
057        GitScmTestUtils.setupRejectAllCommitsPrePushHook(getWorkingCopy());
058        @SuppressWarnings("deprecation")
059        BranchScmResult branchResult = getScmManager()
060                .getProviderByUrl(getScmUrl())
061                .branch(getScmRepository(), new ScmFileSet(getWorkingCopy()), branch);
062
063        assertFalse("Branch should not have been pushed", branchResult.isSuccess());
064    }
065}