Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
CiviCRM Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Development
CiviCRM Core
Commits
cd6b6c41
Commit
cd6b6c41
authored
8 years ago
by
totten
Browse files
Options
Downloads
Patches
Plain Diff
bin/givi - Update to satisfy civilint
parent
0a03e42f
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/givi
+37
-58
37 additions, 58 deletions
bin/givi
with
37 additions
and
58 deletions
bin/givi
+
37
−
58
View file @
cd6b6c41
...
...
@@ -13,7 +13,7 @@ class DirStack {
/**
* @param array $dirs
*/
function
__construct
(
$dirs
=
array
())
{
public
function
__construct
(
$dirs
=
array
())
{
$this
->
dirs
=
$dirs
;
}
...
...
@@ -22,17 +22,18 @@ class DirStack {
*
* @throws Exception
*/
function
push
(
$dir
)
{
public
function
push
(
$dir
)
{
$this
->
dirs
[]
=
getcwd
();
if
(
!
chdir
(
$dir
))
{
throw
new
Exception
(
"Failed to chdir(
$dir
)"
);
}
}
function
pop
()
{
public
function
pop
()
{
$oldDir
=
array_pop
(
$this
->
dirs
);
chdir
(
$oldDir
);
}
}
/**
...
...
@@ -94,6 +95,7 @@ class PullRequest {
public
function
getRequestorRepoUrl
()
{
return
$this
->
data
->
head
->
repo
->
git_url
;
}
}
/**
...
...
@@ -184,7 +186,7 @@ class Givi {
/**
*
*/
function
__construct
()
{
public
function
__construct
()
{
$this
->
dirStack
=
new
DirStack
();
$this
->
repos
=
array
(
'core'
=>
'.'
,
...
...
@@ -201,7 +203,7 @@ class Givi {
*
* @throws Exception
*/
function
main
(
$args
)
{
public
function
main
(
$args
)
{
if
(
!
$this
->
parseOptions
(
$args
))
{
printf
(
"Error parsing arguments
\n
"
);
$this
->
doHelp
();
...
...
@@ -228,31 +230,40 @@ class Givi {
case
'checkout'
:
call_user_func_array
(
array
(
$this
,
'doCheckoutAll'
),
$this
->
arguments
);
break
;
case
'fetch'
:
call_user_func_array
(
array
(
$this
,
'doFetchAll'
),
$this
->
arguments
);
break
;
case
'status'
:
call_user_func_array
(
array
(
$this
,
'doStatusAll'
),
$this
->
arguments
);
break
;
case
'begin'
:
call_user_func_array
(
array
(
$this
,
'doBegin'
),
$this
->
arguments
);
break
;
case
'resume'
:
call_user_func_array
(
array
(
$this
,
'doResume'
),
$this
->
arguments
);
break
;
case
'review'
:
call_user_func_array
(
array
(
$this
,
'doReview'
),
$this
->
arguments
);
break
;
//case 'merge-forward':
// call_user_func_array(array($this, 'doMergeForward'), $this->arguments);
// break;
case
'push'
:
call_user_func_array
(
array
(
$this
,
'doPush'
),
$this
->
arguments
);
break
;
case
'help'
:
case
''
:
$this
->
doHelp
();
break
;
default
:
return
$this
->
returnError
(
"unrecognized action:
{
$this
->
action
}
\n
"
);
}
...
...
@@ -271,7 +282,7 @@ class Givi {
* @param $args
* @return bool
*/
function
parseOptions
(
$args
)
{
public
function
parseOptions
(
$args
)
{
$this
->
branches
=
array
();
$this
->
arguments
=
array
();
...
...
@@ -321,7 +332,7 @@ class Givi {
return
TRUE
;
}
function
doHelp
()
{
public
function
doHelp
()
{
$program
=
basename
(
$this
->
program
);
echo
"Givi - Coordinate git checkouts across CiviCRM repositories
\n
"
;
echo
"Scenario:
\n
"
;
...
...
@@ -380,7 +391,7 @@ class Givi {
*
* @return bool
*/
function
doCheckoutAll
(
$baseBranch
=
NULL
)
{
public
function
doCheckoutAll
(
$baseBranch
=
NULL
)
{
if
(
!
$baseBranch
)
{
return
$this
->
returnError
(
"Missing <branch>
\n
"
);
}
...
...
@@ -399,7 +410,7 @@ class Givi {
/**
* @return bool
*/
function
doStatusAll
()
{
public
function
doStatusAll
()
{
foreach
(
$this
->
repos
as
$repo
=>
$relPath
)
{
$this
->
run
(
$repo
,
$relPath
,
'git'
,
'status'
);
}
...
...
@@ -411,7 +422,7 @@ class Givi {
*
* @return bool
*/
function
doBegin
(
$baseBranch
=
NULL
)
{
public
function
doBegin
(
$baseBranch
=
NULL
)
{
if
(
!
$baseBranch
)
{
return
$this
->
returnError
(
"Missing <base-branch>
\n
"
);
}
...
...
@@ -444,7 +455,7 @@ class Givi {
* @return bool
* @throws Exception
*/
function
doResume
(
$baseBranch
=
NULL
)
{
public
function
doResume
(
$baseBranch
=
NULL
)
{
if
(
!
$baseBranch
)
{
return
$this
->
returnError
(
"Missing <base-branch>
\n
"
);
}
...
...
@@ -475,7 +486,7 @@ class Givi {
*
* @return bool
*/
function
doReview
(
$baseBranch
=
NULL
)
{
public
function
doReview
(
$baseBranch
=
NULL
)
{
if
(
!
$this
->
doCheckoutAll
(
$baseBranch
))
{
return
FALSE
;
}
...
...
@@ -507,47 +518,13 @@ class Givi {
return
TRUE
;
}
/*
If we want merge-forward changes to be subject to PR process, then this
should useful. Currently using a simpler process based on
toosl/scripts/merge-forward
function doMergeForward($maintBranch, $devBranch) {
if (!$maintBranch) {
return $this->returnError("Missing <maintenace-base-branch>\n");
}
if (!$devBranch) {
return $this->returnError("Missing <development-base-branch>\n");
}
list ($maintBranchRepo, $maintBranchName) = $this->parseBranchRepo($maintBranch);
list ($devBranchRepo, $devBranchName) = $this->parseBranchRepo($devBranch);
$newBranchRepo = $devBranchRepo;
$newBranchName = $maintBranchName . '-' . $devBranchName . '-' . date('Y-m-d-H-i-s');
if ($this->fetch) {
$this->doFetchAll();
}
foreach ($this->repos as $repo => $relPath) {
$filteredMaintBranch = $this->filterBranchName($repo, $maintBranch);
$filteredDevBranch = $this->filterBranchName($repo, $devBranch);
$filteredNewBranchName = $this->filterBranchName($repo, $newBranchName);
$this->run($repo, $relPath, 'git', 'checkout', '-b', $filteredNewBranchName, $filteredDevBranch);
$this->run($repo, $relPath, 'git', 'merge', $filteredMaintBranch);
}
}
*/
/**
* @param $newBranchRepo
* @param $newBranchNames
*
* @return bool
*/
function
doPush
(
$newBranchRepo
,
$newBranchNames
)
{
public
function
doPush
(
$newBranchRepo
,
$newBranchNames
)
{
if
(
!
$newBranchRepo
)
{
return
$this
->
returnError
(
"Missing <remote>
\n
"
);
}
...
...
@@ -580,7 +557,7 @@ class Givi {
* @param string $name branch name
* @return bool
*/
function
hasLocalBranch
(
$repo
,
$name
)
{
public
function
hasLocalBranch
(
$repo
,
$name
)
{
$path
=
$this
->
repos
[
$repo
]
.
'/.git/refs/heads/'
.
$name
;
return
file_exists
(
$path
);
}
...
...
@@ -596,7 +573,7 @@ class Givi {
* @throws Exception
* @return array
*/
function
parseBranchRepo
(
$ref
,
$defaultRemote
=
'origin'
)
{
public
function
parseBranchRepo
(
$ref
,
$defaultRemote
=
'origin'
)
{
$parts
=
explode
(
'/'
,
$ref
);
if
(
count
(
$parts
)
==
1
)
{
return
array
(
$defaultRemote
,
$parts
[
1
]);
...
...
@@ -620,7 +597,7 @@ class Givi {
*
* @return string
*/
function
run
(
$repoName
,
$runDir
,
$command
)
{
public
function
run
(
$repoName
,
$runDir
,
$command
)
{
$this
->
dirStack
->
push
(
$runDir
);
$args
=
func_get_args
();
...
...
@@ -644,7 +621,7 @@ class Givi {
return
$r
;
}
function
doFetchAll
()
{
public
function
doFetchAll
()
{
foreach
(
$this
->
repos
as
$repo
=>
$relPath
)
{
$this
->
run
(
$repo
,
$relPath
,
'git'
,
'fetch'
,
'--all'
);
}
...
...
@@ -656,7 +633,7 @@ class Givi {
*
* @return array ($repoName => $gitRef)
*/
function
resolveBranches
(
$default
,
$overrides
)
{
public
function
resolveBranches
(
$default
,
$overrides
)
{
$branches
=
$overrides
;
foreach
(
$this
->
repos
as
$repo
=>
$relPath
)
{
if
(
!
isset
(
$branches
[
$repo
]))
{
...
...
@@ -672,7 +649,7 @@ class Givi {
*
* @return string
*/
function
filterBranchName
(
$repoName
,
$branchName
)
{
public
function
filterBranchName
(
$repoName
,
$branchName
)
{
if
(
$branchName
==
''
)
{
return
''
;
}
...
...
@@ -698,7 +675,7 @@ class Givi {
* @throws Exception
* @return array ($repoName => $repoDir)
*/
function
filterRepos
(
$filter
,
$repos
)
{
public
function
filterRepos
(
$filter
,
$repos
)
{
if
(
$filter
==
'all'
)
{
return
$repos
;
}
...
...
@@ -720,11 +697,12 @@ class Givi {
*
* @return bool
*/
function
returnError
(
$message
)
{
public
function
returnError
(
$message
)
{
echo
"
\n
ERROR: "
,
$message
,
"
\n\n
"
;
$this
->
doHelp
();
return
FALSE
;
}
}
/**
...
...
@@ -737,7 +715,7 @@ class HttpClient {
*
* @return bool
*/
static
function
download
(
$url
,
$file
)
{
public
static
function
download
(
$url
,
$file
)
{
// PHP native client is unreliable PITA for HTTPS
if
(
exec
(
"which wget"
))
{
self
::
run
(
'wget'
,
'-q'
,
'-O'
,
$file
,
$url
);
...
...
@@ -755,7 +733,7 @@ class HttpClient {
*
* @return mixed
*/
static
function
getJson
(
$url
)
{
public
static
function
getJson
(
$url
)
{
$file
=
tempnam
(
sys_get_temp_dir
(),
'givi-json-'
);
HttpClient
::
download
(
$url
,
$file
);
$data
=
json_decode
(
file_get_contents
(
$file
));
...
...
@@ -773,7 +751,7 @@ class HttpClient {
* @internal param string $runDir
* @return string
*/
static
function
run
(
$command
)
{
public
static
function
run
(
$command
)
{
$args
=
func_get_args
();
array_shift
(
$args
);
foreach
(
$args
as
$arg
)
{
...
...
@@ -784,6 +762,7 @@ class HttpClient {
return
$r
;
}
}
$givi
=
new
Givi
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment