Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
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
justinfreeman (Agileware)
Core
Commits
1f4afc40
Commit
1f4afc40
authored
11 years ago
by
Kurund Jalmi
Browse files
Options
Downloads
Plain Diff
Merge pull request #428 from totten/4.3-givi
givi - Add "--setup" which calls setup.sh
parents
4d2290ee
4384f1bb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/givi
+139
-9
139 additions, 9 deletions
bin/givi
with
139 additions
and
9 deletions
bin/givi
+
139
−
9
View file @
1f4afc40
...
@@ -69,11 +69,26 @@ class Givi {
...
@@ -69,11 +69,26 @@ class Givi {
*/
*/
protected
$rebase
=
FALSE
;
protected
$rebase
=
FALSE
;
/**
* @var string, the word 'all' or comma-delimited list of repo names
*/
protected
$repoFilter
=
'all'
;
/**
/**
* @var array ($repoName => $relPath)
* @var array ($repoName => $relPath)
*/
*/
protected
$repos
;
protected
$repos
;
/**
* @var bool
*/
protected
$useGencode
=
FALSE
;
/**
* @var bool
*/
protected
$useSetup
=
FALSE
;
/**
/**
* @var array, non-hyphenated arguments after the basedir
* @var array, non-hyphenated arguments after the basedir
*/
*/
...
@@ -120,6 +135,8 @@ class Givi {
...
@@ -120,6 +135,8 @@ class Givi {
return
$this
->
returnError
(
"Root appears to be invalid -- missing too many repos. Try --root=<dir>
\n
"
);
return
$this
->
returnError
(
"Root appears to be invalid -- missing too many repos. Try --root=<dir>
\n
"
);
}
}
$this
->
repos
=
$this
->
filterRepos
(
$this
->
repoFilter
,
$this
->
repos
);
// Run the action
// Run the action
switch
(
$this
->
action
)
{
switch
(
$this
->
action
)
{
case
'checkout'
:
case
'checkout'
:
...
@@ -137,6 +154,12 @@ class Givi {
...
@@ -137,6 +154,12 @@ class Givi {
case
'resume'
:
case
'resume'
:
call_user_func_array
(
array
(
$this
,
'doResume'
),
$this
->
arguments
);
call_user_func_array
(
array
(
$this
,
'doResume'
),
$this
->
arguments
);
break
;
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
'help'
:
case
''
:
case
''
:
$this
->
doHelp
();
$this
->
doHelp
();
...
@@ -145,6 +168,13 @@ class Givi {
...
@@ -145,6 +168,13 @@ class Givi {
return
$this
->
returnError
(
"unrecognized action:
{
$this
->
action
}
\n
"
);
return
$this
->
returnError
(
"unrecognized action:
{
$this
->
action
}
\n
"
);
}
}
if
(
$this
->
useSetup
)
{
$this
->
run
(
'core'
,
$this
->
civiRoot
.
'/bin'
,
'bash'
,
'setup.sh'
);
}
elseif
(
$this
->
useGencode
)
{
$this
->
run
(
'core'
,
$this
->
civiRoot
.
'/xml'
,
'php'
,
'GenCode.php'
);
}
$this
->
dirStack
->
pop
();
$this
->
dirStack
->
pop
();
}
}
...
@@ -166,12 +196,21 @@ class Givi {
...
@@ -166,12 +196,21 @@ class Givi {
elseif
(
$arg
==
'--dry-run'
||
$arg
==
'-n'
)
{
elseif
(
$arg
==
'--dry-run'
||
$arg
==
'-n'
)
{
$this
->
dryRun
=
TRUE
;
$this
->
dryRun
=
TRUE
;
}
}
elseif
(
$arg
==
'--gencode'
)
{
$this
->
useGencode
=
TRUE
;
}
elseif
(
$arg
==
'--setup'
)
{
$this
->
useSetup
=
TRUE
;
}
elseif
(
preg_match
(
'/^--d([678])/'
,
$arg
,
$matches
))
{
elseif
(
preg_match
(
'/^--d([678])/'
,
$arg
,
$matches
))
{
$this
->
drupalVersion
=
$matches
[
1
];
$this
->
drupalVersion
=
$matches
[
1
];
}
}
elseif
(
preg_match
(
'/^--root=(.*)/'
,
$arg
,
$matches
))
{
elseif
(
preg_match
(
'/^--root=(.*)/'
,
$arg
,
$matches
))
{
$this
->
civiRoot
=
$matches
[
1
];
$this
->
civiRoot
=
$matches
[
1
];
}
}
elseif
(
preg_match
(
'/^--repos=(.*)/'
,
$arg
,
$matches
))
{
$this
->
repoFilter
=
$matches
[
1
];
}
elseif
(
preg_match
(
'/^--(core|packages|joomla|drupal|wordpress)=(.*)/'
,
$arg
,
$matches
))
{
elseif
(
preg_match
(
'/^--(core|packages|joomla|drupal|wordpress)=(.*)/'
,
$arg
,
$matches
))
{
$this
->
branches
[
$matches
[
1
]]
=
$matches
[
2
];
$this
->
branches
[
$matches
[
1
]]
=
$matches
[
2
];
}
}
...
@@ -203,18 +242,25 @@ class Givi {
...
@@ -203,18 +242,25 @@ class Givi {
echo
"
$program
[options] status
\n
"
;
echo
"
$program
[options] status
\n
"
;
echo
"
$program
[options] begin <base-branch> [--core=<new-branch>|--drupal=<new-branch>|...]
\n
"
;
echo
"
$program
[options] begin <base-branch> [--core=<new-branch>|--drupal=<new-branch>|...]
\n
"
;
echo
"
$program
[options] resume [--rebase] <base-branch> [--core=<custom-branch>|--drupal=<custom-branch>|...]
\n
"
;
echo
"
$program
[options] resume [--rebase] <base-branch> [--core=<custom-branch>|--drupal=<custom-branch>|...]
\n
"
;
#echo " $program [options] merge-forward <maintenace-branch> <development-branch>\n";
#echo " $program [options] push <remote> <branch>[:<branch>]\n";
echo
"Actions:
\n
"
;
echo
"Actions:
\n
"
;
echo
" checkout: Checkout same branch name on all repos
\n
"
;
echo
" checkout: Checkout same branch name on all repos
\n
"
;
echo
" fetch: Fetch remote changes on all repos
\n
"
;
echo
" fetch: Fetch remote changes on all repos
\n
"
;
echo
" status: Display status on all repos
\n
"
;
echo
" status: Display status on all repos
\n
"
;
echo
" begin: Begin work on a new branch on some repo (and use base-branch for all others)
\n
"
;
echo
" begin: Begin work on a new branch on some repo (and use base-branch for all others)
\n
"
;
echo
" resume: Resume work on an existing branch on some repo (and use base-branch for all others)
\n
"
;
echo
" resume: Resume work on an existing branch on some repo (and use base-branch for all others)
\n
"
;
#echo " merge-forward: On each repo, merge changes from maintenance branch to development branch\n";
#echo " push: On each repo, push a branch to a remote (Note: only intended for use with merge-forward)\n";
echo
"Common options:
\n
"
;
echo
"Common options:
\n
"
;
echo
" --dry-run: Don't do anything; only print commands that would be run
\n
"
;
echo
" --dry-run: Don't do anything; only print commands that would be run
\n
"
;
echo
" --d6: Specify that Drupal branches should use 6.x-* prefixes
\n
"
;
echo
" --d6: Specify that Drupal branches should use 6.x-* prefixes
\n
"
;
echo
" --d7: Specify that Drupal branches should use 7.x-* prefixes (default)
\n
"
;
echo
" --d7: Specify that Drupal branches should use 7.x-* prefixes (default)
\n
"
;
echo
" --fetch: Fetch the latest code before creating, updating, or checking-out anything
\n
"
;
echo
" --fetch: Fetch the latest code before creating, updating, or checking-out anything
\n
"
;
echo
" --repos=X: Restrict operations to the listed repos (comma-delimited list) (default: all)"
;
echo
" --root=X: Specify CiviCRM root directory (default: .)
\n
"
;
echo
" --root=X: Specify CiviCRM root directory (default: .)
\n
"
;
echo
" --gencode: Run xml/GenCode after checking out code
\n
"
;
echo
" --setup: Run bin/setup.sh (incl xml/GenCode) after checking out code
\n
"
;
echo
"Special options:
\n
"
;
echo
"Special options:
\n
"
;
echo
" --core=X: Specify the branch to use on the core repository
\n
"
;
echo
" --core=X: Specify the branch to use on the core repository
\n
"
;
echo
" --packages=X: Specify the branch to use on the packages repository
\n
"
;
echo
" --packages=X: Specify the branch to use on the packages repository
\n
"
;
...
@@ -242,14 +288,14 @@ class Givi {
...
@@ -242,14 +288,14 @@ class Givi {
foreach
(
$this
->
repos
as
$repo
=>
$relPath
)
{
foreach
(
$this
->
repos
as
$repo
=>
$relPath
)
{
$filteredBranch
=
$this
->
filterBranchName
(
$repo
,
$branches
[
$repo
]);
$filteredBranch
=
$this
->
filterBranchName
(
$repo
,
$branches
[
$repo
]);
$this
->
run
(
$relPath
,
'git'
,
'checkout'
,
$filteredBranch
);
$this
->
run
(
$repo
,
$relPath
,
'git'
,
'checkout'
,
$filteredBranch
);
}
}
return
TRUE
;
return
TRUE
;
}
}
function
doStatusAll
()
{
function
doStatusAll
()
{
foreach
(
$this
->
repos
as
$repo
=>
$relPath
)
{
foreach
(
$this
->
repos
as
$repo
=>
$relPath
)
{
$this
->
run
(
$relPath
,
'git'
,
'status'
);
$this
->
run
(
$repo
,
$relPath
,
'git'
,
'status'
);
}
}
return
TRUE
;
return
TRUE
;
}
}
...
@@ -271,10 +317,10 @@ class Givi {
...
@@ -271,10 +317,10 @@ class Givi {
$filteredBaseBranch
=
$this
->
filterBranchName
(
$repo
,
$baseBranch
);
$filteredBaseBranch
=
$this
->
filterBranchName
(
$repo
,
$baseBranch
);
if
(
$filteredBranch
==
$filteredBaseBranch
)
{
if
(
$filteredBranch
==
$filteredBaseBranch
)
{
$this
->
run
(
$relPath
,
'git'
,
'checkout'
,
$filteredBranch
);
$this
->
run
(
$repo
,
$relPath
,
'git'
,
'checkout'
,
$filteredBranch
);
}
}
else
{
else
{
$this
->
run
(
$relPath
,
'git'
,
'checkout'
,
'-b'
,
$filteredBranch
,
$filteredBaseBranch
);
$this
->
run
(
$repo
,
$relPath
,
'git'
,
'checkout'
,
'-b'
,
$filteredBranch
,
$filteredBaseBranch
);
}
}
}
}
}
}
...
@@ -295,12 +341,70 @@ class Givi {
...
@@ -295,12 +341,70 @@ class Givi {
$filteredBranch
=
$this
->
filterBranchName
(
$repo
,
$branches
[
$repo
]);
$filteredBranch
=
$this
->
filterBranchName
(
$repo
,
$branches
[
$repo
]);
$filteredBaseBranch
=
$this
->
filterBranchName
(
$repo
,
$baseBranch
);
$filteredBaseBranch
=
$this
->
filterBranchName
(
$repo
,
$baseBranch
);
$this
->
run
(
$relPath
,
'git'
,
'checkout'
,
$filteredBranch
);
$this
->
run
(
$repo
,
$relPath
,
'git'
,
'checkout'
,
$filteredBranch
);
if
(
$filteredBranch
!=
$filteredBaseBranch
&&
$this
->
rebase
)
{
if
(
$filteredBranch
!=
$filteredBaseBranch
&&
$this
->
rebase
)
{
list
(
$baseRemoteRepo
,
$baseRemoteBranch
)
=
$this
->
parseBranchRepo
(
$filteredBaseBranch
);
list
(
$baseRemoteRepo
,
$baseRemoteBranch
)
=
$this
->
parseBranchRepo
(
$filteredBaseBranch
);
$this
->
run
(
$relPath
,
'git'
,
'pull'
,
'--rebase'
,
$baseRemoteRepo
,
$baseRemoteBranch
);
$this
->
run
(
$repo
,
$relPath
,
'git'
,
'pull'
,
'--rebase'
,
$baseRemoteRepo
,
$baseRemoteBranch
);
}
}
}
/*
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);
}
}
*/
function
doPush
(
$newBranchRepo
,
$newBranchNames
)
{
if
(
!
$newBranchRepo
)
{
return
$this
->
returnError
(
"Missing <remote>
\n
"
);
}
if
(
!
$newBranchNames
)
{
return
$this
->
returnError
(
"Missing <branch>[:<branch>]
\n
"
);
}
if
(
FALSE
!==
strpos
(
$newBranchNames
,
':'
))
{
list
(
$newBranchFromName
,
$newBranchToName
)
=
explode
(
':'
,
$newBranchNames
);
foreach
(
$this
->
repos
as
$repo
=>
$relPath
)
{
$filteredFromName
=
$this
->
filterBranchName
(
$repo
,
$newBranchFromName
);
$filteredToName
=
$this
->
filterBranchName
(
$repo
,
$newBranchToName
);
$this
->
run
(
$repo
,
$relPath
,
'git'
,
'push'
,
$newBranchRepo
,
$filteredFromName
.
':'
.
$filteredToName
);
}
}
else
{
foreach
(
$this
->
repos
as
$repo
=>
$relPath
)
{
$filteredName
=
$this
->
filterBranchName
(
$repo
,
$newBranchNames
);
$this
->
run
(
$repo
,
$relPath
,
'git'
,
'push'
,
$newBranchRepo
,
$filteredName
);
}
}
}
}
}
}
/**
/**
...
@@ -333,16 +437,17 @@ class Givi {
...
@@ -333,16 +437,17 @@ class Givi {
* @param string $command
* @param string $command
* @return string
* @return string
*/
*/
function
run
(
$runDir
,
$command
)
{
function
run
(
$repoName
,
$runDir
,
$command
)
{
$this
->
dirStack
->
push
(
$runDir
);
$this
->
dirStack
->
push
(
$runDir
);
$args
=
func_get_args
();
$args
=
func_get_args
();
array_shift
(
$args
);
array_shift
(
$args
);
array_shift
(
$args
);
array_shift
(
$args
);
array_shift
(
$args
);
foreach
(
$args
as
$arg
)
{
foreach
(
$args
as
$arg
)
{
$command
.
=
' '
.
escapeshellarg
(
$arg
);
$command
.
=
' '
.
escapeshellarg
(
$arg
);
}
}
printf
(
"
\n
RUN [%s]: %s
\n
"
,
$r
unDir
,
$command
);
printf
(
"
\
n\n\
n
RUN [%s]: %s
\n
"
,
$r
epoName
,
$command
);
if
(
$this
->
dryRun
)
{
if
(
$this
->
dryRun
)
{
$r
=
NULL
;
$r
=
NULL
;
}
else
{
}
else
{
...
@@ -355,7 +460,7 @@ class Givi {
...
@@ -355,7 +460,7 @@ class Givi {
function
doFetchAll
()
{
function
doFetchAll
()
{
foreach
(
$this
->
repos
as
$repo
=>
$relPath
)
{
foreach
(
$this
->
repos
as
$repo
=>
$relPath
)
{
$this
->
run
(
$relPath
,
'git'
,
'fetch'
,
'--all'
);
$this
->
run
(
$repo
,
$relPath
,
'git'
,
'fetch'
,
'--all'
);
}
}
}
}
...
@@ -374,6 +479,9 @@ class Givi {
...
@@ -374,6 +479,9 @@ class Givi {
}
}
function
filterBranchName
(
$repoName
,
$branchName
)
{
function
filterBranchName
(
$repoName
,
$branchName
)
{
if
(
$branchName
==
''
)
{
return
''
;
}
if
(
$repoName
==
'drupal'
)
{
if
(
$repoName
==
'drupal'
)
{
$parts
=
explode
(
'/'
,
$branchName
);
$parts
=
explode
(
'/'
,
$branchName
);
$last
=
$this
->
drupalVersion
.
'.x-'
.
array_pop
(
$parts
);
$last
=
$this
->
drupalVersion
.
'.x-'
.
array_pop
(
$parts
);
...
@@ -383,6 +491,28 @@ class Givi {
...
@@ -383,6 +491,28 @@ class Givi {
return
$branchName
;
return
$branchName
;
}
}
/**
* @param string $filter e.g. "all" or "repo1,repo2"
* @param array $repos ($repoName => $repoDir)
* @return array ($repoName => $repoDir)
*/
function
filterRepos
(
$filter
,
$repos
)
{
if
(
$filter
==
'all'
)
{
return
$repos
;
}
$inclRepos
=
explode
(
','
,
$filter
);
$unknowns
=
array_diff
(
$inclRepos
,
array_keys
(
$repos
));
if
(
!
empty
(
$unknowns
))
{
throw
new
Exception
(
"Unknown Repos: "
.
implode
(
','
,
$unknowns
));
}
$unwanted
=
array_diff
(
array_keys
(
$repos
),
$inclRepos
);
foreach
(
$unwanted
as
$repo
)
{
unset
(
$repos
[
$repo
]);
}
return
$repos
;
}
function
returnError
(
$message
)
{
function
returnError
(
$message
)
{
echo
"ERROR: "
,
$message
,
"
\n
"
;
echo
"ERROR: "
,
$message
,
"
\n
"
;
$this
->
doHelp
();
$this
->
doHelp
();
...
...
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