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

Commit6a9154b

Browse files
committed
Added git clone & git add
1 parent97cdb40 commit6a9154b

File tree

2 files changed

+61
-6
lines changed

2 files changed

+61
-6
lines changed

‎doc/source/quickstart.rst

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ There are a few ways to create a :class:`git.Repo <git.repo.base.Repo>` object
1616
An existing local path
1717
######################
1818

19+
$ git init path/to/dir
20+
1921
..literalinclude::../../test/test_quick_doc.py
2022
:language: python
2123
:dedent: 8
@@ -34,4 +36,27 @@ Existing local git Repo
3436
Clone from URL
3537
##############
3638

37-
For the rest of this tutorial we will use a clone from https://github.com
39+
For the rest of this tutorial we will use a clone from https://github.com/LeoDaCoda/GitPython-TestFileSys.git
40+
41+
git clone https://some_repo_url
42+
43+
..literalinclude::../../test/test_quick_doc.py
44+
:language: python
45+
:dedent: 8
46+
:start-after: # [1-test_cloned_repo_object]
47+
:end-before: # ![1-test_cloned_repo_object]
48+
49+
Usage
50+
****************
51+
52+
* git add filepath
53+
54+
55+
56+
57+
* git commit -m message
58+
* git log file
59+
* git status
60+
61+
62+

‎test/test_quick_doc.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
importpytest
22

3-
importgit
3+
44
fromtest.libimportTestBase
55
fromtest.lib.helperimportwith_rw_directory
66

@@ -18,16 +18,46 @@ def test_init_repo_object(self, rw_dir):
1818
# [1-test_init_repo_object]
1919
fromgitimportRepo
2020

21-
repo=Repo.init(path_to_dir)
22-
assertrepo.__class__isRepo# Test to confirm repo was initialized
21+
repo=Repo.init(path_to_dir)# git init path/to/dir
22+
assertrepo.__class__isRepo# Test to confirm repo was initialized
2323
# ![1-test_init_repo_object]
2424

2525
# [2-test_init_repo_object]
26+
importgit
27+
2628
try:
2729
repo=Repo(path_to_dir)
2830
exceptgit.NoSuchPathError:
2931
assertFalse,f"No such path{path_to_dir}"
30-
# ! [2-test_init_repo_object]
32+
# ![2-test_init_repo_object]
33+
34+
@with_rw_directory
35+
deftest_cloned_repo_object(self,rw_dir):
36+
local_dir=rw_dir
3137

32-
# [3 - test_init_repo_object]
38+
fromgitimportRepo
39+
importgit
40+
# code to clone from url
41+
# [1-test_cloned_repo_object]
42+
repo_url="https://github.com/LeoDaCoda/GitPython-TestFileSys.git"
43+
44+
try:
45+
repo=Repo.clone_from(repo_url,local_dir)
46+
exceptgit.CommandError:
47+
assertFalse,f"Invalid address{repo_url}"
48+
# ![1-test_cloned_repo_object]
49+
50+
# code to add files
51+
# [2-test_cloned_repo_object]
52+
# We must make a change to a file so that we can add the update to git
53+
54+
update_file='dir1/file2.txt'# we'll use /dir1/file2.txt
55+
withopen(f"{local_dir}/{update_file}",'a')asf:
56+
f.write('\nUpdate version 2')
57+
# ![2-test_cloned_repo_object]
58+
59+
# [3-test_cloned_repo_object]
60+
add_file= [f"{local_dir}/{update_file}"]
61+
repo.index.add(add_file)# notice the add function requires a list of paths
62+
# [3-test_cloned_repo_object]
3363

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp