Skip to content
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

Add list_repo_commits to list git history of a repo #1331

Merged
merged 6 commits into from
Feb 16, 2023

Conversation

Wauplin
Copy link
Contributor

@Wauplin Wauplin commented Feb 10, 2023

FIX #1288 (following server-side implementation -internal link- thanks @Kakulukian).

This PR adds a new helper list_repo_commits (similar to list_repo_refs and list_repo_files`). It lists the all history of a repository on the Hub for a given revision. Commits are sorted by date (last commit first).

@camenduru this will finally solve your problem on "how to create an empty branch?". I did not make a special parameter in create_branch that would use list_repo_commits under the hood as I thought it was a quite specific use case.

>>> from huggingface_hub import HfApi
>>> api = HfApi()

# Get initial commit on a repo
>>> initial_commit = api.list_repo_commits("gpt2")[-1]

# Initial commit is always a system commit containing the `.gitattributes` file.
>>> initial_commit
GitCommitInfo(
    commit_id='9b865efde13a30c13e0a33e536cf3e4a5a9d71d8',
    authors=['system'],
    created_at=datetime.datetime(2019, 2, 18, 10, 36, 15, tzinfo=datetime.timezone.utc),
    title='initial commit',
    message='',
    formatted_title=None,
    formatted_message=None
)

# Create an "empty branch" by deriving from initial commit (branch is not entirely empty, `.gitattributes` is still there :) )
>>> api.create_branch("gpt2", "new_empty_branch", revision=initial_commit.commit_id)

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Feb 10, 2023

The documentation is not available anymore as the PR was closed or merged.

Copy link
Member

@julien-c julien-c left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really cool!

Co-authored-by: Julien Chaumond <julien@huggingface.co>
@codecov
Copy link

codecov bot commented Feb 10, 2023

Codecov Report

❗ No coverage uploaded for pull request base (main@ad31403). Click here to learn what that means.
Patch coverage: 100.00% of modified lines in pull request are covered.

❗ Current head 837297a differs from pull request most recent head e17ffa2. Consider uploading reports for the commit e17ffa2 to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1331   +/-   ##
=======================================
  Coverage        ?   83.83%           
=======================================
  Files           ?       47           
  Lines           ?     4727           
  Branches        ?        0           
=======================================
  Hits            ?     3963           
  Misses          ?      764           
  Partials        ?        0           
Impacted Files Coverage Δ
src/huggingface_hub/__init__.py 75.75% <ø> (ø)
src/huggingface_hub/hf_api.py 87.41% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@camenduru
Copy link

🎉 thanks @Kakulukian ♥️ thanks @Wauplin ♥️

Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @Wauplin, very clean!

@Wauplin Wauplin merged commit 23b1312 into main Feb 16, 2023
@Wauplin Wauplin deleted the 1288-list-repo-commits branch February 16, 2023 08:41
@camenduru
Copy link

🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Is it possible to drop everything inside the main branch before creating a new branch?
5 participants