libgit2 / pygit2

Python bindings for libgit2
https://www.pygit2.org/
Other
1.58k stars 382 forks source link

Submodule init, update, caching, reload, status #1248

Closed jorio closed 7 months ago

jorio commented 7 months ago

This PR fleshes out submodules a bit.


Notes about API design: The PR brings in new enums (GIT_SUBMODULESTATUS...) that I encapsulated as enum classes (IntFlag, IntEnum) in enums.py.

This allows for friendlier development – function signatures can say they return a SubmoduleStatus instead of just an int, and calling repr on a SubmoduleStatus returns more descriptive text than just a number, such as: <SubmoduleStatus.IN_HEAD|IN_INDEX|IN_CONFIG|WD_UNINITIALIZED: 135>

This isn't how pygit2 currently exposes enums to Python code – but if you think it'd improve pygit2, we could progressively convert the existing enums to IntFlag/IntEnum classes. (The raw GIT_* values would still be available for legacy code.)

If you'd rather not have enums.py for consistency with the existing API, let me know and I'll edit this PR accordingly.

jdavid commented 7 months ago

Merged, thanks.

My only concern is the API consistency of the Repository class:

add_submodule
init_submodules
listall_submodules
lookup_submodule
update_submodules
submodule_status (NEW)
submodule_cache_all (NEW)
submodule_cache_clear (NEW)

I think it would be best to do like the remotes and have:

.submodules.add
.submodules.init
.submodules.__iter__
.submodules.__getitem__
.submodules.update
.submodules.status
.submodules.cache_all
.submodules.cache_clear

With the old function names kept for backwards compatibility, as deprecated.

What do you think? Do you mind to make a new PR in that direction?

jorio commented 7 months ago

I agree, this looks better. I'll submit a new PR this week!