Skip to content

Commit 40d15fe

Browse files
committed
将 特性分支 替换为 主题分支
修正格式
1 parent 55d47a5 commit 40d15fe

File tree

14 files changed

+344
-127
lines changed

14 files changed

+344
-127
lines changed

.travis.yml

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
11
language: ruby
2+
sudo: false
23
git:
34
depth: false
45
cache: bundler
56
before_install:
6-
- bundle install
7-
after_success:
8-
- script/tag_on_master
7+
- wget https://raw.githubusercontent.com/progit/progit2-pub/master/bootstrap.sh
8+
- sh bootstrap.sh
99
script: bundle exec rake book:build
10-
env:
11-
secure: "O+YCTDgLfCYAJjjOv2sApDRV5NJe6pkhiYIkORFuf2flO8HE72fEtDRpSWh1vulnIH6AjRK2jH7C8qA3MVbUO8D0io+Ha+vnbMXIp1JPCptcJNEkJrW13VTR66SWOzsgLp3mCrIC+YdE2JoYWGcnDsRMQwdnrWnxBzSOd22ZKzU="
12-
13-
before_deploy: bundle install && bundle exec rake book:build
10+
after_success: bundle exec rake book:tag
1411
deploy:
1512
provider: releases
13+
file_glob: true
1614
file:
17-
- progit.epub
18-
- progit.mobi
19-
- progit.pdf
15+
- progit*.epub
16+
- progit*.mobi
17+
- progit*.pdf
2018
skip_cleanup: true
2119
on:
2220
tags: true
23-
api-key:
24-
secure: "l3XdupX6dT48IoTieJXrd7Yx8+KhiR2QYrNrDzT6RKxA7UyXGSP/axsVerg7OjKfIHWZgDJRVzcc2RswE+Xjw9sOY8r2h2q9uCwj8G0EqtFbtgGK0La5LB0euh0tNJN8GLFj1OdSZGY7dWWK88GXeHCua2WSify0V79R4ClIM+s="
21+
api-key: $GITHUB_API_TOKEN
2522
branches:
2623
only:
2724
- master
2825
- /^2\.1(\.\d+)+$/
2926

27+
addons:
28+
apt:
29+
packages:
30+
- epubcheck
3031
notifications:
3132
email:
3233
on_success: never

README.asc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
image::https://travis-ci.org/progit/progit2-zh.svg?branch=master[]
2-
= 翻译、校对、修改前请阅读 TRANSLATION_NOTES.asc,遵守翻译规范!
32
= Pro Git,第二版,简体中文
43

4+
**翻译、校对、修改前请阅读 link:TRANSLATION_NOTES.asc[翻译规范]!**
5+
56
欢迎阅读 Pro Git 第二版。
67

78
你可以访问 https://git-scm.com/book 在线阅读本书。

Rakefile

+236-21
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,250 @@
1+
# coding: utf-8
2+
require 'octokit'
3+
require 'github_changelog_generator'
4+
5+
def exec_or_raise(command)
6+
puts `#{command}`
7+
if (! $?.success?)
8+
raise "'#{command}' failed"
9+
end
10+
end
11+
12+
module GitHubChangelogGenerator
13+
14+
#OPTIONS = %w[ user project token date_format output
15+
# bug_prefix enhancement_prefix issue_prefix
16+
# header merge_prefix issues
17+
# add_issues_wo_labels add_pr_wo_labels
18+
# pulls filter_issues_by_milestone author
19+
# unreleased_only unreleased unreleased_label
20+
# compare_link include_labels exclude_labels
21+
# bug_labels enhancement_labels
22+
# between_tags exclude_tags exclude_tags_regex since_tag max_issues
23+
# github_site github_endpoint simple_list
24+
# future_release release_branch verbose release_url
25+
# base configure_sections add_sections]
26+
27+
def get_log(&task_block)
28+
options = Parser.default_options
29+
yield(options) if task_block
30+
31+
options[:user],options[:project] = ENV['TRAVIS_REPO_SLUG'].split('/')
32+
options[:token] = ENV['GITHUB_API_TOKEN']
33+
options[:unreleased] = false
34+
35+
generator = Generator.new options
36+
generator.compound_changelog
37+
end
38+
39+
module_function :get_log
40+
end
41+
142
namespace :book do
243
desc 'build basic book formats'
344
task :build do
445

5-
begin
6-
version_string = ENV['TRAVIS_TAG'] || `git describe --tags`.chomp
7-
if version_string.empty?
8-
version_string = '0'
9-
end
10-
date_string = Time.now.strftime("%Y-%m-%d")
11-
params = "--attribute revnumber='#{version_string}' --attribute revdate='#{date_string}'"
12-
puts "Generating contributors list"
13-
`git shortlog -s | grep -v -E "(Straub|Chacon)" | cut -f 2- | column -c 120 > book/contributors.txt`
46+
puts "Generating contributors list"
47+
exec_or_raise("git shortlog -s --all $translation_origin | grep -v -E '(Straub|Chacon)' | cut -f 2- | sort | column -c 110 > book/contributors.txt")
1448

15-
puts "Converting to HTML..."
16-
`bundle exec asciidoctor #{params} progit.asc`
17-
puts " -- HTML output at progit.html"
49+
# detect if the deployment is using glob
50+
travis = File.read(".travis.yml")
51+
version_string = ENV['TRAVIS_TAG'] || '0'
52+
if travis.match(/file_glob/)
53+
progit_v = "progit_v#{version_string}"
54+
else
55+
progit_v = "progit"
56+
end
57+
text = File.read('progit.asc')
58+
new_contents = text.gsub("$$VERSION$$", version_string).gsub("$$DATE$$", Time.now.strftime("%Y-%m-%d"))
59+
File.open("#{progit_v}.asc", "w") {|file| file.puts new_contents }
60+
61+
puts "Converting to HTML..."
62+
exec_or_raise("bundle exec asciidoctor #{progit_v}.asc")
63+
puts " -- HTML output at #{progit_v}.html"
1864

19-
puts "Converting to EPub..."
20-
`bundle exec asciidoctor-epub3 #{params} progit.asc`
21-
puts " -- Epub output at progit.epub"
65+
puts "Converting to EPub..."
66+
exec_or_raise("bundle exec asciidoctor-epub3 #{progit_v}.asc")
67+
puts " -- Epub output at #{progit_v}.epub"
2268

23-
puts "Converting to Mobi (kf8)..."
24-
`bundle exec asciidoctor-epub3 #{params} -a ebook-format=kf8 progit.asc`
25-
puts " -- Mobi output at progit.mobi"
69+
exec_or_raise("epubcheck #{progit_v}.epub")
2670

27-
puts "Converting to PDF... (this one takes a while)"
28-
`bundle exec asciidoctor-pdf #{params} progit.asc 2>/dev/null`
29-
puts " -- PDF output at progit.pdf"
71+
puts "Converting to Mobi (kf8)..."
72+
exec_or_raise("bundle exec asciidoctor-epub3 -a ebook-format=kf8 #{progit_v}.asc")
73+
# remove the fake epub that would shadow the really one
74+
exec_or_raise("rm progit*kf8.epub")
75+
puts " -- Mobi output at #{progit_v}.mobi"
3076

77+
repo = ENV['TRAVIS_REPO_SLUG']
78+
puts "Converting to PDF... (this one takes a while)"
79+
if (repo == "progit/progit2-zh")
80+
exec_or_raise("asciidoctor-pdf-cjk-kai_gen_gothic-install")
81+
exec_or_raise("bundle exec asciidoctor-pdf -r asciidoctor-pdf-cjk -r asciidoctor-pdf-cjk-kai_gen_gothic -a pdf-style=KaiGenGothicCN #{progit_v}.asc")
82+
elsif (repo == "progit/progit2-ja")
83+
exec_or_raise("asciidoctor-pdf-cjk-kai_gen_gothic-install")
84+
exec_or_raise("bundle exec asciidoctor-pdf -r asciidoctor-pdf-cjk -r asciidoctor-pdf-cjk-kai_gen_gothic -a pdf-style=KaiGenGothicJP #{progit_v}.asc")
85+
elsif (repo == "progit/progit2-zh-tw")
86+
exec_or_raise("asciidoctor-pdf-cjk-kai_gen_gothic-install")
87+
exec_or_raise("bundle exec asciidoctor-pdf -r asciidoctor-pdf-cjk -r asciidoctor-pdf-cjk-kai_gen_gothic -a pdf-style=KaiGenGothicTW #{progit_v}.asc")
88+
elsif (repo == "progit/progit2-ko")
89+
exec_or_raise("asciidoctor-pdf-cjk-kai_gen_gothic-install")
90+
exec_or_raise("bundle exec asciidoctor-pdf -r asciidoctor-pdf-cjk -r asciidoctor-pdf-cjk-kai_gen_gothic -a pdf-style=KaiGenGothicKR #{progit_v}.asc")
91+
else
92+
exec_or_raise("bundle exec asciidoctor-pdf #{progit_v}.asc 2>/dev/null")
3193
end
94+
puts " -- PDF output at #{progit_v}.pdf"
95+
end
96+
97+
desc 'tag the repo with the latest version'
98+
task :tag do
99+
api_token = ENV['GITHUB_API_TOKEN']
100+
if ((api_token) && (ENV['TRAVIS_PULL_REQUEST'] == 'false'))
101+
repo = ENV['TRAVIS_REPO_SLUG']
102+
@octokit = Octokit::Client.new(:access_token => api_token)
103+
begin
104+
last_version=@octokit.latest_release(repo).tag_name
105+
rescue
106+
last_version="2.1.-1"
107+
end
108+
new_patchlevel= last_version.split('.')[-1].to_i + 1
109+
new_version="2.1.#{new_patchlevel}"
110+
if (ENV['TRAVIS_BRANCH']=='master')
111+
obj = @octokit.create_tag(repo, new_version, "Version " + new_version,
112+
ENV['TRAVIS_COMMIT'], 'commit',
113+
'Automatic build', '[email protected]',
114+
Time.now.utc.iso8601)
115+
begin
116+
@octokit.create_ref(repo, "tags/#{new_version}", obj.sha)
117+
rescue
118+
p "the ref already exists ???"
119+
end
120+
p "Created tag #{last_version}"
121+
elsif (ENV['TRAVIS_TAG'])
122+
version = ENV['TRAVIS_TAG']
123+
changelog = GitHubChangelogGenerator.get_log do |config|
124+
config[:since_tag] = last_version
125+
end
126+
credit_line = "\\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*"
127+
changelog.gsub!(credit_line, "")
128+
@octokit.create_release(repo, new_version, {:name => "v#{new_version}", :body => changelog})
129+
p "Created release #{new_version}"
130+
else
131+
p 'This only runs on a commit to master'
132+
end
133+
else
134+
p 'No interaction with GitHub'
135+
end
136+
end
137+
138+
desc 'convert book to asciidoctor compatibility'
139+
task:convert do
140+
`cp -aR ../progit2/images .`
141+
`sed -i -e 's!/images/!!' .gitignore`
142+
`git add images`
143+
`git rm -r book/*/images`
144+
145+
chapters = [
146+
["01", "introduction" ],
147+
["02", "git-basics" ],
148+
["03", "git-branching" ],
149+
["04", "git-server" ],
150+
["05", "distributed-git" ],
151+
["06", "github" ],
152+
["07", "git-tools" ],
153+
["08", "customizing-git" ],
154+
["09", "git-and-other-scms" ],
155+
["10", "git-internals" ],
156+
["A", "git-in-other-environments" ],
157+
["B", "embedding-git" ],
158+
["C", "git-commands" ]
159+
]
160+
161+
crossrefs = {}
162+
chapters.each { | num, title |
163+
if num =~ /[ABC]/
164+
chap = "#{num}-#{title}"
165+
else
166+
chap = "ch#{num}-#{title}"
167+
end
168+
Dir[File.join ["book","#{num}-#{title}" , "sections","*.asc"]].map { |filename|
169+
File.read(filename).scan(/\[\[(.*?)\]\]/)
170+
}.flatten.each { |ref|
171+
crossrefs[ref] = "#{chap}"
172+
}
173+
}
174+
175+
headrefs = {}
176+
chapters.each { | num, title |
177+
if num =~ /[ABC]/
178+
chap = "#{num}-#{title}"
179+
else
180+
chap = "ch#{num}-#{title}"
181+
end
182+
Dir[File.join ["book","#{num}-#{title}", "*.asc"]].map { |filename|
183+
File.read(filename).scan(/\[\[([_a-z0-9]*?)\]\]/)
184+
}.flatten.each { |ref|
185+
headrefs[ref] = "#{chap}"
186+
}
187+
}
188+
189+
# transform all internal cross refs
190+
chapters.each { | num, title |
191+
if num =~ /[ABC]/
192+
chap = "#{num}-#{title}"
193+
else
194+
chap = "ch#{num}-#{title}"
195+
end
196+
files = Dir[File.join ["book","#{num}-#{title}" , "sections","*.asc"]] +
197+
Dir[File.join ["book","#{num}-#{title}" ,"1-*.asc"]]
198+
p files
199+
files.each { |filename|
200+
content = File.read(filename)
201+
new_contents = content.gsub(/\[\[([_a-z0-9]*?)\]\]/, '[[r\1]]').gsub(
202+
"&rarr;", "→").gsub(/<<([_a-z0-9]*?)>>/) { |match|
203+
ch = crossrefs[$1]
204+
h = headrefs[$1]
205+
# p " #{match} -> #{ch}, #{h}"
206+
if ch
207+
# if local do not add the file
208+
if ch==chap
209+
"<<r#{$1}>>"
210+
else
211+
"<<#{ch}#r#{$1}>>"
212+
end
213+
elsif h
214+
if h==chap
215+
"<<#{chap}>>"
216+
else
217+
"<<#{h}##{h}>>"
218+
end
219+
else
220+
p "could not match xref #{$1}"
221+
"<<#{$1}>>"
222+
end
223+
}
224+
File.open(filename, "w") {|file| file.puts new_contents }
225+
}
226+
}
227+
228+
chapters.each { | num, title |
229+
if num =~ /[ABC]/
230+
chap = "#{num}-#{title}"
231+
else
232+
chap = "ch#{num}-#{title}"
233+
end
234+
Dir[File.join ["book","#{num}-#{title}" ,"1*.asc"]].map { |filename|
235+
content = File.read (filename)
236+
new_contents = content.gsub(/include::(.*?)asc/) {|match|
237+
"include::book/#{num}-#{title}/#{$1}asc"}
238+
`git rm -f #{filename}`
239+
File.open("#{chap}.asc", "w") {|file|
240+
file.puts "[##{chap}]\n"
241+
file.puts new_contents }
242+
`git add "#{chap}.asc"`
243+
}
244+
}
32245
end
33246
end
34247

248+
249+
35250
task :default => "book:build"

book/03-git-branching/sections/rebasing.asc

+7-7
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ image::images/basic-rebase-4.png[`master` 分支的快进合并。]
6868

6969
在对两个分支进行变基时,所生成的“重放”并不一定要在目标分支上应用,你也可以指定另外的一个分支进行应用。
7070
就像 <<rbdiag_e>> 中的例子那样。
71-
你创建了一个特性分支 `server`,为服务端添加了一些功能,提交了 `C3` 和 `C4`。
72-
然后从 `C3` 上创建了特性分支 `client`,为客户端添加了一些功能,提交了 `C8` 和 `C9`。
71+
你创建了一个主题分支 `server`,为服务端添加了一些功能,提交了 `C3` 和 `C4`。
72+
然后从 `C3` 上创建了主题分支 `client`,为客户端添加了一些功能,提交了 `C8` 和 `C9`。
7373
最后,你回到 `server` 分支,又提交了 `C10`。
7474

7575
[[rbdiag_e]]
76-
.从一个特性分支里再分出一个特性分支的提交历史
77-
image::images/interesting-rebase-1.png[从一个特性分支里再分出一个特性分支的提交历史。]
76+
.从一个主题分支里再分出一个主题分支的提交历史
77+
image::images/interesting-rebase-1.png[从一个主题分支里再分出一个主题分支的提交历史。]
7878

7979
假设你希望将 `client` 中的修改合并到主分支并发布,但暂时并不想合并 `server` 中的修改,
8080
因为它们还需要经过更全面的测试。这时,你就可以使用 `git rebase` 命令的 `--onto` 选项,
@@ -88,8 +88,8 @@ $ git rebase --onto master server client
8888
以上命令的意思是:“取出 `client` 分支,找出 `server` 分支之后的分歧的补丁,
8989
然后把它们在 `master` 分支上重放一遍”。这理解起来有一点复杂,不过效果非常酷。
9090

91-
.截取特性分支上的另一个特性分支,然后变基到其他分支
92-
image::images/interesting-rebase-2.png[截取特性分支上的另一个特性分支,然后变基到其他分支。]
91+
.截取主题分支上的另一个主题分支,然后变基到其他分支
92+
image::images/interesting-rebase-2.png[截取主题分支上的另一个主题分支,然后变基到其他分支。]
9393

9494
现在可以快进合并 `master` 分支了。(如图 <<rbdiag_g>>):
9595

@@ -104,7 +104,7 @@ $ git merge client
104104
image::images/interesting-rebase-3.png[快进合并 `master` 分支,使之包含来自 `client` 分支的修改。]
105105

106106
接下来你决定将 `server` 分支中的修改也整合进来。
107-
使用 `git rebase <basebranch> <topicbranch>` 命令可以直接将特性分支
107+
使用 `git rebase <basebranch> <topicbranch>` 命令可以直接将主题分支
108108
(即本例中的 `server`)变基到目标分支(即 `master`)上。
109109
这样做能省去你先切换到 `server` 分支,再对其执行变基命令的多个步骤。
110110

0 commit comments

Comments
 (0)