summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/source/tutorial.rst16
-rw-r--r--git/test/test_docs.py26
2 files changed, 42 insertions, 0 deletions
diff --git a/doc/source/tutorial.rst b/doc/source/tutorial.rst
index 3f45b70d..4921d07b 100644
--- a/doc/source/tutorial.rst
+++ b/doc/source/tutorial.rst
@@ -415,6 +415,22 @@ The previous approach would brutally overwrite the user's changes in the working
repo.heads.master.checkout() # checkout the branch using git-checkout
repo.heads.other_branch.checkout()
+Initializing a repository
+*************************
+
+In this example, we will initialize an empty repository, add an empty file to the index, and commit the change::
+
+ repo_dir = 'my-new-repo'
+ file_name = os.path.join(repo_dir, 'new-file')
+
+ r = git.Repo.init(repo_dir)
+ # This function just creates an empty file ...
+ touch(file_name)
+ r.index.add([file_name])
+ r.index.commit("initial commit")
+
+Please have a look at the individual methods as they usually support a vast amount of arguments to customize their behavior.
+
Using git directly
******************
In case you are missing functionality as it has not been wrapped, you may conveniently use the git command directly. It is owned by each repository instance::
diff --git a/git/test/test_docs.py b/git/test/test_docs.py
new file mode 100644
index 00000000..5ebae513
--- /dev/null
+++ b/git/test/test_docs.py
@@ -0,0 +1,26 @@
+#-*-coding:utf-8-*-
+# test_git.py
+# Copyright (C) 2008, 2009 Michael Trier (mtrier@gmail.com) and contributors
+#
+# This module is part of GitPython and is released under
+# the BSD License: http://www.opensource.org/licenses/bsd-license.php
+import os
+
+import git
+from git.test.lib import TestBase
+from gitdb.test.lib import with_rw_directory
+from git.repo.fun import touch
+
+
+class TestGit(TestBase):
+
+ @with_rw_directory
+ def test_add_file_and_commit(self, rw_dir):
+ repo_dir = os.path.join(rw_dir, 'my-new-repo')
+ file_name = os.path.join(repo_dir, 'new-file')
+
+ r = git.Repo.init(repo_dir)
+ # This function just creates an empty file ...
+ touch(file_name)
+ r.index.add([file_name])
+ r.index.commit("initial commit")