Skip to main content

a package for automatic repo snapshot using git

Project description

gsnapshot

A package use to automatic snapshot your repo using git.

gsnapshot snapshot your repo by adding all current changes in your working directory, make a new git commit, and create a annotated tag for that commit. If there is nothing to be added, gsnapshot will only create a annotated tag. After doing all the snapshot work, gsnapshot will rewind your repo back to starting state, you will still sit on the same commit, with origin stage and working directory.

Documentation

def snapshot_repo(tag_anno: str, tag_msg: str, commit_msg: str) -> str:
    '''
    tag_anno: str, tag name for new created tag
    tag_msg: str, tag message for new created tag message
    commit_msg: str, commit message for new created commit (if created)

    return: snapshot commit id
    '''

def get_repo_root() -> str:
    '''
    return: repo root path
    '''

def curr_commit_id() -> str:
    '''
    return: current git commit id
    '''

def curr_branch_name() -> Optional[str]:
    '''
    return: current git branch name
    '''

environment requirements

You must have git in your PATH.

Example

import gsnapshot

"""
import os
import filelock

ID_FILE = 'id.txt'
ID_LOCK_FILE = os.path.join(
    gsnapshot.get_repo_root(), '.git', '.gen_id.lock'
)
ID_LOCK = filelock.FileLock(ID_LOCK_FILE)
def create_unique_id() -> str:
    with ID_LOCK:
        if not os.path.exists(ID_FILE):
            unique_id = 0
        else:
            with open(ID_FILE, 'r') as f:
                unique_id = int(f.read())            
        with open(ID_FILE, 'w') as f:
            f.write(str(unique_id + 1))
    return f'{unique_id:04}'
"""

unique_id: str = create_unique_id() 
# you can create unique using filelock and a id file 
# like comments above, 
# !!!! you better add id file to .gitignore before snapshot,
# otherwise there will be problem when you working in multiple environment.

snapshot_commit = gsnapshot.snapshot_repo(
    f'v{unique_id}', 
    f'tag for {unique_id}',
    f'gsnapshot commit for {unique_id}',
)

print('snapshot at commit:', snapshot_commit)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gsnapshot-0.0.2.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gsnapshot-0.0.2-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file gsnapshot-0.0.2.tar.gz.

File metadata

  • Download URL: gsnapshot-0.0.2.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.11

File hashes

Hashes for gsnapshot-0.0.2.tar.gz
Algorithm Hash digest
SHA256 9252341206efaabf2f4967bba25ba4ab9c2632db82c1adff5e7c60a47f183ae0
MD5 013b80e405b8fa9012416a2a78c8ca1d
BLAKE2b-256 9acc75844b09f00bf8ad3aaa0db9421e2a28206b1e7389b41a1e809e2ca8381d

See more details on using hashes here.

File details

Details for the file gsnapshot-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: gsnapshot-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.11

File hashes

Hashes for gsnapshot-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6409b87c3af4345f13d5ddec3b09d799a40dbe3eb83a222fccd15fd75c6130fb
MD5 e293da3d30c8921246603ccf57257d45
BLAKE2b-256 b7cc20ddd8686623da6014a4adacb35c04d8f63dbe723444716f43c2d20b2425

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page