Compare commits

...

2 Commits

Author SHA1 Message Date
David Doblas Jiménez 1f7354666b Create new .ugit directory 2024-02-10 19:09:11 +01:00
David Doblas Jiménez 55b2c17913 Add change 03 instructions 2024-02-10 19:08:21 +01:00
3 changed files with 30 additions and 1 deletions

18
how_to/Change_03.md Normal file
View File

@ -0,0 +1,18 @@
- init: Create new .ugit directory
The 'ugit init' command creates a new empty repository.
Git stores all repository data locally, in a subdirectory called ".git", so upon
initialization we'll create one.
I named the directory ".ugit" rather than ".git" so that it doesn't clash with
Git, but the idea is the same.
To implement 'init', we could have just called os.makedirs from cli.py, but I
want to have some separation between different logical parts of the code:
+ cli.py - In charge of parsing and processing user input.
+ data.py - Manages the data in .ugit directory. Here will be the code that
actually touches files on disk.
This separation will be useful as the code will get larger.

View File

@ -1,4 +1,7 @@
import argparse
from pathlib import Path
from . import data
def main():
@ -19,4 +22,5 @@ def parse_args():
def init(args):
print("Hello, World!")
data.init()
print(f"Initialized empty ugit repository in {Path.cwd()}/{data.GIT_DIR}")

7
ugit/data.py Normal file
View File

@ -0,0 +1,7 @@
from pathlib import Path
GIT_DIR = ".ugit"
def init():
Path.mkdir(GIT_DIR)