Coder Social home page Coder Social logo

elixir-git-cli's Introduction

Elixir Git CLI Build Status

Simple wrapper of git CLI for Elixir.

Installation

Add the dependency to your mix.exs deps:

  defp deps do
    [{:git_cli, "~> 0.3"}]
  end

Usage

The usage is basically Git.COMMAND REPO, ARGS, where REPO is a Git.Repository and ARGS is either a string or a list of strings. So for example, git pull --rebase origin master would translate to Git.pull repo, ~w(--rebase origin master).

The only exceptions are Git.clone, Git.init, and Git.new, which do not take a repository as first argument.

Here are a few examples.

Git.clone Example

{:ok, repo} = Git.clone "https://github.com/danhper/elixir-git-cli"
Git.remote repo, ~w(add upstream https://git.example.com)
Git.pull repo, ~w(--rebase upstream master)
Git.diff repo, "HEAD~1"
Git.add repo, "."
Git.commit repo, ["-m" "my message"]
Git.push repo
IO.puts Git.log!(repo)

Git.new Example

repo = Git.new "/path/to/existing/repo"
IO.puts Git.status! repo
Git.commit repo, ["-m" "my message"]
Git.push repo
IO.puts Git.log!(repo)

Note that all functions return :ok or {:ok, result}, and come with their bang version which only returns result when relevant. On error, the normal version returns {:error, Git.Error} and the bang version simply raises the exception.

Note

As this is a wrapper for git, you need to have the git command available on your path.

The commands are generated from git-commands.txt, except for init, clone, and new which return a Git.Repository struct and not the git process stdout. The apply command is not generated as it conflicts with elixir Kernel function. The commands with dashes have their function equivalent with dashes replaced by underscores, so for example, git ls-files become Git.ls_files.

TODO

  • Write more tests
  • Parse git log, git diff etc into struct

elixir-git-cli's People

Contributors

alfert avatar amorphid avatar danhper avatar jordan0day avatar lustrousgorilla avatar wrightling avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

elixir-git-cli's Issues

Deprecation warning with Git.clone/1

warning: not passing the :switches or :strict option to OptionParser is deprecated
(elixir) lib/option_parser.ex:600: OptionParser.build_config/1
(elixir) lib/option_parser.ex:222: OptionParser.parse/2
(git_cli) lib/git.ex:8: Git.get_repo_path/1
(git_cli) lib/git.ex:23: anonymous fn/2 in Git.clone/1

Create new repository via init

Currently when you execute a Git.init command you can't give a repository as parameter.

So to initialise the repository from the path we need to as:

repo = Git.new "/path/to/repo"
Git.execute_command repo, "init", [], (fn _ -> {:ok, repo} end)

It would be great to be able to do this through the function Git.init

Thanks

Git.shortlog! running forever...

Heyo. Trying to get to the git shortlog -s -n command, but it never returns when I try to use the library with Git.shortlog! repo, ["-s", "-n"]. Any ideas?

Git.clone with cli arguments returns invalid repo path

I want to be able to specify command line arguments directly to clone, the returned repository has an invalid path assigned.

Here are some examples:

URL followed by cli arguments:

iex(20)> {_, repo} = Git.clone ["https://github.com/tuvistavie/elixir-git-cli", "--depth=1"]
{:ok, %Git.Repository{path: "/private/tmp/--depth=1"}}
iex(21)> Git.pull repo
spawn: Could not cd to /private/tmp/--depth=1
{:error, %Git.Error{args: [], code: 2, command: "pull", message: ""}}

CLI arguments, followed by URL

iex(24)> {_, repo} = Git.clone ["--depth=1", "https://github.com/tuvistavie/elixir-git-cli"]
{:ok,
 %Git.Repository{
   path: "/private/tmp/https:/github.com/tuvistavie/elixir-git-cli"
 }}
iex(25)> Git.pull repo
spawn: Could not cd to /private/tmp/https:/github.com/tuvistavie/elixir-git-cli
{:error, %Git.Error{args: [], code: 2, command: "pull", message: ""}}

Currently using something along these lines as a workaround for http/s urls:

clone = fn(repo, args) ->    
 Git.clone! [repo] ++ args
 URI.parse(repo).path 
 |> Path.rootname 
 |> Path.basename
 |> Git.new
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.