-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontroller.php
More file actions
82 lines (61 loc) · 1.64 KB
/
controller.php
File metadata and controls
82 lines (61 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
include dirname(__FILE__)."/config.php";
// set up the environment
session_start();
$view = "default";
$views = array('commit','pull','push','status','branch','checkout','add','deploy');
if (in_array($_REQUEST['view'],$views)) $view = $_REQUEST['view'];
include dirname(__FILE__)."/Git.php";
if ($view != 'default')
{
$repo = Git::open(REPO);
$repo->setenv('user.name',GIT_NAME);
$repo->setenv('user.email',GIT_EMAIL);
}
switch ($view) {
case "status":
$out = $repo->status();
break;
case "add":
$out = $repo->add(".");
case "commit";
$message = ($_REQUEST['message'])?$_REQUEST['message']:'No Commit message supplied';
$active_branch = $repo->active_branch();
$out .= $repo->commit($message);
if ($_REQUEST['pushit'])
{
$out .= $repo->push('origin',$active_branch);
}
$view = "commit";
break;
case "branch":
// do stuff if needed
if ($_POST['checkout'])
{
$out = $repo->checkout($_POST['checkout']);
$out .= $repo->status();
}
if ($_POST['pull'])
{
$out = $repo->pull('origin',$_POST['pull']);
$out .= $repo->status();
}
if ($_POST['push'])
{
$out = $repo->push('origin',$_POST['push']);
$out .= $repo->status();
}
$branches = $repo->list_branches();
$active_branch = $repo->active_branch();
break;
case "deploy":
$branches = $repo->list_branches();
if (in_array($_POST['deploy'],$branches))
{
$branch = $_POST['deploy'];
$cmd = 'echo "/home/robert/web/deploy/deploy.sh ' . $branch . '" | at now';
exec($cmd);
$message = "Deploy Script launched for " . $branch . " branch - this may take a little bit";
}
break;
}