From 97cdb403fd11778916b006b22679f427a3c1a8ac Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Sat, 8 Jul 2023 15:22:33 -0400 Subject: [PATCH 01/36] Made the init repo section of quickdoc --- doc/source/quickstart.rst | 37 +++++++++++++++++++++++++++++++++++++ test/test_quick_doc.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 doc/source/quickstart.rst create mode 100644 test/test_quick_doc.py diff --git a/doc/source/quickstart.rst b/doc/source/quickstart.rst new file mode 100644 index 000000000..602ca423f --- /dev/null +++ b/doc/source/quickstart.rst @@ -0,0 +1,37 @@ +.. _quickdoc_toplevel: + +.. highlight:: python + +.. _quickdoc-label: + +============================== +GitPython Quick Start Tutorial +============================== + +git.Repo +******** + +There are a few ways to create a :class:`git.Repo ` object + +An existing local path +###################### + +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [1-test_init_repo_object] + :end-before: # ![1-test_init_repo_object] + +Existing local git Repo +####################### + +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [2-test_init_repo_object] + :end-before: # ![2-test_init_repo_object] + +Clone from URL +############## + +For the rest of this tutorial we will use a clone from https://github.com \ No newline at end of file diff --git a/test/test_quick_doc.py b/test/test_quick_doc.py new file mode 100644 index 000000000..a6dfb8e53 --- /dev/null +++ b/test/test_quick_doc.py @@ -0,0 +1,33 @@ +import pytest + +import git +from test.lib import TestBase +from test.lib.helper import with_rw_directory + + +class QuickDoc(TestBase): + def tearDown(self): + import gc + + gc.collect() + + @with_rw_directory + def test_init_repo_object(self, rw_dir): + path_to_dir = rw_dir + + # [1-test_init_repo_object] + from git import Repo + + repo = Repo.init(path_to_dir) + assert repo.__class__ is Repo # Test to confirm repo was initialized + # ![1-test_init_repo_object] + + # [2-test_init_repo_object] + try: + repo = Repo(path_to_dir) + except git.NoSuchPathError: + assert False, f"No such path {path_to_dir}" + # ! [2-test_init_repo_object] + + # [3 - test_init_repo_object] + From 6a9154b1bfcebe7ee28edebec6617993ad6a5569 Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Sat, 8 Jul 2023 20:52:04 -0400 Subject: [PATCH 02/36] Added git clone & git add --- doc/source/quickstart.rst | 27 +++++++++++++++++++++++++- test/test_quick_doc.py | 40 ++++++++++++++++++++++++++++++++++----- 2 files changed, 61 insertions(+), 6 deletions(-) diff --git a/doc/source/quickstart.rst b/doc/source/quickstart.rst index 602ca423f..ebdb2520a 100644 --- a/doc/source/quickstart.rst +++ b/doc/source/quickstart.rst @@ -16,6 +16,8 @@ There are a few ways to create a :class:`git.Repo ` object An existing local path ###################### +$ git init path/to/dir + .. literalinclude:: ../../test/test_quick_doc.py :language: python :dedent: 8 @@ -34,4 +36,27 @@ Existing local git Repo Clone from URL ############## -For the rest of this tutorial we will use a clone from https://github.com \ No newline at end of file +For the rest of this tutorial we will use a clone from https://github.com/LeoDaCoda/GitPython-TestFileSys.git + +git clone https://some_repo_url + +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [1-test_cloned_repo_object] + :end-before: # ![1-test_cloned_repo_object] + +Usage +**************** + +* git add filepath + + + + +* git commit -m message +* git log file +* git status + + + diff --git a/test/test_quick_doc.py b/test/test_quick_doc.py index a6dfb8e53..0188367cf 100644 --- a/test/test_quick_doc.py +++ b/test/test_quick_doc.py @@ -1,6 +1,6 @@ import pytest -import git + from test.lib import TestBase from test.lib.helper import with_rw_directory @@ -18,16 +18,46 @@ def test_init_repo_object(self, rw_dir): # [1-test_init_repo_object] from git import Repo - repo = Repo.init(path_to_dir) - assert repo.__class__ is Repo # Test to confirm repo was initialized + repo = Repo.init(path_to_dir) # git init path/to/dir + assert repo.__class__ is Repo # Test to confirm repo was initialized # ![1-test_init_repo_object] # [2-test_init_repo_object] + import git + try: repo = Repo(path_to_dir) except git.NoSuchPathError: assert False, f"No such path {path_to_dir}" - # ! [2-test_init_repo_object] + # ![2-test_init_repo_object] + + @with_rw_directory + def test_cloned_repo_object(self, rw_dir): + local_dir = rw_dir - # [3 - test_init_repo_object] + from git import Repo + import git + # code to clone from url + # [1-test_cloned_repo_object] + repo_url = "https://github.com/LeoDaCoda/GitPython-TestFileSys.git" + + try: + repo = Repo.clone_from(repo_url, local_dir) + except git.CommandError: + assert False, f"Invalid address {repo_url}" + # ![1-test_cloned_repo_object] + + # code to add files + # [2-test_cloned_repo_object] + # We must make a change to a file so that we can add the update to git + + update_file = 'dir1/file2.txt' # we'll use /dir1/file2.txt + with open(f"{local_dir}/{update_file}", 'a') as f: + f.write('\nUpdate version 2') + # ![2-test_cloned_repo_object] + + # [3-test_cloned_repo_object] + add_file = [f"{local_dir}/{update_file}"] + repo.index.add(add_file) # notice the add function requires a list of paths + # [3-test_cloned_repo_object] From 3c42baebf5bd7c509b9962d1490f59e8874f1323 Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Sun, 9 Jul 2023 05:34:09 -0400 Subject: [PATCH 03/36] Finishing touches for Repo quickstart --- doc/source/quickstart.rst | 85 +++++++++++++++++++++++++++++++++++++-- test/test_quick_doc.py | 71 ++++++++++++++++++++++++++++++-- 2 files changed, 149 insertions(+), 7 deletions(-) diff --git a/doc/source/quickstart.rst b/doc/source/quickstart.rst index ebdb2520a..0a728e485 100644 --- a/doc/source/quickstart.rst +++ b/doc/source/quickstart.rst @@ -49,14 +49,91 @@ git clone https://some_repo_url Usage **************** -* git add filepath +* $ git add filepath +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [2-test_cloned_repo_object] + :end-before: # ![2-test_cloned_repo_object] + +Now lets add the updated file to git + +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [3-test_cloned_repo_object] + :end-before: # ![3-test_cloned_repo_object] + +Notice the add method requires a list as a parameter + +* $ git commit -m message + +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [4-test_cloned_repo_object] + :end-before: # ![4-test_cloned_repo_object] + +* $ git log file + +A list of commits associated with a file + +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [5-test_cloned_repo_object] + :end-before: # ![5-test_cloned_repo_object] + +Notice this returns a generator object + +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [6-test_cloned_repo_object] + :end-before: # ![6-test_cloned_repo_object] + +returns list of :class:`Commit ` objects + +* $ git status + + * Untracked files + + Lets create a new file + + .. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [7-test_cloned_repo_object] + :end-before: # ![7-test_cloned_repo_object] + + .. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [8-test_cloned_repo_object] + :end-before: # ![8-test_cloned_repo_object] + + * Modified files + + .. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [9-test_cloned_repo_object] + :end-before: # ![9-test_cloned_repo_object] + .. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [10-test_cloned_repo_object] + :end-before: # ![10-test_cloned_repo_object] + returns a list of :class:`Diff ` objects -* git commit -m message -* git log file -* git status + .. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [11-test_cloned_repo_object] + :end-before: # ![11-test_cloned_repo_object] diff --git a/test/test_quick_doc.py b/test/test_quick_doc.py index 0188367cf..bb3372905 100644 --- a/test/test_quick_doc.py +++ b/test/test_quick_doc.py @@ -51,13 +51,78 @@ def test_cloned_repo_object(self, rw_dir): # [2-test_cloned_repo_object] # We must make a change to a file so that we can add the update to git - update_file = 'dir1/file2.txt' # we'll use /dir1/file2.txt + update_file = 'dir1/file2.txt' # we'll use ./dir1/file2.txt with open(f"{local_dir}/{update_file}", 'a') as f: f.write('\nUpdate version 2') # ![2-test_cloned_repo_object] # [3-test_cloned_repo_object] - add_file = [f"{local_dir}/{update_file}"] + add_file = [f"{update_file}"] # relative path from git root repo.index.add(add_file) # notice the add function requires a list of paths - # [3-test_cloned_repo_object] + # ![3-test_cloned_repo_object] + + # code to commit - not sure how to test this + # [4-test_cloned_repo_object] + repo.index.commit("Update to file2") + # ![4-test_cloned_repo_object] + + # [5-test_cloned_repo_object] + file = 'dir1/file2.txt' # relative path from git root + repo.iter_commits('--all', max_count=100, paths=file) + + # Outputs: + + # ![5-test_cloned_repo_object] + + # [6-test_cloned_repo_object] + commits_for_file_generator = repo.iter_commits('--all', max_count=100, paths=file) + commits_for_file = [c for c in commits_for_file_generator] + commits_for_file + + # Outputs: [, + # ] + # ![6-test_cloned_repo_object] + + # Untracked files - create new file + # [7-test_cloned_repo_object] + # We'll create a file5.txt + + file5 = f'{local_dir}/file5.txt' + with open(file5, 'w') as f: + f.write('file5 version 1') + # ![7-test_cloned_repo_object] + + # [8-test_cloned_repo_object] + repo.untracked_files + # Output: ['file5.txt'] + # ![8-test_cloned_repo_object] + + # Modified files + # [9-test_cloned_repo_object] + # Lets modify one of our tracked files + file3 = f'{local_dir}/Downloads/file3.txt' + with open(file3, 'w') as f: + f.write('file3 version 2') # overwrite file 3 + # ![9-test_cloned_repo_object] + + # [10-test_cloned_repo_object] + repo.index.diff(None) + # Output: [, + # ] + # ![10-test_cloned_repo_object] + + # [11-test_cloned_repo_object] + diffs = repo.index.diff(None) + for d in diffs: + print(d.a_path) + + # Downloads/file3.txt + # file4.txt + # ![11-test_cloned_repo_object] + + + + + + From 10ea113ca6141b8a74e78858e6ff6f52bfd04d9f Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Sun, 9 Jul 2023 21:29:26 -0400 Subject: [PATCH 04/36] finished code for quickstart --- doc/source/quickstart.rst | 70 +++++++++++++++++++++++++++++++++++++++ test/test_quick_doc.py | 46 +++++++++++++++++++++++++ 2 files changed, 116 insertions(+) diff --git a/doc/source/quickstart.rst b/doc/source/quickstart.rst index 0a728e485..9d63c5674 100644 --- a/doc/source/quickstart.rst +++ b/doc/source/quickstart.rst @@ -136,4 +136,74 @@ returns list of :class:`Commit ` objects :end-before: # ![11-test_cloned_repo_object] +Trees & Blobs +************** +Latest Commit Tree +################## + +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [12-test_cloned_repo_object] + :end-before: # ![12-test_cloned_repo_object] + +Any Commit Tree +############### + +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [13-test_cloned_repo_object] + :end-before: # ![13-test_cloned_repo_object] + +Display level 1 Contents +######################## + +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [14-test_cloned_repo_object] + :end-before: # ![14-test_cloned_repo_object] + +Recurse through the Tree +######################## + +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [15-test_cloned_repo_object] + :end-before: # ![15-test_cloned_repo_object] + +.. code-block:: python + + print_files_from_git(tree) + +.. code-block:: python + + # Output + | Downloads, tree + ----| Downloads/file3.txt, blob + | dir1, tree + ----| dir1/file1.txt, blob + ----| dir1/file2.txt, blob + | file4.txt, blob + + +Print file version +################## + +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [16-test_cloned_repo_object] + :end-before: # ![16-test_cloned_repo_object] + +.. code-block:: python + + blob = tree[print_file] + print(blob.data_stream.read().decode()) + + # Output + # file 2 version 1 + # Update version 2 diff --git a/test/test_quick_doc.py b/test/test_quick_doc.py index bb3372905..2a95bfff5 100644 --- a/test/test_quick_doc.py +++ b/test/test_quick_doc.py @@ -120,7 +120,53 @@ def test_cloned_repo_object(self, rw_dir): # file4.txt # ![11-test_cloned_repo_object] + '''Trees and Blobs''' + # Latest commit tree + # [12-test_cloned_repo_object] + tree = repo.tree() + # ![12-test_cloned_repo_object] + + # Previous commit tree + # [13-test_cloned_repo_object] + prev_commits = [c for c in repo.iter_commits('--all', max_count=10)] + tree = prev_commits[0].tree + # ![13-test_cloned_repo_object] + + # Iterating through tree + # [14-test_cloned_repo_object] + tree = repo.tree() + files_dirs = [fd for fd in tree] + files_dirs + + # Output + # [, + # , + # ] + + # ![14-test_cloned_repo_object] + + # [15-test_cloned_repo_object] + def print_files_from_git(tree, delim='-', i=0): + files_dirs = [fd for fd in tree] + for fd in files_dirs: + print(f'{delim if i != 0 else ""}| {fd.path}, {fd.type}') + if fd.type == "tree": + print_files_from_git(fd, delim * 4, i + 1) + + # ![15-test_cloned_repo_object] + + # Printing text files + # [16-test_cloned_repo_object] + print_file = 'dir1/file2.txt' + tree[print_file] + + # Output + # ![16-test_cloned_repo_object] + + # [17-test_cloned_repo_object] + + # ![17-test_cloned_repo_object] From b0da0a9e53a30dfcefaa7d77fe0bd0104b3a814e Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Sun, 9 Jul 2023 21:29:26 -0400 Subject: [PATCH 05/36] finished code for quickstart --- doc/source/quickstart.rst | 70 +++++++++++++++++++++++++++++++++++++++ test/test_quick_doc.py | 46 +++++++++++++++++++++++++ 2 files changed, 116 insertions(+) diff --git a/doc/source/quickstart.rst b/doc/source/quickstart.rst index 0a728e485..9d63c5674 100644 --- a/doc/source/quickstart.rst +++ b/doc/source/quickstart.rst @@ -136,4 +136,74 @@ returns list of :class:`Commit ` objects :end-before: # ![11-test_cloned_repo_object] +Trees & Blobs +************** +Latest Commit Tree +################## + +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [12-test_cloned_repo_object] + :end-before: # ![12-test_cloned_repo_object] + +Any Commit Tree +############### + +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [13-test_cloned_repo_object] + :end-before: # ![13-test_cloned_repo_object] + +Display level 1 Contents +######################## + +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [14-test_cloned_repo_object] + :end-before: # ![14-test_cloned_repo_object] + +Recurse through the Tree +######################## + +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [15-test_cloned_repo_object] + :end-before: # ![15-test_cloned_repo_object] + +.. code-block:: python + + print_files_from_git(tree) + +.. code-block:: python + + # Output + | Downloads, tree + ----| Downloads/file3.txt, blob + | dir1, tree + ----| dir1/file1.txt, blob + ----| dir1/file2.txt, blob + | file4.txt, blob + + +Print file version +################## + +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [16-test_cloned_repo_object] + :end-before: # ![16-test_cloned_repo_object] + +.. code-block:: python + + blob = tree[print_file] + print(blob.data_stream.read().decode()) + + # Output + # file 2 version 1 + # Update version 2 diff --git a/test/test_quick_doc.py b/test/test_quick_doc.py index bb3372905..2a95bfff5 100644 --- a/test/test_quick_doc.py +++ b/test/test_quick_doc.py @@ -120,7 +120,53 @@ def test_cloned_repo_object(self, rw_dir): # file4.txt # ![11-test_cloned_repo_object] + '''Trees and Blobs''' + # Latest commit tree + # [12-test_cloned_repo_object] + tree = repo.tree() + # ![12-test_cloned_repo_object] + + # Previous commit tree + # [13-test_cloned_repo_object] + prev_commits = [c for c in repo.iter_commits('--all', max_count=10)] + tree = prev_commits[0].tree + # ![13-test_cloned_repo_object] + + # Iterating through tree + # [14-test_cloned_repo_object] + tree = repo.tree() + files_dirs = [fd for fd in tree] + files_dirs + + # Output + # [, + # , + # ] + + # ![14-test_cloned_repo_object] + + # [15-test_cloned_repo_object] + def print_files_from_git(tree, delim='-', i=0): + files_dirs = [fd for fd in tree] + for fd in files_dirs: + print(f'{delim if i != 0 else ""}| {fd.path}, {fd.type}') + if fd.type == "tree": + print_files_from_git(fd, delim * 4, i + 1) + + # ![15-test_cloned_repo_object] + + # Printing text files + # [16-test_cloned_repo_object] + print_file = 'dir1/file2.txt' + tree[print_file] + + # Output + # ![16-test_cloned_repo_object] + + # [17-test_cloned_repo_object] + + # ![17-test_cloned_repo_object] From fb35ed1d611113637c52a559d6f77aaadb6d403d Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Sun, 9 Jul 2023 21:36:28 -0400 Subject: [PATCH 06/36] fixed some indentation --- doc/source/quickstart.rst | 60 +++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/doc/source/quickstart.rst b/doc/source/quickstart.rst index 9d63c5674..1c0832ed5 100644 --- a/doc/source/quickstart.rst +++ b/doc/source/quickstart.rst @@ -99,41 +99,41 @@ returns list of :class:`Commit ` objects * Untracked files - Lets create a new file + Lets create a new file - .. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [7-test_cloned_repo_object] - :end-before: # ![7-test_cloned_repo_object] + .. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [7-test_cloned_repo_object] + :end-before: # ![7-test_cloned_repo_object] - .. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [8-test_cloned_repo_object] - :end-before: # ![8-test_cloned_repo_object] + .. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [8-test_cloned_repo_object] + :end-before: # ![8-test_cloned_repo_object] * Modified files - .. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [9-test_cloned_repo_object] - :end-before: # ![9-test_cloned_repo_object] - - .. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [10-test_cloned_repo_object] - :end-before: # ![10-test_cloned_repo_object] - - returns a list of :class:`Diff ` objects - - .. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [11-test_cloned_repo_object] - :end-before: # ![11-test_cloned_repo_object] + .. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [9-test_cloned_repo_object] + :end-before: # ![9-test_cloned_repo_object] + + .. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [10-test_cloned_repo_object] + :end-before: # ![10-test_cloned_repo_object] + + returns a list of :class:`Diff ` objects + + .. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [11-test_cloned_repo_object] + :end-before: # ![11-test_cloned_repo_object] Trees & Blobs From 47c83629cfa0550fae71f2c266bd8b236b63fdc6 Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Sun, 9 Jul 2023 22:17:03 -0400 Subject: [PATCH 07/36] added quickstart to toctree and fixed sphinx warning --- doc/source/index.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/index.rst b/doc/source/index.rst index 69fb573a4..72db8ee5a 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -9,6 +9,7 @@ GitPython Documentation :maxdepth: 2 intro + quickstart tutorial reference roadmap From b7955ed1f1511dd7d873e4198b3372c104102b4f Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Sun, 9 Jul 2023 22:17:03 -0400 Subject: [PATCH 08/36] added quickstart to toctree to fix sphinx warning --- doc/source/index.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/index.rst b/doc/source/index.rst index 69fb573a4..72db8ee5a 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -9,6 +9,7 @@ GitPython Documentation :maxdepth: 2 intro + quickstart tutorial reference roadmap From 03d26f0c92055759e296a36f2bde1ff9fb439b29 Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Mon, 10 Jul 2023 13:51:40 -0400 Subject: [PATCH 09/36] Removed code from RST --- doc/source/quickstart.rst | 34 ++++++++++++++-------------------- test/test_quick_doc.py | 25 ++++++++++++++++++++----- 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/doc/source/quickstart.rst b/doc/source/quickstart.rst index 1c0832ed5..5845bf9e2 100644 --- a/doc/source/quickstart.rst +++ b/doc/source/quickstart.rst @@ -175,35 +175,29 @@ Recurse through the Tree :start-after: # [15-test_cloned_repo_object] :end-before: # ![15-test_cloned_repo_object] -.. code-block:: python +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [16-test_cloned_repo_object] + :end-before: # ![16-test_cloned_repo_object] - print_files_from_git(tree) -.. code-block:: python - # Output - | Downloads, tree - ----| Downloads/file3.txt, blob - | dir1, tree - ----| dir1/file1.txt, blob - ----| dir1/file2.txt, blob - | file4.txt, blob +Printing text files +#################### -Print file version -################## +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [17-test_cloned_repo_object] + :end-before: # ![17-test_cloned_repo_object] .. literalinclude:: ../../test/test_quick_doc.py :language: python :dedent: 8 - :start-after: # [16-test_cloned_repo_object] - :end-before: # ![16-test_cloned_repo_object] + :start-after: # [18-test_cloned_repo_object] + :end-before: # ![18-test_cloned_repo_object] -.. code-block:: python - blob = tree[print_file] - print(blob.data_stream.read().decode()) - # Output - # file 2 version 1 - # Update version 2 diff --git a/test/test_quick_doc.py b/test/test_quick_doc.py index 2a95bfff5..f1d644382 100644 --- a/test/test_quick_doc.py +++ b/test/test_quick_doc.py @@ -156,19 +156,34 @@ def print_files_from_git(tree, delim='-', i=0): # ![15-test_cloned_repo_object] - # Printing text files # [16-test_cloned_repo_object] - print_file = 'dir1/file2.txt' - tree[print_file] + print_files_from_git(tree) - # Output - # ![16-test_cloned_repo_object] + # Output + # | Downloads, tree + # ---- | Downloads / file3.txt, blob + # | dir1, tree + # ---- | dir1 / file1.txt, blob + # ---- | dir1 / file2.txt, blob + # | file4.txt, blob + # # ![16-test_cloned_repo_object] + # Printing text files # [17-test_cloned_repo_object] + print_file = 'dir1/file2.txt' + tree[print_file] + # Output # ![17-test_cloned_repo_object] + # [18-test_cloned_repo_object] + blob = tree[print_file] + print(blob.data_stream.read().decode()) + # Output + # file 2 version 1 + # Update version 2 + # ![18-test_cloned_repo_object] From a0045d8844b937e703156adfbeb496ebc70c8950 Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Mon, 10 Jul 2023 15:00:06 -0400 Subject: [PATCH 10/36] Made variable names more intuitive --- test/test_quick_doc.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/test/test_quick_doc.py b/test/test_quick_doc.py index f1d644382..49d9a0f36 100644 --- a/test/test_quick_doc.py +++ b/test/test_quick_doc.py @@ -136,8 +136,8 @@ def test_cloned_repo_object(self, rw_dir): # Iterating through tree # [14-test_cloned_repo_object] tree = repo.tree() - files_dirs = [fd for fd in tree] - files_dirs + files_and_dirs = [entry for entry in tree] + files_and_dirs # Output # [, @@ -147,12 +147,11 @@ def test_cloned_repo_object(self, rw_dir): # ![14-test_cloned_repo_object] # [15-test_cloned_repo_object] - def print_files_from_git(tree, delim='-', i=0): - files_dirs = [fd for fd in tree] - for fd in files_dirs: - print(f'{delim if i != 0 else ""}| {fd.path}, {fd.type}') - if fd.type == "tree": - print_files_from_git(fd, delim * 4, i + 1) + def print_files_from_git(root, delim='-', i=0): + for entry in root: + print(f'{delim if i != 0 else ""}| {entry.path}, {entry.type}') + if entry.type == "tree": + print_files_from_git(entry, delim * 4, i + 1) # ![15-test_cloned_repo_object] From 98336551260f0b3093f5be085573b193198a4271 Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Mon, 10 Jul 2023 15:19:00 -0400 Subject: [PATCH 11/36] Updated the sample repo URL --- test/test_quick_doc.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/test/test_quick_doc.py b/test/test_quick_doc.py index 49d9a0f36..e76bf3a12 100644 --- a/test/test_quick_doc.py +++ b/test/test_quick_doc.py @@ -12,8 +12,7 @@ def tearDown(self): gc.collect() @with_rw_directory - def test_init_repo_object(self, rw_dir): - path_to_dir = rw_dir + def test_init_repo_object(self, path_to_dir): # [1-test_init_repo_object] from git import Repo @@ -32,19 +31,15 @@ def test_init_repo_object(self, rw_dir): # ![2-test_init_repo_object] @with_rw_directory - def test_cloned_repo_object(self, rw_dir): - local_dir = rw_dir + def test_cloned_repo_object(self, local_dir): from git import Repo import git # code to clone from url # [1-test_cloned_repo_object] - repo_url = "https://github.com/LeoDaCoda/GitPython-TestFileSys.git" + repo_url = "https://github.com/gitpython-developers/QuickStartTutorialFiles.git" - try: - repo = Repo.clone_from(repo_url, local_dir) - except git.CommandError: - assert False, f"Invalid address {repo_url}" + repo = Repo.clone_from(repo_url, local_dir) # ![1-test_cloned_repo_object] # code to add files From 3cda530b1fc1e5ae3c2403a43a7270f6a73f07fb Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Mon, 10 Jul 2023 15:24:05 -0400 Subject: [PATCH 12/36] removed try/except and updated sample url --- doc/source/quickstart.rst | 2 +- test/test_quick_doc.py | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/doc/source/quickstart.rst b/doc/source/quickstart.rst index 5845bf9e2..5c1c18701 100644 --- a/doc/source/quickstart.rst +++ b/doc/source/quickstart.rst @@ -38,7 +38,7 @@ Clone from URL For the rest of this tutorial we will use a clone from https://github.com/LeoDaCoda/GitPython-TestFileSys.git -git clone https://some_repo_url +$ git clone https://github.com/gitpython-developers/QuickStartTutorialFiles.git .. literalinclude:: ../../test/test_quick_doc.py :language: python diff --git a/test/test_quick_doc.py b/test/test_quick_doc.py index e76bf3a12..64586f186 100644 --- a/test/test_quick_doc.py +++ b/test/test_quick_doc.py @@ -18,16 +18,10 @@ def test_init_repo_object(self, path_to_dir): from git import Repo repo = Repo.init(path_to_dir) # git init path/to/dir - assert repo.__class__ is Repo # Test to confirm repo was initialized - # ![1-test_init_repo_object] + # ![1-test_init_repo_object] # [2-test_init_repo_object] - import git - - try: - repo = Repo(path_to_dir) - except git.NoSuchPathError: - assert False, f"No such path {path_to_dir}" + repo = Repo(path_to_dir) # ![2-test_init_repo_object] @with_rw_directory From e4bbc7a520d83b7e5db208d0fe901cec0125c2f9 Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Mon, 10 Jul 2023 17:13:44 -0400 Subject: [PATCH 13/36] correct way to get the latest commit tree --- test/test_quick_doc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_quick_doc.py b/test/test_quick_doc.py index 64586f186..f8c973bad 100644 --- a/test/test_quick_doc.py +++ b/test/test_quick_doc.py @@ -113,7 +113,7 @@ def test_cloned_repo_object(self, local_dir): # Latest commit tree # [12-test_cloned_repo_object] - tree = repo.tree() + tree = repo.head.commit.tree # ![12-test_cloned_repo_object] # Previous commit tree From a1dfd4ade535242bb535cbda9b2f02153d2a423e Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Mon, 10 Jul 2023 23:56:06 -0400 Subject: [PATCH 14/36] convert from --all flag to all=True --- test/test_quick_doc.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/test_quick_doc.py b/test/test_quick_doc.py index f8c973bad..701d3994a 100644 --- a/test/test_quick_doc.py +++ b/test/test_quick_doc.py @@ -57,14 +57,14 @@ def test_cloned_repo_object(self, local_dir): # [5-test_cloned_repo_object] file = 'dir1/file2.txt' # relative path from git root - repo.iter_commits('--all', max_count=100, paths=file) + repo.iter_commits(all=True, max_count=10, paths=file) # gets the last 10 commits from all branches # Outputs: # ![5-test_cloned_repo_object] # [6-test_cloned_repo_object] - commits_for_file_generator = repo.iter_commits('--all', max_count=100, paths=file) + commits_for_file_generator = repo.iter_commits(all=True, max_count=10, paths=file) commits_for_file = [c for c in commits_for_file_generator] commits_for_file @@ -95,7 +95,8 @@ def test_cloned_repo_object(self, local_dir): # ![9-test_cloned_repo_object] # [10-test_cloned_repo_object] - repo.index.diff(None) + repo.index.diff(None) # compares staging area to working directory + repo.index.diff(repo.head.commit) # compares staging area to last commit # Output: [, # ] # ![10-test_cloned_repo_object] @@ -118,7 +119,7 @@ def test_cloned_repo_object(self, local_dir): # Previous commit tree # [13-test_cloned_repo_object] - prev_commits = [c for c in repo.iter_commits('--all', max_count=10)] + prev_commits = [c for c in repo.iter_commits(all=True, max_count=10)] # last 10 commits from all branches tree = prev_commits[0].tree # ![13-test_cloned_repo_object] From a8b58639f57f5a4952f98ee097def5ad9543b566 Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Tue, 11 Jul 2023 00:02:20 -0400 Subject: [PATCH 15/36] removed unnecessary variables --- test/test_quick_doc.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/test/test_quick_doc.py b/test/test_quick_doc.py index 701d3994a..9756f0da5 100644 --- a/test/test_quick_doc.py +++ b/test/test_quick_doc.py @@ -46,7 +46,7 @@ def test_cloned_repo_object(self, local_dir): # ![2-test_cloned_repo_object] # [3-test_cloned_repo_object] - add_file = [f"{update_file}"] # relative path from git root + add_file = [update_file] # relative path from git root repo.index.add(add_file) # notice the add function requires a list of paths # ![3-test_cloned_repo_object] @@ -56,15 +56,15 @@ def test_cloned_repo_object(self, local_dir): # ![4-test_cloned_repo_object] # [5-test_cloned_repo_object] - file = 'dir1/file2.txt' # relative path from git root - repo.iter_commits(all=True, max_count=10, paths=file) # gets the last 10 commits from all branches + # relative path from git root + repo.iter_commits(all=True, max_count=10, paths=update_file) # gets the last 10 commits from all branches # Outputs: # ![5-test_cloned_repo_object] # [6-test_cloned_repo_object] - commits_for_file_generator = repo.iter_commits(all=True, max_count=10, paths=file) + commits_for_file_generator = repo.iter_commits(all=True, max_count=10, paths=update_file) commits_for_file = [c for c in commits_for_file_generator] commits_for_file @@ -76,8 +76,7 @@ def test_cloned_repo_object(self, local_dir): # [7-test_cloned_repo_object] # We'll create a file5.txt - file5 = f'{local_dir}/file5.txt' - with open(file5, 'w') as f: + with open(f'{local_dir}/file5.txt', 'w') as f: f.write('file5 version 1') # ![7-test_cloned_repo_object] @@ -89,8 +88,8 @@ def test_cloned_repo_object(self, local_dir): # Modified files # [9-test_cloned_repo_object] # Lets modify one of our tracked files - file3 = f'{local_dir}/Downloads/file3.txt' - with open(file3, 'w') as f: + + with open(f'{local_dir}/Downloads/file3.txt', 'w') as f: f.write('file3 version 2') # overwrite file 3 # ![9-test_cloned_repo_object] From abe7e6e5075ba4b9ea4cfc74b6121ad977dc7e4f Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Tue, 11 Jul 2023 00:23:18 -0400 Subject: [PATCH 16/36] replaced output cell to generic commit ID --- test/test_quick_doc.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test/test_quick_doc.py b/test/test_quick_doc.py index 9756f0da5..0f09d4ed9 100644 --- a/test/test_quick_doc.py +++ b/test/test_quick_doc.py @@ -68,8 +68,8 @@ def test_cloned_repo_object(self, local_dir): commits_for_file = [c for c in commits_for_file_generator] commits_for_file - # Outputs: [, - # ] + # Outputs: [, + # ] # ![6-test_cloned_repo_object] # Untracked files - create new file @@ -124,14 +124,13 @@ def test_cloned_repo_object(self, local_dir): # Iterating through tree # [14-test_cloned_repo_object] - tree = repo.tree() files_and_dirs = [entry for entry in tree] files_and_dirs # Output - # [, - # , - # ] + # [, + # , + # ] # ![14-test_cloned_repo_object] From 1369bdc6d7d06e473b7c211a4070dcee94438e64 Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Thu, 13 Jul 2023 01:35:41 -0400 Subject: [PATCH 17/36] replaced hash with generic --- test/test_quick_doc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_quick_doc.py b/test/test_quick_doc.py index 0f09d4ed9..d1aea44e7 100644 --- a/test/test_quick_doc.py +++ b/test/test_quick_doc.py @@ -160,7 +160,7 @@ def print_files_from_git(root, delim='-', i=0): print_file = 'dir1/file2.txt' tree[print_file] - # Output + # Output # ![17-test_cloned_repo_object] # [18-test_cloned_repo_object] From 9cd9431906acff137e441a2dd82d1d6d4e6322d7 Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Thu, 13 Jul 2023 01:36:17 -0400 Subject: [PATCH 18/36] draft of description --- doc/source/quickstart.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/source/quickstart.rst b/doc/source/quickstart.rst index 5c1c18701..018e13a76 100644 --- a/doc/source/quickstart.rst +++ b/doc/source/quickstart.rst @@ -7,6 +7,9 @@ ============================== GitPython Quick Start Tutorial ============================== +Welcome to the GitPython Quickstart Guide! Designed for developers seeking a practical and interactive learning experience, this concise resource offers step-by-step code snippets to swiftly initialize/clone repositories, perform essential Git operations, and explore GitPython's capabilities. Get ready to dive in, experiment, and unleash the power of GitPython in your projects! + +All code presented here originated from `***** insert link **** `_ to assure correctness. Knowing this should also allow you to more easily run the code for your own testing purposes. All you need is a developer installation of git-python. git.Repo ******** From 393bae5184abda11cdaab128049fccba2fcb213f Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Thu, 13 Jul 2023 01:42:24 -0400 Subject: [PATCH 19/36] clarified comment --- doc/source/quickstart.rst | 2 +- test/test_quick_doc.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/quickstart.rst b/doc/source/quickstart.rst index 018e13a76..bd5ddd7b8 100644 --- a/doc/source/quickstart.rst +++ b/doc/source/quickstart.rst @@ -39,7 +39,7 @@ Existing local git Repo Clone from URL ############## -For the rest of this tutorial we will use a clone from https://github.com/LeoDaCoda/GitPython-TestFileSys.git +For the rest of this tutorial we will use a clone from https://github.com/gitpython-developers/QuickStartTutorialFiles.git $ git clone https://github.com/gitpython-developers/QuickStartTutorialFiles.git diff --git a/test/test_quick_doc.py b/test/test_quick_doc.py index d1aea44e7..3dc29a22c 100644 --- a/test/test_quick_doc.py +++ b/test/test_quick_doc.py @@ -40,7 +40,7 @@ def test_cloned_repo_object(self, local_dir): # [2-test_cloned_repo_object] # We must make a change to a file so that we can add the update to git - update_file = 'dir1/file2.txt' # we'll use ./dir1/file2.txt + update_file = 'dir1/file2.txt' # we'll use local_dir/dir1/file2.txt with open(f"{local_dir}/{update_file}", 'a') as f: f.write('\nUpdate version 2') # ![2-test_cloned_repo_object] From aa6d27f9204d68b21cd24366c8a58fb4f9578553 Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Thu, 13 Jul 2023 16:15:16 -0400 Subject: [PATCH 20/36] refactored print git tree --- test/test_quick_doc.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/test_quick_doc.py b/test/test_quick_doc.py index 3dc29a22c..0aa27a361 100644 --- a/test/test_quick_doc.py +++ b/test/test_quick_doc.py @@ -135,11 +135,11 @@ def test_cloned_repo_object(self, local_dir): # ![14-test_cloned_repo_object] # [15-test_cloned_repo_object] - def print_files_from_git(root, delim='-', i=0): + def print_files_from_git(root, level=0): for entry in root: - print(f'{delim if i != 0 else ""}| {entry.path}, {entry.type}') + print(f'{"-" * 4 * level}| {entry.path}, {entry.type}') if entry.type == "tree": - print_files_from_git(entry, delim * 4, i + 1) + print_files_from_git(entry, level + 1) # ![15-test_cloned_repo_object] @@ -148,10 +148,10 @@ def print_files_from_git(root, delim='-', i=0): # Output # | Downloads, tree - # ---- | Downloads / file3.txt, blob + # ----| Downloads / file3.txt, blob # | dir1, tree - # ---- | dir1 / file1.txt, blob - # ---- | dir1 / file2.txt, blob + # ----| dir1 / file1.txt, blob + # ----| dir1 / file2.txt, blob # | file4.txt, blob # # ![16-test_cloned_repo_object] From 6d78ff1ac33fa2adeb0518feb33a634c09b0b5b5 Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Sun, 16 Jul 2023 11:58:46 -0400 Subject: [PATCH 21/36] Made trees and blobs the first section --- doc/source/quickstart.rst | 133 +++++++++++++++++++------------------- 1 file changed, 68 insertions(+), 65 deletions(-) diff --git a/doc/source/quickstart.rst b/doc/source/quickstart.rst index bd5ddd7b8..11f8123bb 100644 --- a/doc/source/quickstart.rst +++ b/doc/source/quickstart.rst @@ -11,6 +11,74 @@ Welcome to the GitPython Quickstart Guide! Designed for developers seeking a pra All code presented here originated from `***** insert link **** `_ to assure correctness. Knowing this should also allow you to more easily run the code for your own testing purposes. All you need is a developer installation of git-python. + +Trees & Blobs +************** + +Latest Commit Tree +################## + +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [12-test_cloned_repo_object] + :end-before: # ![12-test_cloned_repo_object] + +Any Commit Tree +############### + +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [13-test_cloned_repo_object] + :end-before: # ![13-test_cloned_repo_object] + +Display level 1 Contents +######################## + +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [14-test_cloned_repo_object] + :end-before: # ![14-test_cloned_repo_object] + +Recurse through the Tree +######################## + +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [15-test_cloned_repo_object] + :end-before: # ![15-test_cloned_repo_object] + +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [16-test_cloned_repo_object] + :end-before: # ![16-test_cloned_repo_object] + + + + +Printing text files +#################### + +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [17-test_cloned_repo_object] + :end-before: # ![17-test_cloned_repo_object] + +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [18-test_cloned_repo_object] + :end-before: # ![18-test_cloned_repo_object] + + + + + git.Repo ******** @@ -139,68 +207,3 @@ returns list of :class:`Commit ` objects :end-before: # ![11-test_cloned_repo_object] -Trees & Blobs -************** - -Latest Commit Tree -################## - -.. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [12-test_cloned_repo_object] - :end-before: # ![12-test_cloned_repo_object] - -Any Commit Tree -############### - -.. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [13-test_cloned_repo_object] - :end-before: # ![13-test_cloned_repo_object] - -Display level 1 Contents -######################## - -.. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [14-test_cloned_repo_object] - :end-before: # ![14-test_cloned_repo_object] - -Recurse through the Tree -######################## - -.. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [15-test_cloned_repo_object] - :end-before: # ![15-test_cloned_repo_object] - -.. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [16-test_cloned_repo_object] - :end-before: # ![16-test_cloned_repo_object] - - - - -Printing text files -#################### - -.. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [17-test_cloned_repo_object] - :end-before: # ![17-test_cloned_repo_object] - -.. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [18-test_cloned_repo_object] - :end-before: # ![18-test_cloned_repo_object] - - - From 2c9c0c122d7dddce62d593f564d2b0c6f7a33e69 Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Sun, 16 Jul 2023 12:05:18 -0400 Subject: [PATCH 22/36] Added warning about index add --- doc/source/quickstart.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/source/quickstart.rst b/doc/source/quickstart.rst index 11f8123bb..693562b17 100644 --- a/doc/source/quickstart.rst +++ b/doc/source/quickstart.rst @@ -138,6 +138,8 @@ Now lets add the updated file to git Notice the add method requires a list as a parameter +Warning: If you experience any trouble with this, try to invoke :class:`git ` instead via repo.git.add(path) + * $ git commit -m message .. literalinclude:: ../../test/test_quick_doc.py From d276107039d69bb3ad32595756b70fd4e51267d1 Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Sun, 16 Jul 2023 12:08:19 -0400 Subject: [PATCH 23/36] Updated generic sha hash --- test/test_quick_doc.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/test_quick_doc.py b/test/test_quick_doc.py index 0aa27a361..5aa5664bc 100644 --- a/test/test_quick_doc.py +++ b/test/test_quick_doc.py @@ -68,8 +68,8 @@ def test_cloned_repo_object(self, local_dir): commits_for_file = [c for c in commits_for_file_generator] commits_for_file - # Outputs: [, - # ] + # Outputs: [, + # ] # ![6-test_cloned_repo_object] # Untracked files - create new file @@ -128,9 +128,9 @@ def test_cloned_repo_object(self, local_dir): files_and_dirs # Output - # [, - # , - # ] + # [, + # , + # ] # ![14-test_cloned_repo_object] From f3968f2e34467735935ee7a39a7d2b2f07229e7d Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Sun, 16 Jul 2023 12:19:44 -0400 Subject: [PATCH 24/36] Removed all reference to source code --- doc/source/quickstart.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/doc/source/quickstart.rst b/doc/source/quickstart.rst index 693562b17..0cbb4f45c 100644 --- a/doc/source/quickstart.rst +++ b/doc/source/quickstart.rst @@ -9,8 +9,6 @@ GitPython Quick Start Tutorial ============================== Welcome to the GitPython Quickstart Guide! Designed for developers seeking a practical and interactive learning experience, this concise resource offers step-by-step code snippets to swiftly initialize/clone repositories, perform essential Git operations, and explore GitPython's capabilities. Get ready to dive in, experiment, and unleash the power of GitPython in your projects! -All code presented here originated from `***** insert link **** `_ to assure correctness. Knowing this should also allow you to more easily run the code for your own testing purposes. All you need is a developer installation of git-python. - Trees & Blobs ************** From 9ca25d767e554681ad9863138911800868c29b49 Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Sun, 16 Jul 2023 13:30:09 -0400 Subject: [PATCH 25/36] WIP major changes to structure to improve readability --- doc/source/quickstart.rst | 122 ++++++++++++++++++++------------------ test/test_quick_doc.py | 27 ++++++++- 2 files changed, 87 insertions(+), 62 deletions(-) diff --git a/doc/source/quickstart.rst b/doc/source/quickstart.rst index 0cbb4f45c..f33d51600 100644 --- a/doc/source/quickstart.rst +++ b/doc/source/quickstart.rst @@ -10,6 +10,41 @@ GitPython Quick Start Tutorial Welcome to the GitPython Quickstart Guide! Designed for developers seeking a practical and interactive learning experience, this concise resource offers step-by-step code snippets to swiftly initialize/clone repositories, perform essential Git operations, and explore GitPython's capabilities. Get ready to dive in, experiment, and unleash the power of GitPython in your projects! +git.Repo +******** + +There are a few ways to create a :class:`git.Repo ` object + +Initialize a new git Repo +######################### + +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [1-test_init_repo_object] + :end-before: # ![1-test_init_repo_object] + +Existing local git Repo +####################### + +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [2-test_init_repo_object] + :end-before: # ![2-test_init_repo_object] + +Clone from URL +############## + +For the rest of this tutorial we will use a clone from https://github.com/gitpython-developers/QuickStartTutorialFiles.git + +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [1-test_cloned_repo_object] + :end-before: # ![1-test_cloned_repo_object] + + Trees & Blobs ************** @@ -40,6 +75,12 @@ Display level 1 Contents :start-after: # [14-test_cloned_repo_object] :end-before: # ![14-test_cloned_repo_object] +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [14.1-test_cloned_repo_object] + :end-before: # ![14.1-test_cloned_repo_object] + Recurse through the Tree ######################## @@ -58,67 +99,10 @@ Recurse through the Tree -Printing text files -#################### - -.. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [17-test_cloned_repo_object] - :end-before: # ![17-test_cloned_repo_object] - -.. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [18-test_cloned_repo_object] - :end-before: # ![18-test_cloned_repo_object] - - - - - -git.Repo -******** - -There are a few ways to create a :class:`git.Repo ` object - -An existing local path -###################### - -$ git init path/to/dir - -.. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [1-test_init_repo_object] - :end-before: # ![1-test_init_repo_object] - -Existing local git Repo -####################### - -.. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [2-test_init_repo_object] - :end-before: # ![2-test_init_repo_object] - -Clone from URL -############## - -For the rest of this tutorial we will use a clone from https://github.com/gitpython-developers/QuickStartTutorialFiles.git - -$ git clone https://github.com/gitpython-developers/QuickStartTutorialFiles.git - -.. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [1-test_cloned_repo_object] - :end-before: # ![1-test_cloned_repo_object] - Usage **************** -* $ git add filepath +* $ git add .. literalinclude:: ../../test/test_quick_doc.py :language: python @@ -146,7 +130,7 @@ Warning: If you experience any trouble with this, try to invoke :class:`git A list of commits associated with a file @@ -166,6 +150,24 @@ Notice this returns a generator object returns list of :class:`Commit ` objects +Printing text files +#################### +Lets print the latest version of ` dir1/file2.txt` + +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [17-test_cloned_repo_object] + :end-before: # ![17-test_cloned_repo_object] + +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [18-test_cloned_repo_object] + :end-before: # ![18-test_cloned_repo_object] + +Previous version of `/dir1/file2.txt` + * $ git status * Untracked files @@ -207,3 +209,5 @@ returns list of :class:`Commit ` objects :end-before: # ![11-test_cloned_repo_object] + + diff --git a/test/test_quick_doc.py b/test/test_quick_doc.py index 5aa5664bc..61b8082d0 100644 --- a/test/test_quick_doc.py +++ b/test/test_quick_doc.py @@ -15,6 +15,8 @@ def tearDown(self): def test_init_repo_object(self, path_to_dir): # [1-test_init_repo_object] + # $ git init + from git import Repo repo = Repo.init(path_to_dir) # git init path/to/dir @@ -31,6 +33,8 @@ def test_cloned_repo_object(self, local_dir): import git # code to clone from url # [1-test_cloned_repo_object] + # $ git clone + repo_url = "https://github.com/gitpython-developers/QuickStartTutorialFiles.git" repo = Repo.clone_from(repo_url, local_dir) @@ -128,12 +132,22 @@ def test_cloned_repo_object(self, local_dir): files_and_dirs # Output - # [, - # , - # ] + # [, + # , + # ] # ![14-test_cloned_repo_object] + # [14.1-test_cloned_repo_object] + files_and_dirs = [(entry, entry.name) for entry in tree] + files_and_dirs + + # Output + # [(< git.Tree "SHA1-HEX_HASH" >, 'Downloads', 'tree'), + # (< git.Tree "SHA1-HEX_HASH" >, 'dir1', 'tree'), + # (< git.Blob "SHA1-HEX_HASH" >, 'file4.txt', 'blob')] + # ![14.1-test_cloned_repo_object] + # [15-test_cloned_repo_object] def print_files_from_git(root, level=0): for entry in root: @@ -163,6 +177,13 @@ def print_files_from_git(root, level=0): # Output # ![17-test_cloned_repo_object] + # print pre + # [17.1-test_cloned_repo_object] + commits_for_file = [c for c in repo.iter_commits(all=True, paths=print_file)] + blob = tree[print_file] + + # ![17.1-test_cloned_repo_object] + # [18-test_cloned_repo_object] blob = tree[print_file] print(blob.data_stream.read().decode()) From 7fa57e5e30e56e7aa247cf77d1b84ddf5d08d1e7 Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Sun, 16 Jul 2023 18:33:24 -0400 Subject: [PATCH 26/36] Added new section to print prev file --- doc/source/quickstart.rst | 6 ++++++ test/test_quick_doc.py | 19 +++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/doc/source/quickstart.rst b/doc/source/quickstart.rst index f33d51600..29c500a72 100644 --- a/doc/source/quickstart.rst +++ b/doc/source/quickstart.rst @@ -168,6 +168,12 @@ Lets print the latest version of ` dir1/file2.txt` Previous version of `/dir1/file2.txt` +.. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [18.1-test_cloned_repo_object] + :end-before: # ![18.1-test_cloned_repo_object] + * $ git status * Untracked files diff --git a/test/test_quick_doc.py b/test/test_quick_doc.py index 61b8082d0..0397eb6d9 100644 --- a/test/test_quick_doc.py +++ b/test/test_quick_doc.py @@ -177,13 +177,7 @@ def print_files_from_git(root, level=0): # Output # ![17-test_cloned_repo_object] - # print pre - # [17.1-test_cloned_repo_object] - commits_for_file = [c for c in repo.iter_commits(all=True, paths=print_file)] - blob = tree[print_file] - - # ![17.1-test_cloned_repo_object] - + # print latest file # [18-test_cloned_repo_object] blob = tree[print_file] print(blob.data_stream.read().decode()) @@ -191,7 +185,16 @@ def print_files_from_git(root, level=0): # Output # file 2 version 1 # Update version 2 - # ![18-test_cloned_repo_object] + # print previous tree + # [18.1-test_cloned_repo_object] + commits_for_file = [c for c in repo.iter_commits(all=True, paths=print_file)] + tree = commits_for_file[-1].tree # gets the first commit tree + blob = tree[print_file] + + print(blob.data_stream.read().decode()) + # Output + # file 2 version 1 + # ![18.1-test_cloned_repo_object] \ No newline at end of file From 9d878af964947a09e74f29e3a13b5a26d606e86f Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Mon, 17 Jul 2023 14:21:17 -0400 Subject: [PATCH 27/36] change to formatting - removed = bash cmds --- doc/source/quickstart.rst | 166 +++++++++++++++++++------------------- test/test_quick_doc.py | 12 +-- 2 files changed, 91 insertions(+), 87 deletions(-) diff --git a/doc/source/quickstart.rst b/doc/source/quickstart.rst index 29c500a72..01a664e9c 100644 --- a/doc/source/quickstart.rst +++ b/doc/source/quickstart.rst @@ -102,117 +102,119 @@ Recurse through the Tree Usage **************** -* $ git add - -.. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [2-test_cloned_repo_object] - :end-before: # ![2-test_cloned_repo_object] - -Now lets add the updated file to git - -.. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [3-test_cloned_repo_object] - :end-before: # ![3-test_cloned_repo_object] - -Notice the add method requires a list as a parameter - -Warning: If you experience any trouble with this, try to invoke :class:`git ` instead via repo.git.add(path) - -* $ git commit -m message - -.. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [4-test_cloned_repo_object] - :end-before: # ![4-test_cloned_repo_object] - -* $ git log - -A list of commits associated with a file - -.. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [5-test_cloned_repo_object] - :end-before: # ![5-test_cloned_repo_object] - -Notice this returns a generator object - -.. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [6-test_cloned_repo_object] - :end-before: # ![6-test_cloned_repo_object] - -returns list of :class:`Commit ` objects - -Printing text files -#################### -Lets print the latest version of ` dir1/file2.txt` +Add file to staging area +######################## -.. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [17-test_cloned_repo_object] - :end-before: # ![17-test_cloned_repo_object] -.. literalinclude:: ../../test/test_quick_doc.py + .. literalinclude:: ../../test/test_quick_doc.py :language: python :dedent: 8 - :start-after: # [18-test_cloned_repo_object] - :end-before: # ![18-test_cloned_repo_object] + :start-after: # [2-test_cloned_repo_object] + :end-before: # ![2-test_cloned_repo_object] -Previous version of `/dir1/file2.txt` + Now lets add the updated file to git -.. literalinclude:: ../../test/test_quick_doc.py + .. literalinclude:: ../../test/test_quick_doc.py :language: python :dedent: 8 - :start-after: # [18.1-test_cloned_repo_object] - :end-before: # ![18.1-test_cloned_repo_object] + :start-after: # [3-test_cloned_repo_object] + :end-before: # ![3-test_cloned_repo_object] -* $ git status + Notice the add method requires a list as a parameter - * Untracked files + Warning: If you experience any trouble with this, try to invoke :class:`git ` instead via repo.git.add(path) - Lets create a new file +Commit +###### .. literalinclude:: ../../test/test_quick_doc.py :language: python :dedent: 8 - :start-after: # [7-test_cloned_repo_object] - :end-before: # ![7-test_cloned_repo_object] + :start-after: # [4-test_cloned_repo_object] + :end-before: # ![4-test_cloned_repo_object] + +List of commits associated with a file +####################################### .. literalinclude:: ../../test/test_quick_doc.py :language: python :dedent: 8 - :start-after: # [8-test_cloned_repo_object] - :end-before: # ![8-test_cloned_repo_object] + :start-after: # [5-test_cloned_repo_object] + :end-before: # ![5-test_cloned_repo_object] - * Modified files + Notice this returns a generator object .. literalinclude:: ../../test/test_quick_doc.py :language: python :dedent: 8 - :start-after: # [9-test_cloned_repo_object] - :end-before: # ![9-test_cloned_repo_object] + :start-after: # [6-test_cloned_repo_object] + :end-before: # ![6-test_cloned_repo_object] + + returns list of :class:`Commit ` objects + +Printing text files +#################### +Lets print the latest version of ` dir1/file2.txt` .. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [10-test_cloned_repo_object] - :end-before: # ![10-test_cloned_repo_object] + :language: python + :dedent: 8 + :start-after: # [17-test_cloned_repo_object] + :end-before: # ![17-test_cloned_repo_object] + + .. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [18-test_cloned_repo_object] + :end-before: # ![18-test_cloned_repo_object] - returns a list of :class:`Diff ` objects + Previous version of `/dir1/file2.txt` .. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [11-test_cloned_repo_object] - :end-before: # ![11-test_cloned_repo_object] + :language: python + :dedent: 8 + :start-after: # [18.1-test_cloned_repo_object] + :end-before: # ![18.1-test_cloned_repo_object] + +Status +###### + * Untracked files + + Lets create a new file + + .. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [7-test_cloned_repo_object] + :end-before: # ![7-test_cloned_repo_object] + + .. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [8-test_cloned_repo_object] + :end-before: # ![8-test_cloned_repo_object] + + * Modified files + + .. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [9-test_cloned_repo_object] + :end-before: # ![9-test_cloned_repo_object] + + .. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [10-test_cloned_repo_object] + :end-before: # ![10-test_cloned_repo_object] + + returns a list of :class:`Diff ` objects + + .. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [11-test_cloned_repo_object] + :end-before: # ![11-test_cloned_repo_object] diff --git a/test/test_quick_doc.py b/test/test_quick_doc.py index 0397eb6d9..4ab2a59a6 100644 --- a/test/test_quick_doc.py +++ b/test/test_quick_doc.py @@ -50,16 +50,20 @@ def test_cloned_repo_object(self, local_dir): # ![2-test_cloned_repo_object] # [3-test_cloned_repo_object] + # $ git add add_file = [update_file] # relative path from git root repo.index.add(add_file) # notice the add function requires a list of paths # ![3-test_cloned_repo_object] # code to commit - not sure how to test this # [4-test_cloned_repo_object] + # $ git commit -m repo.index.commit("Update to file2") # ![4-test_cloned_repo_object] # [5-test_cloned_repo_object] + # $ git log + # relative path from git root repo.iter_commits(all=True, max_count=10, paths=update_file) # gets the last 10 commits from all branches @@ -78,15 +82,13 @@ def test_cloned_repo_object(self, local_dir): # Untracked files - create new file # [7-test_cloned_repo_object] - # We'll create a file5.txt - - with open(f'{local_dir}/file5.txt', 'w') as f: - f.write('file5 version 1') + f = open(f'{local_dir}/untracked.txt', 'w') # creates an empty file + f.close() # ![7-test_cloned_repo_object] # [8-test_cloned_repo_object] repo.untracked_files - # Output: ['file5.txt'] + # Output: ['untracked.txt'] # ![8-test_cloned_repo_object] # Modified files From 315405d9395ff94348d43912d15471e6dd465100 Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Mon, 17 Jul 2023 18:49:34 -0400 Subject: [PATCH 28/36] formatting wip --- test/test_quick_doc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_quick_doc.py b/test/test_quick_doc.py index 4ab2a59a6..c09845a6a 100644 --- a/test/test_quick_doc.py +++ b/test/test_quick_doc.py @@ -93,7 +93,7 @@ def test_cloned_repo_object(self, local_dir): # Modified files # [9-test_cloned_repo_object] - # Lets modify one of our tracked files + # Let's modify one of our tracked files with open(f'{local_dir}/Downloads/file3.txt', 'w') as f: f.write('file3 version 2') # overwrite file 3 @@ -174,7 +174,7 @@ def print_files_from_git(root, level=0): # Printing text files # [17-test_cloned_repo_object] print_file = 'dir1/file2.txt' - tree[print_file] + tree[print_file] # the head commit tree # Output # ![17-test_cloned_repo_object] From bccf8bc3ee2384048548e717e64a5d42156ba236 Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Tue, 18 Jul 2023 00:16:07 -0400 Subject: [PATCH 29/36] added new section for diffs and formatting --- doc/source/quickstart.rst | 24 ++++++++++++++++++++++++ test/test_quick_doc.py | 39 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/doc/source/quickstart.rst b/doc/source/quickstart.rst index 01a664e9c..0826dec29 100644 --- a/doc/source/quickstart.rst +++ b/doc/source/quickstart.rst @@ -216,6 +216,30 @@ Status :start-after: # [11-test_cloned_repo_object] :end-before: # ![11-test_cloned_repo_object] +Diffs +###### + + Compare staging area to head commit + + .. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [11.1-test_cloned_repo_object] + :end-before: # ![11.1-test_cloned_repo_object] + + .. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [11.2-test_cloned_repo_object] + :end-before: # ![11.2-test_cloned_repo_object] + + Compare commit to commit + + .. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [11.3-test_cloned_repo_object] + :end-before: # ![11.3-test_cloned_repo_object] diff --git a/test/test_quick_doc.py b/test/test_quick_doc.py index c09845a6a..f79a9645e 100644 --- a/test/test_quick_doc.py +++ b/test/test_quick_doc.py @@ -19,7 +19,7 @@ def test_init_repo_object(self, path_to_dir): from git import Repo - repo = Repo.init(path_to_dir) # git init path/to/dir + repo = Repo.init(path_to_dir) # ![1-test_init_repo_object] # [2-test_init_repo_object] @@ -111,10 +111,43 @@ def test_cloned_repo_object(self, local_dir): for d in diffs: print(d.a_path) + # Output # Downloads/file3.txt - # file4.txt # ![11-test_cloned_repo_object] + # compares staging area to head commit + # [11.1-test_cloned_repo_object] + diffs = repo.index.diff(repo.head.commit) + for d in diffs: + print(d.a_path) + + # Output + + # ![11.1-test_cloned_repo_object] + # [11.2-test_cloned_repo_object] + # lets add untracked.txt + repo.index.add(['untracked.txt']) + diffs = repo.index.diff(repo.head.commit) + for d in diffs: + print(d.a_path) + + # Output + # untracked.txt + # ![11.2-test_cloned_repo_object] + + # Compare commit to commit + # [11.3-test_cloned_repo_object] + first_commit = [c for c in repo.iter_commits(all=True)][-1] + diffs = repo.head.commit.diff(first_commit) + for d in diffs: + print(d.a_path) + + # Output + # dir1/file2.txt + # ![11.3-test_cloned_repo_object] + + + '''Trees and Blobs''' # Latest commit tree @@ -141,7 +174,7 @@ def test_cloned_repo_object(self, local_dir): # ![14-test_cloned_repo_object] # [14.1-test_cloned_repo_object] - files_and_dirs = [(entry, entry.name) for entry in tree] + files_and_dirs = [(entry, entry.name, entry.type) for entry in tree] files_and_dirs # Output From cad1e2e835b0b7876277c0514bcba2ac6fedab81 Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Tue, 18 Jul 2023 00:19:21 -0400 Subject: [PATCH 30/36] tabbed all code-blocks --- doc/source/quickstart.rst | 90 +++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/doc/source/quickstart.rst b/doc/source/quickstart.rst index 0826dec29..2b6c1c99f 100644 --- a/doc/source/quickstart.rst +++ b/doc/source/quickstart.rst @@ -18,31 +18,31 @@ There are a few ways to create a :class:`git.Repo ` object Initialize a new git Repo ######################### -.. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [1-test_init_repo_object] - :end-before: # ![1-test_init_repo_object] + .. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [1-test_init_repo_object] + :end-before: # ![1-test_init_repo_object] Existing local git Repo ####################### -.. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [2-test_init_repo_object] - :end-before: # ![2-test_init_repo_object] + .. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [2-test_init_repo_object] + :end-before: # ![2-test_init_repo_object] Clone from URL ############## For the rest of this tutorial we will use a clone from https://github.com/gitpython-developers/QuickStartTutorialFiles.git -.. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [1-test_cloned_repo_object] - :end-before: # ![1-test_cloned_repo_object] + .. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [1-test_cloned_repo_object] + :end-before: # ![1-test_cloned_repo_object] Trees & Blobs @@ -51,50 +51,50 @@ Trees & Blobs Latest Commit Tree ################## -.. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [12-test_cloned_repo_object] - :end-before: # ![12-test_cloned_repo_object] + .. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [12-test_cloned_repo_object] + :end-before: # ![12-test_cloned_repo_object] Any Commit Tree ############### -.. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [13-test_cloned_repo_object] - :end-before: # ![13-test_cloned_repo_object] + .. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [13-test_cloned_repo_object] + :end-before: # ![13-test_cloned_repo_object] Display level 1 Contents ######################## -.. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [14-test_cloned_repo_object] - :end-before: # ![14-test_cloned_repo_object] + .. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [14-test_cloned_repo_object] + :end-before: # ![14-test_cloned_repo_object] -.. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [14.1-test_cloned_repo_object] - :end-before: # ![14.1-test_cloned_repo_object] + .. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [14.1-test_cloned_repo_object] + :end-before: # ![14.1-test_cloned_repo_object] Recurse through the Tree ######################## -.. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [15-test_cloned_repo_object] - :end-before: # ![15-test_cloned_repo_object] + .. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [15-test_cloned_repo_object] + :end-before: # ![15-test_cloned_repo_object] -.. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [16-test_cloned_repo_object] - :end-before: # ![16-test_cloned_repo_object] + .. literalinclude:: ../../test/test_quick_doc.py + :language: python + :dedent: 8 + :start-after: # [16-test_cloned_repo_object] + :end-before: # ![16-test_cloned_repo_object] From 7e589f3d852461e2c143035c1cc3ceb1a81ecd61 Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Tue, 18 Jul 2023 00:29:44 -0400 Subject: [PATCH 31/36] fixed tabbing --- doc/source/quickstart.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/quickstart.rst b/doc/source/quickstart.rst index 2b6c1c99f..ebebc37d1 100644 --- a/doc/source/quickstart.rst +++ b/doc/source/quickstart.rst @@ -219,7 +219,7 @@ Status Diffs ###### - Compare staging area to head commit +Compare staging area to head commit .. literalinclude:: ../../test/test_quick_doc.py :language: python @@ -233,7 +233,7 @@ Diffs :start-after: # [11.2-test_cloned_repo_object] :end-before: # ![11.2-test_cloned_repo_object] - Compare commit to commit +Compare commit to commit .. literalinclude:: ../../test/test_quick_doc.py :language: python From 2a45f94d976e3cb91a7e700649eeea12f6655f7c Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Tue, 18 Jul 2023 00:38:38 -0400 Subject: [PATCH 32/36] redundant line --- test/test_quick_doc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_quick_doc.py b/test/test_quick_doc.py index f79a9645e..cea96690e 100644 --- a/test/test_quick_doc.py +++ b/test/test_quick_doc.py @@ -101,7 +101,7 @@ def test_cloned_repo_object(self, local_dir): # [10-test_cloned_repo_object] repo.index.diff(None) # compares staging area to working directory - repo.index.diff(repo.head.commit) # compares staging area to last commit + # Output: [, # ] # ![10-test_cloned_repo_object] From ef4d6d52fe02b7006224765cb65c824b8eca91e5 Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Tue, 18 Jul 2023 15:18:24 -0400 Subject: [PATCH 33/36] redundant code cell --- doc/source/quickstart.rst | 7 ------- test/test_quick_doc.py | 13 +------------ 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/doc/source/quickstart.rst b/doc/source/quickstart.rst index ebebc37d1..33ddf5901 100644 --- a/doc/source/quickstart.rst +++ b/doc/source/quickstart.rst @@ -75,12 +75,6 @@ Display level 1 Contents :start-after: # [14-test_cloned_repo_object] :end-before: # ![14-test_cloned_repo_object] - .. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [14.1-test_cloned_repo_object] - :end-before: # ![14.1-test_cloned_repo_object] - Recurse through the Tree ######################## @@ -242,4 +236,3 @@ Compare commit to commit :end-before: # ![11.3-test_cloned_repo_object] - diff --git a/test/test_quick_doc.py b/test/test_quick_doc.py index cea96690e..cb782aa3c 100644 --- a/test/test_quick_doc.py +++ b/test/test_quick_doc.py @@ -163,17 +163,6 @@ def test_cloned_repo_object(self, local_dir): # Iterating through tree # [14-test_cloned_repo_object] - files_and_dirs = [entry for entry in tree] - files_and_dirs - - # Output - # [, - # , - # ] - - # ![14-test_cloned_repo_object] - - # [14.1-test_cloned_repo_object] files_and_dirs = [(entry, entry.name, entry.type) for entry in tree] files_and_dirs @@ -181,7 +170,7 @@ def test_cloned_repo_object(self, local_dir): # [(< git.Tree "SHA1-HEX_HASH" >, 'Downloads', 'tree'), # (< git.Tree "SHA1-HEX_HASH" >, 'dir1', 'tree'), # (< git.Blob "SHA1-HEX_HASH" >, 'file4.txt', 'blob')] - # ![14.1-test_cloned_repo_object] + # ![14-test_cloned_repo_object] # [15-test_cloned_repo_object] def print_files_from_git(root, level=0): From 8138b3a56d16f68cfe6a5d9371e2fde3d587161c Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Tue, 18 Jul 2023 15:25:43 -0400 Subject: [PATCH 34/36] generic hash --- test/test_quick_doc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_quick_doc.py b/test/test_quick_doc.py index cb782aa3c..eaee4e581 100644 --- a/test/test_quick_doc.py +++ b/test/test_quick_doc.py @@ -77,7 +77,7 @@ def test_cloned_repo_object(self, local_dir): commits_for_file # Outputs: [, - # ] + # ] # ![6-test_cloned_repo_object] # Untracked files - create new file @@ -198,7 +198,7 @@ def print_files_from_git(root, level=0): print_file = 'dir1/file2.txt' tree[print_file] # the head commit tree - # Output + # Output # ![17-test_cloned_repo_object] # print latest file From 84885a3ea412261adf457aee1c6471606ba7095c Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Wed, 19 Jul 2023 13:47:28 -0400 Subject: [PATCH 35/36] added more resources section --- doc/source/quickstart.rst | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/doc/source/quickstart.rst b/doc/source/quickstart.rst index 33ddf5901..2a9e41e62 100644 --- a/doc/source/quickstart.rst +++ b/doc/source/quickstart.rst @@ -222,17 +222,23 @@ Compare staging area to head commit :end-before: # ![11.1-test_cloned_repo_object] .. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [11.2-test_cloned_repo_object] - :end-before: # ![11.2-test_cloned_repo_object] + :language: python + :dedent: 8 + :start-after: # [11.2-test_cloned_repo_object] + :end-before: # ![11.2-test_cloned_repo_object] Compare commit to commit .. literalinclude:: ../../test/test_quick_doc.py - :language: python - :dedent: 8 - :start-after: # [11.3-test_cloned_repo_object] - :end-before: # ![11.3-test_cloned_repo_object] + :language: python + :dedent: 8 + :start-after: # [11.3-test_cloned_repo_object] + :end-before: # ![11.3-test_cloned_repo_object] + +More Resources +**************** +Remember, this is just the beginning! There's a lot more you can achieve with GitPython in your development workflow. +To explore further possibilities and discover advanced features, check out the full :ref:`GitPython tutorial ` +and the :ref:`API Reference `. Happy coding! From cf3a899ebd498bd8053bc17dab1ff4c36edc005e Mon Sep 17 00:00:00 2001 From: LeoDaCoda Date: Wed, 19 Jul 2023 13:50:25 -0400 Subject: [PATCH 36/36] typo --- doc/source/quickstart.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/quickstart.rst b/doc/source/quickstart.rst index 2a9e41e62..c5930eb8a 100644 --- a/doc/source/quickstart.rst +++ b/doc/source/quickstart.rst @@ -148,7 +148,7 @@ List of commits associated with a file Printing text files #################### -Lets print the latest version of ` dir1/file2.txt` +Lets print the latest version of `/dir1/file2.txt` .. literalinclude:: ../../test/test_quick_doc.py :language: python pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy