git_reflow 0.8.6 → 0.8.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +348 -348
  4. data/Gemfile.lock +13 -15
  5. data/LICENSE +20 -20
  6. data/README.rdoc +461 -461
  7. data/Rakefile +8 -8
  8. data/bin/console +7 -7
  9. data/bin/setup +6 -6
  10. data/circle.yml +5 -5
  11. data/exe/git-reflow +36 -36
  12. data/git_reflow.gemspec +1 -1
  13. data/lib/git_reflow/commands/deliver.rb +10 -10
  14. data/lib/git_reflow/commands/refresh.rb +20 -20
  15. data/lib/git_reflow/commands/review.rb +13 -13
  16. data/lib/git_reflow/commands/setup.rb +11 -11
  17. data/lib/git_reflow/commands/stage.rb +9 -9
  18. data/lib/git_reflow/commands/start.rb +22 -22
  19. data/lib/git_reflow/commands/status.rb +7 -7
  20. data/lib/git_reflow/config.rb +9 -9
  21. data/lib/git_reflow/git_server/base.rb +68 -68
  22. data/lib/git_reflow/git_server/bit_bucket/pull_request.rb +84 -84
  23. data/lib/git_reflow/git_server/bit_bucket.rb +101 -101
  24. data/lib/git_reflow/git_server/git_hub/pull_request.rb +4 -1
  25. data/lib/git_reflow/git_server/pull_request.rb +11 -2
  26. data/lib/git_reflow/git_server.rb +63 -63
  27. data/lib/git_reflow/logger.rb +49 -0
  28. data/lib/git_reflow/merge_error.rb +9 -9
  29. data/lib/git_reflow/os_detector.rb +23 -23
  30. data/lib/git_reflow/rspec/command_line_helpers.rb +12 -8
  31. data/lib/git_reflow/rspec/stub_helpers.rb +13 -13
  32. data/lib/git_reflow/rspec.rb +2 -2
  33. data/lib/git_reflow/sandbox.rb +11 -6
  34. data/lib/git_reflow/version.rb +1 -1
  35. data/lib/git_reflow/workflow.rb +59 -59
  36. data/lib/git_reflow/workflows/core.rb +238 -238
  37. data/lib/git_reflow/workflows/flat_merge.rb +10 -10
  38. data/lib/git_reflow.rb +11 -0
  39. data/spec/fixtures/awesome_workflow.rb +7 -0
  40. data/spec/fixtures/git/git_config +7 -0
  41. data/spec/fixtures/issues/comment.json.erb +27 -0
  42. data/spec/fixtures/issues/comments.json +29 -0
  43. data/spec/fixtures/issues/comments.json.erb +15 -0
  44. data/spec/fixtures/pull_requests/comment.json.erb +45 -0
  45. data/spec/fixtures/pull_requests/comments.json +47 -0
  46. data/spec/fixtures/pull_requests/comments.json.erb +15 -0
  47. data/spec/fixtures/pull_requests/commits.json +29 -0
  48. data/spec/fixtures/pull_requests/external_pull_request.json +145 -0
  49. data/spec/fixtures/pull_requests/pull_request.json +142 -0
  50. data/spec/fixtures/pull_requests/pull_request.json.erb +142 -0
  51. data/spec/fixtures/pull_requests/pull_request_exists_error.json +32 -0
  52. data/spec/fixtures/pull_requests/pull_requests.json +136 -0
  53. data/spec/fixtures/repositories/commit.json +53 -0
  54. data/spec/fixtures/repositories/commit.json.erb +53 -0
  55. data/spec/fixtures/repositories/commits.json.erb +13 -0
  56. data/spec/fixtures/repositories/statuses.json +31 -0
  57. data/spec/fixtures/workflow_with_super.rb +8 -0
  58. data/spec/lib/git_reflow/config_spec.rb +74 -0
  59. data/spec/lib/git_reflow/git_helpers_spec.rb +182 -0
  60. data/spec/lib/git_reflow/git_server/bit_bucket_spec.rb +81 -0
  61. data/spec/lib/git_reflow/git_server/git_hub/pull_request_spec.rb +587 -0
  62. data/spec/lib/git_reflow/git_server/git_hub_spec.rb +221 -0
  63. data/spec/lib/git_reflow/git_server/pull_request_spec.rb +524 -0
  64. data/spec/lib/git_reflow/git_server_spec.rb +101 -0
  65. data/spec/lib/git_reflow/logger_spec.rb +18 -0
  66. data/spec/lib/git_reflow/sandbox_spec.rb +15 -0
  67. data/spec/lib/git_reflow/workflow_spec.rb +59 -0
  68. data/spec/lib/git_reflow/workflows/core_spec.rb +665 -0
  69. data/spec/lib/git_reflow/workflows/flat_merge_spec.rb +59 -0
  70. data/spec/lib/git_reflow_spec.rb +75 -0
  71. data/spec/spec_helper.rb +38 -0
  72. data/spec/support/fake_github.rb +128 -0
  73. data/spec/support/fixtures.rb +54 -0
  74. data/spec/support/github_helpers.rb +109 -0
  75. data/spec/support/mock_pull_request.rb +17 -0
  76. data/spec/support/web_mocks.rb +39 -0
  77. metadata +83 -6
data/README.rdoc CHANGED
@@ -1,461 +1,461 @@
1
- = git-reflow (2015 Fukuoka Ruby Award Winner)
2
-
3
- {<img src="https://circleci.com/gh/reenhanced/gitreflow.svg?style=svg" alt="Circle CI" />}[https://circleci.com/gh/reenhanced/gitreflow]
4
- {<img src="https://img.shields.io/badge/git--reflow-v0.8.0-blue.svg?style=flat&link=https://github.com/reenhanced/gitreflow" alt="Git workflow powered by git-reflow" />}[https://github.com/reenhanced/gitreflow]
5
- {<img src="http://inch-ci.org/github/reenhanced/gitreflow.svg?branch=master&style=shields" alt="Documentation" />}[http://inch-ci.org/github/reenhanced/gitreflow]
6
-
7
- {RDocs}[http://www.rubydoc.info/gems/git_reflow]
8
-
9
- http://reenhanced.com/reflow/git-reflow-deliver.gif
10
-
11
- If your workflow looks like this:
12
- 1. Create a feature branch
13
- 2. Write great code
14
- 3. Create a pull request against master
15
- 4. Get 'lgtm' through a code review
16
- 5. Squash merge to master (Why is squash merging our preferred workflow? https://github.com/reenhanced/gitreflow/issues/52)
17
- 6. Delete the feature branch
18
-
19
- Reflow will make your life easier.
20
-
21
- Reflow automatically creates pull requests, ensures the code review is approved, and squash merges finished branches to master with a great commit message template.
22
-
23
- == Quickstart
24
- Create and switch to new branch +nh-branchy-branch+:
25
- $ git reflow start nh-branchy-branch
26
-
27
- Create a pull request for your branch against +master+ or a custom +base_branch+:
28
- $ git reflow review
29
-
30
- If your code is 'LGTM'd, squash merge to +base_branch+ and delete the feature branch:
31
- $ git reflow deliver
32
-
33
- ----
34
-
35
- == Benefits:
36
- * Enforce code reviews across your team.
37
- * Know that your entire team delivers code the same way.
38
- * Reduce the knowledge needed to deliver great code.
39
- * Have a commit history that's clean and actually usable.
40
- * Revert features with ease (if needed).
41
- * Work with diverse teams with less worry about different processes.
42
- * Stop searching for other git workflows.
43
- Reflow covers 90% of your needs without junk you'll never use.
44
-
45
- == Features:
46
- * Automatically create pull requests to master
47
- * Automatically ensure that your code is reviewed before merging
48
- * Start with sensible commit messages by default
49
- * Squash merge feature branches because results are more important than details
50
- * Automatically clean up obsolete feature branches after a successful merge
51
-
52
- ----
53
-
54
- == How to use
55
-
56
- === Dependencies
57
-
58
- *Editor* When reviewing the title and body for a new pull request, or reviewing the
59
- commit message when delivering a feature, we will open a temporary file with
60
- your default editor. We will use git's chosen editor first ("core.editor" git config key), then we try your
61
- "EDITOR" environment variable, and lastly we fallback on "vim".
62
- If you would like to use an editor of your choice, we recommend setting it with
63
- git's config. As an example, to use Atom as your editor for all git commands:
64
- $ git config --global core.editor "atom --wait"
65
- See GitHub's full article on [associating text editors with Git](https://help.github.com/articles/associating-text-editors-with-git/) for more information on adding this.
66
-
67
-
68
- === Installation
69
- $ gem install reflow
70
- or
71
- $ gem install git_reflow
72
-
73
- (`git_reflow` is the official gem, and `reflow` just declares `git_reflow` as a dependency.)
74
-
75
- === Setup
76
- On your first install, you'll need to setup your Github credentials. These are used only to get an oauth token that's stored in your global git config.
77
- We use the Github credentials so we can create pull requests from the command line.
78
-
79
- After installation, run:
80
- git reflow setup
81
-
82
- It looks like this:
83
- $ git reflow setup
84
- Please enter your GitHub username: nhance
85
- Please enter your GitHub password (we do NOT store this):
86
-
87
- Your GitHub account was successfully setup!
88
-
89
- This is safe to run multiple times. We don't care.
90
-
91
- === Usage with Github Enterprise
92
- To use GitReflow with a GitHub Enterprise account, there are some additional switches available to the GitReflow setup command. You should be able to use GitReflow for both your Enterprise and non-Enterprise repositories. Because of this, there are a few scenarios that may apply to your usage of GitReflow:
93
-
94
- You use a GitHub Enterprise account for the majority of your repositories:
95
- git reflow setup --enterprise
96
- After this, anytime you want to use GitReflow with project that uses a regular GitHub account:
97
- cd replace_with_your_non_enterprise_project_path
98
- git reflow setup --local
99
- This will setup your project's git config with the OAuth token generated from the credentials you provide
100
-
101
- If you only use GitHub Enterprise for a select few repositories, you'll first want to setup GitReflow as normal:
102
- git reflow setup
103
- Then for your Enterprise projects, you have to setup GitReflow for each one:
104
- cd replace_with_your_enterprise_project_path
105
- git reflow setup --enterprise --local
106
-
107
- === Refreshing your current branch based on your base branch
108
-
109
- git reflow refresh
110
-
111
- This command updates your feature_branch and base_branch according to the remote_location and then merges your base_branch into your feature_branch. This is just a handy command to keep your branches up to date at any point in time if someone else has committed to the base_branch or the remote.
112
-
113
- git reflow refresh -r <remote_location> -b <base_branch_name>
114
-
115
- You pass in the name of the remote to fetch from and the name of the base_branch that you would like to merge into your feature_branch. The remote_location defaults to "origin" and the base_branch defaults to "master". This command also takes in remote and branch name as flag options.
116
-
117
- === Starting a feature branch
118
- http://reenhanced.com/reflow/git-reflow-start.gif
119
-
120
- git reflow start
121
-
122
- This sets up a feature branch remotely and brings a local copy to your machine. Yeah, you can do this by hand pretty easily, so skip this command if you want. This is just a handy shortcut with no magic.
123
-
124
- git reflow start nh-branch-name
125
-
126
- "Git Reflow Start" takes in the name of the new branch name that you want to create your feature on.
127
- In addition, it takes in an optional flag of a base branch name. If you don't pass in this parameter, then it defaults to "master".
128
- The base branch name is the base branch that you want to base your feature off of.
129
- This ensures that everytime you start a new base branch, it will be based off of your latest remote base.
130
-
131
- git reflow start nh-branch-name --base base-branch-name
132
-
133
- [PROTIP] Use your initials at the beginning of each branch so your team knows
134
- who is responsible for each. My initials are 'NH', so all of my branches start with +nh-+
135
-
136
- === Reviewing your work
137
- http://reenhanced.com/reflow/git-reflow-review.gif
138
-
139
- git reflow review
140
-
141
- All of our work is reviewed by our team. This helps spread knowledge to multiple parties and keeps the quality of our code consistent.
142
-
143
- The +review+ step creates a pull request for the currently checked out feature branch against master. That's all you want to do most of the time.
144
- We assume you know what you're doing, so if you need something different, do it by hand.
145
-
146
- After making commits to your branch, run +review+. Didn't push it up? We don't care, we'll do it for you.
147
-
148
- git reflow review -t <title> -m <message>
149
-
150
- If you do not pass the title or message options to the review command, you will be given an editor to write your PR request commit message, similar to `git commit`. The first line is the title, the rest is the body.
151
-
152
- $ git reflow review
153
-
154
- Review your PR:
155
- --------
156
- Title:
157
- rj_209_test
158
-
159
- Body:
160
- [lib] updates review command to address issues
161
- --------
162
- Submit pull request? (Y): <enter>
163
- git fetch origin master
164
- From github.com:meesterdude/gitreflow
165
- * branch master -> FETCH_HEAD
166
-
167
- git push origin rj_test
168
- Everything up-to-date
169
-
170
- Successfully created pull request #6: rj_test
171
- Pull Request URL: https://github.com/meesterdude/gitreflow/pull/6
172
- Would you like to push this branch to your remote repo and cleanup your feature branch? y
173
-
174
-
175
- [OSX/Ubuntu only] You can automatically open your default web browser to the pull request.
176
- This lets you edit the pull request with all of the detailed information you'll need before submitting it to your team.
177
-
178
- We output the pull request URL so you can distribute it to your team without leaving the terminal.
179
-
180
- ==== How it works
181
- Behind the scenes, this is how +review+ works:
182
- git fetch origin
183
-
184
- Are we up-to-date with changes from master?
185
- If not, fail with "master has newer changes".
186
-
187
- Then,
188
- git push origin current-branch # Updates remote branch
189
-
190
- Do we have pull request?
191
- If not, create it and print "Pull request created at http://pull-url/". If so, print the url for the existing request.
192
-
193
- === Checking your branch status
194
- http://reenhanced.com/reflow/git-reflow-status.gif
195
-
196
- git reflow status
197
-
198
- Sometimes you start working on a branch and can't get back to it for a while. It happens. Use +status+ to check on the status of your work.
199
-
200
- $ git reflow status
201
-
202
- Here's the status of your review:
203
- branches: reenhanced:nh-readme-update -> reenhanced:master
204
- number: 35
205
- reviewed by:
206
- url: https://github.com/reenhanced/gitreflow/pull/35
207
-
208
- [notice] No one has reviewed your pull request...
209
- Would you like to open it in your browser? n
210
-
211
- This gives you details on who's reviewed your pull request. If someone has participated, but not given you a 'LGTM', this will tell you.
212
- +status+ prevents you from having to open a browser to find out where your pull request is at. But in case you want to take a look, we give you the option to open it for you.
213
-
214
- === Delivering approved code
215
-
216
- ==== Note: This documentation is for the process for the github "remote" merge process via the github_api.
217
- For the bitbucket standard or github manual process (used when the user applies -f force flag to the "remote" merge via the github_api), please go to section B.
218
-
219
- ==== A:
220
- http://reenhanced.com/reflow/git-reflow-deliver.gif
221
-
222
- git reflow deliver
223
-
224
- You kick butt. You've got your code reviewed and now you're ready to merge it down to +master+ and deploy. Reflow +deliver+ will take care of all of the steps for you to make this happen.
225
-
226
- Reflow's +deliver+ requires you to have a pull request, so you'll be protected on those mornings when the coffee isn't working yet.
227
- We built this <b>to get in your way and make you follow the process</b>. If you don't like it, do it by hand. You already know what you're doing.
228
-
229
- You'll be presented with a prefilled commit message based on the body of your pull request with references to the pull request and reviewers.
230
-
231
- Want to clean up your feature branch afterwards? You'll be prompted after you edit your commit message if you want to clean up your +feature_branch+ on github. If you answer 'n', then your feature_branch will exist for you to clean it up later.
232
-
233
- This is what it looks like:
234
-
235
- $ git reflow deliver
236
- Here's the status of your review:
237
- branches: simonzhu24:test1234 -> simonzhu24:master
238
- number: 51
239
- reviewed by:
240
- url: https://github.com/simonzhu24/test/pull/51
241
-
242
- [notice] No one has reviewed your pull request.
243
- Would you like to open it in your browser? n
244
- This is the current status of your Pull Request. Are you sure you want to deliver? Y
245
- Merging pull request #51: 'last commit message', from 'simonzhu24:test1234' into 'simonzhu24:master'
246
- git checkout master
247
- Switched to branch 'master'
248
- Your branch is ahead of 'origin/master' by 1 commit.
249
- (use "git push" to publish your local commits)
250
-
251
- [success] Pull Request successfully merged.
252
- Would you like to cleanup your feature branch? Y
253
- git pull origin master
254
- remote: Counting objects: 1, done.
255
- remote: Total 1 (delta 0), reused 0 (delta 0), pack-reused 0
256
- Unpacking objects: 100% (1/1), done.
257
- From https://github.com/simonzhu24/test
258
- * branch master -> FETCH_HEAD
259
- 0d8f5e0..f853efa master -> origin/master
260
- Updating 0b6782f..f853efa
261
- Fast-forward
262
- README.md | 2 +-
263
- 1 file changed, 1 insertion(+), 1 deletion(-)
264
-
265
- git push origin :test1234
266
- To https://github.com/simonzhu24/test.git
267
- - [deleted] test1234
268
-
269
- git branch -D test1234
270
- Deleted branch test1234 (was e130c7a).
271
- Nice job buddy.
272
-
273
- ==== How it works
274
-
275
- This is what we do behind the scenes when you do +deliver+
276
-
277
- * Does a pull request exist?
278
-
279
- If not, stop here. You need to run +review+.
280
-
281
- * Has the review been completed? Did we get a +LGTM+ from everyone who's participated?
282
-
283
- If not, show a list of authors that need to provide a +LGTM+.
284
-
285
- * If the review is done, it's time to merge. Here's what happens:
286
-
287
- First, we use the github_api gem to merge the pull request.
288
-
289
- We call the public API for:
290
-
291
- github.pull_requests.merge 'user-name', 'repo-name', 'number', payload
292
-
293
- Please take a look at lib/git_reflow/git_server/git_hub/pull_request.rb:102-107 for an example of the call.
294
- This call makes an HTTP request using the Github API to merge the available pull request passing in the user name, repository name, pull request number, and some additional data in the payload.
295
-
296
- The payload contains data in the following format:
297
-
298
- data = {
299
- "commit_title",
300
- "commit_message",
301
- "sha",
302
- "squash"
303
- }
304
-
305
- Notice: "squash" is set to true, meaning that we will do a squash-merge for each pull request.
306
-
307
- For more detailed documentation, please read: https://github.com/piotrmurach/github/blob/master/lib/github_api/client/pull_requests.rb#L197
308
-
309
- * Next, we prompt you if you want to cleanup
310
- Would you like cleanup your feature branch?
311
-
312
- If 'y', then we'll update the +base_branch+ and delete the feature branch
313
-
314
- git pull origin #{base_branch}
315
- git push origin :#{feature_branch}
316
- git branch -D #{feature_branch}
317
-
318
- If 'n', then just stop here. The user can clean up his branch locally.
319
-
320
- And we're done.
321
-
322
- ==== Note: This documentation is for the bitbucket standard or github manual process (used when the user applies -f force flag to the "remote" merge via the github_api).
323
-
324
- ==== B:
325
- This is what the process looks like for bitbucket or if you force deliver:
326
-
327
- From github.com:reenhanced/gitreflow
328
- * branch master -> FETCH_HEAD
329
- Merging pull request #36: 'Enforce at least one LGTM before delivery', from 'reenhanced:nh-fail-without-lgtm' into 'reenhanced:master'
330
- Already up-to-date.
331
- Switched to branch 'nh-fail-without-lgtm'
332
- Switched to branch 'master'
333
- Updating c2ec1b1..f90e111
334
- Squash commit -- not updating HEAD
335
- lib/git_reflow.rb | 71 +++++++++++++++++++++++++++----------------------------
336
- 1 file changed, 35 insertions(+), 36 deletions(-)
337
- [master d1b4dd5] Enforces LGTM before deliver, even with no comments.
338
- 1 file changed, 35 insertions(+), 36 deletions(-)
339
- Merge complete!
340
- Would you like to push this branch to your remote repo and cleanup your feature branch? y
341
- Counting objects: 7, done.
342
- Delta compression using up to 16 threads.
343
- Compressing objects: 100% (4/4), done.
344
- Writing objects: 100% (4/4), 1.38 KiB, done.
345
- Total 4 (delta 2), reused 0 (delta 0)
346
- To git@github.com:reenhanced/gitreflow.git
347
- c2ec1b1..d1b4dd5 master -> master
348
-
349
- To git@github.com:reenhanced/gitreflow.git
350
- - [deleted] nh-fail-without-lgtm
351
-
352
- Deleted branch nh-fail-without-lgtm (was f90e111).
353
-
354
- This is what the default commit message looks like:
355
- Enforces LGTM before deliver, even with no comments.
356
- Removes the need to review the pull request yourself if you make a
357
- comment.
358
-
359
- Better error message if setup fails.
360
-
361
- Bug fixes.
362
-
363
- Closes #36
364
-
365
- LGTM given by: @codenamev
366
-
367
- Squashed commit of the following:
368
-
369
- commit f90e111
370
- Author: Nicholas Hance <nhance@reenhanced.com>
371
- Date: Thu Jul 11 15:33:29 2013 -0400
372
- ...
373
-
374
- If the review is done, it's time to merge. Here's what happens:
375
-
376
- First, update our local +master+ so we don't get conflicts
377
- git checkout master
378
- git pull origin master
379
-
380
- Next, squash merge our feature branch
381
- git merge --squash nh-branch-name
382
-
383
- Now, we'll apply a little magic so we have a great commit message by default. Your editor will open and you'll see a nice default for your commit message based on the pull request body.
384
-
385
- Once you've saved the commit, prompt the user to see if we should continue
386
- Merge complete!
387
- Would you like to push this branch to your remote repo and cleanup your feature branch?
388
-
389
- If 'y', then we'll push to +master+ and delete the feature branch
390
- git pull origin master
391
- git push origin master
392
- git push origin :nh-branch-name
393
- git branch -D nh-branch-name
394
-
395
- If 'n', then just stop here. The user can reset his local +master+.
396
- And we're done.
397
-
398
- == Guiding principles:
399
- * Your workflow should resemble the following:
400
- http://reenhanced.com/images/reflow.png
401
-
402
- * You should already know what you're doing.
403
- We assume you know how to use git.
404
-
405
- * The +master+ branch is your codebase.
406
- You don't need multiple branches for code actually want to use.
407
-
408
- * +master+ should remain stable at all times.
409
- The entire team depends on it.
410
-
411
- * No direct commits to +master+.
412
- All work happens in feature branches. From a single commit to hundreds.
413
-
414
- * All feature branches are reviewed via pull requests.
415
-
416
- * Looks Good To Me. All feature branches require approval.
417
- We look for the string 'LGTM' in a comment on the pull request to know it's ready to merge.
418
-
419
- * If you make a new commit in your branch, you require another review.
420
-
421
- * Depending on the minimumApprovals that you specify in your ~/.gitconfig.reflow (created upon reflow setup), you can have the following:
422
-
423
- "" : All participants in a pull request must approve the pull request.
424
- "0": 0 approvals required for you to merge PR.
425
- "1": You need a minimum of 1 LGTM and the last comment on your PR must be an LGTM.
426
- "2": You need a minimum of 2 LGTM and the last comment on your PR must be an LGTM.
427
- ...
428
-
429
- * Once approved, your feature branch is squash-merged to your base_branch.
430
- This makes the history of the base_branch branch extremely clean and easy to follow.
431
-
432
- * Git blame becomes your friend. You'll know who to blame and can see the full context of changes.
433
- Squash commits to base_branch mean every commit represents the whole feature, not a "typo fix".
434
-
435
-
436
- == Configuration
437
-
438
- In order to streamline delivery you can set the following git config to:
439
-
440
- 1. always clean up the feature branch after the PR is merged
441
- 2. always deliver without further prompt
442
-
443
- git config --global --add "reflow.always-cleanup" "true"
444
- git config --global --add "reflow.always-deliver" "true"
445
-
446
- ---
447
-
448
- == Contributing
449
- Pull requests are welcome. Please fork and submit. We use this tool every single day and as long as what you want to add doesn't change our workflow, we are happy to accept your updates. Feel free to add your github username to the list below.
450
-
451
- Authors:
452
- * @codenamev
453
- * @armyofgnomes
454
- * @nhance
455
-
456
- Built by Reenhanced:
457
- http://www.reenhanced.com
458
-
459
- <B>Looking for a capable team for your project? Get in touch. We're looking to grow.</B>
460
-
461
- <em>Licensed using the MIT license. Do whatever you like with this, but don't blame us if it breaks anything. You're a professional, and you're responsible for the tools you use.</em>
1
+ = git-reflow (2015 Fukuoka Ruby Award Winner)
2
+
3
+ {<img src="https://circleci.com/gh/reenhanced/gitreflow.svg?style=svg" alt="Circle CI" />}[https://circleci.com/gh/reenhanced/gitreflow]
4
+ {<img src="https://img.shields.io/badge/git--reflow-v0.8.0-blue.svg?style=flat&link=https://github.com/reenhanced/gitreflow" alt="Git workflow powered by git-reflow" />}[https://github.com/reenhanced/gitreflow]
5
+ {<img src="http://inch-ci.org/github/reenhanced/gitreflow.svg?branch=master&style=shields" alt="Documentation" />}[http://inch-ci.org/github/reenhanced/gitreflow]
6
+
7
+ {RDocs}[http://www.rubydoc.info/gems/git_reflow]
8
+
9
+ http://reenhanced.com/reflow/git-reflow-deliver.gif
10
+
11
+ If your workflow looks like this:
12
+ 1. Create a feature branch
13
+ 2. Write great code
14
+ 3. Create a pull request against master
15
+ 4. Get 'lgtm' through a code review
16
+ 5. Squash merge to master (Why is squash merging our preferred workflow? https://github.com/reenhanced/gitreflow/issues/52)
17
+ 6. Delete the feature branch
18
+
19
+ Reflow will make your life easier.
20
+
21
+ Reflow automatically creates pull requests, ensures the code review is approved, and squash merges finished branches to master with a great commit message template.
22
+
23
+ == Quickstart
24
+ Create and switch to new branch +nh-branchy-branch+:
25
+ $ git reflow start nh-branchy-branch
26
+
27
+ Create a pull request for your branch against +master+ or a custom +base_branch+:
28
+ $ git reflow review
29
+
30
+ If your code is 'LGTM'd, squash merge to +base_branch+ and delete the feature branch:
31
+ $ git reflow deliver
32
+
33
+ ----
34
+
35
+ == Benefits:
36
+ * Enforce code reviews across your team.
37
+ * Know that your entire team delivers code the same way.
38
+ * Reduce the knowledge needed to deliver great code.
39
+ * Have a commit history that's clean and actually usable.
40
+ * Revert features with ease (if needed).
41
+ * Work with diverse teams with less worry about different processes.
42
+ * Stop searching for other git workflows.
43
+ Reflow covers 90% of your needs without junk you'll never use.
44
+
45
+ == Features:
46
+ * Automatically create pull requests to master
47
+ * Automatically ensure that your code is reviewed before merging
48
+ * Start with sensible commit messages by default
49
+ * Squash merge feature branches because results are more important than details
50
+ * Automatically clean up obsolete feature branches after a successful merge
51
+
52
+ ----
53
+
54
+ == How to use
55
+
56
+ === Dependencies
57
+
58
+ *Editor* When reviewing the title and body for a new pull request, or reviewing the
59
+ commit message when delivering a feature, we will open a temporary file with
60
+ your default editor. We will use git's chosen editor first ("core.editor" git config key), then we try your
61
+ "EDITOR" environment variable, and lastly we fallback on "vim".
62
+ If you would like to use an editor of your choice, we recommend setting it with
63
+ git's config. As an example, to use Atom as your editor for all git commands:
64
+ $ git config --global core.editor "atom --wait"
65
+ See GitHub's full article on [associating text editors with Git](https://help.github.com/articles/associating-text-editors-with-git/) for more information on adding this.
66
+
67
+
68
+ === Installation
69
+ $ gem install reflow
70
+ or
71
+ $ gem install git_reflow
72
+
73
+ (`git_reflow` is the official gem, and `reflow` just declares `git_reflow` as a dependency.)
74
+
75
+ === Setup
76
+ On your first install, you'll need to setup your Github credentials. These are used only to get an oauth token that's stored in your global git config.
77
+ We use the Github credentials so we can create pull requests from the command line.
78
+
79
+ After installation, run:
80
+ git reflow setup
81
+
82
+ It looks like this:
83
+ $ git reflow setup
84
+ Please enter your GitHub username: nhance
85
+ Please enter your GitHub password (we do NOT store this):
86
+
87
+ Your GitHub account was successfully setup!
88
+
89
+ This is safe to run multiple times. We don't care.
90
+
91
+ === Usage with Github Enterprise
92
+ To use GitReflow with a GitHub Enterprise account, there are some additional switches available to the GitReflow setup command. You should be able to use GitReflow for both your Enterprise and non-Enterprise repositories. Because of this, there are a few scenarios that may apply to your usage of GitReflow:
93
+
94
+ You use a GitHub Enterprise account for the majority of your repositories:
95
+ git reflow setup --enterprise
96
+ After this, anytime you want to use GitReflow with project that uses a regular GitHub account:
97
+ cd replace_with_your_non_enterprise_project_path
98
+ git reflow setup --local
99
+ This will setup your project's git config with the OAuth token generated from the credentials you provide
100
+
101
+ If you only use GitHub Enterprise for a select few repositories, you'll first want to setup GitReflow as normal:
102
+ git reflow setup
103
+ Then for your Enterprise projects, you have to setup GitReflow for each one:
104
+ cd replace_with_your_enterprise_project_path
105
+ git reflow setup --enterprise --local
106
+
107
+ === Refreshing your current branch based on your base branch
108
+
109
+ git reflow refresh
110
+
111
+ This command updates your feature_branch and base_branch according to the remote_location and then merges your base_branch into your feature_branch. This is just a handy command to keep your branches up to date at any point in time if someone else has committed to the base_branch or the remote.
112
+
113
+ git reflow refresh -r <remote_location> -b <base_branch_name>
114
+
115
+ You pass in the name of the remote to fetch from and the name of the base_branch that you would like to merge into your feature_branch. The remote_location defaults to "origin" and the base_branch defaults to "master". This command also takes in remote and branch name as flag options.
116
+
117
+ === Starting a feature branch
118
+ http://reenhanced.com/reflow/git-reflow-start.gif
119
+
120
+ git reflow start
121
+
122
+ This sets up a feature branch remotely and brings a local copy to your machine. Yeah, you can do this by hand pretty easily, so skip this command if you want. This is just a handy shortcut with no magic.
123
+
124
+ git reflow start nh-branch-name
125
+
126
+ "Git Reflow Start" takes in the name of the new branch name that you want to create your feature on.
127
+ In addition, it takes in an optional flag of a base branch name. If you don't pass in this parameter, then it defaults to "master".
128
+ The base branch name is the base branch that you want to base your feature off of.
129
+ This ensures that everytime you start a new base branch, it will be based off of your latest remote base.
130
+
131
+ git reflow start nh-branch-name --base base-branch-name
132
+
133
+ [PROTIP] Use your initials at the beginning of each branch so your team knows
134
+ who is responsible for each. My initials are 'NH', so all of my branches start with +nh-+
135
+
136
+ === Reviewing your work
137
+ http://reenhanced.com/reflow/git-reflow-review.gif
138
+
139
+ git reflow review
140
+
141
+ All of our work is reviewed by our team. This helps spread knowledge to multiple parties and keeps the quality of our code consistent.
142
+
143
+ The +review+ step creates a pull request for the currently checked out feature branch against master. That's all you want to do most of the time.
144
+ We assume you know what you're doing, so if you need something different, do it by hand.
145
+
146
+ After making commits to your branch, run +review+. Didn't push it up? We don't care, we'll do it for you.
147
+
148
+ git reflow review -t <title> -m <message>
149
+
150
+ If you do not pass the title or message options to the review command, you will be given an editor to write your PR request commit message, similar to `git commit`. The first line is the title, the rest is the body.
151
+
152
+ $ git reflow review
153
+
154
+ Review your PR:
155
+ --------
156
+ Title:
157
+ rj_209_test
158
+
159
+ Body:
160
+ [lib] updates review command to address issues
161
+ --------
162
+ Submit pull request? (Y): <enter>
163
+ git fetch origin master
164
+ From github.com:meesterdude/gitreflow
165
+ * branch master -> FETCH_HEAD
166
+
167
+ git push origin rj_test
168
+ Everything up-to-date
169
+
170
+ Successfully created pull request #6: rj_test
171
+ Pull Request URL: https://github.com/meesterdude/gitreflow/pull/6
172
+ Would you like to push this branch to your remote repo and cleanup your feature branch? y
173
+
174
+
175
+ [OSX/Ubuntu only] You can automatically open your default web browser to the pull request.
176
+ This lets you edit the pull request with all of the detailed information you'll need before submitting it to your team.
177
+
178
+ We output the pull request URL so you can distribute it to your team without leaving the terminal.
179
+
180
+ ==== How it works
181
+ Behind the scenes, this is how +review+ works:
182
+ git fetch origin
183
+
184
+ Are we up-to-date with changes from master?
185
+ If not, fail with "master has newer changes".
186
+
187
+ Then,
188
+ git push origin current-branch # Updates remote branch
189
+
190
+ Do we have pull request?
191
+ If not, create it and print "Pull request created at http://pull-url/". If so, print the url for the existing request.
192
+
193
+ === Checking your branch status
194
+ http://reenhanced.com/reflow/git-reflow-status.gif
195
+
196
+ git reflow status
197
+
198
+ Sometimes you start working on a branch and can't get back to it for a while. It happens. Use +status+ to check on the status of your work.
199
+
200
+ $ git reflow status
201
+
202
+ Here's the status of your review:
203
+ branches: reenhanced:nh-readme-update -> reenhanced:master
204
+ number: 35
205
+ reviewed by:
206
+ url: https://github.com/reenhanced/gitreflow/pull/35
207
+
208
+ [notice] No one has reviewed your pull request...
209
+ Would you like to open it in your browser? n
210
+
211
+ This gives you details on who's reviewed your pull request. If someone has participated, but not given you a 'LGTM', this will tell you.
212
+ +status+ prevents you from having to open a browser to find out where your pull request is at. But in case you want to take a look, we give you the option to open it for you.
213
+
214
+ === Delivering approved code
215
+
216
+ ==== Note: This documentation is for the process for the github "remote" merge process via the github_api.
217
+ For the bitbucket standard or github manual process (used when the user applies -f force flag to the "remote" merge via the github_api), please go to section B.
218
+
219
+ ==== A:
220
+ http://reenhanced.com/reflow/git-reflow-deliver.gif
221
+
222
+ git reflow deliver
223
+
224
+ You kick butt. You've got your code reviewed and now you're ready to merge it down to +master+ and deploy. Reflow +deliver+ will take care of all of the steps for you to make this happen.
225
+
226
+ Reflow's +deliver+ requires you to have a pull request, so you'll be protected on those mornings when the coffee isn't working yet.
227
+ We built this <b>to get in your way and make you follow the process</b>. If you don't like it, do it by hand. You already know what you're doing.
228
+
229
+ You'll be presented with a prefilled commit message based on the body of your pull request with references to the pull request and reviewers.
230
+
231
+ Want to clean up your feature branch afterwards? You'll be prompted after you edit your commit message if you want to clean up your +feature_branch+ on github. If you answer 'n', then your feature_branch will exist for you to clean it up later.
232
+
233
+ This is what it looks like:
234
+
235
+ $ git reflow deliver
236
+ Here's the status of your review:
237
+ branches: simonzhu24:test1234 -> simonzhu24:master
238
+ number: 51
239
+ reviewed by:
240
+ url: https://github.com/simonzhu24/test/pull/51
241
+
242
+ [notice] No one has reviewed your pull request.
243
+ Would you like to open it in your browser? n
244
+ This is the current status of your Pull Request. Are you sure you want to deliver? Y
245
+ Merging pull request #51: 'last commit message', from 'simonzhu24:test1234' into 'simonzhu24:master'
246
+ git checkout master
247
+ Switched to branch 'master'
248
+ Your branch is ahead of 'origin/master' by 1 commit.
249
+ (use "git push" to publish your local commits)
250
+
251
+ [success] Pull Request successfully merged.
252
+ Would you like to cleanup your feature branch? Y
253
+ git pull origin master
254
+ remote: Counting objects: 1, done.
255
+ remote: Total 1 (delta 0), reused 0 (delta 0), pack-reused 0
256
+ Unpacking objects: 100% (1/1), done.
257
+ From https://github.com/simonzhu24/test
258
+ * branch master -> FETCH_HEAD
259
+ 0d8f5e0..f853efa master -> origin/master
260
+ Updating 0b6782f..f853efa
261
+ Fast-forward
262
+ README.md | 2 +-
263
+ 1 file changed, 1 insertion(+), 1 deletion(-)
264
+
265
+ git push origin :test1234
266
+ To https://github.com/simonzhu24/test.git
267
+ - [deleted] test1234
268
+
269
+ git branch -D test1234
270
+ Deleted branch test1234 (was e130c7a).
271
+ Nice job buddy.
272
+
273
+ ==== How it works
274
+
275
+ This is what we do behind the scenes when you do +deliver+
276
+
277
+ * Does a pull request exist?
278
+
279
+ If not, stop here. You need to run +review+.
280
+
281
+ * Has the review been completed? Did we get a +LGTM+ from everyone who's participated?
282
+
283
+ If not, show a list of authors that need to provide a +LGTM+.
284
+
285
+ * If the review is done, it's time to merge. Here's what happens:
286
+
287
+ First, we use the github_api gem to merge the pull request.
288
+
289
+ We call the public API for:
290
+
291
+ github.pull_requests.merge 'user-name', 'repo-name', 'number', payload
292
+
293
+ Please take a look at lib/git_reflow/git_server/git_hub/pull_request.rb:102-107 for an example of the call.
294
+ This call makes an HTTP request using the Github API to merge the available pull request passing in the user name, repository name, pull request number, and some additional data in the payload.
295
+
296
+ The payload contains data in the following format:
297
+
298
+ data = {
299
+ "commit_title",
300
+ "commit_message",
301
+ "sha",
302
+ "squash"
303
+ }
304
+
305
+ Notice: "squash" is set to true, meaning that we will do a squash-merge for each pull request.
306
+
307
+ For more detailed documentation, please read: https://github.com/piotrmurach/github/blob/master/lib/github_api/client/pull_requests.rb#L197
308
+
309
+ * Next, we prompt you if you want to cleanup
310
+ Would you like cleanup your feature branch?
311
+
312
+ If 'y', then we'll update the +base_branch+ and delete the feature branch
313
+
314
+ git pull origin #{base_branch}
315
+ git push origin :#{feature_branch}
316
+ git branch -D #{feature_branch}
317
+
318
+ If 'n', then just stop here. The user can clean up his branch locally.
319
+
320
+ And we're done.
321
+
322
+ ==== Note: This documentation is for the bitbucket standard or github manual process (used when the user applies -f force flag to the "remote" merge via the github_api).
323
+
324
+ ==== B:
325
+ This is what the process looks like for bitbucket or if you force deliver:
326
+
327
+ From github.com:reenhanced/gitreflow
328
+ * branch master -> FETCH_HEAD
329
+ Merging pull request #36: 'Enforce at least one LGTM before delivery', from 'reenhanced:nh-fail-without-lgtm' into 'reenhanced:master'
330
+ Already up-to-date.
331
+ Switched to branch 'nh-fail-without-lgtm'
332
+ Switched to branch 'master'
333
+ Updating c2ec1b1..f90e111
334
+ Squash commit -- not updating HEAD
335
+ lib/git_reflow.rb | 71 +++++++++++++++++++++++++++----------------------------
336
+ 1 file changed, 35 insertions(+), 36 deletions(-)
337
+ [master d1b4dd5] Enforces LGTM before deliver, even with no comments.
338
+ 1 file changed, 35 insertions(+), 36 deletions(-)
339
+ Merge complete!
340
+ Would you like to push this branch to your remote repo and cleanup your feature branch? y
341
+ Counting objects: 7, done.
342
+ Delta compression using up to 16 threads.
343
+ Compressing objects: 100% (4/4), done.
344
+ Writing objects: 100% (4/4), 1.38 KiB, done.
345
+ Total 4 (delta 2), reused 0 (delta 0)
346
+ To git@github.com:reenhanced/gitreflow.git
347
+ c2ec1b1..d1b4dd5 master -> master
348
+
349
+ To git@github.com:reenhanced/gitreflow.git
350
+ - [deleted] nh-fail-without-lgtm
351
+
352
+ Deleted branch nh-fail-without-lgtm (was f90e111).
353
+
354
+ This is what the default commit message looks like:
355
+ Enforces LGTM before deliver, even with no comments.
356
+ Removes the need to review the pull request yourself if you make a
357
+ comment.
358
+
359
+ Better error message if setup fails.
360
+
361
+ Bug fixes.
362
+
363
+ Closes #36
364
+
365
+ LGTM given by: @codenamev
366
+
367
+ Squashed commit of the following:
368
+
369
+ commit f90e111
370
+ Author: Nicholas Hance <nhance@reenhanced.com>
371
+ Date: Thu Jul 11 15:33:29 2013 -0400
372
+ ...
373
+
374
+ If the review is done, it's time to merge. Here's what happens:
375
+
376
+ First, update our local +master+ so we don't get conflicts
377
+ git checkout master
378
+ git pull origin master
379
+
380
+ Next, squash merge our feature branch
381
+ git merge --squash nh-branch-name
382
+
383
+ Now, we'll apply a little magic so we have a great commit message by default. Your editor will open and you'll see a nice default for your commit message based on the pull request body.
384
+
385
+ Once you've saved the commit, prompt the user to see if we should continue
386
+ Merge complete!
387
+ Would you like to push this branch to your remote repo and cleanup your feature branch?
388
+
389
+ If 'y', then we'll push to +master+ and delete the feature branch
390
+ git pull origin master
391
+ git push origin master
392
+ git push origin :nh-branch-name
393
+ git branch -D nh-branch-name
394
+
395
+ If 'n', then just stop here. The user can reset his local +master+.
396
+ And we're done.
397
+
398
+ == Guiding principles:
399
+ * Your workflow should resemble the following:
400
+ http://reenhanced.com/images/reflow.png
401
+
402
+ * You should already know what you're doing.
403
+ We assume you know how to use git.
404
+
405
+ * The +master+ branch is your codebase.
406
+ You don't need multiple branches for code actually want to use.
407
+
408
+ * +master+ should remain stable at all times.
409
+ The entire team depends on it.
410
+
411
+ * No direct commits to +master+.
412
+ All work happens in feature branches. From a single commit to hundreds.
413
+
414
+ * All feature branches are reviewed via pull requests.
415
+
416
+ * Looks Good To Me. All feature branches require approval.
417
+ We look for the string 'LGTM' in a comment on the pull request to know it's ready to merge.
418
+
419
+ * If you make a new commit in your branch, you require another review.
420
+
421
+ * Depending on the minimumApprovals that you specify in your ~/.gitconfig.reflow (created upon reflow setup), you can have the following:
422
+
423
+ "" : All participants in a pull request must approve the pull request.
424
+ "0": 0 approvals required for you to merge PR.
425
+ "1": You need a minimum of 1 LGTM and the last comment on your PR must be an LGTM.
426
+ "2": You need a minimum of 2 LGTM and the last comment on your PR must be an LGTM.
427
+ ...
428
+
429
+ * Once approved, your feature branch is squash-merged to your base_branch.
430
+ This makes the history of the base_branch branch extremely clean and easy to follow.
431
+
432
+ * Git blame becomes your friend. You'll know who to blame and can see the full context of changes.
433
+ Squash commits to base_branch mean every commit represents the whole feature, not a "typo fix".
434
+
435
+
436
+ == Configuration
437
+
438
+ In order to streamline delivery you can set the following git config to:
439
+
440
+ 1. always clean up the feature branch after the PR is merged
441
+ 2. always deliver without further prompt
442
+
443
+ git config --global --add "reflow.always-cleanup" "true"
444
+ git config --global --add "reflow.always-deliver" "true"
445
+
446
+ ---
447
+
448
+ == Contributing
449
+ Pull requests are welcome. Please fork and submit. We use this tool every single day and as long as what you want to add doesn't change our workflow, we are happy to accept your updates. Feel free to add your github username to the list below.
450
+
451
+ Authors:
452
+ * @codenamev
453
+ * @armyofgnomes
454
+ * @nhance
455
+
456
+ Built by Reenhanced:
457
+ http://www.reenhanced.com
458
+
459
+ <B>Looking for a capable team for your project? Get in touch. We're looking to grow.</B>
460
+
461
+ <em>Licensed using the MIT license. Do whatever you like with this, but don't blame us if it breaks anything. You're a professional, and you're responsible for the tools you use.</em>