Skip to content
This repository has been archived by the owner on Jun 15, 2018. It is now read-only.

Commit

Permalink
Added GitRemoteShowTask and a build target demonstrating its usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Kaufman committed Jan 4, 2011
1 parent 70bf5a7 commit 8b768ba
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 5 deletions.
94 changes: 94 additions & 0 deletions GitRemoteShowTask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

require_once 'phing/Task.php';
require_once 'phing/tasks/ext/git/GitBaseTask.php';

/**
* Wrapper around git-remote-show
*
* @see VersionControl_Git
*/
class GitRemoteShowTask extends GitBaseTask
{
/**
* Remote heads are not queried first with git ls-remote <name>. See -n of git-remote-show
* @var boolean
*/
private $noQuery = false;

/**
* <name> argument to git-remote-show
* @var string
*/
private $name;

/**
* Property name to set with output value from git-remote-show
* @var string
*/
private $outputProperty;

/**
* The main entry point for the task
*/
public function main()
{
if (null === $this->getRepository()) {
throw new BuildException('"repository" is required parameter');
}

if (null === $this->getName()) {
throw new BuildException('"name" is required parameter');
}

$client = $this->getGitClient(false, $this->getRepository());
$command = $client->getCommand('remote show');
$command->setOption('n', $this->isNoQuery());
$command->addArgument($this->getName());

try {
$output = $command->execute();
} catch (Exception $e) {
throw new BuildException('Task execution failed');
}

if (null !== $this->outputProperty) {
$this->project->setProperty($this->outputProperty, $output);
}

$this->log(
sprintf('git-remote-show: remotes for "%s" repository', $this->getRepository()),
Project::MSG_INFO);
$this->log('git-remote-show output: ' . trim($output), Project::MSG_INFO);
}

public function setNoQuery($flag)
{
$this->noQuery = (bool)$flag;
}

public function getNoQuery()
{
return $this->noQuery;
}

public function isNoQuery()
{
return $this->getNoQuery();
}

public function setName($remote)
{
$this->name = $remote;
}

public function getName()
{
return $this->name;
}

public function setOutputProperty($prop)
{
$this->outputProperty = $prop;
}
}
20 changes: 15 additions & 5 deletions build.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="phing-ext-gittasks" default="build">
<!-- add custom tasks from current directory -->
<taskdef name="gitdescribe" classname="GitDescribeTask" />
<taskdef name="gitdiff" classname="GitDiffTask" />
<taskdef name="gitlog" classname="GitLogTask" />
<taskdef name="gittag" classname="GitTagTask" />
<taskdef name="gitdescribe" classname="GitDescribeTask" />
<taskdef name="gitdiff" classname="GitDiffTask" />
<taskdef name="gitlog" classname="GitLogTask" />
<taskdef name="gitremoteshow" classname="GitRemoteShowTask" />
<taskdef name="gittag" classname="GitTagTask" />

<!-- assume our current directory IS the git repo to operate on -->
<property name="repo.dir" value="." />
Expand Down Expand Up @@ -62,6 +63,15 @@
<echo msg="Everything that's happened since HEAD^: ${gitLogOutput}" />
</target>

<!-- demonstrate task for git-remote-show command -->
<target name="gitremoteshow">
<echo msg="Equivalent to `git remote show origin`" />
<gitremoteshow repository="${repo.dir.resolved}"
name="origin"
outputProperty="gitRemoteShowOutput" />
<echo msg="All the dirt we have on origin: ${gitRemoteShowOutput}" />
</target>

<!-- demonstrate task for git-tag command -->
<target name="gittag">
<echo msg="Equivalent to `git tag -a -m 'foo bar baz' MyUnsignedTag`" />
Expand All @@ -87,5 +97,5 @@
</target>

<!-- do them all by default -->
<target name="build" depends="gitdescribe,gitdiff,gitlog,gittag" />
<target name="build" depends="gitdescribe,gitdiff,gitlog,gitremoteshow,gittag" />
</project>

0 comments on commit 8b768ba

Please sign in to comment.