Skip to content

RFE: Give Commit objects a replace method that returns new Commit with modified attributes #1123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
larsks opened this issue Feb 15, 2021 · 0 comments · Fixed by #1124
Closed

Comments

@larsks
Copy link
Contributor

larsks commented Feb 15, 2021

The datetime objects produced by Python's datetime module are immutable, much like Commit objects. The datetime module provides a convenient replace function that returns a new object based on an old with one or more attributes replaced. E.g, I can write:

>>> d = datetime.datetime.now()
>>> d.replace(hour=0, minute=0, second=0)
datetime.datetime(2021, 2, 15, 0, 0, 0, 318021)

I would like to see the same api on Commit objects, so that one could write:

>>> newcommit = oldcommit.replace(message='This is a test', author='Cookie Monster')
larsks added a commit to larsks/GitPython that referenced this issue Feb 15, 2021
(marked WIP until I add appropriate tests)

This adds a replace method to git.Commit. The replace method returns a
copy of the Commit object with attributes replaced from keyword
arguments. For example:

>>> old = repo.head.commit
>>> new = old.replace(message='This is a test')

closes gitpython-developers#1123
larsks added a commit to larsks/GitPython that referenced this issue Feb 16, 2021
This adds a replace method to git.Commit. The replace method returns a
copy of the Commit object with attributes replaced from keyword
arguments. For example:

>>> old = repo.head.commit
>>> new = old.replace(message='This is a test')

closes gitpython-developers#1123
larsks added a commit to larsks/GitPython that referenced this issue Feb 16, 2021
This adds a replace method to git.Commit. The replace method returns a
copy of the Commit object with attributes replaced from keyword
arguments. For example:

>>> old = repo.head.commit
>>> new = old.replace(message='This is a test')

closes gitpython-developers#1123

@feature/replace
larsks added a commit to larsks/GitPython that referenced this issue Feb 16, 2021
This adds a replace method to git.Commit. The replace method returns a
copy of the Commit object with attributes replaced from keyword
arguments. For example:

>>> old = repo.head.commit
>>> new = old.replace(message='This is a test')

closes gitpython-developers#1123
@Byron Byron added this to the v3.1.14 - Bugfixes milestone Feb 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants