| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c3c6c81 commit e48e520
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,6 +7,8 @@ Changelog | |||
| 7 | 7 | * Added `Repo.merge_base()` implementation. See the `respective issue on github <https://github.com/gitpython-developers/GitPython/issues/169>`_ | |
| 8 | 8 | * `[include]` sections in git configuration files are now respected | |
| 9 | 9 | * Added `GitConfigParser.rename_section()` | |
| 10 | + * DOCS: special members like `__init__` are now listed in the API documentation | ||
| 11 | + * DOCS: tutorial section was revised entirely | ||
| 10 | 12 | * Added `Submodule.rename()` | |
| 11 | 13 | * **POSSIBLY BREAKING CHANGE**: As `rev_parse` will now throw `BadName` as well as `BadObject`, client code will have to catch both exception types. | |
| 12 | 14 | * A list of all issues can be found here: https://github.com/gitpython-developers/GitPython/issues?q=milestone%3A%22v0.3.6+-+Features%22+ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,7 +8,8 @@ Objects.Base | |||
| 8 | 8 | ||
| 9 | 9 | .. automodule:: git.objects.base | |
| 10 | 10 | :members: | |
| 11 | - :undoc-members: | ||
| 11 | + :undoc-members: | ||
| 12 | + :special-members: | ||
| 12 | 13 | ||
| 13 | 14 | Objects.Blob | |
| 14 | 15 | ------------ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,42 +8,54 @@ | |||
| 8 | 8 | GitPython Tutorial | |
| 9 | 9 | ================== | |
| 10 | 10 | ||
| 11 | - GitPython provides object model access to your git repository. This tutorial is composed of multiple sections, each of which explains a real-life usecase. | ||
| 11 | + GitPython provides object model access to your git repository. This tutorial is composed of multiple sections, each of which explains a real-life usecase. | ||
| 12 | 12 | ||
| 13 | - Initialize a Repo object | ||
| 14 | - ************************ | ||
| 13 | + Meet the Repo type | ||
| 14 | + ****************** | ||
| 15 | 15 | ||
| 16 | - The first step is to create a ``Repo`` object to represent your repository:: | ||
| 16 | + The first step is to create a :class:`git.Repo <git.repo.base.Repo>` object to represent your repository. | ||
| 17 | 17 | ||
| 18 | - from git import * | ||
| 19 | - repo = Repo("/Users/mtrier/Development/git-python") | ||
| 20 | - assert repo.bare == False | ||
| 18 | + .. literalinclude:: ../../git/test/test_docs.py | ||
| 19 | + :language: python | ||
| 20 | + :start-after: def test_init_repo_object | ||
| 21 | + :end-before: # ![1-test_init_repo_object] | ||
| 21 | 22 | ||
| 22 | - In the above example, the directory ``/Users/mtrier/Development/git-python`` is my working repository and contains the ``.git`` directory. You can also initialize GitPython with a *bare* repository:: | ||
| 23 | + In the above example, the directory ``self.rorepo.working_tree_dir`` equals ``/Users/mtrier/Development/git-python`` and is my working repository which contains the ``.git`` directory. You can also initialize GitPython with a *bare* repository. | ||
| 23 | 24 | ||
| 24 | - repo = Repo.init("/var/git/git-python.git", bare=True) | ||
| 25 | - assert repo.bare == True | ||
| 25 | + .. literalinclude:: ../../git/test/test_docs.py | ||
| 26 | + :language: python | ||
| 27 | + :start-after: # [2-test_init_repo_object] | ||
| 28 | + :end-before: # ![2-test_init_repo_object] | ||
| 26 | 29 | ||
| 27 | - A repo object provides high-level access to your data, it allows you to create and delete heads, tags and remotes and access the configuration of the repository:: | ||
| 30 | + A repo object provides high-level access to your data, it allows you to create and delete heads, tags and remotes and access the configuration of the repository. | ||
| 28 | 31 | ||
| 29 | - repo.config_reader() # get a config reader for read-only access | ||
| 30 | - repo.config_writer() # get a config writer to change configuration | ||
| 32 | + .. literalinclude:: ../../git/test/test_docs.py | ||
| 33 | + :language: python | ||
| 34 | + :start-after: # [3-test_init_repo_object] | ||
| 35 | + :end-before: # ![3-test_init_repo_object] | ||
| 31 | 36 | ||
| 32 | - Query the active branch, query untracked files or whether the repository data has been modified:: | ||
| 37 | + Query the active branch, query untracked files or whether the repository data has been modified. | ||
| 33 | 38 | ||
| 34 | - repo.is_dirty() | ||
| 35 | - False | ||
| 36 | - repo.untracked_files | ||
| 37 | - ['my_untracked_file'] | ||
| 39 | + .. literalinclude:: ../../git/test/test_docs.py | ||
| 40 | + :language: python | ||
| 41 | + :start-after: # [4-test_init_repo_object] | ||
| 42 | + :end-before: # ![4-test_init_repo_object] | ||
| 38 | 43 | ||
| 39 | - Clone from existing repositories or initialize new empty ones:: | ||
| 44 | + Clone from existing repositories or initialize new empty ones. | ||
| 40 | 45 | ||
| 41 | - cloned_repo = repo.clone("to/this/path") | ||
| 42 | - new_repo = Repo.init("path/for/new/repo") | ||
| 46 | + .. literalinclude:: ../../git/test/test_docs.py | ||
| 47 | + :language: python | ||
| 48 | + :start-after: # [5-test_init_repo_object] | ||
| 49 | + :end-before: # ![5-test_init_repo_object] | ||
| 43 | 50 | ||
| 44 | - Archive the repository contents to a tar file:: | ||
| 51 | + Archive the repository contents to a tar file. | ||
| 52 | + | ||
| 53 | + .. literalinclude:: ../../git/test/test_docs.py | ||
| 54 | + :language: python | ||
| 55 | + :start-after: # [6-test_init_repo_object] | ||
| 56 | + :end-before: # ![6-test_init_repo_object] | ||
| 45 | 57 | ||
| 46 | - repo.archive(open("repo.tar",'w')) | ||
| 58 | + .. todo repo paths, heads, remotes, submodules | ||
| 47 | 59 | ||
| 48 | 60 | ||
| 49 | 61 | Object Databases | |
@@ -418,16 +430,12 @@ The previous approach would brutally overwrite the user's changes in the working | |||
| 418 | 430 | Initializing a repository | |
| 419 | 431 | ************************* | |
| 420 | 432 | ||
| 421 | - In this example, we will initialize an empty repository, add an empty file to the index, and commit the change:: | ||
| 422 | - | ||
| 423 | - repo_dir = 'my-new-repo' | ||
| 424 | - file_name = os.path.join(repo_dir, 'new-file') | ||
| 433 | + In this example, we will initialize an empty repository, add an empty file to the index, and commit the change. | ||
| 425 | 434 | ||
| 426 | - r = git.Repo.init(repo_dir) | ||
| 427 | - # This function just creates an empty file ... | ||
| 428 | - touch(file_name) | ||
| 429 | - r.index.add([file_name]) | ||
| 430 | - r.index.commit("initial commit") | ||
| 435 | + .. literalinclude:: ../../git/test/test_docs.py | ||
| 436 | + :language: python | ||
| 437 | + :start-after: def test_add_file_and_commit | ||
| 438 | + :end-before: # ![test_add_file_and_commit] | ||
| 431 | 439 | ||
| 432 | 440 | Please have a look at the individual methods as they usually support a vast amount of arguments to customize their behavior. | |
| 433 | 441 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -295,7 +295,7 @@ def wait(self): | |||
| 295 | 295 | :raise GitCommandError: if the return status is not 0""" | |
| 296 | 296 | status = self.proc.wait() | |
| 297 | 297 | if status != 0: | |
| 298 | - raise GitCommandError(self.args, status, self.proc.stderr.read().decode(defenc)) | ||
| 298 | + raise GitCommandError(self.args, status, self.proc.stderr.read()) | ||
| 299 | 299 | # END status handling | |
| 300 | 300 | return status | |
| 301 | 301 | # END auto interrupt | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -132,9 +132,11 @@ class IndexObject(Object): | |||
| 132 | 132 | ||
| 133 | 133 | def __init__(self, repo, binsha, mode=None, path=None): | |
| 134 | 134 | """Initialize a newly instanced IndexObject | |
| 135 | + | ||
| 135 | 136 | :param repo: is the Repo we are located in | |
| 136 | 137 | :param binsha: 20 byte sha1 | |
| 137 | - :param mode: is the stat compatible file mode as int, use the stat module | ||
| 138 | + :param mode: | ||
| 139 | + is the stat compatible file mode as int, use the stat module | ||
| 138 | 140 | to evaluate the infomration | |
| 139 | 141 | :param path: | |
| 140 | 142 | is the path to the file in the file system, relative to the git repository root, i.e. | |
@@ -149,7 +151,8 @@ def __init__(self, repo, binsha, mode=None, path=None): | |||
| 149 | 151 | self.path = path | |
| 150 | 152 | ||
| 151 | 153 | def __hash__(self): | |
| 152 | - """:return: | ||
| 154 | + """ | ||
| 155 | + :return: | ||
| 153 | 156 | Hash of our path as index items are uniquely identifyable by path, not | |
| 154 | 157 | by their data !""" | |
| 155 | 158 | return hash(self.path) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,21 +6,62 @@ | |||
| 6 | 6 | # the BSD License: http://www.opensource.org/licenses/bsd-license.php | |
| 7 | 7 | import os | |
| 8 | 8 | ||
| 9 | - import git | ||
| 10 | 9 | from git.test.lib import TestBase | |
| 11 | 10 | from gitdb.test.lib import with_rw_directory | |
| 12 | - from git.repo.fun import touch | ||
| 13 | 11 | ||
| 14 | 12 | ||
| 15 | - class TestGit(TestBase): | ||
| 13 | + class Tutorials(TestBase): | ||
| 14 | + | ||
| 15 | + @with_rw_directory | ||
| 16 | + def test_init_repo_object(self, rw_dir): | ||
| 17 | + from git import Repo | ||
| 18 | + join = os.path.join | ||
| 19 | + | ||
| 20 | + # rorepo is a a Repo instance pointing to the git-python repository. | ||
| 21 | + # For all you know, the first argument to Repo is a path to the repository | ||
| 22 | + # you want to work with | ||
| 23 | + repo = Repo(self.rorepo.working_tree_dir) | ||
| 24 | + assert repo.bare == False | ||
| 25 | + # ![1-test_init_repo_object] | ||
| 26 | + | ||
| 27 | + # [2-test_init_repo_object] | ||
| 28 | + bare_empty_repo = Repo.init(join(rw_dir, 'bare-repo'), bare=True) | ||
| 29 | + assert bare_empty_repo.bare == True | ||
| 30 | + # ![2-test_init_repo_object] | ||
| 31 | + | ||
| 32 | + # [3-test_init_repo_object] | ||
| 33 | + repo.config_reader() # get a config reader for read-only access | ||
| 34 | + cw = repo.config_writer() # get a config writer to change configuration | ||
| 35 | + cw.release() # call release() to be sure changes are written and locks are released | ||
| 36 | + # ![3-test_init_repo_object] | ||
| 37 | + | ||
| 38 | + # [4-test_init_repo_object] | ||
| 39 | + repo.is_dirty() | ||
| 40 | + # False | ||
| 41 | + repo.untracked_files | ||
| 42 | + # ['my_untracked_file'] | ||
| 43 | + # ![4-test_init_repo_object] | ||
| 44 | + | ||
| 45 | + # [5-test_init_repo_object] | ||
| 46 | + assert repo.clone(join(rw_dir, 'to/this/path')).__class__ is Repo | ||
| 47 | + assert Repo.init(join(rw_dir, 'path/for/new/repo')).__class__ is Repo | ||
| 48 | + # ![5-test_init_repo_object] | ||
| 49 | + | ||
| 50 | + # [6-test_init_repo_object] | ||
| 51 | + repo.archive(open(join(rw_dir, 'repo.tar'), 'w')) | ||
| 52 | + # ![6-test_init_repo_object] | ||
| 16 | 53 | ||
| 17 | 54 | @with_rw_directory | |
| 18 | 55 | def test_add_file_and_commit(self, rw_dir): | |
| 56 | + import git | ||
| 57 | + | ||
| 19 | 58 | repo_dir = os.path.join(rw_dir, 'my-new-repo') | |
| 20 | 59 | file_name = os.path.join(repo_dir, 'new-file') | |
| 21 | 60 | ||
| 22 | 61 | r = git.Repo.init(repo_dir) | |
| 23 | 62 | # This function just creates an empty file ... | |
| 24 | - touch(file_name) | ||
| 63 | + open(file_name, 'wb').close() | ||
| 25 | 64 | r.index.add([file_name]) | |
| 26 | 65 | r.index.commit("initial commit") | |
| 66 | + | ||
| 67 | + # ![test_add_file_and_commit] | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -783,7 +783,7 @@ def test_branch_renames(self, rw_dir): | |||
| 783 | 783 | # Setup initial sandbox: | |
| 784 | 784 | # parent repo has one submodule, which has all the latest changes | |
| 785 | 785 | source_url = self._submodule_url() | |
| 786 | - sm_source_repo = git.Repo.clone_from(source_url, os.path.join(rw_dir, 'sm-source')) | ||
| 786 | + sm_source_repo = git.Repo.clone_from(source_url, os.path.join(rw_dir, 'sm-source'), b='master') | ||
| 787 | 787 | parent_repo = git.Repo.init(os.path.join(rw_dir, 'parent')) | |
| 788 | 788 | sm = parent_repo.create_submodule('mysubmodule', 'subdir/submodule', | |
| 789 | 789 | sm_source_repo.working_tree_dir, branch='master') | |
| Back | FazBrowse Home | New Git URL |
0 commit comments