1
|
|
<?php
|
2
|
|
/**
|
3
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
4
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
5
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
6
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
7
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
8
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
9
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
10
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
11
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
12
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
13
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
14
|
|
*
|
15
|
|
* This software consists of voluntary contributions made by many individuals
|
16
|
|
* and is licensed under the LGPL. For more information please see
|
17
|
|
* <http://phing.info>.
|
18
|
|
*/
|
19
|
|
|
20
|
|
/**
|
21
|
|
* Repository archive task
|
22
|
|
*
|
23
|
|
* @author Siad Ardroumli <siad.ardroumli@gmail.com>
|
24
|
|
* @package phing.tasks.ext.git
|
25
|
|
* @see VersionControl_Git
|
26
|
|
*/
|
27
|
|
class GitArchiveTask extends GitBaseTask
|
28
|
|
{
|
29
|
|
/**
|
30
|
|
* @var string|false $format
|
31
|
|
*/
|
32
|
|
private $format = false;
|
33
|
|
|
34
|
|
/**
|
35
|
|
* @var PhingFile $output
|
36
|
|
*/
|
37
|
|
private $output;
|
38
|
|
|
39
|
|
/**
|
40
|
|
* @var string|false $prefix
|
41
|
|
*/
|
42
|
|
private $prefix = false;
|
43
|
|
|
44
|
|
/**
|
45
|
|
* @var string $treeish
|
46
|
|
*/
|
47
|
|
private $treeish;
|
48
|
|
|
49
|
|
/**
|
50
|
|
* @var string|false $remoteRepo
|
51
|
|
*/
|
52
|
|
private $remoteRepo = false;
|
53
|
|
|
54
|
|
/**
|
55
|
|
* The main entry point for the task
|
56
|
|
*/
|
57
|
1
|
public function main()
|
58
|
|
{
|
59
|
1
|
if (null === $this->getRepository() && false === $this->getRemoteRepo()) {
|
60
|
1
|
throw new BuildException('"repository" is required parameter');
|
61
|
|
}
|
62
|
|
|
63
|
1
|
if (null === $this->getTreeish()) {
|
64
|
1
|
throw new BuildException('"treeish" is required parameter');
|
65
|
|
}
|
66
|
|
|
67
|
1
|
$cmd = $this->getGitClient(false, $this->getRepository() ?? './')
|
68
|
1
|
->getCommand('archive')
|
69
|
1
|
->setOption('prefix', $this->prefix)
|
70
|
1
|
->setOption('output', $this->output !== null ? $this->output->getPath() : false)
|
71
|
1
|
->setOption('format', $this->format)
|
72
|
1
|
->setOption('remote', $this->remoteRepo)
|
73
|
1
|
->addArgument($this->treeish);
|
74
|
|
|
75
|
1
|
$this->log('Git command : ' . $cmd->createCommandString(), Project::MSG_DEBUG);
|
76
|
|
|
77
|
1
|
$cmd->execute();
|
78
|
|
|
79
|
1
|
$msg = 'git-archive: archivating "' . $this->getRepository() . '" repository (' . $this->getTreeish() . ')';
|
80
|
1
|
$this->log($msg, Project::MSG_INFO);
|
81
|
|
}
|
82
|
|
|
83
|
|
/**
|
84
|
|
* @return string
|
85
|
|
*/
|
86
|
0
|
public function getFormat()
|
87
|
|
{
|
88
|
0
|
return $this->format;
|
89
|
|
}
|
90
|
|
|
91
|
|
/**
|
92
|
|
* @param string $format
|
93
|
|
*/
|
94
|
1
|
public function setFormat($format)
|
95
|
|
{
|
96
|
1
|
$this->format = $format;
|
97
|
|
}
|
98
|
|
|
99
|
|
/**
|
100
|
|
* @return PhingFile
|
101
|
|
*/
|
102
|
0
|
public function getOutput()
|
103
|
|
{
|
104
|
0
|
return $this->output;
|
105
|
|
}
|
106
|
|
|
107
|
|
/**
|
108
|
|
* @param PhingFile $output
|
109
|
|
*/
|
110
|
1
|
public function setOutput(PhingFile $output)
|
111
|
|
{
|
112
|
1
|
$this->output = $output;
|
113
|
|
}
|
114
|
|
|
115
|
|
/**
|
116
|
|
* @return string
|
117
|
|
*/
|
118
|
0
|
public function getPrefix()
|
119
|
|
{
|
120
|
0
|
return $this->prefix;
|
121
|
|
}
|
122
|
|
|
123
|
|
/**
|
124
|
|
* @param string $prefix
|
125
|
|
*/
|
126
|
0
|
public function setPrefix($prefix)
|
127
|
|
{
|
128
|
0
|
$this->prefix = $prefix;
|
129
|
|
}
|
130
|
|
|
131
|
|
/**
|
132
|
|
* @return string
|
133
|
|
*/
|
134
|
1
|
public function getTreeish()
|
135
|
|
{
|
136
|
1
|
return $this->treeish;
|
137
|
|
}
|
138
|
|
|
139
|
|
/**
|
140
|
|
* @param string $treeish
|
141
|
|
*/
|
142
|
1
|
public function setTreeish($treeish)
|
143
|
|
{
|
144
|
1
|
$this->treeish = $treeish;
|
145
|
|
}
|
146
|
|
|
147
|
|
/**
|
148
|
|
* @return string
|
149
|
|
*/
|
150
|
1
|
public function getRemoteRepo()
|
151
|
|
{
|
152
|
1
|
return $this->remoteRepo;
|
153
|
|
}
|
154
|
|
|
155
|
|
/**
|
156
|
|
* @param string $repo
|
157
|
|
*/
|
158
|
1
|
public function setRemoteRepo($repo)
|
159
|
|
{
|
160
|
1
|
$this->remoteRepo = $repo;
|
161
|
|
}
|
162
|
|
}
|