Another Attempt at Wag 2
Last time we had created
cmd_init(args) function. We add more functionality to cmd_init(args).
This was our code till last time.
We had added an argument to your sub parser called path. If the value of path is not specified it would be ‘.’ current directory or it would whatever specified. This would help us
A repository in git is consisted to two things a work tree where we have our files are there for version control and the git directory i.e.
.git directory where Git stores its own data. In regular practice our work tree is a regular directory and git directory is child of that directory. Git supports all cases also our program would work in this case only.
For any command we run related to git there would be in git repo. So we create an object which would help us manage things. We would be working with lot of files we need to import another python module os.
So let’s create a class call GitRepository who’s object would give us worktree directory and .git directory. Later when we would create other commands into our code we can use this to check whether we are executing commands on a valid repository or not.
We would create another function for our init command called
`repo_create(path)` which would take our path argument from init.
Now when you
./wag init you would get something like
. ./.git and if you do
./wag init test and you would get
test test/.git. So this would help us in creating directories.
As we have worktree path and git directory path we can check if worktree exist, if it doesn’t then we can create a directory. This would be used for creating things with
./wag init test
In wag, we would only allow to init git if already existing repository is empty otherwise we won’t. Now we need to create
.git directory and other directories inside it.