Module: Bringit::Committing
- Includes:
- Merge
- Included in:
- Wrapper
- Defined in:
- lib/bringit/committing.rb,
lib/bringit/committing/merge.rb
Overview
Methods for committing. Use all these methods only mutexed with the git repository as the key.
Defined Under Namespace
Modules: Merge Classes: Error, HeadChangedError, InvalidPathError
Instance Method Summary collapse
-
#commit_multichange(options, previous_head_sha = nil) ⇒ Object
Apply multiple file changes to the repository.
-
#create_file(options, previous_head_sha = nil) ⇒ Object
Create a file in repository and return commit sha.
-
#mkdir(path, options, previous_head_sha = nil) ⇒ Object
Create a new directory with a .gitkeep file.
-
#remove_file(options, previous_head_sha = nil) ⇒ Object
Remove file from repository and return commit sha.
-
#rename_and_update_file(options, previous_head_sha = nil) ⇒ Object
Change contents and path of a file in repository and return commit sha.
-
#rename_file(options, previous_head_sha = nil) ⇒ Object
Rename file from repository and return commit sha This does not change the file content.
-
#update_file(options, previous_head_sha = nil) ⇒ Object
Change the contents of a file in repository and return commit sha.
Methods included from Merge
#add_merge_data, #conflict_hash, #conflict_on_update, #conflicts, #create_merging_commit, #create_user_commit, #diverged?, #merge, #merge_if_needed, #raise_head_changed_error, #with_temp_user_reference
Instance Method Details
#commit_multichange(options, previous_head_sha = nil) ⇒ Object
Apply multiple file changes to the repository
options should contain the following structure:
files: {
[{content: 'Lorem ipsum...',
path: 'documents/story.txt',
action: :create},
{content: 'New Lorem ipsum...',
path: 'documents/old_story',
action: :update},
{content: 'New Lorem ipsum...',
previous_path: 'documents/really_old_story.txt',
path: 'documents/old_story',
action: :rename_and_update},
{path: 'documents/obsolet_story.txt',
action: :remove},
{path: 'documents/old_story',
previus_path: 'documents/really_old_story.txt',
action: :rename},
{path: 'documents/secret',
action: :mkdir}
]
}
},
author: {
email: '[email protected]',
name: 'Test User',
time: Time.now # optional - default: Time.now
},
committer: {
email: '[email protected]',
name: 'Test User',
time: Time.now # optional - default: Time.now
},
commit: {
message: 'Wow such commit',
branch: 'master', # optional - default: 'master'
update_ref: false # optional - default: true
}
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/bringit/committing.rb', line 218 def commit_multichange(, previous_head_sha = nil) commit_with(, previous_head_sha) do |index| [:files].each do |file| = {} [:file_path] = file[:path] if file[:path] [:content] = file[:content] if file[:content] [:encoding] = file[:encoding] if file[:encoding] case file[:action] when :create index.create() when :rename [:previous_path] = file[:previous_path] [:content] ||= blob([:commit][:branch], file[:previous_path]).data index.move() when :update index.update() when :rename_and_update previous_path = file[:previous_path] [:previous_path] = previous_path index.move() when :remove index.delete() when :mkdir index.create_dir() end end end end |
#create_file(options, previous_head_sha = nil) ⇒ Object
Create a file in repository and return commit sha
options should contain the following structure:
file: {
content: 'Lorem ipsum...',
path: 'documents/story.txt'
},
author: {
email: '[email protected]',
name: 'Test User',
time: Time.now # optional - default: Time.now
},
committer: {
email: '[email protected]',
name: 'Test User',
time: Time.now # optional - default: Time.now
},
commit: {
message: 'Wow such commit',
branch: 'master', # optional - default: 'master'
update_ref: false # optional - default: true
}
47 48 49 |
# File 'lib/bringit/committing.rb', line 47 def create_file(, previous_head_sha = nil) commit_multichange((, :create), previous_head_sha) end |
#mkdir(path, options, previous_head_sha = nil) ⇒ Object
Create a new directory with a .gitkeep file. Creates all required nested directories (i.e. mkdir -p behavior)
options should contain the following structure:
author: {
email: '[email protected]',
name: 'Test User',
time: Time.now # optional - default: Time.now
},
committer: {
email: '[email protected]',
name: 'Test User',
time: Time.now # optional - default: Time.now
},
commit: {
message: 'Wow such commit',
branch: 'master', # optional - default: 'master'
update_ref: false # optional - default: true
}
174 175 176 177 |
# File 'lib/bringit/committing.rb', line 174 def mkdir(path, , previous_head_sha = nil) [:file] = {path: path} commit_multichange((, :mkdir), previous_head_sha) end |
#remove_file(options, previous_head_sha = nil) ⇒ Object
Remove file from repository and return commit sha
options should contain the following structure:
file: {
path: 'documents/story.txt'
},
author: {
email: '[email protected]',
name: 'Test User',
time: Time.now # optional - default: Time.now
},
committer: {
email: '[email protected]',
name: 'Test User',
time: Time.now # optional - default: Time.now
},
commit: {
message: 'Remove FILENAME',
branch: 'master' # optional - default: 'master'
}
124 125 126 |
# File 'lib/bringit/committing.rb', line 124 def remove_file(, previous_head_sha = nil) commit_multichange((, :remove), previous_head_sha) end |
#rename_and_update_file(options, previous_head_sha = nil) ⇒ Object
Change contents and path of a file in repository and return commit sha
options should contain the following structure:
file: {
content: 'Lorem ipsum...',
path: 'documents/story.txt',
previous_path: 'documents/old_story.txt'
},
author: {
email: '[email protected]',
name: 'Test User',
time: Time.now # optional - default: Time.now
},
committer: {
email: '[email protected]',
name: 'Test User',
time: Time.now # optional - default: Time.now
},
commit: {
message: 'Wow such commit',
branch: 'master', # optional - default: 'master'
update_ref: false # optional - default: true
}
100 101 102 |
# File 'lib/bringit/committing.rb', line 100 def rename_and_update_file(, previous_head_sha = nil) commit_multichange((, :rename_and_update), previous_head_sha) end |
#rename_file(options, previous_head_sha = nil) ⇒ Object
Rename file from repository and return commit sha This does not change the file content.
options should contain the following structure:
file: {
previous_path: 'documents/old_story.txt'
path: 'documents/story.txt'
},
author: {
email: '[email protected]',
name: 'Test User',
time: Time.now # optional - default: Time.now
},
committer: {
email: '[email protected]',
name: 'Test User',
time: Time.now # optional - default: Time.now
},
commit: {
message: 'Rename FILENAME',
branch: 'master' # optional - default: 'master'
}
151 152 153 |
# File 'lib/bringit/committing.rb', line 151 def rename_file(, previous_head_sha = nil) commit_multichange((, :rename), previous_head_sha) end |
#update_file(options, previous_head_sha = nil) ⇒ Object
Change the contents of a file in repository and return commit sha
options should contain the following structure:
file: {
content: 'Lorem ipsum...',
path: 'documents/story.txt'
},
author: {
email: '[email protected]',
name: 'Test User',
time: Time.now # optional - default: Time.now
},
committer: {
email: '[email protected]',
name: 'Test User',
time: Time.now # optional - default: Time.now
},
commit: {
message: 'Wow such commit',
branch: 'master', # optional - default: 'master'
update_ref: false # optional - default: true
}
73 74 75 |
# File 'lib/bringit/committing.rb', line 73 def update_file(, previous_head_sha = nil) commit_multichange((, :update), previous_head_sha) end |