git-p4son 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.
Files changed (36) hide show
  1. git_p4son-0.1.0/LICENSE +21 -0
  2. git_p4son-0.1.0/PKG-INFO +411 -0
  3. git_p4son-0.1.0/README.md +388 -0
  4. git_p4son-0.1.0/git_p4son/__init__.py +11 -0
  5. git_p4son-0.1.0/git_p4son/__main__.py +10 -0
  6. git_p4son-0.1.0/git_p4son/alias.py +162 -0
  7. git_p4son-0.1.0/git_p4son/changelist_store.py +147 -0
  8. git_p4son-0.1.0/git_p4son/cli.py +460 -0
  9. git_p4son-0.1.0/git_p4son/common.py +265 -0
  10. git_p4son-0.1.0/git_p4son/complete.py +230 -0
  11. git_p4son-0.1.0/git_p4son/completions/_git-p4son +49 -0
  12. git_p4son-0.1.0/git_p4son/completions/git-p4son.ps1 +90 -0
  13. git_p4son-0.1.0/git_p4son/lib.py +437 -0
  14. git_p4son-0.1.0/git_p4son/list_changes.py +99 -0
  15. git_p4son-0.1.0/git_p4son/log.py +146 -0
  16. git_p4son-0.1.0/git_p4son/new.py +77 -0
  17. git_p4son-0.1.0/git_p4son/review.py +205 -0
  18. git_p4son-0.1.0/git_p4son/sync.py +329 -0
  19. git_p4son-0.1.0/git_p4son/update.py +60 -0
  20. git_p4son-0.1.0/git_p4son.egg-info/PKG-INFO +411 -0
  21. git_p4son-0.1.0/git_p4son.egg-info/SOURCES.txt +34 -0
  22. git_p4son-0.1.0/git_p4son.egg-info/dependency_links.txt +1 -0
  23. git_p4son-0.1.0/git_p4son.egg-info/entry_points.txt +2 -0
  24. git_p4son-0.1.0/git_p4son.egg-info/top_level.txt +1 -0
  25. git_p4son-0.1.0/pyproject.toml +39 -0
  26. git_p4son-0.1.0/setup.cfg +4 -0
  27. git_p4son-0.1.0/tests/test_cli.py +177 -0
  28. git_p4son-0.1.0/tests/test_common.py +239 -0
  29. git_p4son-0.1.0/tests/test_complete.py +371 -0
  30. git_p4son-0.1.0/tests/test_lib_changelist.py +212 -0
  31. git_p4son-0.1.0/tests/test_lib_edit.py +207 -0
  32. git_p4son-0.1.0/tests/test_lib_review.py +101 -0
  33. git_p4son-0.1.0/tests/test_list_changes.py +131 -0
  34. git_p4son-0.1.0/tests/test_log.py +217 -0
  35. git_p4son-0.1.0/tests/test_review.py +307 -0
  36. git_p4son-0.1.0/tests/test_sync.py +386 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Andreas Andersson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,411 @@
1
+ Metadata-Version: 2.4
2
+ Name: git-p4son
3
+ Version: 0.1.0
4
+ Summary: Utility for keeping a Perforce workspace and local git repo in sync
5
+ Author-email: Andreas Andersson <andreas@neoboid.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/neoboid/git-p4son
8
+ Project-URL: Repository, https://github.com/neoboid/git-p4son
9
+ Project-URL: Issues, https://github.com/neoboid/git-p4son/issues
10
+ Keywords: perforce,git,version-control,sync
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Software Development :: Version Control
19
+ Requires-Python: >=3.10
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Dynamic: license-file
23
+
24
+ # Git Perforcesson
25
+
26
+ `git-p4son` is a tool for managing a local git repository within a Perforce workspace.
27
+ This way you can use the familiar local git development flow even though you are
28
+ working on a project where perforce is used for source control.
29
+
30
+ The idea is to have a `main` git branch that is kept in sync with a branch of a Perforce depot.
31
+ From `main` you branch out into feature branches, where you do local changes
32
+ and rebase on `main` whenever it is updated.
33
+
34
+ Once your changes is ready to be submitted in perforce `git-p4son` can help you create both
35
+ changelists and push them for reviews. You can even push individual git commits as patches
36
+ for review, so that the reviewer can see the changes in the order you made them locally. Similar
37
+ to the pull request worfkflow on github.
38
+
39
+ This is a bit cumbersome to do manually, but this package provides commands
40
+ that help out with the repetitive and error prone stuff.
41
+
42
+ ## Installation
43
+
44
+ Currently, git-p4son must be installed from source. Clone the repository and install:
45
+
46
+ ```sh
47
+ git clone https://github.com/derwiath/git-p4son.git
48
+ cd git-p4son
49
+ pip install .
50
+ ```
51
+
52
+ ## Development
53
+
54
+ To contribute to git-p4son or modify it for your needs, you can install it in development mode:
55
+
56
+ ```sh
57
+ git clone https://github.com/derwiath/git-p4son.git
58
+ cd git-p4son
59
+ pip install -e .
60
+ ```
61
+
62
+ The `-e` flag installs the package in "editable" mode. Which means that changes
63
+ to the code are immediately available and `git p4son` can be tested right
64
+ away without reinstalling. This is also handy if you want to auto update Git Perforcesson
65
+ whenever you pull from github.
66
+
67
+ ### Development Requirements
68
+
69
+ git-p4son only uses Python standard library modules, no additional packages are required.
70
+
71
+ ## Setup
72
+
73
+ ### Perforce workspace
74
+ * Set clobber flag on your perforce workspace.
75
+ * Sync workspace to a specified changelist
76
+ ```sh
77
+ p4 sync //...@123
78
+ ```
79
+ Take note of the changelist number.
80
+
81
+ ### Local git repo
82
+ * Initialize a local git repo:
83
+ ```sh
84
+ git init
85
+ ```
86
+ It does not have to be in the root of your perforce workspace, you may choose to only
87
+ keep a part of it in your local git repo.
88
+ * Add a `.gitignore` file and commit.
89
+ Ideally your ignore file should ignore the same files that is ignored
90
+ by perforce, as specified by `.p4ignore`.
91
+ * Add all files and commit
92
+ ```sh
93
+ git add .
94
+ git commit -m "Initial commit for CL 123"
95
+ ```
96
+
97
+ ## Usage
98
+
99
+ git-p4son provides six commands: `sync`, `new`, `update`, `review`, `list-changes`, and `alias`.
100
+
101
+ To see help for any command, use `-h`:
102
+
103
+ ```sh
104
+ git p4son -h
105
+ git p4son sync -h
106
+ ```
107
+
108
+ **Note:** When invoking via `git p4son`, the `--help` flag is intercepted by git (to look for man pages). Use `-h` instead, or `git p4son -- --help` to force it through.
109
+ Alternatively, call the executable directly: `git-p4son --help`.
110
+
111
+ ### Sync Command
112
+
113
+ Sync local git repository with a Perforce workspace:
114
+
115
+ ```sh
116
+ git p4son sync <changelist> [--force]
117
+ ```
118
+
119
+ **Arguments:**
120
+ - `changelist`: Changelist number, named alias, or special keywords:
121
+ - `latest`: Sync to the latest changelist affecting the workspace
122
+ - `last-synced`: Re-sync the last synced changelist
123
+
124
+ **Options:**
125
+ - `-f, --force`: Force sync encountered writable files and allow syncing to older changelists.
126
+
127
+ **Examples:**
128
+ ```sh
129
+ git p4son sync 12345
130
+ git p4son sync latest
131
+ git p4son sync last-synced
132
+ git p4son sync 12345 --force
133
+ ```
134
+
135
+ ### New Command
136
+
137
+ Create a new Perforce changelist and add changed files to it. Description will contain an enumerated list of git commits since the base branch.
138
+ Optionally creates a Swarm review.
139
+
140
+ ```sh
141
+ git p4son new -m <message> [--base-branch BASE_BRANCH] [alias] [--force] [--dry-run] [--no-edit] [--shelve] [--review]
142
+ ```
143
+
144
+ **Arguments:**
145
+ - `alias`: Optional alias name to save the new changelist number under
146
+
147
+ **Options:**
148
+ - `-m, --message MESSAGE`: Changelist description message (required)
149
+ - `-b, --base-branch BASE_BRANCH`: Base branch for enumerating commits and finding changed files. Default is `HEAD~1`
150
+ - `-f, --force`: Overwrite an existing alias file
151
+ - `-n, --dry-run`: Pretend and print what would be done, but do not execute
152
+ - `--no-edit`: Skip opening changed files for edit in Perforce
153
+ - `--shelve`: Shelve the changelist after creating it
154
+ - `--review`: Add `#review` keyword and shelve to create a Swarm review
155
+
156
+ **Examples:**
157
+ ```sh
158
+ git p4son new -m "Fix login bug"
159
+ git p4son new -m "Add feature" -b main
160
+ git p4son new -m "Fix bug" myalias
161
+ git p4son new -m "Fix bug" --no-edit
162
+ git p4son new -m "New feature" --review -b main myalias
163
+ ```
164
+
165
+ ### Update Command
166
+
167
+ Update an existing Perforce changelist description by replacing the enumerated commit list with the current commits since the base branch. By default also opens changed files for edit.
168
+
169
+ ```sh
170
+ git p4son update <changelist> [--base-branch BASE_BRANCH] [--dry-run] [--no-edit] [--shelve]
171
+ ```
172
+
173
+ **Arguments:**
174
+ - `changelist`: Changelist number or named alias to update
175
+
176
+ **Options:**
177
+ - `-b, --base-branch BASE_BRANCH`: Base branch for enumerating commits and finding changed files. Default is `HEAD~1`
178
+ - `-n, --dry-run`: Pretend and print what would be done, but do not execute
179
+ - `--no-edit`: Skip opening changed files for edit in Perforce
180
+ - `--shelve`: Re-shelve the changelist after updating
181
+
182
+ **Examples:**
183
+ ```sh
184
+ git p4son update 12345
185
+ git p4son update myalias -b main
186
+ git p4son update myalias --shelve
187
+ git p4son update 12345 --no-edit
188
+ ```
189
+
190
+ ### Review Command
191
+
192
+ Automate the interactive rebase workflow for creating Swarm reviews. This command generates a rebase todo with `exec` lines that run `git p4son new --review` on the first commit and `git p4son update --shelve` on each subsequent commit, then opens it in your editor for review before executing.
193
+
194
+ ```sh
195
+ git p4son review <alias> -m <message> [--base-branch BASE_BRANCH] [--force] [--dry-run]
196
+ ```
197
+
198
+ **Arguments:**
199
+ - `alias`: Alias name for the new changelist
200
+
201
+ **Options:**
202
+ - `-m, --message MESSAGE`: Changelist description message (required)
203
+ - `-b, --base-branch BASE_BRANCH`: Base branch to rebase onto and find commits since. Default is `HEAD~1`
204
+ - `-f, --force`: Overwrite an existing alias file
205
+ - `-n, --dry-run`: Print the generated rebase todo without executing
206
+
207
+ When run, the command generates a todo like this and opens it in your editor:
208
+
209
+ ```
210
+ pick abc1234 First commit
211
+ exec git p4son new my-feature --review -m 'My feature'
212
+ pick def5678 Second commit
213
+ exec git p4son update my-feature --shelve
214
+ pick ghi9012 Third commit
215
+ exec git p4son update my-feature --shelve
216
+ ```
217
+
218
+ You can edit the todo before saving (e.g. reorder commits, remove lines), or abort by clearing the file — just like a normal `git rebase -i`. Each `exec` line automatically sleeps after shelving to give Perforce/Swarm time to process.
219
+
220
+ If the rebase fails mid-way, you can fix the issue and run `git rebase --continue` as usual.
221
+
222
+ **Examples:**
223
+ ```sh
224
+ # Review all commits since main
225
+ git p4son review my-feature -m "Add my feature" -b main
226
+
227
+ # Review just the last commit (default base branch)
228
+ git p4son review my-feature -m "Fix bug"
229
+
230
+ # Preview the generated todo without executing
231
+ git p4son review my-feature -m "Add my feature" -b main --dry-run
232
+ ```
233
+
234
+ ### List-Changes Command
235
+
236
+ List commit subjects since a base branch in chronological order (oldest first):
237
+
238
+ ```sh
239
+ git p4son list-changes [--base-branch BASE_BRANCH]
240
+ ```
241
+
242
+ **Options:**
243
+ - `-b, --base-branch BASE_BRANCH`: Base branch to compare against. Default is `HEAD~1`.
244
+
245
+ **Examples:**
246
+ ```sh
247
+ git p4son list-changes
248
+ git p4son list-changes --base-branch main
249
+ ```
250
+
251
+ This command is useful for generating changelist descriptions by listing all commit messages since the base branch, numbered sequentially.
252
+
253
+ ### Alias Command
254
+
255
+ Manage changelist aliases stored in `.git-p4son/changelists/`.
256
+
257
+ #### alias list
258
+
259
+ List all aliases and their changelist numbers:
260
+
261
+ ```sh
262
+ git p4son alias list
263
+ ```
264
+
265
+ **Examples:**
266
+ ```sh
267
+ git p4son alias list
268
+ ```
269
+
270
+ #### alias set
271
+
272
+ Save a changelist number under a named alias:
273
+
274
+ ```sh
275
+ git p4son alias set <changelist> <alias> [--force]
276
+ ```
277
+
278
+ **Arguments:**
279
+ - `changelist`: Changelist number to save
280
+ - `alias`: Alias name to save the changelist number under
281
+
282
+ **Options:**
283
+ - `-f, --force`: Overwrite an existing alias file
284
+
285
+ **Examples:**
286
+ ```sh
287
+ git p4son alias set 12345 myfeature
288
+ git p4son alias set 67890 myfeature -f
289
+ ```
290
+
291
+ #### alias delete
292
+
293
+ Delete a changelist alias:
294
+
295
+ ```sh
296
+ git p4son alias delete <alias>
297
+ ```
298
+
299
+ **Arguments:**
300
+ - `alias`: Alias name to delete
301
+
302
+ **Examples:**
303
+ ```sh
304
+ git p4son alias delete myfeature
305
+ ```
306
+
307
+ #### alias clean
308
+
309
+ Interactively review and delete changelist aliases:
310
+
311
+ ```sh
312
+ git p4son alias clean
313
+ ```
314
+
315
+ This command iterates through each alias, displays it, and prompts for action:
316
+ - `y` (yes): Delete this alias
317
+ - `n` (no): Keep this alias
318
+ - `a` (all): Delete this and all remaining aliases
319
+ - `q` (quit): Stop and keep remaining aliases
320
+
321
+ **Examples:**
322
+ ```sh
323
+ git p4son alias clean
324
+ ```
325
+
326
+ ## Shell Completions
327
+
328
+ Tab completion is available for both zsh and PowerShell, including commands, flags, and dynamic alias names.
329
+
330
+ ### zsh
331
+
332
+ Add the `completions/` directory to your `fpath` before `compinit` in `~/.zshrc`:
333
+
334
+ ```zsh
335
+ fpath=(/path/to/git-p4son/completions $fpath)
336
+ autoload -Uz compinit && compinit
337
+ ```
338
+
339
+ This enables completion for both `git p4son <TAB>` and `git-p4son <TAB>`.
340
+
341
+ ### PowerShell
342
+
343
+ Dot-source the completion script in your PowerShell profile (`$PROFILE`):
344
+
345
+ ```powershell
346
+ . /path/to/git-p4son/completions/git-p4son.ps1
347
+ ```
348
+
349
+ This enables completion for both `git p4son <TAB>` and `git-p4son <TAB>`.
350
+
351
+ ## Usage Example
352
+
353
+ Here's a typical workflow using git-p4son:
354
+
355
+ ```sh
356
+ # Sync main with latest changes from perforce
357
+ git checkout main
358
+ git p4son sync latest
359
+
360
+ # Start work on a new feature
361
+ git checkout -b my-fancy-feature
362
+
363
+ # Change some code
364
+ git add .
365
+ git commit -m "Feature part1"
366
+
367
+ # Sync to the latest changelist affecting the workspace
368
+ git checkout main
369
+ git p4son sync latest
370
+
371
+ # Rebase your changes on main
372
+ git checkout my-fancy-feature
373
+ git rebase main
374
+
375
+ # Change even more code
376
+ git add .
377
+ git commit -m "Feature part2"
378
+
379
+ # Create a Swarm review with all commits since main in one go.
380
+ # This opens an interactive rebase with pre-filled exec lines updating changelist
381
+ # with git-p4son after each picked changelist.
382
+ #
383
+ # "branch" is a special keyword that gets resolved to current git branch.
384
+ # in this case the review is put in a new changelist, and an alias called "my-fancy-feature" is
385
+ # set up for this changelist number so that you can refer to this CL with the alias instead of number
386
+ # in follow up commands.
387
+ git p4son review branch -m "My fancy feature" -b main
388
+
389
+ # After review feedback, make more changes
390
+ git add .
391
+ git commit -m "Address review feedback"
392
+
393
+ # Update the changelist with latest commit, re-open files, and re-shelve
394
+ # We could have used "branch" here instead of spelling out the alias by name
395
+ git p4son update my-fancy-feature --shelve
396
+
397
+ # After approval, submit in p4v
398
+
399
+ # Sync to the latest changelist from perforce
400
+ git checkout main
401
+ git p4son sync latest
402
+
403
+ # Force remove old branch as you don't need it anymore
404
+ git branch -D my-fancy-feature
405
+
406
+ # Remove changelist alias
407
+ git p4son alias delete my-fancy-feature
408
+
409
+ # Start working on the next feature
410
+ git checkout -b my-next-fancy-feature
411
+ ```