This Python program implements basic Git functionalities to explore Git objects, trees, and repositories. It provides commands for initializing a Git directory, listing tree contents, hashing objects, and more.
- Initialize a Git Repository: Set up a minimal
.gitdirectory structure. - Hash a File: Compute and optionally write the hash of a file in Git's object storage.
- Inspect Git Objects: Read and display the content of a blob or tree object.
- List Tree Contents: Show the entries in a tree object.
python script.py initCreates a minimal .git directory structure:
.git/objects.git/refs.git/HEADpointing torefs/heads/main.
python script.py hash-object [-w] <file_path>- Compute the SHA-1 hash of the file's content.
- Optionally write the file into the
.git/objectsdirectory with the-wflag.
Examples:
- Compute hash only:
python script.py hash-object file.txt
- Compute hash and write:
python script.py hash-object -w file.txt
python script.py cat-file -p <object_sha>- Display the content of a Git object (blob, tree, etc.).
- The object is identified by its SHA.
python script.py ls-tree [--name-only] <tree_sha>- List the contents of a tree object.
- The
--name-onlyflag lists only entry names without additional details.
Examples:
- Full details:
python script.py ls-tree <tree_sha>
- Names only:
python script.py ls-tree --name-only <tree_sha>
- Python 3.x
- The program assumes a Git-like
.gitdirectory structure for file-based operations. - Make sure you have a valid
.gitdirectory in the working directory for commands that interact with objects.
This implementation is a simplified version of Git and supports only core features:
- It does not handle branches, commits, or advanced Git concepts.
- The program operates on objects and trees manually, without the full Git plumbing.
This project is open-source and available for educational purposes. Modify and adapt as needed!
Created by [Hanafe Mira].