diff options
author | Mike Frysinger <vapier@google.com> | 2019-06-18 17:23:39 -0400 |
---|---|---|
committer | Mike Frysinger <vapier@google.com> | 2019-07-27 01:10:40 +0000 |
commit | f7c51606f0eae56f0cf52c54713f7816d8e9f97c (patch) | |
tree | 0ed377b68aa43d1440d738cb4fe176e08bca218d /docs/repo-hooks.md | |
parent | 745be2ede1e67421275afc00c04d996d9d6908ee (diff) | |
download | git-repo-f7c51606f0eae56f0cf52c54713f7816d8e9f97c.tar.gz |
hooks: support external hooks running different Python version
As we convert repo to support Python 3, the version of Python that we
use might not be the version that repo hooks users have written for.
Since repo upgrades are not immediate, and not easily under direct
control of end users (relative to the projects maintaining the hook
code), allow hook authors to declare the version of Python that they
want to use.
Now repo will read the shebang from the hook script and compare it
against the version of Python repo itself is running under. If they
differ, we'll try to execute a separate instance of Python and have
it load & execute the hook. If things are compatible, then we still
use the inprocess execution logic that we have today.
This allows repo hook users to upgrade on their own schedule (they
could even upgrade to Python 3 ahead of us) without having to worry
about their supported version being exactly in sync with repo's.
Bug: https://crbug.com/gerrit/10418
Change-Id: I97c7c96b64fb2ee465c39b90e9bdcc76394a146a
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/228432
Reviewed-by: David Pursehouse <dpursehouse@collab.net>
Tested-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'docs/repo-hooks.md')
-rw-r--r-- | docs/repo-hooks.md | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/docs/repo-hooks.md b/docs/repo-hooks.md index e198b390..7c37c30e 100644 --- a/docs/repo-hooks.md +++ b/docs/repo-hooks.md | |||
@@ -83,6 +83,31 @@ then check it directly. Hooks should not normally modify the active git repo | |||
83 | the user. Although user interaction is discouraged in the common case, it can | 83 | the user. Although user interaction is discouraged in the common case, it can |
84 | be useful when deploying automatic fixes. | 84 | be useful when deploying automatic fixes. |
85 | 85 | ||
86 | ### Shebang Handling | ||
87 | |||
88 | *** note | ||
89 | This is intended as a transitional feature. Hooks are expected to eventually | ||
90 | migrate to Python 3 only as Python 2 is EOL & deprecated. | ||
91 | *** | ||
92 | |||
93 | If the hook is written against a specific version of Python (either 2 or 3), | ||
94 | the script can declare that explicitly. Repo will then attempt to execute it | ||
95 | under the right version of Python regardless of the version repo itself might | ||
96 | be executing under. | ||
97 | |||
98 | Here are the shebangs that are recognized. | ||
99 | |||
100 | * `#!/usr/bin/env python` & `#!/usr/bin/python`: The hook is compatible with | ||
101 | Python 2 & Python 3. For maximum compatibility, these are recommended. | ||
102 | * `#!/usr/bin/env python2` & `#!/usr/bin/python2`: The hook requires Python 2. | ||
103 | Version specific names like `python2.7` are also recognized. | ||
104 | * `#!/usr/bin/env python3` & `#!/usr/bin/python3`: The hook requires Python 3. | ||
105 | Version specific names like `python3.6` are also recognized. | ||
106 | |||
107 | If no shebang is detected, or does not match the forms above, we assume that the | ||
108 | hook is compatible with both Python 2 & Python 3 as if `#!/usr/bin/python` was | ||
109 | used. | ||
110 | |||
86 | ## Hooks | 111 | ## Hooks |
87 | 112 | ||
88 | Here are all the points available for hooking. | 113 | Here are all the points available for hooking. |