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; 020 021import org.apache.maven.scm.ScmFileSet; 022import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository; 023import org.apache.maven.scm.provider.git.util.GitUtil; 024import org.apache.maven.scm.providers.gitlib.settings.Settings; 025import org.codehaus.plexus.util.cli.Commandline; 026 027/** 028 * Command utilities for git commands. 029 * 030 * @author <a href="mailto:jerome@coffeebreaks.org">Jerome Lacoste</a> 031 * 032 */ 033public class GitCommandUtils { 034 035 private GitCommandUtils() {} 036 037 public static Commandline getBaseCommand(String commandName, GitScmProviderRepository repo, ScmFileSet fileSet) { 038 return getBaseCommand(commandName, repo, fileSet, null); 039 } 040 041 public static Commandline getBaseCommand( 042 String commandName, GitScmProviderRepository repo, ScmFileSet fileSet, String options) { 043 Settings settings = GitUtil.getSettings(); 044 045 Commandline cl = new Commandline(); 046 047 cl.setExecutable(settings.getGitCommand()); 048 049 cl.setWorkingDirectory(fileSet.getBasedir().getAbsolutePath()); 050 051 if (settings.getTraceGitCommand() != null) { 052 cl.addEnvironment("GIT_TRACE", settings.getTraceGitCommand()); 053 } 054 055 cl.createArg().setLine(options); 056 cl.createArg().setValue(commandName); 057 058 return cl; 059 } 060 061 public static String getRevParseDateFormat() { 062 return GitUtil.getSettings().getRevParseDateFormat(); 063 } 064}