| |   |
| 40 | 40 | |
| 41 | 41 | git://gitorious.org/git-python/mainline.git |
| 42 | 42 | |
| 43 | | USAGE |
| 44 | | ===== |
| 45 | | |
| 46 | | GitPython provides object model access to your git repository. Once you have |
| 47 | | created a repository object, you can traverse it to find parent commit(s), |
| 48 | | trees, blobs, etc. |
| 49 | | |
| 50 | | Initialize a Repo object |
| 51 | | ************************ |
| 52 | | |
| 53 | | The first step is to create a ``Repo`` object to represent your repository. |
| 54 | | |
| 55 | | >>> from git import * |
| 56 | | >>> repo = Repo("/Users/mtrier/Development/git-python") |
| 57 | | |
| 58 | | In the above example, the directory ``/Users/mtrier/Development/git-python`` |
| 59 | | is my working repository and contains the ``.git`` directory. You can also |
| 60 | | initialize GitPython with a bare repository. |
| 61 | | |
| 62 | | >>> repo = Repo.create("/var/git/git-python.git") |
| 63 | | |
| 64 | | Getting a list of commits |
| 65 | | ************************* |
| 66 | | |
| 67 | | From the ``Repo`` object, you can get a list of ``Commit`` |
| 68 | | objects. |
| 69 | | |
| 70 | | >>> repo.commits() |
| 71 | | [<GitPython.Commit "207c0c4418115df0d30820ab1a9acd2ea4bf4431">, |
| 72 | | <GitPython.Commit "a91c45eee0b41bf3cdaad3418ca3850664c4a4b4">, |
| 73 | | <GitPython.Commit "e17c7e11aed9e94d2159e549a99b966912ce1091">, |
| 74 | | <GitPython.Commit "bd795df2d0e07d10e0298670005c0e9d9a5ed867">] |
| 75 | | |
| 76 | | Called without arguments, ``Repo.commits`` returns a list of up to ten commits |
| 77 | | reachable by the master branch (starting at the latest commit). You can ask |
| 78 | | for commits beginning at a different branch, commit, tag, etc. |
| 79 | | |
| 80 | | >>> repo.commits('mybranch') |
| 81 | | >>> repo.commits('40d3057d09a7a4d61059bca9dca5ae698de58cbe') |
| 82 | | >>> repo.commits('v0.1') |
| 83 | | |
| 84 | | You can specify the maximum number of commits to return. |
| 85 | | |
| 86 | | >>> repo.commits('master', 100) |
| 87 | | |
| 88 | | If you need paging, you can specify a number of commits to skip. |
| 89 | | |
| 90 | | >>> repo.commits('master', 10, 20) |
| 91 | | |
| 92 | | The above will return commits 21-30 from the commit list. |
| 93 | | |
| 94 | | The Commit object |
| 95 | | ***************** |
| 96 | | |
| 97 | | Commit objects contain information about a specific commit. |
| 98 | | |
| 99 | | >>> head = repo.commits()[0] |
| 100 | | |
| 101 | | >>> head.id |
| 102 | | '207c0c4418115df0d30820ab1a9acd2ea4bf4431' |
| 103 | | |
| 104 | | >>> head.parents |
| 105 | | [<GitPython.Commit "a91c45eee0b41bf3cdaad3418ca3850664c4a4b4">] |
| 106 | | |
| 107 | | >>> head.tree |
| 108 | | <GitPython.Tree "563413aedbeda425d8d9dcbb744247d0c3e8a0ac"> |
| 109 | | |
| 110 | | >>> head.author |
| 111 | | <GitPython.Actor "Michael Trier <mtrier@gmail.com>"> |
| 112 | | |
| 113 | | >>> head.authored_date |
| 114 | | (2008, 5, 7, 5, 0, 56, 2, 128, 0) |
| 115 | | |
| 116 | | >>> head.committer |
| 117 | | <GitPython.Actor "Michael Trier <mtrier@gmail.com>"> |
| 118 | | |
| 119 | | >>> head.committed_date |
| 120 | | (2008, 5, 7, 5, 0, 56, 2, 128, 0) |
| 121 | | |
| 122 | | >>> head.message |
| 123 | | 'cleaned up a lot of test information. Fixed escaping so it works with |
| 124 | | subprocess.' |
| 125 | | |
| 126 | | Note: date time is represented in a `struct_time`_ format. Conversion to |
| 127 | | human readable form can be accomplished with the various time module methods. |
| 128 | | |
| 129 | | >>> import time |
| 130 | | >>> time.asctime(head.committed_date) |
| 131 | | 'Wed May 7 05:56:02 2008' |
| 132 | | |
| 133 | | >>> time.strftime("%a, %d %b %Y %H:%M", head.committed_date) |
| 134 | | 'Wed, 7 May 2008 05:56' |
| 135 | | |
| 136 | | .. _struct_time: http://docs.python.org/lib/module-time.html |
| 137 | | |
| 138 | | You can traverse a commit's ancestry by chaining calls to ``parents``. |
| 139 | | |
| 140 | | >>> repo.commits()[0].parents[0].parents[0].parents[0] |
| 141 | | |
| 142 | | The above corresponds to ``master^^^`` or ``master~3`` in git parlance. |
| 143 | | |
| 144 | | The Tree object |
| 145 | | *************** |
| 146 | | |
| 147 | | A tree records pointers to the contents of a directory. Let's say you want |
| 148 | | the root tree of the latest commit on the master branch. |
| 149 | | |
| 150 | | >>> tree = repo.commits()[0].tree |
| 151 | | <GitPython.Tree "a006b5b1a8115185a228b7514cdcd46fed90dc92"> |
| 152 | | |
| 153 | | >>> tree.id |
| 154 | | 'a006b5b1a8115185a228b7514cdcd46fed90dc92' |
| 155 | | |
| 156 | | Once you have a tree, you can get the contents. |
| 157 | | |
| 158 | | >>> contents = tree.contents |
| 159 | | [<GitPython.Blob "6a91a439ea968bf2f5ce8bb1cd8ddf5bf2cad6c7">, |
| 160 | | <GitPython.Blob "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391">, |
| 161 | | <GitPython.Tree "eaa0090ec96b054e425603480519e7cf587adfc3">, |
| 162 | | <GitPython.Blob "980e72ae16b5378009ba5dfd6772b59fe7ccd2df">] |
| 163 | | |
| 164 | | This tree contains three ``Blob`` objects and one ``Tree`` object. The trees |
| 165 | | are subdirectories and the blobs are files. Trees below the root have |
| 166 | | additional attributes. |
| 167 | | |
| 168 | | >>> contents = tree.contents[-2] |
| 169 | | <GitPython.Tree "e5445b9db4a9f08d5b4de4e29e61dffda2f386ba"> |
| 170 | | |
| 171 | | >>> contents.name |
| 172 | | 'test' |
| 173 | | |
| 174 | | >>> contents.mode |
| 175 | | '040000' |
| 176 | | |
| 177 | | There is a convenience method that allows you to get a named sub-object |
| 178 | | from a tree. |
| 179 | | |
| 180 | | >>> tree/"lib" |
| 181 | | <GitPython.Tree "c1c7214dde86f76bc3e18806ac1f47c38b2b7a30"> |
| 182 | | |
| 183 | | You can also get a tree directly from the repository if you know its name. |
| 184 | | |
| 185 | | >>> repo.tree() |
| 186 | | <GitPython.Tree "master"> |
| 187 | | |
| 188 | | >>> repo.tree("c1c7214dde86f76bc3e18806ac1f47c38b2b7a30") |
| 189 | | <GitPython.Tree "c1c7214dde86f76bc3e18806ac1f47c38b2b7a30"> |
| 190 | | |
| 191 | | The Blob object |
| 192 | | *************** |
| 193 | | |
| 194 | | A blob represents a file. Trees often contain blobs. |
| 195 | | |
| 196 | | >>> blob = tree.contents[-1] |
| 197 | | <GitPython.Blob "b19574431a073333ea09346eafd64e7b1908ef49"> |
| 198 | | |
| 199 | | A blob has certain attributes. |
| 200 | | |
| 201 | | >>> blob.name |
| 202 | | 'urls.py' |
| 203 | | |
| 204 | | >>> blob.mode |
| 205 | | '100644' |
| 206 | | |
| 207 | | >>> blob.mime_type |
| 208 | | 'text/x-python' |
| 209 | | |
| 210 | | >>> blob.size |
| 211 | | 415 |
| 212 | | |
| 213 | | You can get the data of a blob as a string. |
| 214 | | |
| 215 | | >>> blob.data |
| 216 | | "from django.conf.urls.defaults import *\nfrom django.conf..." |
| 217 | | |
| 218 | | You can also get a blob directly from the repo if you know its name. |
| 219 | | |
| 220 | | >>> repo.blob("b19574431a073333ea09346eafd64e7b1908ef49") |
| 221 | | <GitPython.Blob "b19574431a073333ea09346eafd64e7b1908ef49"> |
| 222 | | |
| 223 | | What Else? |
| 224 | | ********** |
| 225 | | |
| 226 | | There is more stuff in there, like the ability to tar or gzip repos, stats, |
| 227 | | log, blame, and probably a few other things. Additionally calls to the git |
| 228 | | instance are handled through a ``method_missing`` construct, which makes |
| 229 | | available any git commands directly, with a nice conversion of Python dicts |
| 230 | | to command line parameters. |
| 231 | | |
| 232 | | Check the unit tests, they're pretty exhaustive. |
| 233 | | |
| 234 | 43 | LICENSE |
| 235 | 44 | ======= |
| 236 | 45 | |
| toggle raw diff |
--- a/README
+++ b/README
@@ -40,197 +40,6 @@ and cloned from:
git://gitorious.org/git-python/mainline.git
-USAGE
-=====
-
-GitPython provides object model access to your git repository. Once you have
-created a repository object, you can traverse it to find parent commit(s),
-trees, blobs, etc.
-
-Initialize a Repo object
-************************
-
-The first step is to create a ``Repo`` object to represent your repository.
-
- >>> from git import *
- >>> repo = Repo("/Users/mtrier/Development/git-python")
-
-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.
-
- >>> repo = Repo.create("/var/git/git-python.git")
-
-Getting a list of commits
-*************************
-
-From the ``Repo`` object, you can get a list of ``Commit``
-objects.
-
- >>> repo.commits()
- [<GitPython.Commit "207c0c4418115df0d30820ab1a9acd2ea4bf4431">,
- <GitPython.Commit "a91c45eee0b41bf3cdaad3418ca3850664c4a4b4">,
- <GitPython.Commit "e17c7e11aed9e94d2159e549a99b966912ce1091">,
- <GitPython.Commit "bd795df2d0e07d10e0298670005c0e9d9a5ed867">]
-
-Called without arguments, ``Repo.commits`` returns a list of up to ten commits
-reachable by the master branch (starting at the latest commit). You can ask
-for commits beginning at a different branch, commit, tag, etc.
-
- >>> repo.commits('mybranch')
- >>> repo.commits('40d3057d09a7a4d61059bca9dca5ae698de58cbe')
- >>> repo.commits('v0.1')
-
-You can specify the maximum number of commits to return.
-
- >>> repo.commits('master', 100)
-
-If you need paging, you can specify a number of commits to skip.
-
- >>> repo.commits('master', 10, 20)
-
-The above will return commits 21-30 from the commit list.
-
-The Commit object
-*****************
-
-Commit objects contain information about a specific commit.
-
- >>> head = repo.commits()[0]
-
- >>> head.id
- '207c0c4418115df0d30820ab1a9acd2ea4bf4431'
-
- >>> head.parents
- [<GitPython.Commit "a91c45eee0b41bf3cdaad3418ca3850664c4a4b4">]
-
- >>> head.tree
- <GitPython.Tree "563413aedbeda425d8d9dcbb744247d0c3e8a0ac">
-
- >>> head.author
- <GitPython.Actor "Michael Trier <mtrier@gmail.com>">
-
- >>> head.authored_date
- (2008, 5, 7, 5, 0, 56, 2, 128, 0)
-
- >>> head.committer
- <GitPython.Actor "Michael Trier <mtrier@gmail.com>">
-
- >>> head.committed_date
- (2008, 5, 7, 5, 0, 56, 2, 128, 0)
-
- >>> head.message
- 'cleaned up a lot of test information. Fixed escaping so it works with
- subprocess.'
-
-Note: date time is represented in a `struct_time`_ format. Conversion to
-human readable form can be accomplished with the various time module methods.
-
- >>> import time
- >>> time.asctime(head.committed_date)
- 'Wed May 7 05:56:02 2008'
-
- >>> time.strftime("%a, %d %b %Y %H:%M", head.committed_date)
- 'Wed, 7 May 2008 05:56'
-
-.. _struct_time: http://docs.python.org/lib/module-time.html
-
-You can traverse a commit's ancestry by chaining calls to ``parents``.
-
- >>> repo.commits()[0].parents[0].parents[0].parents[0]
-
-The above corresponds to ``master^^^`` or ``master~3`` in git parlance.
-
-The Tree object
-***************
-
-A tree records pointers to the contents of a directory. Let's say you want
-the root tree of the latest commit on the master branch.
-
- >>> tree = repo.commits()[0].tree
- <GitPython.Tree "a006b5b1a8115185a228b7514cdcd46fed90dc92">
-
- >>> tree.id
- 'a006b5b1a8115185a228b7514cdcd46fed90dc92'
-
-Once you have a tree, you can get the contents.
-
- >>> contents = tree.contents
- [<GitPython.Blob "6a91a439ea968bf2f5ce8bb1cd8ddf5bf2cad6c7">,
- <GitPython.Blob "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391">,
- <GitPython.Tree "eaa0090ec96b054e425603480519e7cf587adfc3">,
- <GitPython.Blob "980e72ae16b5378009ba5dfd6772b59fe7ccd2df">]
-
-This tree contains three ``Blob`` objects and one ``Tree`` object. The trees
-are subdirectories and the blobs are files. Trees below the root have
-additional attributes.
-
- >>> contents = tree.contents[-2]
- <GitPython.Tree "e5445b9db4a9f08d5b4de4e29e61dffda2f386ba">
-
- >>> contents.name
- 'test'
-
- >>> contents.mode
- '040000'
-
-There is a convenience method that allows you to get a named sub-object
-from a tree.
-
- >>> tree/"lib"
- <GitPython.Tree "c1c7214dde86f76bc3e18806ac1f47c38b2b7a30">
-
-You can also get a tree directly from the repository if you know its name.
-
- >>> repo.tree()
- <GitPython.Tree "master">
-
- >>> repo.tree("c1c7214dde86f76bc3e18806ac1f47c38b2b7a30")
- <GitPython.Tree "c1c7214dde86f76bc3e18806ac1f47c38b2b7a30">
-
-The Blob object
-***************
-
-A blob represents a file. Trees often contain blobs.
-
- >>> blob = tree.contents[-1]
- <GitPython.Blob "b19574431a073333ea09346eafd64e7b1908ef49">
-
-A blob has certain attributes.
-
- >>> blob.name
- 'urls.py'
-
- >>> blob.mode
- '100644'
-
- >>> blob.mime_type
- 'text/x-python'
-
- >>> blob.size
- 415
-
-You can get the data of a blob as a string.
-
- >>> blob.data
- "from django.conf.urls.defaults import *\nfrom django.conf..."
-
-You can also get a blob directly from the repo if you know its name.
-
- >>> repo.blob("b19574431a073333ea09346eafd64e7b1908ef49")
- <GitPython.Blob "b19574431a073333ea09346eafd64e7b1908ef49">
-
-What Else?
-**********
-
-There is more stuff in there, like the ability to tar or gzip repos, stats,
-log, blame, and probably a few other things. Additionally calls to the git
-instance are handled through a ``method_missing`` construct, which makes
-available any git commands directly, with a nice conversion of Python dicts
-to command line parameters.
-
-Check the unit tests, they're pretty exhaustive.
-
LICENSE
=======
|