Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite48e520

Browse files
committed
Initial set of documentation improvements, and a fix to the submodule tests.
Now travisci tests should work once again.Related togitpython-developers#239
1 parentc3c6c81 commite48e520

File tree

7 files changed

+96
-41
lines changed

7 files changed

+96
-41
lines changed

‎doc/source/changes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Changelog
77
* Added `Repo.merge_base()` implementation. See the `respective issue on github<https://github.com/gitpython-developers/GitPython/issues/169>`_
88
* `[include]` sections in git configuration files are now respected
99
* Added `GitConfigParser.rename_section()`
10+
* DOCS: special members like `__init__` are now listed in the API documentation
11+
* DOCS: tutorial section was revised entirely
1012
* Added `Submodule.rename()`
1113
* **POSSIBLY BREAKING CHANGE**: As `rev_parse` will now throw `BadName` as well as `BadObject`, client code will have to catch both exception types.
1214
* A list of all issues can be found here: https://github.com/gitpython-developers/GitPython/issues?q=milestone%3A%22v0.3.6+-+Features%22+

‎doc/source/reference.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ Objects.Base
88

99
..automodule::git.objects.base
1010
:members:
11-
:undoc-members:
11+
:undoc-members:
12+
:special-members:
1213

1314
Objects.Blob
1415
------------

‎doc/source/tutorial.rst

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,54 @@
88
GitPython Tutorial
99
==================
1010

11-
GitPython provides object model access to your git repository. This tutorial iscomposed 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.
1212

13-
Initialize a Repoobject
14-
************************
13+
Meet the Repotype
14+
******************
1515

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.
1717

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]
2122

22-
In the above example, the directory ``/Users/mtrier/Development/git-python`` is my working repositoryand 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``andis my working repositorywhich contains the ``.git`` directory. You can also initialize GitPython with a *bare* repository.
2324

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]
2629

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 therepository::
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.
2831

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]
3136

32-
Query the active branch, query untracked files or whether the repository datahas been modified::
37+
Query the active branch, query untracked files or whether the repository data has been modified.
3338

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]
3843

39-
Clone from existing repositories or initialize new empty ones::
44+
Clone from existing repositories or initialize new empty ones.
4045

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]
4350

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]
4557

46-
repo.archive(open("repo.tar",'w'))
58+
.. todo repo paths, heads, remotes, submodules
4759
4860
4961
Object Databases
@@ -418,16 +430,12 @@ The previous approach would brutally overwrite the user's changes in the working
418430
Initializing a repository
419431
*************************
420432

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.
425434

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]
431439

432440
Please have a look at the individual methods as they usually support a vast amount of arguments to customize their behavior.
433441

‎git/cmd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def wait(self):
295295
:raise GitCommandError: if the return status is not 0"""
296296
status=self.proc.wait()
297297
ifstatus!=0:
298-
raiseGitCommandError(self.args,status,self.proc.stderr.read().decode(defenc))
298+
raiseGitCommandError(self.args,status,self.proc.stderr.read())
299299
# END status handling
300300
returnstatus
301301
# END auto interrupt

‎git/objects/base.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,11 @@ class IndexObject(Object):
132132

133133
def__init__(self,repo,binsha,mode=None,path=None):
134134
"""Initialize a newly instanced IndexObject
135+
135136
:param repo: is the Repo we are located in
136137
: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
138140
to evaluate the infomration
139141
:param path:
140142
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):
149151
self.path=path
150152

151153
def__hash__(self):
152-
""":return:
154+
"""
155+
:return:
153156
Hash of our path as index items are uniquely identifyable by path, not
154157
by their data !"""
155158
returnhash(self.path)

‎git/test/test_docs.py

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,62 @@
66
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
77
importos
88

9-
importgit
109
fromgit.test.libimportTestBase
1110
fromgitdb.test.libimportwith_rw_directory
12-
fromgit.repo.funimporttouch
1311

1412

15-
classTestGit(TestBase):
13+
classTutorials(TestBase):
14+
15+
@with_rw_directory
16+
deftest_init_repo_object(self,rw_dir):
17+
fromgitimportRepo
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+
assertrepo.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+
assertbare_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+
assertrepo.clone(join(rw_dir,'to/this/path')).__class__isRepo
47+
assertRepo.init(join(rw_dir,'path/for/new/repo')).__class__isRepo
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]
1653

1754
@with_rw_directory
1855
deftest_add_file_and_commit(self,rw_dir):
56+
importgit
57+
1958
repo_dir=os.path.join(rw_dir,'my-new-repo')
2059
file_name=os.path.join(repo_dir,'new-file')
2160

2261
r=git.Repo.init(repo_dir)
2362
# This function just creates an empty file ...
24-
touch(file_name)
63+
open(file_name,'wb').close()
2564
r.index.add([file_name])
2665
r.index.commit("initial commit")
66+
67+
# ![test_add_file_and_commit]

‎git/test/test_submodule.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ def test_branch_renames(self, rw_dir):
783783
# Setup initial sandbox:
784784
# parent repo has one submodule, which has all the latest changes
785785
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')
787787
parent_repo=git.Repo.init(os.path.join(rw_dir,'parent'))
788788
sm=parent_repo.create_submodule('mysubmodule','subdir/submodule',
789789
sm_source_repo.working_tree_dir,branch='master')

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp