зеркало из https://github.com/github/ruby.git
Avoid overwriting revision.h when .git doesn't exist (#6915)
* Avoid overwriting revision.h when .git doesn't exist * Overwrite revision.h if it's blank
This commit is contained in:
Родитель
3e00cb8256
Коммит
7edcdc380f
|
@ -25,6 +25,7 @@ end
|
|||
|
||||
time_format = '%Y-%m-%dT%H:%M:%S%z'
|
||||
vcs = nil
|
||||
create_only = false
|
||||
OptionParser.new {|opts|
|
||||
opts.banner << " paths..."
|
||||
vcs_options = VCS.define_options(opts)
|
||||
|
@ -62,6 +63,9 @@ OptionParser.new {|opts|
|
|||
abort "#{File.basename(Program)}: #{e.message}" unless @suppress_not_found
|
||||
opts.remove
|
||||
(vcs = VCS::Null.new(nil)).set_options(vcs_options)
|
||||
if @format == :revision_h
|
||||
create_only = true # don't overwrite existing revision.h when .git doesn't exist
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
|
@ -92,7 +96,7 @@ ok = true
|
|||
begin
|
||||
data = formatter[*vcs.get_revisions(arg)]
|
||||
data.sub!(/(?<!\A|\n)\z/, "\n")
|
||||
@output.write(data, overwrite: true)
|
||||
@output.write(data, overwrite: true, create_only: create_only)
|
||||
rescue => e
|
||||
warn "#{File.basename(Program)}: #{e.message}"
|
||||
ok = false
|
||||
|
|
|
@ -18,7 +18,7 @@ class Output
|
|||
@vpath.def_options(opt)
|
||||
end
|
||||
|
||||
def write(data, overwrite: false)
|
||||
def write(data, overwrite: false, create_only: false)
|
||||
unless @path
|
||||
$stdout.print data
|
||||
return true
|
||||
|
@ -28,8 +28,8 @@ class Output
|
|||
updated = color.fail("updated")
|
||||
outpath = nil
|
||||
|
||||
if (@ifchange or overwrite) and
|
||||
(@vpath.open(@path, "rb") {|f| outpath = f.path; f.read == data if @ifchange} rescue false)
|
||||
if (@ifchange or overwrite or create_only) and
|
||||
(@vpath.open(@path, "rb") {|f| outpath = f.path; (@ifchange and f.read == data) or (create_only and !f.read.empty?)} rescue false)
|
||||
puts "#{outpath} #{unchanged}"
|
||||
written = false
|
||||
else
|
||||
|
|
Загрузка…
Ссылка в новой задаче