From be3a0b269a7ddff2e5f0f2ae364cf2e50c780980 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sat, 15 Jan 2011 02:06:23 +0100 Subject: [ticket/9805] Script for easily cloning a whole github network. PHPBB3-9805 --- git-tools/setup_github_network.php | 179 +++++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 git-tools/setup_github_network.php (limited to 'git-tools') diff --git a/git-tools/setup_github_network.php b/git-tools/setup_github_network.php new file mode 100644 index 0000000000..bc8e70cfbd --- /dev/null +++ b/git-tools/setup_github_network.php @@ -0,0 +1,179 @@ +contributors as $contributor) + { + $usernames[$contributor->login] = $contributor->login; + } + + return $usernames; +} + +function get_organisation_members($username) +{ + $request = api_request("organizations/$username/public_members"); + + $usernames = array(); + foreach ($request->users as $member) + { + $usernames[$member->login] = $member->login; + } + + return $usernames; +} + +function get_collaborators($username, $repository) +{ + $request = api_request("repos/show/$username/$repository/collaborators"); + + $usernames = array(); + foreach ($request->collaborators as $collaborator) + { + $usernames[$collaborator] = $collaborator; + } + + return $usernames; +} + +function get_network($username, $repository) +{ + $request = api_request("repos/show/$username/$repository/network"); + + $usernames = array(); + foreach ($request->network as $network) + { + $usernames[$network->owner] = array( + 'username' => $network->owner, + 'repository' => $network->name, + ); + } + + return $usernames; +} + +function show_usage($argv) +{ + printf( + "usage: php %s collaborators|organisation|contributors|network [your_github_username]\n", + basename($argv[0]) + ); + exit(1); +} + +function get_arg($argv, $index, $default) +{ + return isset($argv[$index]) ? $argv[$index] : $default; +} + +function run($cmd) +{ + passthru(escapeshellcmd($cmd)); +} -- cgit v1.2.1 From 57bd0c74e50e2171653d45d9723f2417411c71f4 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 16 Jan 2011 17:02:19 +0100 Subject: [ticket/9805] Use getopt(), add a few options, extend show_usage(). PHPBB3-9805 --- git-tools/setup_github_network.php | 52 +++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 18 deletions(-) (limited to 'git-tools') diff --git a/git-tools/setup_github_network.php b/git-tools/setup_github_network.php index bc8e70cfbd..66d7db87da 100644 --- a/git-tools/setup_github_network.php +++ b/git-tools/setup_github_network.php @@ -9,7 +9,7 @@ if ($argc < 2) { - show_usage($argv); + show_usage(); } if (file_exists('.git')) @@ -18,13 +18,38 @@ if (file_exists('.git')) exit(1); } -// Handle arguments -$scope = get_arg($argv, 1, ''); -$developer = get_arg($argv, 2, ''); +function show_usage() +{ + $filename = basename(__FILE__); + + echo "$filename adds repositories of a github network as remotes to a local git repository.\n"; + echo "\n"; + + echo "Usage: php $filename -s collaborators|organisation|contributors|network [OPTIONS]\n"; + echo "\n"; + + echo "Scopes:\n"; + echo " collaborators Repositories of people who have push access to the specified repository\n"; + echo " contributors Repositories of people who have contributed to the specified repository\n"; + echo " organisation Repositories of members of the organisation at github\n"; + echo " network All repositories of the whole github network\n"; + echo "\n"; + + echo "Options:\n"; + echo " -s scope See description above (mandatory)\n"; + echo " -u github_username Overwrites the github username (optional)\n"; + echo " -r repository_name Overwrites the repository name (optional)\n"; + echo " -m your_github_username Sets up ssh:// instead of git:// for pushable repositories (optional)\n"; + + exit(1); +} -// Github setup -$username = 'phpbb'; -$repository = 'phpbb3'; +// Handle arguments +$opts = getopt('s:u:r:m:'); +$scope = get_arg($opts, 's', ''); +$username = get_arg($opts, 'u', 'phpbb'); +$repository = get_arg($opts, 'r', 'phpbb3'); +$developer = get_arg($opts, 'm', ''); // Get some basic data $network = get_network($username, $repository); @@ -159,18 +184,9 @@ function get_network($username, $repository) return $usernames; } -function show_usage($argv) -{ - printf( - "usage: php %s collaborators|organisation|contributors|network [your_github_username]\n", - basename($argv[0]) - ); - exit(1); -} - -function get_arg($argv, $index, $default) +function get_arg($array, $index, $default) { - return isset($argv[$index]) ? $argv[$index] : $default; + return isset($array[$index]) ? $array[$index] : $default; } function run($cmd) -- cgit v1.2.1 From 8eee36dc0f6111c3a4a6a50d0e33833f19430a0e Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 25 Jan 2011 18:41:59 +0100 Subject: [ticket/9805] Add dry-run option. PHPBB3-9805 --- git-tools/setup_github_network.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'git-tools') diff --git a/git-tools/setup_github_network.php b/git-tools/setup_github_network.php index 66d7db87da..04187aaa4a 100644 --- a/git-tools/setup_github_network.php +++ b/git-tools/setup_github_network.php @@ -40,16 +40,19 @@ function show_usage() echo " -u github_username Overwrites the github username (optional)\n"; echo " -r repository_name Overwrites the repository name (optional)\n"; echo " -m your_github_username Sets up ssh:// instead of git:// for pushable repositories (optional)\n"; + echo " -d Outputs the commands instead of running them (optional)\n"; exit(1); } // Handle arguments -$opts = getopt('s:u:r:m:'); +$opts = getopt('s:u:r:m:d'); $scope = get_arg($opts, 's', ''); $username = get_arg($opts, 'u', 'phpbb'); $repository = get_arg($opts, 'r', 'phpbb3'); $developer = get_arg($opts, 'm', ''); +$dry_run = !get_arg($opts, 'd', true); +run(null, $dry_run); // Get some basic data $network = get_network($username, $repository); @@ -189,7 +192,20 @@ function get_arg($array, $index, $default) return isset($array[$index]) ? $array[$index] : $default; } -function run($cmd) +function run($cmd, $dry = false) { - passthru(escapeshellcmd($cmd)); + static $dry_run; + + if (is_null($cmd)) + { + $dry_run = $dry; + } + else if (!empty($dry_run)) + { + echo "$cmd\n"; + } + else + { + passthru(escapeshellcmd($cmd)); + } } -- cgit v1.2.1 From e1ae8c6a71e253f4311c45a6be5b2d93587d2755 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 25 Jan 2011 19:03:32 +0100 Subject: [ticket/9805] Better support for already existing repositories. PHPBB3-9805 --- git-tools/setup_github_network.php | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'git-tools') diff --git a/git-tools/setup_github_network.php b/git-tools/setup_github_network.php index 04187aaa4a..f34787c4c4 100644 --- a/git-tools/setup_github_network.php +++ b/git-tools/setup_github_network.php @@ -12,12 +12,6 @@ if ($argc < 2) show_usage(); } -if (file_exists('.git')) -{ - echo "[error] git repository already exists\n"; - exit(1); -} - function show_usage() { $filename = basename(__FILE__); @@ -58,9 +52,6 @@ run(null, $dry_run); $network = get_network($username, $repository); $collaborators = get_collaborators($username, $repository); -// Clone the blessed repository -clone_repository($username, $repository, isset($collaborators[$developer])); - switch ($scope) { case 'collaborators': @@ -83,14 +74,20 @@ switch ($scope) show_usage(); } -foreach ($remotes as $remote) +if (file_exists('.git')) { - if ($remote['username'] == $username) - { - // Skip blessed repository. - continue; - } + add_remote($username, $repository, isset($collaborators[$developer])); +} +else +{ + clone_repository($username, $repository, isset($collaborators[$developer])); +} +// Skip blessed repository. +unset($remotes[$username]); + +foreach ($remotes as $remote) +{ add_remote($remote['username'], $remote['repository'], $remote['username'] == $developer); } @@ -99,12 +96,12 @@ run('git remote update'); function clone_repository($username, $repository, $pushable = false) { $url = get_repository_url($username, $repository, false); - run("git clone $url ./"); + run("git clone $url ./ --origin $username"); if ($pushable) { $ssh_url = get_repository_url($username, $repository, true); - run("git remote set-url --push origin $ssh_url"); + run("git remote set-url --push $username $ssh_url"); } } -- cgit v1.2.1 From 67fe441f7e94aa9f502f3f8d3ff7ad15bb2ae008 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 25 Jan 2011 19:07:29 +0100 Subject: [ticket/9805] Move check lower down. PHPBB3-9805 --- git-tools/setup_github_network.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'git-tools') diff --git a/git-tools/setup_github_network.php b/git-tools/setup_github_network.php index f34787c4c4..911d336c2d 100644 --- a/git-tools/setup_github_network.php +++ b/git-tools/setup_github_network.php @@ -7,11 +7,6 @@ * */ -if ($argc < 2) -{ - show_usage(); -} - function show_usage() { $filename = basename(__FILE__); @@ -40,7 +35,13 @@ function show_usage() } // Handle arguments -$opts = getopt('s:u:r:m:d'); +$opts = getopt('s:u:r:m:d'); + +if (empty($opts)) +{ + show_usage(); +} + $scope = get_arg($opts, 's', ''); $username = get_arg($opts, 'u', 'phpbb'); $repository = get_arg($opts, 'r', 'phpbb3'); -- cgit v1.2.1 From 50bdb5da89cdbca0d4331a7f4f721f8be712d0ca Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 26 Jan 2011 03:18:31 +0100 Subject: [ticket/9805] Setup security repository for developers. PHPBB3-9805 --- git-tools/setup_github_network.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'git-tools') diff --git a/git-tools/setup_github_network.php b/git-tools/setup_github_network.php index 911d336c2d..08e99e2f32 100644 --- a/git-tools/setup_github_network.php +++ b/git-tools/setup_github_network.php @@ -84,6 +84,12 @@ else clone_repository($username, $repository, isset($collaborators[$developer])); } +// Add private security repository for developers +if ($username == 'phpbb' && $repository == 'phpbb3' && isset($collaborators[$developer])) +{ + run("git remote add $username-security " . get_repository_url($username, "$repository-security", true)); +} + // Skip blessed repository. unset($remotes[$username]); -- cgit v1.2.1 From 0f3378ca28308eec4cc61d8e5170c4f40ad41699 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 15 Feb 2011 04:45:54 -0500 Subject: [ticket/10044] Made setup_github_network.php runnable as a script PHPBB3-10044 --- git-tools/setup_github_network.php | 1 + 1 file changed, 1 insertion(+) mode change 100644 => 100755 git-tools/setup_github_network.php (limited to 'git-tools') diff --git a/git-tools/setup_github_network.php b/git-tools/setup_github_network.php old mode 100644 new mode 100755 index 08e99e2f32..80cc62df8a --- a/git-tools/setup_github_network.php +++ b/git-tools/setup_github_network.php @@ -1,3 +1,4 @@ +#!/usr/bin/env php Date: Tue, 15 Feb 2011 04:49:48 -0500 Subject: [ticket/10044] Error handling for remote requests in setup_github_network.php PHPBB3-10044 --- git-tools/setup_github_network.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'git-tools') diff --git a/git-tools/setup_github_network.php b/git-tools/setup_github_network.php index 80cc62df8a..ae3d34f5fe 100755 --- a/git-tools/setup_github_network.php +++ b/git-tools/setup_github_network.php @@ -134,12 +134,21 @@ function get_repository_url($username, $repository, $ssh = false) function api_request($query) { - return json_decode(file_get_contents("http://github.com/api/v2/json/$query")); + $contents = file_get_contents("http://github.com/api/v2/json/$query"); + if ($contents === false) + { + return false; + } + return json_decode($contents); } function get_contributors($username, $repository) { $request = api_request("repos/show/$username/$repository/contributors"); + if ($request === false) + { + return false; + } $usernames = array(); foreach ($request->contributors as $contributor) @@ -153,6 +162,10 @@ function get_contributors($username, $repository) function get_organisation_members($username) { $request = api_request("organizations/$username/public_members"); + if ($request === false) + { + return false; + } $usernames = array(); foreach ($request->users as $member) @@ -166,6 +179,10 @@ function get_organisation_members($username) function get_collaborators($username, $repository) { $request = api_request("repos/show/$username/$repository/collaborators"); + if ($request === false) + { + return false; + } $usernames = array(); foreach ($request->collaborators as $collaborator) @@ -179,6 +196,10 @@ function get_collaborators($username, $repository) function get_network($username, $repository) { $request = api_request("repos/show/$username/$repository/network"); + if ($request === false) + { + return false; + } $usernames = array(); foreach ($request->network as $network) -- cgit v1.2.1 From bf137b70051d00f6b0e6636ae08e5579c6f3739e Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 15 Feb 2011 05:11:21 -0500 Subject: [ticket/10044] Added -h to setup_github_network.php. PHPBB3-10044 --- git-tools/setup_github_network.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'git-tools') diff --git a/git-tools/setup_github_network.php b/git-tools/setup_github_network.php index ae3d34f5fe..9ada9e437a 100755 --- a/git-tools/setup_github_network.php +++ b/git-tools/setup_github_network.php @@ -31,14 +31,15 @@ function show_usage() echo " -r repository_name Overwrites the repository name (optional)\n"; echo " -m your_github_username Sets up ssh:// instead of git:// for pushable repositories (optional)\n"; echo " -d Outputs the commands instead of running them (optional)\n"; + echo " -h This help text\n"; exit(1); } // Handle arguments -$opts = getopt('s:u:r:m:d'); +$opts = getopt('s:u:r:m:dh'); -if (empty($opts)) +if (empty($opts) || isset($opts['h'])) { show_usage(); } -- cgit v1.2.1 From ed53cef0aaa2a23d4688c2429cc7961ad79ca496 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 15 Feb 2011 05:13:48 -0500 Subject: [ticket/10044] Stop when failed to retrieve network/collaborators. PHPBB3-10044 --- git-tools/setup_github_network.php | 90 +++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 40 deletions(-) (limited to 'git-tools') diff --git a/git-tools/setup_github_network.php b/git-tools/setup_github_network.php index 9ada9e437a..a3606575b2 100755 --- a/git-tools/setup_github_network.php +++ b/git-tools/setup_github_network.php @@ -50,57 +50,67 @@ $repository = get_arg($opts, 'r', 'phpbb3'); $developer = get_arg($opts, 'm', ''); $dry_run = !get_arg($opts, 'd', true); run(null, $dry_run); +exit(work($scope, $username, $repository, $developer)); -// Get some basic data -$network = get_network($username, $repository); -$collaborators = get_collaborators($username, $repository); - -switch ($scope) +function work($scope, $username, $repository, $developer) { - case 'collaborators': - $remotes = array_intersect_key($network, $collaborators); - break; + // Get some basic data + $network = get_network($username, $repository); + $collaborators = get_collaborators($username, $repository); - case 'organisation': - $remotes = array_intersect_key($network, get_organisation_members($username)); - break; + if ($network === false || $collaborators === false) + { + echo "Error: failed to retrieve network or collaborators\n"; + return 1; + } - case 'contributors': - $remotes = array_intersect_key($network, get_contributors($username, $repository)); - break; + switch ($scope) + { + case 'collaborators': + $remotes = array_intersect_key($network, $collaborators); + break; - case 'network': - $remotes = $network; - break; + case 'organisation': + $remotes = array_intersect_key($network, get_organisation_members($username)); + break; - default: - show_usage(); -} + case 'contributors': + $remotes = array_intersect_key($network, get_contributors($username, $repository)); + break; -if (file_exists('.git')) -{ - add_remote($username, $repository, isset($collaborators[$developer])); -} -else -{ - clone_repository($username, $repository, isset($collaborators[$developer])); -} + case 'network': + $remotes = $network; + break; -// Add private security repository for developers -if ($username == 'phpbb' && $repository == 'phpbb3' && isset($collaborators[$developer])) -{ - run("git remote add $username-security " . get_repository_url($username, "$repository-security", true)); -} + default: + show_usage(); + } + + if (file_exists('.git')) + { + add_remote($username, $repository, isset($collaborators[$developer])); + } + else + { + clone_repository($username, $repository, isset($collaborators[$developer])); + } -// Skip blessed repository. -unset($remotes[$username]); + // Add private security repository for developers + if ($username == 'phpbb' && $repository == 'phpbb3' && isset($collaborators[$developer])) + { + run("git remote add $username-security " . get_repository_url($username, "$repository-security", true)); + } -foreach ($remotes as $remote) -{ - add_remote($remote['username'], $remote['repository'], $remote['username'] == $developer); -} + // Skip blessed repository. + unset($remotes[$username]); + + foreach ($remotes as $remote) + { + add_remote($remote['username'], $remote['repository'], $remote['username'] == $developer); + } -run('git remote update'); + run('git remote update'); +} function clone_repository($username, $repository, $pushable = false) { -- cgit v1.2.1 From 5af3cfe9cae4a59478bff2581f8484657a0d5bc9 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 16 Feb 2011 21:13:35 -0500 Subject: [ticket/10044] Updated invocation documentation. PHPBB3-10044 --- git-tools/setup_github_network.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git-tools') diff --git a/git-tools/setup_github_network.php b/git-tools/setup_github_network.php index a3606575b2..e4e212eef6 100755 --- a/git-tools/setup_github_network.php +++ b/git-tools/setup_github_network.php @@ -15,7 +15,7 @@ function show_usage() echo "$filename adds repositories of a github network as remotes to a local git repository.\n"; echo "\n"; - echo "Usage: php $filename -s collaborators|organisation|contributors|network [OPTIONS]\n"; + echo "Usage: [php] $filename -s collaborators|organisation|contributors|network [OPTIONS]\n"; echo "\n"; echo "Scopes:\n"; -- cgit v1.2.1 From 16a46e6a2451b39310cc4352ab8fae603a07effd Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 2 Mar 2011 00:04:45 +0100 Subject: [ticket/9824] Remove space after PHPBB3-12345 in prepared commit message. PHPBB3-9824 --- git-tools/hooks/prepare-commit-msg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git-tools') diff --git a/git-tools/hooks/prepare-commit-msg b/git-tools/hooks/prepare-commit-msg index 2bf25e58a4..2c6426ad6f 100755 --- a/git-tools/hooks/prepare-commit-msg +++ b/git-tools/hooks/prepare-commit-msg @@ -38,5 +38,5 @@ then tail="\n\nPHPBB3-${branch##ticket/}"; fi - echo "[$branch]$tail $(cat "$1")" > "$1" + echo "[$branch]$tail$(cat "$1")" > "$1" fi -- cgit v1.2.1 From 9bed2b119c9d3214b7869cecb416a231878aad66 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 2 Mar 2011 00:07:45 +0100 Subject: [ticket/9824] Add space after [ticket/12345] in prepared commit message. PHPBB3-9824 --- git-tools/hooks/prepare-commit-msg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git-tools') diff --git a/git-tools/hooks/prepare-commit-msg b/git-tools/hooks/prepare-commit-msg index 2c6426ad6f..c3e5dfa90c 100755 --- a/git-tools/hooks/prepare-commit-msg +++ b/git-tools/hooks/prepare-commit-msg @@ -38,5 +38,5 @@ then tail="\n\nPHPBB3-${branch##ticket/}"; fi - echo "[$branch]$tail$(cat "$1")" > "$1" + echo "[$branch] $tail$(cat "$1")" > "$1" fi -- cgit v1.2.1 From c489b189df39c75195f85ab26afe08cd44ad7f2e Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 1 Mar 2011 20:17:59 -0500 Subject: [ticket/9824] Handle empty commit messages in commit-msg hook. Git already handles the case of commit message being empty by aborting the commit and displaying a reasonably helpful message. If there is no commit message, the hook will exit with success exit code to let git do its thing. PHPBB3-9824 --- git-tools/hooks/commit-msg | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'git-tools') diff --git a/git-tools/hooks/commit-msg b/git-tools/hooks/commit-msg index a6777ff9c9..1d33995162 100755 --- a/git-tools/hooks/commit-msg +++ b/git-tools/hooks/commit-msg @@ -55,6 +55,17 @@ quit() fi } +# Check for empty commit message +if ! grep -qv '^#' "$1" +then + # Commit message is empty (or contains only comments). + # Let git handle this. + # It will abort with a message like so: + # + # Aborting commit due to empty commit message. + exit 0 +fi + msg=$(grep -nE '.{81,}' "$1"); if [ $? -eq 0 ] -- cgit v1.2.1 From b90e01392c1b88f5403d39e044cf80353923ca54 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 1 Mar 2011 20:20:29 -0500 Subject: [ticket/9824] Use printf instead of echo to render \n. On FreeBSD `echo "\n"` prints \n verbatim. Use printf instead. PHPBB3-9824 --- git-tools/hooks/prepare-commit-msg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git-tools') diff --git a/git-tools/hooks/prepare-commit-msg b/git-tools/hooks/prepare-commit-msg index c3e5dfa90c..11d2b6b2f2 100755 --- a/git-tools/hooks/prepare-commit-msg +++ b/git-tools/hooks/prepare-commit-msg @@ -35,7 +35,7 @@ then # Branch is prefixed with 'ticket/', append ticket ID to message if [ "$branch" != "${branch##ticket/}" ]; then - tail="\n\nPHPBB3-${branch##ticket/}"; + tail="$(printf "\n\nPHPBB3-${branch##ticket/}")"; fi echo "[$branch] $tail$(cat "$1")" > "$1" -- cgit v1.2.1 From d7a38fd7ef2bea57107968014cf63652372b45c1 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 1 Mar 2011 20:40:35 -0500 Subject: [ticket/9824] Allow empty lines after ticket reference. PHPBB3-9824 --- git-tools/hooks/commit-msg | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'git-tools') diff --git a/git-tools/hooks/commit-msg b/git-tools/hooks/commit-msg index 1d33995162..319e27b811 100755 --- a/git-tools/hooks/commit-msg +++ b/git-tools/hooks/commit-msg @@ -139,6 +139,10 @@ do # Should not end up here false ;; + "possibly-eof") + # Allow empty and/or comment lines at the end + ! tail -n +"$i" "$1" |grep -qvE '^($|#)' + ;; "comment") echo "$line" | grep -Eq "^#"; ;; @@ -199,7 +203,7 @@ do in_description=1; ;; "footer") - expecting="footer eof"; + expecting="footer possibly-eof"; if [ "$tickets" = "" ] then tickets="$line"; @@ -210,6 +214,9 @@ do "comment") # Comments should expect the same thing again ;; + "possibly-eof") + expecting="eof"; + ;; *) echo "Unrecognised token $expect" >&2; quit 254; -- cgit v1.2.1 From e55228712831a2422cc1c171a6a1160c20d25f1e Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 1 Mar 2011 20:56:57 -0500 Subject: [ticket/9824] Accept commit messages with less than perfect headings. Some commit messages exist only temporarily, because they are given on commits that are intended to be squashed. Accept such commit messages with a warning. PHPBB3-9824 --- git-tools/hooks/commit-msg | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'git-tools') diff --git a/git-tools/hooks/commit-msg b/git-tools/hooks/commit-msg index 319e27b811..ad4d69a9da 100755 --- a/git-tools/hooks/commit-msg +++ b/git-tools/hooks/commit-msg @@ -118,7 +118,19 @@ do case $expect in "header") err=$ERR_HEADER; - echo "$line" | grep -Eq "^\[(ticket/[0-9]+|feature/$branch_regex|task/$branch_regex)\] [A-Z].+$" + echo "$line" | grep -Eq "^\[(ticket/[0-9]+|feature/$branch_regex|task/$branch_regex)\] .+$" + result=$? + if ! echo "$line" | grep -Eq "^\[(ticket/[0-9]+|feature/$branch_regex|task/$branch_regex)\] [A-Z].+$" + then + # Don't be too strict. + # Commits may be temporary, intended to be squashed later. + # Just issue a warning here. + echo "Warning: heading should be a sentence beginning with a capital letter." 1>&2 + echo "You entered:" 1>&2 + echo "$line" 1>&2 + fi + # restore exit code + (exit $result) ;; "empty") err=$ERR_EMPTY; -- cgit v1.2.1 From 7cf134c73d043e1adc1ac6361b202afa0d0f4ca9 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 11 Mar 2011 19:26:07 -0500 Subject: [ticket/10092] Ignore overlength comment lines in commit-msg hook. PHPBB3-10092 --- git-tools/hooks/commit-msg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git-tools') diff --git a/git-tools/hooks/commit-msg b/git-tools/hooks/commit-msg index ad4d69a9da..6d4f02a1d2 100755 --- a/git-tools/hooks/commit-msg +++ b/git-tools/hooks/commit-msg @@ -66,7 +66,7 @@ then exit 0 fi -msg=$(grep -nE '.{81,}' "$1"); +msg=$(grep -v '^#' "$1" |grep -nE '.{81,}') if [ $? -eq 0 ] then -- cgit v1.2.1 From 94e09ac041ac7bc9fd52c8bd1d13d1a91da1da6f Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 11 Mar 2011 19:27:38 -0500 Subject: [ticket/10078] Avoid \n in strings given to echo for portability. Also preserve whitespace (including newlines) when printing the lines that exceed 80 character limit. PHPBB3-10078 --- git-tools/hooks/commit-msg | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'git-tools') diff --git a/git-tools/hooks/commit-msg b/git-tools/hooks/commit-msg index ad4d69a9da..9114cd368a 100755 --- a/git-tools/hooks/commit-msg +++ b/git-tools/hooks/commit-msg @@ -70,8 +70,9 @@ msg=$(grep -nE '.{81,}' "$1"); if [ $? -eq 0 ] then - echo "The following lines are greater than 80 characters long:\n" >&2; - echo $msg >&2; + echo "The following lines are greater than 80 characters long:" >&2; + echo >&2 + echo "$msg" >&2; quit $ERR_LENGTH; fi -- cgit v1.2.1 From 1d2634f0ee90a95b05a5ba52a36a05f2505400af Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 12 Mar 2011 22:55:38 +0100 Subject: [ticket/9806] Script for merging pull requests PHPBB3-9806 --- git-tools/merge.php | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100755 git-tools/merge.php (limited to 'git-tools') diff --git a/git-tools/merge.php b/git-tools/merge.php new file mode 100755 index 0000000000..cbd84b896f --- /dev/null +++ b/git-tools/merge.php @@ -0,0 +1,175 @@ +#!/usr/bin/env php +getMessage(); + exit($e->getCode()); +} + +function work($pull_id, $remote) +{ + // Get some basic data + $pull = get_pull('phpbb', 'phpbb3', $pull_id); + + if (!$pull_id) + { + show_usage(); + } + + if ($pull['state'] != 'open') + { + throw new RuntimeException(sprintf("Error: pull request is closed\n", + $target_branch), 5); + } + + $pull_user = $pull['head'][0]; + $pull_branch = $pull['head'][1]; + $target_branch = $pull['base'][1]; + + switch ($target_branch) + { + case 'develop-olympus': + run("git checkout develop-olympus"); + run("git pull $remote develop-olympus"); + + add_remote($pull_user, 'phpbb3'); + run("git fetch $pull_user"); + run("git merge --no-ff $pull_user/$pull_branch"); + run("phpunit"); + + run("git checkout develop"); + run("git pull $remote develop"); + run("git merge --no-ff develop-olympus"); + run("phpunit"); + break; + + case 'develop': + run("git checkout develop"); + run("git pull $remote develop"); + + add_remote($pull_user, 'phpbb3'); + run("git fetch $pull_user"); + run("git merge --no-ff $pull_user/$pull_branch"); + run("phpunit"); + break; + + default: + throw new RuntimeException(sprintf("Error: pull request target branch '%s' is not a main branch\n", + $target_branch), 5); + break; + } +} + +function add_remote($username, $repository, $pushable = false) +{ + $url = get_repository_url($username, $repository, false); + run("git remote add $username $url", true); + + if ($pushable) + { + $ssh_url = get_repository_url($username, $repository, true); + run("git remote set-url --push $username $ssh_url"); + } +} + +function get_repository_url($username, $repository, $ssh = false) +{ + $url_base = ($ssh) ? 'git@github.com:' : 'git://github.com/'; + + return $url_base . $username . '/' . $repository . '.git'; +} + +function api_request($query) +{ + $contents = file_get_contents("http://github.com/api/v2/json/$query"); + + if ($contents === false) + { + throw new RuntimeException("Error: failed to retrieve pull request data\n", 4); + } + + return json_decode($contents); +} + +function get_pull($username, $repository, $pull_id) +{ + $request = api_request("pulls/$username/$repository/$pull_id"); + + $pull = $request->pull; + + $pull_data = array( + 'base' => array($pull->base->user->login, $pull->base->ref), + 'head' => array($pull->head->user->login, $pull->head->ref), + 'state' => $pull->state, + ); + + return $pull_data; +} + +function get_arg($array, $index, $default) +{ + return isset($array[$index]) ? $array[$index] : $default; +} + +function run($cmd, $ignore_fail = false) +{ + global $dry_run; + + if (!empty($dry_run)) + { + echo "$cmd\n"; + } + else + { + passthru(escapeshellcmd($cmd), $status); + + if ($status != 0 && !$ignore_fail) + { + throw new RuntimeException(sprintf("Error: command '%s' failed with status %s'\n", + $cmd, $status), 6); + } + } +} -- cgit v1.2.1