summaryrefslogtreecommitdiff
path: root/git/test
diff options
context:
space:
mode:
Diffstat (limited to 'git/test')
-rw-r--r--git/test/test_docs.py49
-rw-r--r--git/test/test_submodule.py2
2 files changed, 46 insertions, 5 deletions
diff --git a/git/test/test_docs.py b/git/test/test_docs.py
index 5ebae513..6befb9ea 100644
--- a/git/test/test_docs.py
+++ b/git/test/test_docs.py
@@ -6,21 +6,62 @@
# 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):
+class Tutorials(TestBase):
+
+ @with_rw_directory
+ def test_init_repo_object(self, rw_dir):
+ from git import Repo
+ join = os.path.join
+
+ # rorepo is a a Repo instance pointing to the git-python repository.
+ # For all you know, the first argument to Repo is a path to the repository
+ # you want to work with
+ repo = Repo(self.rorepo.working_tree_dir)
+ assert repo.bare == False
+ # ![1-test_init_repo_object]
+
+ # [2-test_init_repo_object]
+ bare_empty_repo = Repo.init(join(rw_dir, 'bare-repo'), bare=True)
+ assert bare_empty_repo.bare == True
+ # ![2-test_init_repo_object]
+
+ # [3-test_init_repo_object]
+ repo.config_reader() # get a config reader for read-only access
+ cw = repo.config_writer() # get a config writer to change configuration
+ cw.release() # call release() to be sure changes are written and locks are released
+ # ![3-test_init_repo_object]
+
+ # [4-test_init_repo_object]
+ repo.is_dirty()
+ # False
+ repo.untracked_files
+ # ['my_untracked_file']
+ # ![4-test_init_repo_object]
+
+ # [5-test_init_repo_object]
+ assert repo.clone(join(rw_dir, 'to/this/path')).__class__ is Repo
+ assert Repo.init(join(rw_dir, 'path/for/new/repo')).__class__ is Repo
+ # ![5-test_init_repo_object]
+
+ # [6-test_init_repo_object]
+ repo.archive(open(join(rw_dir, 'repo.tar'), 'w'))
+ # ![6-test_init_repo_object]
@with_rw_directory
def test_add_file_and_commit(self, rw_dir):
+ import git
+
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)
+ open(file_name, 'wb').close()
r.index.add([file_name])
r.index.commit("initial commit")
+
+ # ![test_add_file_and_commit]
diff --git a/git/test/test_submodule.py b/git/test/test_submodule.py
index 49ab2586..1d4cf178 100644
--- a/git/test/test_submodule.py
+++ b/git/test/test_submodule.py
@@ -783,7 +783,7 @@ class TestSubmodule(TestBase):
# Setup initial sandbox:
# parent repo has one submodule, which has all the latest changes
source_url = self._submodule_url()
- sm_source_repo = git.Repo.clone_from(source_url, os.path.join(rw_dir, 'sm-source'))
+ sm_source_repo = git.Repo.clone_from(source_url, os.path.join(rw_dir, 'sm-source'), b='master')
parent_repo = git.Repo.init(os.path.join(rw_dir, 'parent'))
sm = parent_repo.create_submodule('mysubmodule', 'subdir/submodule',
sm_source_repo.working_tree_dir, branch='master')