Class: GitHack::GitRepo
- Inherits:
-
Git::Path
- Object
- Git::Path
- GitHack::GitRepo
- Includes:
- PathCommon, SaveExecute
- Defined in:
- lib/git-hack/git_repo.rb
Overview
Instance Attribute Summary collapse
-
#commits ⇒ Object
Returns the value of attribute commits.
-
#current_commit ⇒ Object
Returns the value of attribute current_commit.
-
#git ⇒ Object
属性函数.
-
#remote ⇒ Object
Returns the value of attribute remote.
-
#work ⇒ Object
Returns the value of attribute work.
Instance Method Summary collapse
- #commit_facade ⇒ Object
-
#get_gitdir(path) ⇒ Object
得到本身或是上层目录中.git文件的路经.
-
#git_save(msg, options = {}) ⇒ Object
把工作目录的文件添加到git仓库并提交.
-
#goto(number, options = {}) ⇒ Object
回到前第number个保存.
-
#init(dir) ⇒ Object
初始化空文件夹成为git库.
-
#initialize(path) ⇒ GitRepo
constructor
A new instance of GitRepo.
-
#redo ⇒ Object
redo 到当前提交的下一个提交.
- #show_commits ⇒ Object
-
#undo ⇒ Object
undo 回到上一次提交.
Methods included from SaveExecute
#execute_success, #ready_to_execute, #success?
Methods included from PathCommon
#absolute_path, #join, #project_dir, #project_file, #require_p
Constructor Details
#initialize(path) ⇒ GitRepo
Returns a new instance of GitRepo.
28 29 30 31 32 33 |
# File 'lib/git-hack/git_repo.rb', line 28 def initialize(path) @workingdirectory = get_gitdir(path) @git = nil @commits = nil @commit_facade = nil end |
Instance Attribute Details
#commits ⇒ Object
Returns the value of attribute commits.
26 27 28 |
# File 'lib/git-hack/git_repo.rb', line 26 def commits @commits end |
#current_commit ⇒ Object
Returns the value of attribute current_commit.
26 27 28 |
# File 'lib/git-hack/git_repo.rb', line 26 def current_commit @current_commit end |
#git ⇒ Object
属性函数
36 37 38 |
# File 'lib/git-hack/git_repo.rb', line 36 def git @git end |
#remote ⇒ Object
Returns the value of attribute remote.
26 27 28 |
# File 'lib/git-hack/git_repo.rb', line 26 def remote @remote end |
#work ⇒ Object
Returns the value of attribute work.
26 27 28 |
# File 'lib/git-hack/git_repo.rb', line 26 def work @work end |
Instance Method Details
#commit_facade ⇒ Object
39 40 41 |
# File 'lib/git-hack/git_repo.rb', line 39 def commit_facade @commit_facade ||= CommitFacade.new(@workingdirectory) end |
#get_gitdir(path) ⇒ Object
得到本身或是上层目录中.git文件的路经
92 93 94 95 96 97 |
# File 'lib/git-hack/git_repo.rb', line 92 def get_gitdir(path) git_path = absolute_path(path) return nil if git_path == "/" return git_path if is_gitdir?(git_path) return get_gitdir(join(git_path,"/../")) end |
#git_save(msg, options = {}) ⇒ Object
把工作目录的文件添加到git仓库并提交
48 49 50 51 52 53 54 55 |
# File 'lib/git-hack/git_repo.rb', line 48 def git_save(msg,={}) ready_to_execute return self if not_git_directory? add_workingdirectory commit(msg) execute_success self end |
#goto(number, options = {}) ⇒ Object
回到前第number个保存
73 74 75 76 77 78 79 80 |
# File 'lib/git-hack/git_repo.rb', line 73 def goto(number,={}) ready_to_execute return self if not_git_directory? ap commits git.reset_hard(commits[number].sha) execute_success self end |
#init(dir) ⇒ Object
初始化空文件夹成为git库
82 83 84 85 |
# File 'lib/git-hack/git_repo.rb', line 82 def init(dir) @git = Git.init(dir) @workingdirectory = dir end |
#redo ⇒ Object
redo 到当前提交的下一个提交
62 63 64 65 66 67 68 69 70 |
# File 'lib/git-hack/git_repo.rb', line 62 def redo ready_to_execute return self if not_git_directory? next_commit = commit_facade.get_next_commit return self if !next_commit git.reset_hard(next_commit) execute_success self end |
#show_commits ⇒ Object
86 87 88 |
# File 'lib/git-hack/git_repo.rb', line 86 def show_commits ap commits end |
#undo ⇒ Object
undo 回到上一次提交
58 59 60 |
# File 'lib/git-hack/git_repo.rb', line 58 def undo goto(1) end |