git-surface 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- git_surface-0.1.0/LICENSE +202 -0
- git_surface-0.1.0/MANIFEST.in +5 -0
- git_surface-0.1.0/PKG-INFO +131 -0
- git_surface-0.1.0/README.md +110 -0
- git_surface-0.1.0/docs/classes.md +124 -0
- git_surface-0.1.0/docs/commands.md +78 -0
- git_surface-0.1.0/docs/limitations-and-security.md +40 -0
- git_surface-0.1.0/docs/other-tools.md +211 -0
- git_surface-0.1.0/git_surface/__init__.py +4 -0
- git_surface-0.1.0/git_surface/__main__.py +6 -0
- git_surface-0.1.0/git_surface/_common.py +314 -0
- git_surface-0.1.0/git_surface/classify.py +275 -0
- git_surface-0.1.0/git_surface/surface.py +257 -0
- git_surface-0.1.0/git_surface.egg-info/PKG-INFO +131 -0
- git_surface-0.1.0/git_surface.egg-info/SOURCES.txt +23 -0
- git_surface-0.1.0/git_surface.egg-info/dependency_links.txt +1 -0
- git_surface-0.1.0/git_surface.egg-info/entry_points.txt +2 -0
- git_surface-0.1.0/git_surface.egg-info/top_level.txt +1 -0
- git_surface-0.1.0/pyproject.toml +35 -0
- git_surface-0.1.0/setup.cfg +4 -0
- git_surface-0.1.0/tests/fixtures.py +118 -0
- git_surface-0.1.0/tests/test_adversarial.py +130 -0
- git_surface-0.1.0/tests/test_docs.py +76 -0
- git_surface-0.1.0/tests/test_package.py +55 -0
- git_surface-0.1.0/tests/test_surface.py +373 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: git-surface
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A git subcommand that reports which branches change what runs or is trusted.
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Project-URL: Homepage, https://github.com/jacob-adm/git-surface
|
|
7
|
+
Project-URL: Documentation, https://github.com/jacob-adm/git-surface/tree/main/docs
|
|
8
|
+
Project-URL: Source, https://github.com/jacob-adm/git-surface
|
|
9
|
+
Project-URL: Issues, https://github.com/jacob-adm/git-surface/issues
|
|
10
|
+
Keywords: git,pull-request,code-review,supply-chain,security,cli
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Topic :: Software Development :: Version Control :: Git
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# git-surface
|
|
23
|
+
|
|
24
|
+
git-surface is one git command, `git surface`. Installing it puts `git-surface` on your `PATH`;
|
|
25
|
+
git runs any `git-NAME` program on `PATH` as `git NAME`, so no configuration is needed.
|
|
26
|
+
|
|
27
|
+
When many branches arrive at once, many of them written by coding agents, a reviewer needs to
|
|
28
|
+
know which ones change something that runs or is trusted: a CI workflow, a git hook, an install
|
|
29
|
+
script, a dependency, a build file, or text that hides content from a human reader. Text in an
|
|
30
|
+
issue or pull request can steer an agent into exactly such a change, and malicious packages
|
|
31
|
+
spread through install scripts and new dependencies. `git surface` lists, for each branch, every
|
|
32
|
+
change of that kind, so those branches get a closer look.
|
|
33
|
+
|
|
34
|
+
It only reports. It does not block, score or rewrite anything; what to do with a report is up
|
|
35
|
+
to whoever runs it.
|
|
36
|
+
|
|
37
|
+
## Requirements
|
|
38
|
+
|
|
39
|
+
- Python 3.9 or later, standard library only.
|
|
40
|
+
- git 2.38 or later, as an executable named `git` on `PATH`.
|
|
41
|
+
|
|
42
|
+
## Install
|
|
43
|
+
|
|
44
|
+
From a clone:
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
git clone https://github.com/jacob-adm/git-surface
|
|
48
|
+
cd git-surface
|
|
49
|
+
pip install .
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
pip installs `git-surface` as a console script. Check the install:
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
git surface --version
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
```text
|
|
59
|
+
git-surface 0.1.0
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Use `-h` for usage: `git surface --help` is answered by git itself, which looks for a manual
|
|
63
|
+
page. Without installing, it also runs from a clone as `python3 -m git_surface`.
|
|
64
|
+
|
|
65
|
+
## How it works
|
|
66
|
+
|
|
67
|
+
1. **List the branches.** Pipe the branch names in, one per line. Only the first TAB-separated
|
|
68
|
+
field of each line is read, so the output of `git footprint BASE` (from git-overlap) pipes
|
|
69
|
+
straight in too.
|
|
70
|
+
2. **Diff each branch against BASE.** For each branch, `git surface BASE` compares the branch
|
|
71
|
+
with its merge base with BASE: the same changes a pull request's "files changed" shows.
|
|
72
|
+
Changes BASE made after the branch left it are not the branch's.
|
|
73
|
+
3. **Classify each changed path.** By its name, a path may be `ci`, `hook`, `install`, `deps` or
|
|
74
|
+
`exec`; a file that becomes executable is `exec` too. `package.json`, `pyproject.toml` and
|
|
75
|
+
`requirements*.txt` are read to name added and removed dependencies, version changes and
|
|
76
|
+
changed install steps.
|
|
77
|
+
4. **Check the added lines.** Only lines the branch adds are read. An HTML tag such as `<img>` or
|
|
78
|
+
`<script>`, or an HTML comment, on an added line of a Markdown file, or an invisible or
|
|
79
|
+
bidirectional Unicode character on an added line of any text file, is `hidden`.
|
|
80
|
+
5. **Read the report.** One line per finding, `ref TAB class TAB detail TAB path`. Like `grep`,
|
|
81
|
+
the command exits 1 when it reports something, 0 when it reports nothing and 2 on an error.
|
|
82
|
+
|
|
83
|
+
The full list of classes and rules is in [Classes](https://github.com/jacob-adm/git-surface/blob/main/docs/classes.md).
|
|
84
|
+
|
|
85
|
+
## Commands
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
git surface [-z] BASE < refs report what each ref changes that runs or is trusted
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
See [Commands](https://github.com/jacob-adm/git-surface/blob/main/docs/commands.md) for the input, output, options and exit status.
|
|
92
|
+
|
|
93
|
+
## Quick start
|
|
94
|
+
|
|
95
|
+
Inside the repository to check, list the branches one per line and pipe them in. Replace `main`
|
|
96
|
+
with the base branch and `refs/heads/agent/` with the refs to check, for example
|
|
97
|
+
`refs/remotes/origin/` for every branch fetched from `origin`.
|
|
98
|
+
|
|
99
|
+
```sh
|
|
100
|
+
git for-each-ref --format='%(refname:short)' refs/heads/agent/ | git surface main
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
```text
|
|
104
|
+
agent/ci ci M .github/workflows/test.yml
|
|
105
|
+
agent/ci exec A +x scripts/release.sh
|
|
106
|
+
agent/deps deps M +left-pad package.json
|
|
107
|
+
agent/deps install M scripts.postinstall package.json
|
|
108
|
+
agent/docs hidden <!-- line 4 README.md
|
|
109
|
+
agent/docs hidden <img line 5 README.md
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
`agent/ci` changes a workflow and adds an executable script. `agent/deps` adds the dependency
|
|
113
|
+
`left-pad` and a `postinstall` script. `agent/docs` adds an HTML comment and an image tag to the
|
|
114
|
+
README, neither of which shows when the Markdown is rendered. A fourth branch, `agent/fix`, only
|
|
115
|
+
changes application code, so it has no line.
|
|
116
|
+
|
|
117
|
+
## Documentation
|
|
118
|
+
|
|
119
|
+
- [Commands](https://github.com/jacob-adm/git-surface/blob/main/docs/commands.md): input, output, options, exit status and errors.
|
|
120
|
+
- [Classes](https://github.com/jacob-adm/git-surface/blob/main/docs/classes.md): every class, the paths and content each one covers, and the detail
|
|
121
|
+
field.
|
|
122
|
+
- [Limitations and security](https://github.com/jacob-adm/git-surface/blob/main/docs/limitations-and-security.md): what the command misses, and
|
|
123
|
+
what it reads and runs.
|
|
124
|
+
- [Using it with other tools](https://github.com/jacob-adm/git-surface/blob/main/docs/other-tools.md): tested stacks with
|
|
125
|
+
git-overlap, trust-path, pr-merge-audit and release-drift.
|
|
126
|
+
- [Contributing](https://github.com/jacob-adm/git-surface/blob/main/CONTRIBUTING.md): running the tests and contributing a change.
|
|
127
|
+
- [Reporting a vulnerability](https://github.com/jacob-adm/git-surface/blob/main/SECURITY.md)
|
|
128
|
+
|
|
129
|
+
## License
|
|
130
|
+
|
|
131
|
+
Apache License 2.0; see [LICENSE](https://github.com/jacob-adm/git-surface/blob/main/LICENSE).
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# git-surface
|
|
2
|
+
|
|
3
|
+
git-surface is one git command, `git surface`. Installing it puts `git-surface` on your `PATH`;
|
|
4
|
+
git runs any `git-NAME` program on `PATH` as `git NAME`, so no configuration is needed.
|
|
5
|
+
|
|
6
|
+
When many branches arrive at once, many of them written by coding agents, a reviewer needs to
|
|
7
|
+
know which ones change something that runs or is trusted: a CI workflow, a git hook, an install
|
|
8
|
+
script, a dependency, a build file, or text that hides content from a human reader. Text in an
|
|
9
|
+
issue or pull request can steer an agent into exactly such a change, and malicious packages
|
|
10
|
+
spread through install scripts and new dependencies. `git surface` lists, for each branch, every
|
|
11
|
+
change of that kind, so those branches get a closer look.
|
|
12
|
+
|
|
13
|
+
It only reports. It does not block, score or rewrite anything; what to do with a report is up
|
|
14
|
+
to whoever runs it.
|
|
15
|
+
|
|
16
|
+
## Requirements
|
|
17
|
+
|
|
18
|
+
- Python 3.9 or later, standard library only.
|
|
19
|
+
- git 2.38 or later, as an executable named `git` on `PATH`.
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
From a clone:
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
git clone https://github.com/jacob-adm/git-surface
|
|
27
|
+
cd git-surface
|
|
28
|
+
pip install .
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
pip installs `git-surface` as a console script. Check the install:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
git surface --version
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```text
|
|
38
|
+
git-surface 0.1.0
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Use `-h` for usage: `git surface --help` is answered by git itself, which looks for a manual
|
|
42
|
+
page. Without installing, it also runs from a clone as `python3 -m git_surface`.
|
|
43
|
+
|
|
44
|
+
## How it works
|
|
45
|
+
|
|
46
|
+
1. **List the branches.** Pipe the branch names in, one per line. Only the first TAB-separated
|
|
47
|
+
field of each line is read, so the output of `git footprint BASE` (from git-overlap) pipes
|
|
48
|
+
straight in too.
|
|
49
|
+
2. **Diff each branch against BASE.** For each branch, `git surface BASE` compares the branch
|
|
50
|
+
with its merge base with BASE: the same changes a pull request's "files changed" shows.
|
|
51
|
+
Changes BASE made after the branch left it are not the branch's.
|
|
52
|
+
3. **Classify each changed path.** By its name, a path may be `ci`, `hook`, `install`, `deps` or
|
|
53
|
+
`exec`; a file that becomes executable is `exec` too. `package.json`, `pyproject.toml` and
|
|
54
|
+
`requirements*.txt` are read to name added and removed dependencies, version changes and
|
|
55
|
+
changed install steps.
|
|
56
|
+
4. **Check the added lines.** Only lines the branch adds are read. An HTML tag such as `<img>` or
|
|
57
|
+
`<script>`, or an HTML comment, on an added line of a Markdown file, or an invisible or
|
|
58
|
+
bidirectional Unicode character on an added line of any text file, is `hidden`.
|
|
59
|
+
5. **Read the report.** One line per finding, `ref TAB class TAB detail TAB path`. Like `grep`,
|
|
60
|
+
the command exits 1 when it reports something, 0 when it reports nothing and 2 on an error.
|
|
61
|
+
|
|
62
|
+
The full list of classes and rules is in [Classes](https://github.com/jacob-adm/git-surface/blob/main/docs/classes.md).
|
|
63
|
+
|
|
64
|
+
## Commands
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
git surface [-z] BASE < refs report what each ref changes that runs or is trusted
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
See [Commands](https://github.com/jacob-adm/git-surface/blob/main/docs/commands.md) for the input, output, options and exit status.
|
|
71
|
+
|
|
72
|
+
## Quick start
|
|
73
|
+
|
|
74
|
+
Inside the repository to check, list the branches one per line and pipe them in. Replace `main`
|
|
75
|
+
with the base branch and `refs/heads/agent/` with the refs to check, for example
|
|
76
|
+
`refs/remotes/origin/` for every branch fetched from `origin`.
|
|
77
|
+
|
|
78
|
+
```sh
|
|
79
|
+
git for-each-ref --format='%(refname:short)' refs/heads/agent/ | git surface main
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
```text
|
|
83
|
+
agent/ci ci M .github/workflows/test.yml
|
|
84
|
+
agent/ci exec A +x scripts/release.sh
|
|
85
|
+
agent/deps deps M +left-pad package.json
|
|
86
|
+
agent/deps install M scripts.postinstall package.json
|
|
87
|
+
agent/docs hidden <!-- line 4 README.md
|
|
88
|
+
agent/docs hidden <img line 5 README.md
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`agent/ci` changes a workflow and adds an executable script. `agent/deps` adds the dependency
|
|
92
|
+
`left-pad` and a `postinstall` script. `agent/docs` adds an HTML comment and an image tag to the
|
|
93
|
+
README, neither of which shows when the Markdown is rendered. A fourth branch, `agent/fix`, only
|
|
94
|
+
changes application code, so it has no line.
|
|
95
|
+
|
|
96
|
+
## Documentation
|
|
97
|
+
|
|
98
|
+
- [Commands](https://github.com/jacob-adm/git-surface/blob/main/docs/commands.md): input, output, options, exit status and errors.
|
|
99
|
+
- [Classes](https://github.com/jacob-adm/git-surface/blob/main/docs/classes.md): every class, the paths and content each one covers, and the detail
|
|
100
|
+
field.
|
|
101
|
+
- [Limitations and security](https://github.com/jacob-adm/git-surface/blob/main/docs/limitations-and-security.md): what the command misses, and
|
|
102
|
+
what it reads and runs.
|
|
103
|
+
- [Using it with other tools](https://github.com/jacob-adm/git-surface/blob/main/docs/other-tools.md): tested stacks with
|
|
104
|
+
git-overlap, trust-path, pr-merge-audit and release-drift.
|
|
105
|
+
- [Contributing](https://github.com/jacob-adm/git-surface/blob/main/CONTRIBUTING.md): running the tests and contributing a change.
|
|
106
|
+
- [Reporting a vulnerability](https://github.com/jacob-adm/git-surface/blob/main/SECURITY.md)
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
|
|
110
|
+
Apache License 2.0; see [LICENSE](https://github.com/jacob-adm/git-surface/blob/main/LICENSE).
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# Classes
|
|
2
|
+
|
|
3
|
+
The list is fixed. A path is in a class because of its name, its mode or the lines a branch
|
|
4
|
+
adds to it; nothing is guessed from what the code does. Path rules match the path relative to
|
|
5
|
+
the repository root; "anywhere" means the file name in any directory.
|
|
6
|
+
|
|
7
|
+
## ci: what a CI service runs
|
|
8
|
+
|
|
9
|
+
- Anything under `.github/workflows/`, `.github/actions/`, `.gitea/workflows/`,
|
|
10
|
+
`.forgejo/workflows/`, `.gitlab/ci/`, `.circleci/`, `.buildkite/`, `.woodpecker/`,
|
|
11
|
+
`.azure-pipelines/`.
|
|
12
|
+
- At the root: `.gitlab-ci.yml`, `.travis.yml`, `azure-pipelines.yml`, `azure-pipelines.yaml`,
|
|
13
|
+
`bitbucket-pipelines.yml`, `.drone.yml`, `.woodpecker.yml`, `appveyor.yml`, `.appveyor.yml`,
|
|
14
|
+
`cloudbuild.yaml`, `cloudbuild.yml`, `action.yml`, `action.yaml`.
|
|
15
|
+
- Anywhere: `Jenkinsfile`.
|
|
16
|
+
|
|
17
|
+
Detail: the status letter.
|
|
18
|
+
|
|
19
|
+
## hook: what a git hook manager runs on a developer's machine
|
|
20
|
+
|
|
21
|
+
- Anything under `.githooks/` or `.husky/`.
|
|
22
|
+
- At the root: `.pre-commit-config.yaml`, `.pre-commit-hooks.yaml`, `lefthook.yml`,
|
|
23
|
+
`lefthook.yaml`, `.lefthook.yml`, `.lefthook.yaml`, `lefthook-local.yml`.
|
|
24
|
+
|
|
25
|
+
Detail: the status letter.
|
|
26
|
+
|
|
27
|
+
## install: what runs when the project is installed or built, or when Python starts
|
|
28
|
+
|
|
29
|
+
- Anywhere: `setup.py`, `sitecustomize.py`, `usercustomize.py`, `binding.gyp` (npm builds it on
|
|
30
|
+
install), `build.rs` (Cargo runs it on build), and any `*.pth` file.
|
|
31
|
+
Detail: the status letter.
|
|
32
|
+
- `pyproject.toml` when an added line is inside its `[build-system]` table (the build backend
|
|
33
|
+
and its requirements). Detail: `M [build-system]` (or `A`).
|
|
34
|
+
- `package.json` when one of the npm scripts `preinstall`, `install`, `postinstall`, `prepare`,
|
|
35
|
+
`prepack`, `postpack` or `prepublish` is added, changed or removed. Detail: the status letter
|
|
36
|
+
and each such script, for example `M scripts.postinstall`.
|
|
37
|
+
- `package.json` when either version is not a JSON object (or is nested too deeply for Python's
|
|
38
|
+
JSON parser), so its scripts cannot be compared. A submodule at a manifest path has no content
|
|
39
|
+
to read and counts as an empty file.
|
|
40
|
+
Detail: the status letter and `unparsed`, for example `M unparsed`.
|
|
41
|
+
|
|
42
|
+
## deps: dependency manifests and lockfiles
|
|
43
|
+
|
|
44
|
+
- Anywhere: `package.json`, `package-lock.json`, `npm-shrinkwrap.json`, `yarn.lock`,
|
|
45
|
+
`pnpm-lock.yaml`, `bun.lock`, `bun.lockb`, `Pipfile`, `Pipfile.lock`, `poetry.lock`,
|
|
46
|
+
`uv.lock`, `pdm.lock`, `pyproject.toml`, `setup.cfg`, `constraints.txt`, `Cargo.toml`,
|
|
47
|
+
`Cargo.lock`, `go.mod`, `go.sum`, `Gemfile`, `Gemfile.lock`, `composer.json`,
|
|
48
|
+
`composer.lock`, `pom.xml`, `build.gradle`, `build.gradle.kts`, `gradle.lockfile`,
|
|
49
|
+
`packages.lock.json`, any `*.gemspec`, and any `requirements*.txt`.
|
|
50
|
+
|
|
51
|
+
Detail: the status letter, then, where the file is cheap to read, one word for each added or
|
|
52
|
+
removed dependency and two for each version change:
|
|
53
|
+
|
|
54
|
+
- `+NAME`: a dependency the old version did not have (every one, for a new file);
|
|
55
|
+
- `-NAME`: a dependency the new version no longer has (every one, for a deleted file);
|
|
56
|
+
- `NAME OLD->NEW`: a dependency both versions have, whose version changed.
|
|
57
|
+
|
|
58
|
+
They come in that order, `+` words, then `-` words, then version changes, each group sorted by
|
|
59
|
+
name, for example `M +left-pad -lodash express 4.18.2->4.19.2`. Which files are read:
|
|
60
|
+
|
|
61
|
+
- `package.json`: names in `dependencies`, `devDependencies`, `optionalDependencies` and
|
|
62
|
+
`peerDependencies`. A name in several of them takes its version from the first in that
|
|
63
|
+
order. Any change of the version string is a version change, so a range shows as written
|
|
64
|
+
(`^1.0.0->^1.2.0`).
|
|
65
|
+
- `requirements*.txt`: project names, normalised (lower case, runs of `-_.` as `-`). A version
|
|
66
|
+
change is reported only when both versions pin the project with a single `==` (an
|
|
67
|
+
environment marker, a trailing `\` or options such as `--hash` may follow the pin); a change
|
|
68
|
+
to or from a range shows no version words. The first line naming a project counts. Option
|
|
69
|
+
lines (`-r`, `-e`, ...) and URL lines are skipped.
|
|
70
|
+
|
|
71
|
+
A name must start with a letter, a digit or `@` and contain only `A-Z a-z 0-9 @ / . _ ~ -`; a
|
|
72
|
+
version may contain only those and `^ < > = * + : !`, and not `->`. Other names, and version
|
|
73
|
+
changes with other versions (a range with spaces, a version that is not a string), are left out
|
|
74
|
+
of the detail, so every word is printable ASCII without spaces. Other manifests and every
|
|
75
|
+
lockfile report the status letter only.
|
|
76
|
+
|
|
77
|
+
To list the version changes as `NAME TAB OLD TAB NEW`, one per line, for a tool that fetches a
|
|
78
|
+
package by name and version (such as `release-drift fetch`):
|
|
79
|
+
|
|
80
|
+
```sh
|
|
81
|
+
git surface main < refs | awk -F'\t' '$2 == "deps" {
|
|
82
|
+
n = split($3, w, " ")
|
|
83
|
+
for (i = 2; i < n; i++) if (w[i] !~ /^[+-]/ && w[i+1] ~ /->/) {
|
|
84
|
+
split(w[i+1], v, "->"); print w[i] "\t" v[1] "\t" v[2]; i++
|
|
85
|
+
}
|
|
86
|
+
}'
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
A pinned requirement gives exact versions; a `package.json` range must be resolved to a version
|
|
90
|
+
first.
|
|
91
|
+
|
|
92
|
+
## exec: build and shell files, and files that become executable
|
|
93
|
+
|
|
94
|
+
- Anywhere: `Makefile`, `makefile`, `GNUmakefile`, `Dockerfile`, `Dockerfile.*`,
|
|
95
|
+
`Containerfile`, `justfile`, `Justfile`, `.envrc`, `docker-compose.yml`,
|
|
96
|
+
`docker-compose.yaml`, `compose.yml`, `compose.yaml`, and files ending in `.sh`, `.bash`,
|
|
97
|
+
`.zsh`, `.ps1`, `.bat`, `.cmd`, `.mk` or `.dockerfile` (case-insensitive).
|
|
98
|
+
- Any file whose mode becomes `100755` (executable): a new executable file, or a mode change.
|
|
99
|
+
|
|
100
|
+
Detail: the status letter, then ` +x` if the file became executable, for example `A +x` or
|
|
101
|
+
`M +x`.
|
|
102
|
+
|
|
103
|
+
## hidden: content a human reader may not see
|
|
104
|
+
|
|
105
|
+
Only lines the branch adds are checked; a removed line is never reported. A file with a NUL
|
|
106
|
+
byte on an added line is treated as binary and not checked.
|
|
107
|
+
|
|
108
|
+
- In Markdown files (`*.md`, `*.markdown`, `*.mdx`, case-insensitive): an HTML comment `<!--`,
|
|
109
|
+
or an opening or closing tag `img`, `picture`, `source`, `svg`, `script`, `style`, `iframe`,
|
|
110
|
+
`object`, `embed`, `link`, `meta`, `base`, `form`, `input` or `details`, in any case. Tags in
|
|
111
|
+
fenced code blocks count too.
|
|
112
|
+
- In every text file, these characters:
|
|
113
|
+
- zero-width and directional marks: U+200B to U+200F, U+2060 to U+2064, U+FEFF (except as
|
|
114
|
+
the first character of a file), U+061C;
|
|
115
|
+
- bidirectional embeddings, overrides and isolates: U+202A to U+202E, U+2066 to U+2069;
|
|
116
|
+
- tag characters U+E0000 to U+E007F, reported as one kind, `U+E0000..U+E007F`;
|
|
117
|
+
- supplementary variation selectors U+E0100 to U+E01EF, reported as one kind,
|
|
118
|
+
`U+E0100..U+E01EF`.
|
|
119
|
+
|
|
120
|
+
Detail: what was found and the line, in the new file, of its first occurrence, for example
|
|
121
|
+
`<img line 12`, `<!-- line 3` or `U+202E line 40`. A file has one line per kind found.
|
|
122
|
+
|
|
123
|
+
U+200D (zero-width joiner) is part of many emoji, so an added emoji can be reported. That is
|
|
124
|
+
expected: the report says what is there, not whether it is harmful.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Commands
|
|
2
|
+
|
|
3
|
+
## git surface [-z] BASE
|
|
4
|
+
|
|
5
|
+
For each ref on standard input, reports the changes since its merge base with BASE that touch
|
|
6
|
+
what runs or is trusted. It runs in the repository of the current directory and never changes a
|
|
7
|
+
ref, the index, the worktree or the object store.
|
|
8
|
+
|
|
9
|
+
### Input
|
|
10
|
+
|
|
11
|
+
One record per line. The ref is everything before the first TAB; the rest of the record is
|
|
12
|
+
ignored. So both of these work:
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
git for-each-ref --format='%(refname:short)' refs/heads/agent/ | git surface main
|
|
16
|
+
git for-each-ref --format='%(refname:short)' refs/heads/agent/ | git footprint main | git surface main
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The second form takes `git footprint` output (`ref TAB status TAB path`) as it is. `git surface`
|
|
20
|
+
does not use the paths in it: it runs its own diff for each ref, so the report is complete for
|
|
21
|
+
that ref even if the records were filtered.
|
|
22
|
+
|
|
23
|
+
- A ref is any commit-ish (`main`, `origin/x`, a commit id, `HEAD~2`), printed exactly as given.
|
|
24
|
+
A ref repeated in the input is reported once, at its first occurrence.
|
|
25
|
+
- A trailing CR on a line is removed and empty lines are skipped.
|
|
26
|
+
- BASE and every ref are resolved before any diff runs. A range such as `a..b` is not a ref.
|
|
27
|
+
|
|
28
|
+
### Output
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
ref TAB class TAB detail TAB path
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
- `class` is one of `ci`, `deps`, `exec`, `hidden`, `hook`, `install`; see
|
|
35
|
+
[Classes](classes.md).
|
|
36
|
+
- `detail` is printable ASCII and starts with git's status letter (`A` added, `M` modified, `D`
|
|
37
|
+
deleted, `T` type changed) for every class except `hidden`, whose detail names what was found
|
|
38
|
+
and the line it was first found on. [Classes](classes.md) lists every detail.
|
|
39
|
+
- `path` is relative to the repository root, whatever directory the command runs in. It is last,
|
|
40
|
+
so in `-z` mode a path may itself contain TAB.
|
|
41
|
+
- A path can be in several classes and then has one line per class.
|
|
42
|
+
- Refs keep their input order. Within a ref, lines are sorted by class, then path, then detail,
|
|
43
|
+
bytewise. The same repository and the same input give byte-identical output.
|
|
44
|
+
- In LF mode, a ref or path holding TAB, LF or CR cannot be written as a line: the command exits
|
|
45
|
+
2 with a message naming `-z`. Output to a pipe or file is never quoted or escaped. On a
|
|
46
|
+
terminal, control bytes and bytes that are not valid UTF-8 are shown as `\xHH`.
|
|
47
|
+
|
|
48
|
+
To keep only the ref, class and path: `cut -f1,2,4`. To count findings per branch:
|
|
49
|
+
`cut -f1 | uniq -c`.
|
|
50
|
+
|
|
51
|
+
### Options
|
|
52
|
+
|
|
53
|
+
- `-z`: records end with NUL instead of LF, on input and output.
|
|
54
|
+
- `-h`: show usage.
|
|
55
|
+
- `--version`: show the version.
|
|
56
|
+
|
|
57
|
+
Any other argument, even one starting with `-`, is BASE. `--` ends option parsing.
|
|
58
|
+
|
|
59
|
+
### Exit status
|
|
60
|
+
|
|
61
|
+
Like `grep`: 0 ran and reported nothing, 1 ran and reported something, 2 error. Errors are one
|
|
62
|
+
line on standard error, `git-surface: <message>`; an error about an input record starts with
|
|
63
|
+
`record N: `. Errors include an unknown BASE or ref and a missing or extra BASE. A reader that
|
|
64
|
+
closes the pipe early (`| head`) is not an error.
|
|
65
|
+
|
|
66
|
+
A ref that shares no history with BASE (an orphan branch, say) has nothing to diff against. It
|
|
67
|
+
does not stop the run: it is named on standard error as `git-surface: REF: no merge base with
|
|
68
|
+
BASE`, escaped like every other error, and the other refs are still reported. The exit status
|
|
69
|
+
is then 2, whatever else was reported, so a script cannot mistake a partial report for a whole
|
|
70
|
+
one.
|
|
71
|
+
|
|
72
|
+
### The diff
|
|
73
|
+
|
|
74
|
+
Both diffs `git surface` runs are pinned so that user configuration cannot change the result:
|
|
75
|
+
renames off (a rename is a deletion and an addition), no external diff or textconv, paths
|
|
76
|
+
relative to the root, submodule changes included, no colour, fixed prefixes, the default diff
|
|
77
|
+
algorithm, no context lines between hunks. `--text` is passed, so a `.gitattributes` entry that marks a file `binary` or `-diff`
|
|
78
|
+
does not hide its added lines. git runs without a shell and with `LC_ALL=C`.
|