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.1.tar.gz (4.1 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.1-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for gsnapshot-0.0.1.tar.gz
Algorithm Hash digest
SHA256 235219b250c943417a6d9660ce353599ca0601e04dcf96237b67706b815b34d7
MD5 e184e5f307645313e8fa92138aac3d37
BLAKE2b-256 47f8d9fc61af4d21fb40bfa646cbba75c8a43f0820fa1bcede994565a1487720

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for gsnapshot-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6bf73d1215488aa22a825f44ec3056b3fc301034e387560a07b2fe9245698c7d
MD5 13332f4ecbec6b2566416e54ac5881a9
BLAKE2b-256 2f398c7687acea559b0ff6d3acd4654a5bf4d1c1521280f79302af34a96464ab

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