Skip to content

Instantly share code, notes, and snippets.

@arthurschreiber
Forked from mhodgson/gist:9006859
Last active August 29, 2015 13:56
Show Gist options
  • Save arthurschreiber/9011609 to your computer and use it in GitHub Desktop.
Save arthurschreiber/9011609 to your computer and use it in GitHub Desktop.
require 'rugged'
repo = Rugged::Repository.init_at('./test-repo')
index = repo.index
base_commit_options = {
author: { name: "Matt", email: "matt@test.com" },
committer: { name: "Matt", email: "matt@test.com" },
update_ref: 'HEAD'
}
version_one = "
Balance Sheets Are Awesome
The cool balance sheet, sometimes called the statement of financial position, lists the company's assets, liabilities,and stockholders' equity as of a specific moment in time.
That specific moment is the close of business on the date of the balance sheet.
A balance sheet is like a nice photograph; it captures the financial position of a company at a particular point in time.
Study about the assets, liabilities, and stockholders equity contained in a balance sheet.
"
builder = Rugged::Tree::Builder.new
builder << {
:type => :blob,
:name => "test_file.txt",
:oid => builder.write(repo),
:filemode => 0100644
}
commit_options = base_commit_options.merge(
parents: repo.empty? ? [] : [repo.head.target].compact,
tree: index.write_tree(repo),
message: 'first commit'
)
Rugged::Commit.create(repo, commit_options)
branch = repo.create_branch('branch')
repo.head = branch.canonical_name
version_two = "
Balance Sheets Are The Best
The cool balance sheet, sometimes called the statement of financial position, lists the company's assets, liabilities,and stockholders' equity as of a specific moment in time.
That specific moment is the close of business on the date of the balance sheet.
A balance sheet is like a nice photograph; it captures the financial position of a company at a particular point in time.
Study about the assets, liabilities, and stockholders equity contained in a balance sheet.
"
builder = Rugged::Tree::Builder.new
builder << {
:type => :blob,
:name => "test_file.txt",
:oid => repo.write(version_two, :blob),
:filemode => 0100644
}
commit_options = base_commit_options.merge(
parents: repo.empty? ? [] : [repo.head.target].compact,
tree: builder.write(repo),
message: 'branch commit'
)
Rugged::Commit.create(repo, commit_options)
master = repo.branches['master']
repo.head = master.canonical_name
version_three = "
Balance Sheets Are Awesome
The cool balance sheet, sometimes called the statement of financial position, lists the company's assets, liabilities,and stockholders' equity as of a specific moment in time.
That specific moment is the close of business on the date of the balance sheet.
A balance sheet is really like a nice photograph; it captures the financial position of a company at a particular point in time.
Study about the assets, and stockholders equity contained in a balance sheet.
"
builder = Rugged::Tree::Builder.new
builder << {
:type => :blob,
:name => "test_file.txt",
:oid => repo.write(version_three, :blob),
:filemode => 0100644
}
commit_options = base_commit_options.merge(
parents: repo.empty? ? [] : [repo.head.target].compact,
tree: builder.write(repo),
message: 'another master commit'
)
Rugged::Commit.create(repo, commit_options)
branch = repo.branches['branch']
master = repo.branches['master']
branch_commit = branch.target
master_commit = master.target
merge_index = repo.merge_commits(master_commit, branch_commit)
raise "Conflict detected!" if merge_index.conflicts?
commit_options = base_commit_options.merge(
parents: [repo.branches['branch'].target, repo.branches['master'].target],
tree: merge_index.write_tree(repo),
message: 'Merged `branch` into `master`'
)
Rugged::Commit.create(repo, commit_options)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment