forked from thathoff/kirby-git-content
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.php
96 lines (84 loc) · 1.92 KB
/
helpers.php
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
require_once('Git.php/Git.php');
/**
* Compose Commit message for content repository
*
* @param string $commitMessage
* @return false
*/
function gitCommitContent($commitMessage)
{
gitCommit($commitMessage,"../content");
}
/**
* Compose Commit message for accounts repository
*
* @param string $commitMessage
* @return false
*/
function gitCommitAccounts($commitMessage)
{
gitCommit($commitMessage,"../site/accounts");
}
/**
* Compose Commit message for avatars repository
*
* @param string $commitMessage
* @return false
*/
function gitCommitAvatars($commitMessage)
{
gitCommit($commitMessage,"../assets/avatars");
}
/**
* Compose Commit message, appends " by Username"
*
* @param string $commitMessage
*
* @return false
*/
function gitCommit($commitMessage, $repoPath)
{
$debugMode = c::get('debug', false);
$branch = c::get('gcapc-branch', 'master');
$pull = c::get('gcapc-pull', true);
$push = c::get('gcapc-push', true);
$commit = c::get('gcapc-commit', true);
$gitBin = c::get('gcapc-gitBin', '');
$windowsMode = c::get('gcapc-windowsMode', false);
/*
* Setup git environment
*/
if ($windowsMode) {
Git::windows_mode();
}
if ($gitBin) {
Git::set_bin($gitBin);
}
$repo = Git::open($repoPath);
if ($debugMode) {
if (!$repo->test_git()) {
echo 'git could not be found or is not working properly. ' . Git::get_bin();
exit;
}
if (!Git::is_repo($repo)) {
echo '$repo is not an instance of GitRepo';
exit;
}
}
/*
* Git Pull, Commit and Push
*/
if ($pull) {
$repo->checkout($branch);
$repo->pull('origin', $branch);
}
if ($commit) {
$repo->add('.');
$repo->commit($commitMessage . ' by ' . site()->user());
}
if ($push) {
$repo->push('origin', $branch);
}
return false;
}