I am writing a Lua script that creates a directory, creates some files inside of it and initializes git, adding those files to it and finally committing everything. However there's no way to use cd
from inside Lua (you can, but it won't have effect), so I wonder if it's possible to git init
a directory, git add
some files and finally git commit -a -m "message"
, all while the working directory is the directory above the desired directory.
Edit: -C
works, thanks everyone. For anyone wondering, in Lua, cd
"resets" after the call to os.execute
ends. So, os.execute("cd mydir"); os.execute("git init");
won't work as expected. To get it to work, use os.execute("cd mydir; git init;");
.
By following the hint in the comments about -C I did:
to make the git repo in dir newStuff (which I had already created)
Then I added two files to newStuff, and from it's parent using using -C
I see the new files. Now add and commit them: