| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 048ffa5 commit e395ac9
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -415,6 +415,22 @@ The previous approach would brutally overwrite the user's changes in the working | |||
| 415 | 415 | repo.heads.master.checkout() # checkout the branch using git-checkout | |
| 416 | 416 | repo.heads.other_branch.checkout() | |
| 417 | 417 | ||
| 418 | + Initializing a repository | ||
| 419 | + ************************* | ||
| 420 | + | ||
| 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') | ||
| 425 | + | ||
| 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") | ||
| 431 | + | ||
| 432 | + Please have a look at the individual methods as they usually support a vast amount of arguments to customize their behavior. | ||
| 433 | + | ||
| 418 | 434 | Using git directly | |
| 419 | 435 | ****************** | |
| 420 | 436 | In case you are missing functionality as it has not been wrapped, you may conveniently use the git command directly. It is owned by each repository instance:: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,26 @@ | |||
| 1 | + #-*-coding:utf-8-*- | ||
| 2 | + # test_git.py | ||
| 3 | + # Copyright (C) 2008, 2009 Michael Trier (mtrier@gmail.com) and contributors | ||
| 4 | + # | ||
| 5 | + # This module is part of GitPython and is released under | ||
| 6 | + # the BSD License: http://www.opensource.org/licenses/bsd-license.php | ||
| 7 | + import os | ||
| 8 | + | ||
| 9 | + import git | ||
| 10 | + from git.test.lib import TestBase | ||
| 11 | + from gitdb.test.lib import with_rw_directory | ||
| 12 | + from git.repo.fun import touch | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + class TestGit(TestBase): | ||
| 16 | + | ||
| 17 | + @with_rw_directory | ||
| 18 | + def test_add_file_and_commit(self, rw_dir): | ||
| 19 | + repo_dir = os.path.join(rw_dir, 'my-new-repo') | ||
| 20 | + file_name = os.path.join(repo_dir, 'new-file') | ||
| 21 | + | ||
| 22 | + r = git.Repo.init(repo_dir) | ||
| 23 | + # This function just creates an empty file ... | ||
| 24 | + touch(file_name) | ||
| 25 | + r.index.add([file_name]) | ||
| 26 | + r.index.commit("initial commit") | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments