Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
ba3923e
ajout des objets
AkaTFL Jun 12, 2025
80479e6
maj objets
AkaTFL Jun 12, 2025
eec391e
Merge pull request #1 from Freeky-inc/obj
AkaTFL Jun 12, 2025
268acba
added hash function
iGrec-a2n Jun 12, 2025
17dde2b
Merge pull request #2 from Freeky-inc/dev
iGrec-a2n Jun 12, 2025
f592db9
Adding argparse et test des commande {init et commit}
iGrec-a2n Jun 13, 2025
409f146
efkeo
bnjjs1998 Jun 13, 2025
75a96c5
he
bnjjs1998 Jun 13, 2025
a6e478c
suppression du fichier que baptiste à ajouter au repo de manière tota…
iGrec-a2n Jun 16, 2025
0b36f52
Added Lanching script steps
iGrec-a2n Jun 16, 2025
c8d6d03
ajout write-tree
AkaTFL Jun 17, 2025
c30a2e2
mise en place de la fonction qui contient l'index
bnjjs1998 Jun 17, 2025
300199a
commande add affiche le print mis dans la fonction update_index
bnjjs1998 Jun 17, 2025
8660164
vérification de l'existence du fichier
bnjjs1998 Jun 17, 2025
e6dc70c
Merge pull request #22 from Freeky-inc/7-git-write-tree
AkaTFL Jun 17, 2025
aa76011
Add ls_files script to list files in a Git repository
damnthonyy Jun 17, 2025
9157d96
Update terminal.py to support unknown arguments and execute ls_files …
damnthonyy Jun 17, 2025
668d1eb
Remove unnecessary newline in terminal.py
damnthonyy Jun 17, 2025
76caff4
ajout du commit-tree et fix du write-tree
AkaTFL Jun 18, 2025
ffb6e97
refix (ajout date et parent dans commit)
AkaTFL Jun 18, 2025
b1bc999
Merge pull request #23 from Freeky-inc/17-git-ls-files
AkaTFL Jun 18, 2025
2ea668c
Merge pull request #24 from Freeky-inc/dev
AkaTFL Jun 18, 2025
93cc98c
Merge branch 'main' into 9-git-commit-tree-tree_sha--m-msg--p-parent
AkaTFL Jun 18, 2025
6d1810a
plus qu'à changer le commit change
bnjjs1998 Jun 18, 2025
a19c0bd
adaptation terminale.py
AkaTFL Jun 18, 2025
ad63061
plus qu'à changer le commit change
bnjjs1998 Jun 18, 2025
e790fb5
Merge pull request #28 from Freeky-inc/dev_index_implementation
AkaTFL Jun 19, 2025
d1795ac
Merge pull request #25 from Freeky-inc/9-git-commit-tree-tree_sha--m-…
AkaTFL Jun 19, 2025
6f41a9e
unification du code
AkaTFL Jun 19, 2025
20322ff
ajout show-ref
AkaTFL Jul 2, 2025
4165ac3
Merge pull request #30 from Freeky-inc/18-git-show-ref
AkaTFL Jul 2, 2025
cbe310b
Add cat-file functionality to retrieve object details and content
AkaTFL Jul 2, 2025
39ae4bf
Merge pull request #31 from Freeky-inc/5-git-cat-file--t-p-oid
AkaTFL Jul 2, 2025
6287b77
ajout rev-parse
AkaTFL Jul 2, 2025
1d65e59
Merge pull request #32 from Freeky-inc/16-git-rev-parse-ref
AkaTFL Jul 2, 2025
f966b41
ajout reset
AkaTFL Jul 2, 2025
9f24e4e
Merge pull request #33 from Freeky-inc/13-git-reset---soft--mixed--ha…
AkaTFL Jul 2, 2025
365cf27
première partie du git status
bnjjs1998 Jul 8, 2025
61a1b91
ajustement
AkaTFL Jul 9, 2025
f0037f8
Merge branch 'main' into main-dev-git-status
AkaTFL Jul 10, 2025
c3f1ac0
Merge pull request #34 from Freeky-inc/main-dev-git-status
AkaTFL Jul 10, 2025
d59ba1b
fix
AkaTFL Jul 10, 2025
c571181
Merge pull request #35 from Freeky-inc/main-dev-git-status
AkaTFL Jul 10, 2025
05e7d8e
ajout de ls_tree
AkaTFL Jul 10, 2025
ea90998
Merge pull request #36 from Freeky-inc/15-git-ls-tree-tree_sha
AkaTFL Jul 10, 2025
93efb6a
simplification du code
AkaTFL Jul 10, 2025
737e77b
Merge branch 'main' into git-log
AkaTFL Jul 14, 2025
eebdc2e
ajout log
AkaTFL Jul 14, 2025
041dd23
Merge pull request #37 from Freeky-inc/git-log
AkaTFL Jul 14, 2025
51598ea
add checkout et fix fonctions
AkaTFL Jul 16, 2025
a07530c
Merge pull request #38 from Freeky-inc/12-git-checkout--b-branchsha
AkaTFL Jul 16, 2025
4c8954c
add ".gitignore"
iGrec-a2n Jul 21, 2025
ee530ce
rm
bnjjs1998 Jul 21, 2025
80f093e
rm
bnjjs1998 Jul 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .fyt/HEAD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ref: refs/heads/test
1 change: 1 addition & 0 deletions .fyt/index
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Launching.md": "8a34efceef0ac0a1d28f6ecd6b787faa858fc371"}
1 change: 1 addition & 0 deletions .fyt/objects/blob/69bce968f88ac26eaa0ebf28d84639b42a4471d7
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ceci est un fichier de text
14 changes: 14 additions & 0 deletions .fyt/objects/blob/8a34efceef0ac0a1d28f6ecd6b787faa858fc371
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Prérequis

- Assurez-vous d'avoir Python 3 installé :
```bash
python --version
```

## Lancement du script

Pour exécuter le script, utilisez la commande suivante :
```bash
python terminal.py [arguments]
```
Remplacez `[arguments]` par les paramètres nécessaires selon l'utilisation du script.
55 changes: 55 additions & 0 deletions .fyt/objects/blob/bc9b311544d0687f60b2a17b1d2055e8c631ea73
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# **Comment lancer le script**
---
## Cas de script Bash
**Rendre le fichier script exécutable**
```bash
chmod +x my_hash_object.sh #Rend le script exécutable
```

**Lancer le fichier avec un argument**
```bash
./my_hash_object.sh mon_fichier.txt
```

## Cas de script Python (notre cas)

```bash
python3 --version # Vérifie que Python 3 est installé

python3 git_hash_object.py mon_fichier.txt
```
---
**ou alors**
## Pour le script Bash
Place-le dans un dossier de ton PATH (par exemple ~/bin/).

Ou utilise un alias dans ton ```.bashrc :```

```bash
alias git-hash-object="$HOME/path/to/my_hash_object.sh"
```
### Pour le script Python
Rends-le exécutable :

```bash
chmod +x git_hash_object.py
```
Ajoute un shebang (première ligne du script) :

```python
#!/usr/bin/env python3
```
Déplace-le dans un dossier du PATH ou utilise un alias :

```bash
alias git-hash-object="python3 $HOME/path/to/git_hash_object.py"
```
### Vérification avec Git
Compare le résultat avec la commande réelle de Git :

```bash
git hash-object test.txt
```

[extrait de deepseek](https://chat.deepseek.com/a/chat/s/00c34d42-1c8e-4fcf-8f1a-a551c10f2804)
Ces étapes peuvent varier entre les utilisateurs de windows et de MacOS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"tree": "2340a8db5d75bd52c074df36bd760aa1531b81be", "message": "bonjour", "date": "2025-07-02T16:21:34.769908"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"tree": "ae91d2597f41e32b3246644d0da6002b7459efc1", "message": "bonjour", "date": "2025-07-16T15:00:53.235825"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"tree": "ae91d2597f41e32b3246644d0da6002b7459efc1", "message": "bonjour", "date": "2025-07-16T15:11:14.809683"}
1 change: 1 addition & 0 deletions .fyt/objects/tree/2340a8db5d75bd52c074df36bd760aa1531b81be
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"files": [["test\\fichier.txt", "69bce968f88ac26eaa0ebf28d84639b42a4471d7"], ["launching.md", "bc9b311544d0687f60b2a17b1d2055e8c631ea73"]]}
1 change: 1 addition & 0 deletions .fyt/objects/tree/ae91d2597f41e32b3246644d0da6002b7459efc1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"files": [["Launching.md", "8a34efceef0ac0a1d28f6ecd6b787faa858fc371"]]}
1 change: 1 addition & 0 deletions .fyt/refs/heads/main
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d167f8150b32689b88347ca2b4ad552757bbaa1d
1 change: 1 addition & 0 deletions .fyt/refs/heads/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d52abe7ef4782155953505139bb08ccf597be44e
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*/__pycache__/
*/*.pyc
14 changes: 14 additions & 0 deletions Launching.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Prérequis

- Assurez-vous d'avoir Python 3 installé :
```bash
python --version
```

## Lancement du script

Pour exécuter le script, utilisez la commande suivante :
```bash
python terminal.py [arguments]
```
Remplacez `[arguments]` par les paramètres nécessaires selon l'utilisation du script.
Binary file added Objects/__pycache__/commit.cpython-313.pyc
Binary file not shown.
Binary file added Objects/__pycache__/o_commit.cpython-313.pyc
Binary file not shown.
Binary file added Objects/__pycache__/o_tree.cpython-313.pyc
Binary file not shown.
Binary file added Objects/__pycache__/tree.cpython-313.pyc
Binary file not shown.
7 changes: 7 additions & 0 deletions Objects/o_blob.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Blob:
def setBlob(self, sha1, donnees):
self.sha1 = sha1
self.donnees = donnees

def getBlobHash(self):
return self.sha1
60 changes: 60 additions & 0 deletions Objects/o_commit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import hashlib
import datetime
import os
import json

class Commit:
def setCommit(self, tree_sha1, message, parent_sha1=None):
# Construction du contenu du commit pour le hash
commit_content = f"tree {tree_sha1}\n"
commit_content += f"message {message}\n"
if parent_sha1:
commit_content += f"parent {parent_sha1}\n"

commit_bytes = commit_content.encode("utf-8")
self.sha1 = hashlib.sha1(commit_bytes).hexdigest()

# Préparation des données à sauvegarder au format JSON
commit_data = {
"tree": tree_sha1,
"message": message,
"date": datetime.datetime.now().isoformat()
}
if parent_sha1:
commit_data["parent"] = parent_sha1

dir_path = ".fyt/objects/commit"
file_path = os.path.join(dir_path, self.sha1)
if os.path.exists(file_path):
with open(file_path, "r") as f:
content = json.load(f)
self.ref = content.get("tree")
self.parent = content.get("parent")
self.date = datetime.datetime.fromisoformat(content.get("date"))
self.message = content.get("message")
print("Un commit identique existe déjà. Aucun nouveau commit créé.")
return

self.ref = tree_sha1
self.parent = parent_sha1
self.date = datetime.datetime.fromisoformat(commit_data["date"])
self.message = message

os.makedirs(dir_path, exist_ok=True)
with open(file_path, "w") as f:
json.dump(commit_data, f)

def getCommitHash(self):
return self.sha1

def getCommitDate(self):
return self.date

def getCommitRef(self):
return self.ref

def getCommitMessage(self):
return self.message

def getCommitParent(self):
return self.parent
31 changes: 31 additions & 0 deletions Objects/o_tree.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os
import json
import hashlib

class Tree:
def setTree(self):
# Charge l'index pour obtenir les chemins d'origine et les hashes de blob
with open(".fyt/index", "r", encoding="utf-8") as idx_file:
index = json.load(idx_file)

# Construit la liste des fichiers pour le tree
files = [[path, blob_hash] for path, blob_hash in index.items()]

tree_data = {"files": files}
tree_json = json.dumps(tree_data).encode("utf-8")
self.sha1 = hashlib.sha1(tree_json).hexdigest()
self.files = files

# Sauvegarde dans .fyt/objects/tree/
dir_path = ".fyt/objects/tree/"
file_path = os.path.join(dir_path, self.sha1)
if os.path.exists(file_path):
print("Un tree identique existe déjà. Aucun nouveau tree créé.")
return

os.makedirs(dir_path, exist_ok=True)
with open(file_path, "wb") as f:
f.write(tree_json)

def getFiles(self):
return self.files
Binary file added __pycache__/add.cpython-313.pyc
Binary file not shown.
Binary file added __pycache__/commit.cpython-313.pyc
Binary file not shown.
Binary file added __pycache__/commit_tree.cpython-313.pyc
Binary file not shown.
Binary file added __pycache__/init.cpython-313.pyc
Binary file not shown.
Binary file added __pycache__/ls_files.cpython-313.pyc
Binary file not shown.
Binary file added __pycache__/write_tree.cpython-313.pyc
Binary file not shown.
Binary file added functions/__pycache__/add.cpython-313.pyc
Binary file not shown.
Binary file added functions/__pycache__/cat_file.cpython-313.pyc
Binary file not shown.
Binary file added functions/__pycache__/checkout.cpython-313.pyc
Binary file not shown.
Binary file added functions/__pycache__/commit.cpython-313.pyc
Binary file not shown.
Binary file added functions/__pycache__/commit_tree.cpython-313.pyc
Binary file not shown.
Binary file added functions/__pycache__/init.cpython-313.pyc
Binary file not shown.
Binary file added functions/__pycache__/log.cpython-313.pyc
Binary file not shown.
Binary file added functions/__pycache__/ls_files.cpython-313.pyc
Binary file not shown.
Binary file added functions/__pycache__/ls_tree.cpython-313.pyc
Binary file not shown.
Binary file added functions/__pycache__/reset.cpython-313.pyc
Binary file not shown.
Binary file added functions/__pycache__/rev_parse.cpython-313.pyc
Binary file not shown.
Binary file added functions/__pycache__/show_ref.cpython-313.pyc
Binary file not shown.
Binary file added functions/__pycache__/write_tree.cpython-313.pyc
Binary file not shown.
85 changes: 85 additions & 0 deletions functions/add.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import os
import json
import hashlib

def add_file(file_path):
with open(file_path, "rb") as f:
content = f.read()
blob_hash = hashlib.sha1(content).hexdigest()
blob_dir = ".fyt/objects/blob"
os.makedirs(blob_dir, exist_ok=True)
blob_path = os.path.join(blob_dir, blob_hash)

with open(blob_path, "wb") as f:
f.write(content)

update_index(file_path, blob_hash)
print(f"Fichier '{file_path}' ajouté (Blob: {blob_hash})")

def update_index(file_path, blob_hash):
index_path = ".fyt/index"
if os.path.exists(index_path):
with open(index_path, "r") as f:
content = f.read().strip()
if content:
index = json.loads(content)
else:
index = {}
else:
index = {}

rel_path = os.path.relpath(file_path, os.getcwd())
file_stat = os.stat(file_path)

index[rel_path] = blob_hash
# Sauvegarder l'index
with open(index_path, "w") as f:
json.dump(index, f)


def status_all():
index_path = ".fyt/index"
project_root = os.path.join(os.getcwd(), "projet-test")

if os.path.exists(index_path):
with open(index_path, "r") as f:
content = f.read().strip()
if content:
index = json.loads(content)
else:
index = {}
else:
index = {}

tracked_files = set(index.keys())
working_dir_files = set()

for root, dirs, files in os.walk(project_root):
# Exclure les dossiers cachés et __pycache__
rel_root = os.path.relpath(root, project_root)
if rel_root == ".fyt" or rel_root.startswith(".fyt" + os.sep):
continue
if rel_root.startswith(".git") or rel_root.startswith("__pycache__") or rel_root.startswith("Objects" + os.sep + "__pycache__"):
continue
# Exclure tous les dossiers cachés
dirs[:] = [d for d in dirs if not d.startswith('.') and d != '__pycache__']
for file in files:
if file.startswith('.') or file.endswith('.pyc'):
continue
path = os.path.join(root, file)
rel_path = os.path.relpath(path, os.getcwd()) # rel_path par rapport à la racine du projet global
working_dir_files.add(rel_path)

with open(path, "rb") as f:
content = f.read()
current_hash = hashlib.sha1(content).hexdigest()

if rel_path not in index:
print(f"{rel_path}: nouveau fichier non suivi")
elif index[rel_path] != current_hash:
print(f"{rel_path}: modifié")
else:
print(f"{rel_path}: inchangé")

for tracked in tracked_files - working_dir_files:
print(f"{tracked}: supprimé")
44 changes: 44 additions & 0 deletions functions/cat_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import os
import json

def cat_file(t, prettier, hash_id):
# Recherche dans les dossiers d'objets possibles
object_dirs = [
".fyt/objects/blob",
".fyt/objects/tree",
".fyt/objects/commit"
]
found = False
for obj_dir in object_dirs:
file_path = os.path.join(obj_dir, hash_id)
if os.path.exists(file_path):
found = True
# Affiche le type si demandé
if t:
if "blob" in obj_dir:
print("blob")
elif "tree" in obj_dir:
print("tree")
elif "commit" in obj_dir:
print("commit")
else:
print("unknown")
# Affiche le contenu si demandé
if prettier:
with open(file_path, "rb") as f:
try:
content = f.read().decode("utf-8")
# Si c'est du JSON, affiche joliment
try:
data = json.loads(content)
print(json.dumps(data, indent=2, ensure_ascii=False))
except Exception:
print(content)
except Exception:
print(f"[binaire] {hash_id}")
# Affiche le hash si demandé
if not t and not prettier:
print("Il faut choisir une option pour afficher le contenu ou le type de l'objet.")
break
if not found:
print(f"Objet {hash_id} introuvable.")
Loading