This repository was archived by the owner on Jul 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-commit-mailer
More file actions
executable file
·137 lines (125 loc) · 3.79 KB
/
git-commit-mailer
File metadata and controls
executable file
·137 lines (125 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
#
# Copyright (C) 2009 Ryo Onodera <[email protected]>
# Copyright (C) 2012-2014 Kouhei Sutou <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# See also post-receive-email in git for git repository
# change detection:
# http://git.kernel.org/?p=git/git.git;a=blob;f=contrib/hooks/post-receive-email
require "git-commit-mailer"
begin
argv = []
processing_change = nil
found_include_option = false
ARGV.each do |arg|
if found_include_option
$LOAD_PATH.unshift(arg)
found_include_option = false
else
case arg
when "-I", "--include"
found_include_option = true
when /\A-I/, /\A--include=?/
path = $POSTMATCH
$LOAD_PATH.unshift(path) unless path.empty?
else
argv << arg
end
end
end
mailer = GitCommitMailer.parse_options_and_create(argv)
if not mailer.track_remote?
running = SpentTime.new("running the whole command")
running.spend do
while line = STDIN.gets
old_revision, new_revision, reference = line.split
processing_change = [old_revision, new_revision, reference]
mailer.process_reference_change(old_revision, new_revision, reference)
mailer.send_all_mails
end
end
if mailer.verbose?
$executing_git.report
$sending_mail.report
running.report
end
else
reference_changes = mailer.fetch
reference_changes.each do |old_revision, new_revision, reference|
processing_change = [old_revision, new_revision, reference]
mailer.process_reference_change(old_revision, new_revision, reference)
mailer.send_all_mails
end
end
rescue Exception => error
require 'net/smtp'
require 'socket'
require 'etc'
to = []
subject = "Error"
user = Etc.getpwuid(Process.uid).name
from = "#{user}@#{Socket.gethostname}"
sender = nil
server = nil
port = nil
begin
to, options = GitCommitMailer.parse(argv)
to = options.error_to unless options.error_to.empty?
from = options.from || from
sender = options.sender
subject = "#{options.name}: #{subject}" if options.name
server = options.server
port = options.port
rescue OptionParser::MissingArgument
argv.delete_if {|argument| $!.args.include?(argument)}
retry
rescue OptionParser::ParseError
if to.empty?
_to, *_ = ARGV.reject {|argument| /^-/.match(argument)}
to = [_to]
end
end
detail = <<-EOM
Processing change: #{processing_change.inspect}
#{error.class}: #{error.message}
#{error.backtrace.join("\n")}
EOM
to = to.compact
if to.empty?
STDERR.puts detail
else
from = GitCommitMailer.extract_email_address(from)
to = to.collect {|address| GitCommitMailer.extract_email_address(address)}
header = <<-HEADER
X-Mailer: #{GitCommitMailer.x_mailer}
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
From: #{from}
To: #{to.join(', ')}
Subject: #{subject}
Date: #{Time.now.rfc2822}
HEADER
header << "Sender: #{sender}\n" if sender
mail = <<-MAIL
#{header}
#{detail}
MAIL
GitCommitMailer.send_mail(server || "localhost", port,
sender || from, to, mail)
exit(false)
end
end