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