-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.rst.j2
439 lines (260 loc) · 10.3 KB
/
README.rst.j2
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
==================
Git Workflow Tools
==================
|github|
|pypi|
|license|
|pythonversions|
.. |github| image:: https://img.shields.io/badge/GitHub--green.svg?style=social&logo=github
:alt: GitHub
:target: https://github.com/connordelacruz/git-workflow
.. |pypi| image:: https://img.shields.io/pypi/v/git-workflow.svg
:alt: PyPI
:target: https://pypi.org/project/git-workflow/
.. |license| image:: https://img.shields.io/pypi/l/git-workflow.svg
:alt: License
.. |pythonversions| image:: https://img.shields.io/pypi/pyversions/git-workflow.svg
:alt: Python Versions
:target: https://pypi.org/project/git-workflow/
.. contents::
:depth: 2
Overview
========
This package contains command line tools to streamline common tasks in our git workflow.
{# Shorthand to include demo gifs #}
{% macro demo_gif(path) -%}
.. image:: https://raw.githubusercontent.com/connordelacruz/git-workflow/assets/{{path}}
{%- endmacro %}
Start New Branch with Commit Template
-------------------------------------
To start a new branch, run:
::
{{workflow.command}} {{start.command}}
This will prompt you for some information and create a new branch with the following name format:
::
[<client>-]<brief-description>-<yyyymmdd>-<initials>
If you provide a ticket number, this will create a git commit message template for the branch. By default, the commit template will be in the following format:
::
[<ticket#>]
Demos
~~~~~
Starting a project branch:
{{ demo_gif('start/0-start-prompt.gif') }}
Commit message will include the specified ticket number:
{{ demo_gif('start/1-commit-message.gif') }}
Different branches can use different commit templates:
{{ demo_gif('start/2-args-and-per-branch.gif') }}
👆 You can also use command line arguments to skip the prompts. Each workflow
command supports a variety of command line options.
Finish a Branch
---------------
When you're finished with a project branch that has been merged, run:
::
{{workflow.command}} {{finish.command}}
This will clean up configs, remove the branch's commit template, and delete the branch.
Demo
~~~~~
{{ demo_gif('finish/0-finish.gif') }}
Create a Commit Template for an Existing Branch
-----------------------------------------------
If you already have a branch created and would like to create a commit template, run:
::
{{workflow.command}} {{set_template.command}}
Demo
~~~~~
{{ demo_gif('set-template/0-set-template.gif') }}
Remove a Branch's Commit Template
---------------------------------
To remove a branch's commit template without deleting the branch, run:
::
{{workflow.command}} {{unset_template.command}}
Demo
~~~~~
{{ demo_gif('unset-template/0-unset-template.gif') }}
Cleanup All Commit Templates in a Repo
--------------------------------------
If you have a bunch of lingering commit templates and would like to tidy up, run:
::
{{workflow.command}} {{cleanup.command}}
By default, this will clean up configs and template files for every branch except the one you have checked out. It will also look for orphaned commit templates with no associated branch and remove them.
Demo
~~~~~
{{ demo_gif('cleanup/0-cleanup.gif') }}
Setup
=====
Prerequisites
-------------
Python 3.6+
~~~~~~~~~~~
This package was developed using features that require **Python 3.6 or greater** (developed using Python 3.9.2).
You can use `this guide to install Python 3 on macOS <https://docs.python-guide.org/starting/install3/osx/#doing-it-right>`_.
Git 2.23+
~~~~~~~~~
This package uses features that require **Git 2.23 or greater**.
To install an updated version of ``git`` on macOS using `Homebrew <https://brew.sh/>`_:
::
brew install git
**Note:** Make sure ``/usr/local/bin`` is added to your ``PATH``. You can do this by adding the following to your ``.bashrc``:
::
export PATH="/usr/local/bin:$PATH"
Installation
------------
Once you have the above prerequisites installed, you can install it using ``pip`` (or ``pip3`` depending on how you installed Python 3):
::
pip install git-workflow
Configure Git to Ignore Commit Template Files
---------------------------------------------
These commands generate files for commit templates, which you likely do not want to track in your repos.
Option 1: Configure Global .gitignore (RECOMMENDED)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1. Create a global gitignore file, e.g. ``~/.gitignore_global``
2. Set the global git config for ``core.excludesfile`` to the path of your global gitignore, e.g.:
::
git config --global core.excludesfile ~/.gitignore_global
3. Add the following to your global gitignore:
::
# Commit message templates
.gitmessage_local*
For more information on ``core.excludesfile``:
- `GitHub - Ignoring files <https://docs.github.com/en/github/using-git/ignoring-files#configuring-ignored-files-for-all-repositories-on-your-computer>`_
- `Git Configuration - core.excludesfile <https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration#_core_excludesfile>`_
Option 2: Ignore for a Single Repo
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To ignore generated template files in a single git repo, add the following to the ``.gitignore`` file:
::
# Commit message templates
.gitmessage_local*
Configure Your Initials
-----------------------
By default, ``workflow {{start.command}}`` will prompt you for your initials every time you start a new branch. You can set the git config ``workflow.initials`` to skip this prompt, e.g. to set your initials to "cd":
::
git config --global workflow.initials cd
For more information, see the `Git Configurations`_ section below.
(Optional) Enable Tab Completion for Workflow Commands
------------------------------------------------------
This package utilizes `argcomplete <https://pypi.org/project/argcomplete/>`_ to support tab completion in Bash. Some additional setup is required to enable tab completion.
Prereq: Enable Tab Completion in Bash
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you haven't already, you will need to enable tab completion in Bash. You can follow `this guide to enable Bash Completion on macOS <https://sourabhbajaj.com/mac-setup/BashCompletion/>`_.
Activate Tab Completion
~~~~~~~~~~~~~~~~~~~~~~~
After setting up tab completion for Bash, you need to activate tab completion for ``argcomplete``. This can be done a couple of ways depending on your Bash version.
Option 1: Activate Global Completion for argcomplete (Bash 4.2+)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
If you have Bash 4.2 or greater, you can simply run the following command:
::
activate-global-python-argcomplete
Then restart Bash for these changes to take effect.
**Note:** The default version of Bash on macOS is 3.2.57. You can follow `this guide to update to a newer version <https://itnext.io/upgrading-bash-on-macos-7138bd1066ba>`_.
Option 2: Activate Completion for Just This Package
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
If you're on an older version of Bash or do not want to enable global completion for some reason, add the following to your ``.bash_rc``:
::
eval "$(register-python-argcomplete workflow)"
Then restart Bash for these changes to take effect.
Workflow Commands
=================
{# Formats RST header for a command #}
{% macro command_header(command) -%}
``{{command}}``
{{ '-' * (command|length() + 4) }}
{%- endmacro %}
{# Usage sections #}
{% macro command_usage(help_text) -%}
Usage
~~~~~
::
{{help_text}}
{%- endmacro %}
{# Details on configs #}
{% macro command_configs(command) -%}
{% if command.configs_used|length > 0 %}
Configs
~~~~~~~
Command uses the following configs:
{% for config_name in command.configs_used %}
- `workflow.{{config_name}}`_
{% endfor %}
{% endif %}
{%- endmacro %}
**Usage:** ``workflow <command>``
{# --- start --- #}
{{ command_header(start.command) }}
{{ start.doc }}
{{ command_usage(start.help) }}
{{ command_configs(start) }}
{# --- finish --- #}
{{ command_header(finish.command) }}
{{ finish.doc }}
{{ command_usage(finish.help) }}
{{ command_configs(finish) }}
{# --- set-template --- #}
{{ command_header(set_template.command) }}
{{ set_template.doc }}
{{ command_usage(set_template.help) }}
{{ command_configs(set_template) }}
{# --- unset-template --- #}
{{ command_header(unset_template.command) }}
{{ unset_template.doc }}
{{ command_usage(unset_template.help) }}
{{ command_configs(unset_template) }}
{# --- cleanup --- #}
{{ command_header(cleanup.command) }}
{{ cleanup.doc }}
{{ command_usage(cleanup.help) }}
{{ command_configs(cleanup) }}
Git Configurations
==================
Workflow commands will use the following git configs if set:
User Details
------------
``workflow.initials``
~~~~~~~~~~~~~~~~~~~~~
{{ configs.INITIALS }}
Branches
--------
``workflow.baseBranch``
~~~~~~~~~~~~~~~~~~~~~~~
{{ configs.BASE_BRANCH }}
``workflow.badBranchNamePatterns``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{{ configs.BAD_BRANCH_NAME_PATTERNS }}
Commit Templates
----------------
``workflow.commitTemplateFormat``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{{ configs.COMMIT_TEMPLATE_FORMAT }}
``workflow.commitTemplateFilenameFormat``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{{ configs.COMMIT_TEMPLATE_FILENAME_FORMAT }}
Ticket Numbers
--------------
``workflow.ticketInputFormatRegex``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{{ configs.TICKET_INPUT_FORMAT_REGEX }}
``workflow.ticketFormatCapitalize``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{{ configs.TICKET_FORMAT_CAPITALIZE }}
Confirmation Prompts
--------------------
``workflow.finishBranchConfirmationPrompt``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{{ configs.FINISH_BRANCH_CONFIRMATION_PROMPT }}
``workflow.unsetTemplateConfirmationPrompt``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{{ configs.UNSET_TEMPLATE_CONFIRMATION_PROMPT }}
``workflow.cleanupConfirmationPrompt``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{{ configs.CLEANUP_CONFIRMATION_PROMPT }}
Future Updates
==============
Planned
-------
- Config to disable "Client" prompt.
- Add ``-R``/``--branch-from-latest-release`` to ``workflow start``
Backburner
----------
Low-priority updates that may be added in a future release:
- Generate API docs using Sphinx.
- Support ``--verbosity`` argument on all commands.
- ``rename`` command: renames branch while keeping its commit template configured.