{"id":13463116,"url":"https://github.com/libgit2/rugged","last_synced_at":"2025-05-13T16:05:55.493Z","repository":{"id":683487,"uuid":"901663","full_name":"libgit2/rugged","owner":"libgit2","description":"ruby bindings to libgit2","archived":false,"fork":false,"pushed_at":"2025-01-03T15:18:01.000Z","size":22186,"stargazers_count":2265,"open_issues_count":121,"forks_count":283,"subscribers_count":68,"default_branch":"master","last_synced_at":"2025-04-30T06:07:38.246Z","etag":null,"topics":["git","libgit2","ruby"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/libgit2.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2010-09-10T16:18:17.000Z","updated_at":"2025-04-30T01:58:24.000Z","dependencies_parsed_at":"2023-07-08T12:17:03.583Z","dependency_job_id":"49537c2c-464c-45f8-99e5-57be6f1ce816","html_url":"https://github.com/libgit2/rugged","commit_stats":{"total_commits":2172,"total_committers":118,"mean_commits":"18.406779661016948","dds":0.6929097605893186,"last_synced_commit":"010e61118f36bb0dca4a955d1fa072293d44d761"},"previous_names":[],"tags_count":85,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libgit2%2Frugged","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libgit2%2Frugged/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libgit2%2Frugged/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libgit2%2Frugged/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/libgit2","download_url":"https://codeload.github.com/libgit2/rugged/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251835906,"owners_count":21651733,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["git","libgit2","ruby"],"created_at":"2024-07-31T13:00:46.256Z","updated_at":"2025-05-05T22:49:25.942Z","avatar_url":"https://github.com/libgit2.png","language":"C","readme":"# Rugged [![Rugged CI](https://github.com/libgit2/rugged/actions/workflows/ci.yml/badge.svg)](https://github.com/libgit2/rugged/actions/workflows/ci.yml)\n**libgit2 bindings in Ruby**\n\nRugged is a library for accessing [libgit2](https://github.com/libgit2/libgit2) in Ruby. It gives you the speed and\nportability of libgit2 with the beauty of the Ruby language.\n\n### libgit2\n\nlibgit2 is a pure C implementation of the Git core methods. It's designed to be\nfast and portable. For more information about libgit2,\n[check out libgit2's website](http://libgit2.github.com) or browse the\n[libgit2 organization](https://github.com/libgit2) on GitHub.\n\n## Install\n\nRugged is a self-contained gem. You can install it by running:\n\n    $ gem install rugged\n\n## Prerequisites\nYou need to have CMake and `pkg-config` installed on your system to be able to build the included version of `libgit2`. \n\n### Debian, Including Ubuntu\nAll Debian-derived Linux distros provide `apt`:\n```bash\n$ sudo apt install libgit2-dev cmake pkg-config\n```\n\nNote that you only need `libgit2-dev` if you want to build with the system\nlibgit2 rather than the vendored version. In this case, note that the major and\nminor versions of libgit2 and rugged must match.\n\n### Mac\nOn OS X, after installing [Homebrew](http://brew.sh/), you can get the required packages with:\n```bash\n$ brew install cmake pkg-config\n```\n\nPlease follow the above in case installation of the gem fails with `ERROR: CMake is required to build Rugged.`.\n\n### Options\n\nIf you want to build Rugged with HTTPS and SSH support, check out the list of optional [libgit2 dependencies](https://github.com/libgit2/libgit2#optional-dependencies).\n\nTo install `rugged` with SSH support ensure you have the `LibSSH2` library present, then pass the required `CMAKE_FLAGS`:\n```bash\nCMAKE_FLAGS='-DUSE_SSH=ON' gem install rugged\n```\n\nOr pass the `--with-ssh` build option:\n```bash\ngem install rugged -- --with-ssh\n```\n\nIf you're using bundler and want to bundle `libgit2` with Rugged, you can use the `:submodules` option:\n\n```ruby\ngem 'rugged', git: 'git://github.com/libgit2/rugged.git', submodules: true\n```\n\nIf you would like to bundle rugged with SSH support add the `--with-ssh` build option to the bundler config:\n```bash\nbundle config build.rugged --with-ssh\n```\n\n## Usage\nTo load Rugged, you'll usually want to add something like this:\n\n```ruby\nrequire 'rugged'\n```\n\n### Use the system provided libgit2\n\nBy default, Rugged builds and uses a bundled version of libgit2. If you\nwant to use the system library instead, you can install rugged as follows:\n\n```\ngem install rugged -- --use-system-libraries\n```\n\nOr if you are using bundler:\n\n```\nbundle config build.rugged --use-system-libraries\nbundle install\n```\n\nHowever, note that Rugged does only support specific versions of libgit2.\n\n## Usage\n\nRugged gives you access to the many parts of a Git repository. You can read and\nwrite objects, walk a tree, access the staging area, and lots more. Let's look\nat each area individually.\n\n### Repositories\n\n#### Instantiation\n\nThe repository is naturally central to Git. Rugged has a `Repository` class that\nyou can instantiate with a path to open an existing repository :\n\n```ruby\nrepo = Rugged::Repository.new('path/to/my/repository')\n# =\u003e #\u003cRugged::Repository:2228536260 {path: \"path/to/my/repository/.git/\"}\u003e\n```\n\nYou can create a new repository with `init_at`. Add a second parameter `:bare` to make a bare repository:\n\n```ruby\nRugged::Repository.init_at('.', :bare)\n```\n\nYou can also let Rugged discover the path to the .git directory if you give it a\nsubdirectory.\n\n```ruby\nRugged::Repository.discover(\"/Users/me/projects/repo/lib/subdir/\")\n# =\u003e \"/Users/me/projects/repo/.git/\"\n```\n\nOnce your Repository instantiated (in the following examples, as `repo`), you\ncan access or modify it.\n\n#### Accessing a Repository\n\n```ruby\n# Does the given SHA1 exist in this repository?\nrepo.exists?('07b44cbda23b726e5d54e2ef383495922c024202')\n# =\u003e true\n\n# Boolean repository state values:\nrepo.bare?\n# =\u003e false\nrepo.empty?\n# =\u003e true\nrepo.head_unborn?\n# =\u003e false\nrepo.head_detached?\n# =\u003e false\n\n# Path accessors\nrepo.path\n# =\u003e \"path/to/my/repository/.git/\"\nrepo.workdir\n# =\u003e \"path/to/my/repository/\"\n\n# The HEAD of the repository.\nref = repo.head\n# =\u003e #\u003cRugged::Reference:2228467240 {name: \"refs/heads/master\", target:  #\u003cRugged::Commit:2228467250 {message: \"helpful message\", tree: #\u003cRugged::Tree:2228467260 {oid: 5d6f29220a0783b8085134df14ec4d960b6c3bf2}\u003e}\u003e\n\n# From the returned ref, you can also access the `name`, `target`, and target SHA:\nref.name\n# =\u003e \"refs/heads/master\"\nref.target\n# =\u003e #\u003cRugged::Commit:2228467250 {message: \"helpful message\", tree: #\u003cRugged::Tree:2228467260 {oid: 5d6f29220a0783b8085134df14ec4d960b6c3bf2}\u003e}\u003e\nref.target_id\n# =\u003e \"2bc6a70483369f33f641ca44873497f13a15cde5\"\n\n# Reading an object\nobject = repo.read('a0ae5566e3c8a3bddffab21022056f0b5e03ef07')\n# =\u003e #\u003cRugged::OdbObject:0x109a64780\u003e\nobject.len\n# =\u003e 237\nobject.data\n# =\u003e \"tree 76f23f186076fc291742816721ea8c3e95567241\\nparent 8e3c5c52b8f29da0adc7e8be8a037cbeaea6de6b\\nauthor Vicent Mart\\303\\255 \u003ctanoku@gmail.com\u003e 1333859005 +0200\\ncommitter Vicent Mart\\303\\255 \u003ctanoku@gmail.com\u003e 1333859005 +0200\\n\\nAdd `Repository#blob_at`\\n\"\nobject.type\n# =\u003e :commit\n```\n\n#### Writing to a Repository\n\nThere's a few ways to write to a repository. To write directly from your\ninstantiated repository object:\n\n```ruby\nsha = repo.write(content, type)\n```\n\nYou can also use the `Commit` object directly to craft a commit; this is a bit\nmore high-level, so it may be preferable:\n\n```ruby\noid = repo.write(\"This is a blob.\", :blob)\nindex = repo.index\nindex.read_tree(repo.head.target.tree)\nindex.add(:path =\u003e \"README.md\", :oid =\u003e oid, :mode =\u003e 0100644)\n\noptions = {}\noptions[:tree] = index.write_tree(repo)\n\noptions[:author] = { :email =\u003e \"testuser@github.com\", :name =\u003e 'Test Author', :time =\u003e Time.now }\noptions[:committer] = { :email =\u003e \"testuser@github.com\", :name =\u003e 'Test Author', :time =\u003e Time.now }\noptions[:message] ||= \"Making a commit via Rugged!\"\noptions[:parents] = repo.empty? ? [] : [ repo.head.target ].compact\noptions[:update_ref] = 'HEAD'\n\nRugged::Commit.create(repo, options)\n```\n\n---\n\n### Objects\n\n`Object` is the main object class - it shouldn't be created directly, but all of\nthese methods should be useful in their derived classes.\n\n```ruby\nobj = repo.lookup(sha)\nobj.oid  # object sha\nobj.type # One of :commit, :tree, :blob or :tag\n\nrobj = obj.read_raw\nstr  = robj.data\nint  = robj.len\n```\n\nThere are four base object types in Git: **blobs**, **commits**, **tags**, and\n**trees**. Each of these object types have a corresponding class within Rugged.\n\n### Commit Objects\n\n```ruby\ncommit = repo.lookup('a0ae5566e3c8a3bddffab21022056f0b5e03ef07')\n# =\u003e #\u003cRugged::Commit:2245304380\u003e\n\ncommit.message\n# =\u003e \"Add `Repository#blob_at`\\n\"\n\ncommit.time\n# =\u003e Sat Apr 07 21:23:25 -0700 2012\n\ncommit.author\n# =\u003e {:email=\u003e\"tanoku@gmail.com\", :name=\u003e\"Vicent Mart\\303\\255\", :time=\u003eSun Apr 08 04:23:25 UTC 2012}\n\ncommit.tree\n# =\u003e #\u003cRugged::Tree:2245269740\u003e\n\ncommit.parents\n# =\u003e [#\u003cRugged::Commit:2245264600 {message: \"Merge pull request #47 from isaac/remotes\\n\\nAdd Rugged::Repository#remotes\", tree: #\u003cRugged::Tree:2245264240 {oid: 6a2aee58a41fa007d07aa55565e2231f9b39b4a9}\u003e]\n```\n\nYou can also write new objects to the database this way:\n\n```ruby\nauthor = {:email=\u003e\"tanoku@gmail.com\", :time=\u003eTime.now, :name=\u003e\"Vicent Mart\\303\\255\"}\n\nRugged::Commit.create(r,\n\t:author =\u003e author,\n\t:message =\u003e \"Hello world\\n\\n\",\n\t:committer =\u003e author,\n\t:parents =\u003e [\"2cb831a8aea28b2c1b9c63385585b864e4d3bad1\"],\n\t:tree =\u003e some_tree,\n\t:update_ref =\u003e \"HEAD\") #=\u003e \"f148106ca58764adc93ad4e2d6b1d168422b9796\"\n```\n\n### Tag Objects\n\n```ruby\ntag  = repo.lookup(tag_sha)\n\nobject = tag.target\nsha    = tag.target.oid\nstr    = tag.target_type # :commit, :tag, :blob\nstr    = tag.name        # \"v1.0\"\nstr    = tag.message\nperson = tag.tagger\n```\n\n### Tree Objects\n\n```ruby\ntree = repo.lookup('779fbb1e17e666832773a9825875300ea736c2da')\n# =\u003e #\u003cRugged::Tree:2245194360\u003e\n\n# number of tree entries\ntree.count\n\ntree[0]           # or...\ntree.first        # or...\ntree.get_entry(0)\n# =\u003e {:type=\u003e:blob, :oid=\u003e\"99e7edb53db9355f10c6f2dfaa5a183f205d93bf\", :filemode=\u003e33188, :name=\u003e\".gitignore\"}\n```\n\nThe tree object is an Enumerable, so you can also do stuff like this:\n\n```ruby\ntree.each { |e| puts e[:oid] }\ntree.sort { |a, b| a[:oid] \u003c=\u003e b[:oid] }.map { |e| e[:name] }.join(':')\n```\n\nAnd there are some Rugged-specific methods, too:\n\n```ruby\ntree.each_tree { |entry| puts entry[:name] }  # list subdirs\ntree.each_blob { |entry| puts entry[:name] }  # list only files\n```\n\nYou can also write trees with the `TreeBuilder`:\n\n```ruby\noid = repo.write(\"This is a blob.\", :blob)\nbuilder = Rugged::Tree::Builder.new(repo)\nbuilder \u003c\u003c { :type =\u003e :blob, :name =\u003e \"README.md\", :oid =\u003e oid, :filemode =\u003e 0100644 }\n\noptions = {}\noptions[:tree] = builder.write\n\noptions[:author] = { :email =\u003e \"testuser@github.com\", :name =\u003e 'Test Author', :time =\u003e Time.now }\noptions[:committer] = { :email =\u003e \"testuser@github.com\", :name =\u003e 'Test Author', :time =\u003e Time.now }\noptions[:message] ||= \"Making a commit via Rugged!\"\noptions[:parents] = repo.empty? ? [] : [ repo.head.target ].compact\noptions[:update_ref] = 'HEAD'\n\nRugged::Commit.create(repo, options)\n```\n\n### Blob Objects\n\nBlob objects represent the data in the files of a Tree Object.\n\n```ruby\nblob = repo.lookup('e1253910439ea902cf49be8a9f02f3c08d89ac73')\nblob.content # =\u003e Gives you the content of the blob.\n```\n\n#### Streaming Blob Objects\n\nThere is currently no way to stream data from a blob, because `libgit2` itself does not (yet) support\nstreaming blobs out of the git object database. While there are hooks and interfaces for supporting it,\nthe default file system backend always loads the entire blob contents into memory. \n\nIf you need to access a Blob object through an IO-like API, you can wrap it with the `StringIO` class.\nNote that the only advantage here is a stream-compatible interface, the complete blob object will still\nbe loaded into memory. Below is an example for streaming a Blob using the Sinatra framework:\n\n```ruby\n# Sinatra endpoint\nget \"/blobs/:sha\" do\n  repo = Rugged::Repository.new(my_repo_path)\n  blob = repo.lookup params[:sha]\n\n  headers({\n    \"Vary\" =\u003e \"Accept\",\n    \"Connection\" =\u003e \"keep-alive\",\n    \"Transfer-Encoding\" =\u003e \"chunked\",\n    \"Content-Type\" =\u003e \"application/octet-stream\",\n  })\n\n  stream do |out|\n    StringIO.new(blob.content).each(8000) do |chunk|\n      out \u003c\u003c chunk\n    end\n  end\nend\n```\n\n---\n\n### Commit Walker\n\n`Rugged::Walker` is a class designed to help you traverse a set of commits over\na repository.\n\nYou first push head SHAs onto the walker, and then call next to get a list of\nthe reachable commit objects one at a time. You can also `hide()` commits if you\nare not interested in anything beneath them (useful in situations like when\nyou're running something like `git log master ^origin/master`).\n\n```ruby\nwalker = Rugged::Walker.new(repo)\nwalker.sorting(Rugged::SORT_TOPO | Rugged::SORT_REVERSE) # optional\nwalker.push(hex_sha_interesting)\nwalker.hide(hex_sha_uninteresting)\nwalker.each { |c| puts c.inspect }\nwalker.reset\n```\n\n---\n\n### Index (\"staging\") area\n\nWe can inspect and manipulate the Git Index as well. To work with the index\ninside an existing repository, instantiate it by using the `Repository.index`\nmethod instead of manually opening the Index by its path.\n\n```ruby\nindex = Rugged::Index.new(path)\n\n# Re-read the index file from disk.\nindex.reload\n\n# Count up index entries.\ncount = index.count\n\n# The collection of index entries.\nindex.entries\n\n# Iterating over index entries.\nindex.each { |i| puts i.inspect }\n\n# Get a particular entry in the index.\nindex[path]\n\n# Unstage.\nindex.remove(path)\n\n# Stage. Also updates existing entry if there is one.\nindex.add(ientry)\n\n# Stage. Create ientry from file in path, updates the index.\nindex.add(path)\n```\n\n---\n\n### Refs\n\nYou can access references through the `Rugged::ReferenceCollection` object returned by `Repository#references`.\n\n```ruby\nref = repo.references[\"refs/heads/master\"]\n\nsha = ref.target_id\nstr = ref.type   # :direct\nstr = ref.name   # \"refs/heads/master\"\n```\n\nYou can also easily iterate over all references:\n\n```ruby\nrepo.references.each do |ref|\n  puts ref.name\nend\n```\n\nOr only over references that match the given pattern (glob):\n\n```ruby\nrepo.references.each(\"refs/tags/*\") do |ref|\n  puts ref.name\nend\n```\n\nIt is also easy to create, update, rename or delete a reference:\n\n```ruby\nref = repo.references.create(\"refs/heads/unit_test\", some_commit_sha)\n\nrepo.references.update(ref, new_sha) # or...\nrepo.references.update(\"refs/heads/unit_test\", new_sha)\n\nrepo.references.rename(ref, \"refs/heads/blead\") # or...\nrepo.references.rename(\"refs/heads/unit_test\", \"refs/heads/blead\")\n\nrepo.references.delete(ref) # or...\nrepo.references.delete(\"refs/heads/unit_test\") # or...\n```\n\nFinally, you can access the reflog for any branch:\n\n```ruby\nref = repo.references[\"refs/heads/master\"]\nentry = ref.log.first\nsha   = entry[:id_old]\nsha   = entry[:id_new]\nstr   = entry[:message]\nprsn  = entry[:committer]\n```\n\n---\n\n### Branches\n\nThe `Rugged::BranchCollection` object returned by `Repository#branches` will help\nyou with all of your branch-related needs.\n\nIterate over all branches:\n\n```ruby\nrepo.branches.each_name().sort\n# =\u003e [\"master\", \"origin/HEAD\", \"origin/master\", \"origin/packed\"]\n\nrepo.branches.each_name(:local).sort\n# =\u003e [\"master\"]\n\nrepo.branches.each_name(:remote).sort\n# =\u003e [\"origin/HEAD\", \"origin/master\", \"origin/packed\"]\n```\n\nLook up branches and get attributes:\n\n```ruby\nbranch = repo.branches[\"master\"]\nbranch.name # =\u003e 'master'\nbranch.canonical_name # =\u003e 'refs/heads/master'\n```\n\nLook up the id for the target of a branch:\n\n```ruby\nrepo.branches[\"master\"].target_id\n# =\u003e \"36060c58702ed4c2a40832c51758d5344201d89a\"\n```\n\nCreation and deletion:\n\n```ruby\nbranch = repo.branches.create(\"test_branch\", \"HEAD\")\n\nrepo.branches.rename(\"test_branch\", \"new_branch\") # or...\nrepo.branches.rename(\"refs/heads/test_branch\", \"new_branch\") # or...\nrepo.branches.rename(ref, \"new_branch\") # or...\n\nrepo.branches.delete(\"test_branch\") # or...\nrepo.branches.delete(\"refs/heads/test_branch\") # or...\nrepo.branches.delete(ref) # or...\n```\n\n---\n\n### Diffs\n\nThere are various ways to get hands on diffs:\n\n```ruby\n# Diff between two subsequent commits\ndiff_commits = commit_object.parents[0].diff(commit_object)\n\n# Diff between two tree objects\ndiff_trees = tree_object_a.diff(tree_object_b)\n\n# Diff between index/staging and current working directory\ndiff_index = repository.index.diff\n\n# Diff between index/staging and another diffable (commit/tree/index)\ndiff_index_diffable = repository.index.diff(some_diffable)\n```\n\nWhen you already have a diff object, you can examine it:\n\n```ruby\n# Get patch\ndiff.patch\n=\u003e \"diff --git a/foo1 b/foo1\\nnew file mode 100644\\nindex 0000000..81b68f0\\n--- /dev/null\\n+++ b/foo1\\n@@ -0,0 +1,2 @@\\n+abc\\n+add line1\\ndiff --git a/txt1 b/txt1\\ndeleted file mode 100644\\nindex 81b68f0..0000000\\n--- a/txt1\\n+++ /dev/null\\n@@ -1,2 +0,0 @@\\n-abc\\n-add line1\\ndiff --git a/txt2 b/txt2\\nindex a7bb42f..a357de7 100644\\n--- a/txt2\\n+++ b/txt2\\n@@ -1,2 +1,3 @@\\n abc2\\n add line2-1\\n+add line2-2\\n\"\n\n# Get delta (faster, if you only need information on what files changed)\ndiff.each_delta{ |d| puts d.inspect }\n#\u003cRugged::Diff::Delta:70144372137380 {old_file: {:oid=\u003e\"0000000000000000000000000000000000000000\", :path=\u003e\"foo1\", :size=\u003e0, :flags=\u003e6, :mode=\u003e0}, new_file: {:oid=\u003e\"81b68f040b120c9627518213f7fc317d1ed18e1c\", :path=\u003e\"foo1\", :size=\u003e14, :flags=\u003e6, :mode=\u003e33188}, similarity: 0, status: :added\u003e\n#\u003cRugged::Diff::Delta:70144372136540 {old_file: {:oid=\u003e\"81b68f040b120c9627518213f7fc317d1ed18e1c\", :path=\u003e\"txt1\", :size=\u003e14, :flags=\u003e6, :mode=\u003e33188}, new_file: {:oid=\u003e\"0000000000000000000000000000000000000000\", :path=\u003e\"txt1\", :size=\u003e0, :flags=\u003e6, :mode=\u003e0}, similarity: 0, status: :deleted\u003e\n#\u003cRugged::Diff::Delta:70144372135780 {old_file: {:oid=\u003e\"a7bb42f71183c162efea5e4c80597437d716c62b\", :path=\u003e\"txt2\", :size=\u003e17, :flags=\u003e6, :mode=\u003e33188}, new_file: {:oid=\u003e\"a357de7d870823acc3953f1b2471f9c18d0d56ea\", :path=\u003e\"txt2\", :size=\u003e29, :flags=\u003e6, :mode=\u003e33188}, similarity: 0, status: :modified\u003e\n\n# Detect renamed files\n# Note that the status field changed from :added/:deleted to :renamed\ndiff.find_similar!\ndiff.each_delta{ |d| puts d.inspect }\n#\u003cRugged::Diff::Delta:70144372230920 {old_file: {:oid=\u003e\"81b68f040b120c9627518213f7fc317d1ed18e1c\", :path=\u003e\"txt1\", :size=\u003e14, :flags=\u003e6, :mode=\u003e33188}, new_file: {:oid=\u003e\"81b68f040b120c9627518213f7fc317d1ed18e1c\", :path=\u003e\"foo1\", :size=\u003e14, :flags=\u003e6, :mode=\u003e33188}, similarity: 100, status: :renamed\u003e\n#\u003cRugged::Diff::Delta:70144372230140 {old_file: {:oid=\u003e\"a7bb42f71183c162efea5e4c80597437d716c62b\", :path=\u003e\"txt2\", :size=\u003e17, :flags=\u003e6, :mode=\u003e33188}, new_file: {:oid=\u003e\"a357de7d870823acc3953f1b2471f9c18d0d56ea\", :path=\u003e\"txt2\", :size=\u003e29, :flags=\u003e6, :mode=\u003e33188}, similarity: 0, status: :modified\u003e\n\n# Merge one diff into another (mutating the first one)\ndiff1.merge!(diff2)\n\n# Write a patch into a file (or any other object responding to write)\n# Note that the patch as in diff.patch will be written, it won't be applied\nfile = File.open('/some/file', 'w')\ndiff.write_patch(file)\nfile.close\n```\n\n---\n\n### Config files\n\nIt's also easy to read and manipulate the Git config file data with Rugged.\n\n```ruby\n# Read values\nrepo.config['core.bare']\n\n# Set values\nrepo.config['user.name'] = true\n\n# Delete values\nrepo.config.delete('user.name')\n```\n\n---\n\n### General methods\n\nRugged also includes a general library for handling basic Git operations. One of\nthese is converting a raw sha (20 bytes) into a readable hex sha (40\ncharacters).\n\n```ruby\nRugged.hex_to_raw('bfde59cdd0dfac1d892814f66a95641abd8a1faf')\n# =\u003e \"\\277\\336Y\\315\\320\\337\\254\\035\\211(\\024\\366j\\225d\\032\\275\\212\\037\\257\"\n\nRugged.raw_to_hex(\"\\277\\336Y\\315\\320\\337\\254\\035\\211(\\024\\366j\\225d\\032\\275\\212\\037\\257\")\n=\u003e \"bfde59cdd0dfac1d892814f66a95641abd8a1faf\"\n```\n\n---\n\n### Alternative backends\n\nYou can store bare repositories in alternative backends instead of storing on disk. (see\n`redbadger/rugged-redis` for an example of how a rugged backend works).\n\n```ruby\na_backend = MyProject::CustomObjectDB(opt1: 'setting', opt2: 'setting')\n\nrepo = Rugged::Repository.init_at('repo_name', :bare, backend: a_backend)\n\n# or\n\nrepo = Rugged::Repository.bare('repo_name', backend: a_backend)\n```\n---\n\n## Contributing\n\nFork libgit2/rugged on GitHub, make it awesomer (preferably in a branch named\nfor the topic), send a pull request.\n\n\n## Development\n\nSimply clone and install:\n\n    $ git clone https://github.com/libgit2/rugged.git\n    $ cd rugged\n    $ bundle install\n    $ rake compile\n    $ rake test\n\n## Support\n\nWe encourage you to use StackOverflow for any questions or concerns regarding Rugged. Please tag your questions with the [rugged](http://stackoverflow.com/questions/tagged/rugged) keyword.\n\nFor bug reports, please open a ticket on the GitHub [issue tracker](https://github.com/libgit2/rugged/issues).\n\n## Authors\n\n* Vicent Marti \u003ctanoku@gmail.com\u003e\n* Scott Chacon \u003cschacon@gmail.com\u003e\n* Arthur Schreiber \u003cschreiber.arthur@gmail.com\u003e\n\n\n## License\n\nMIT. See LICENSE file.\n","funding_links":[],"categories":["Git Tools","Developer Tools","C"],"sub_categories":["git Tools"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibgit2%2Frugged","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flibgit2%2Frugged","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibgit2%2Frugged/lists"}