# 02110-1301, USA.
# To set user mappings, use this command:
-# git config gnt-review.johndoe 'John Doe <johndoe@domain.tld>'
+# git config gnt-review.johndoe 'John Doe <johndoe@example.com>'
+
+# To disable strict mode (enabled by default):
+# git config gnt-review.strict false
+
+# To enable strict mode:
+# git config gnt-review.strict true
set -e
grep -q '^Reviewed-by: ' "$msgfile" && return
perl -i -e '
+ my $reviewer = $ENV{"REVIEWER"};
+ defined($reviewer) or $reviewer = "";
my $sob = 0;
while (<>) {
if ($sob == 0 and m/^Signed-off-by:/) {
$sob = 1;
} elsif ($sob == 1 and not m/^Signed-off-by:/) {
- print "Reviewed-by: \n";
+ print "Reviewed-by: $reviewer\n";
$sob = -1;
}
}
if ($sob == 1) {
- print "Reviewed-by: \n";
+ print "Reviewed-by: $reviewer\n";
}
' "$msgfile"
}
replace_users() {
local msgfile="$1"
- perl -i -e '
+ if perl -i -e '
+ use strict;
+ use warnings;
+
+ my $error = 0;
+ my $strict;
+
sub map_username {
my ($name) = @_;
return $output;
}
+ unless (defined $strict) {
+ @cmd = ("git", "config", "--get", "--bool", "gnt-review.strict");
+
+ open($fh, "-|", @cmd) or die "Command \"@cmd\" failed: $!";
+ $output = do { local $/ = undef; <$fh> };
+ close($fh);
+
+ $strict = ($? != 0 or not $output or $output !~ m/^false$/);
+ }
+
+ if ($strict and $name !~ m/^.+<.+\@.+>$/) {
+ $error = 1;
+ }
+
return $name;
}
$_;
} split(m/,/, $1);
+ # Get unique names
+ my %saw;
+ @names = grep(!$saw{$_}++, @names);
+ undef %saw;
+
foreach (sort @names) {
print "Reviewed-by: $_\n";
}
print;
}
}
+
+ exit($error? 33 : 0);
' "$msgfile"
+ then
+ :
+ else
+ [[ "$?" == 33 ]] && return 1
+ exit 1
+ fi
if ! grep -q '^Reviewed-by: ' "$msgfile"
then
GIT_EDITOR="$me --commit-editor \"\$@\"" git commit -c "$rev" -s
}
-main() {
- local range="$1" target_branch="$2"
+usage() {
+ echo "Usage: $me_plain [from..to] <target-branch>" >&2
+ echo " If not passed from..to defaults to target-branch..HEAD" >&2
+ exit 1
+}
- if [[ -z "$target_branch" || "$range" != *..* ]]
- then
- echo "Usage: $me_plain <from..to> <target-branch>" >&2
- exit 1
- fi
+main() {
+ local range target_branch
+
+ case "$#" in
+ 1)
+ target_branch="$1"
+ range="$target_branch..$(git rev-parse HEAD)"
+ ;;
+ 2)
+ range="$1"
+ target_branch="$2"
+ if [[ "$range" != *..* ]]; then
+ usage
+ fi
+ ;;
+ *)
+ usage
+ ;;
+ esac
git checkout "$target_branch"
local old_head=$(git rev-parse HEAD)