Class: ShopifyCli::Git
- Inherits:
-
Object
- Object
- ShopifyCli::Git
- Defined in:
- lib/shopify-cli/git.rb
Overview
ShopifyCli::Git wraps git functionality to make it easier to integrate will git.
Class Method Summary collapse
-
.branches(ctx) ⇒ Object
will fetch the repos list of branches.
-
.clone(repository, dest, ctx: Context.new) ⇒ Object
will make calls to git to clone a new repo into a supplied destination, it will also output progress of the cloning process.
-
.init(ctx) ⇒ Object
will initialize a new repo in the current directory.
-
.sha(dir: Dir.pwd, ctx: Context.new) ⇒ Object
will return the current sha of the cli repo.
Class Method Details
.branches(ctx) ⇒ Object
will fetch the repos list of branches.
#### Parameters
-
ctx- the current running context of your command, defaults to a new context.
#### Returns
-
branches- [String] an array of strings that are branch names
#### Example
branches = ShopifyCli::Git.branches(@ctx)
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/shopify-cli/git.rb', line 71 def branches(ctx) output, status = ctx.capture2e('git', 'branch', '--list', '--format=%(refname:short)') ctx.abort(ctx.('core.git.error.no_branches_found')) unless status.success? branches = if output == '' ['master'] else output.split("\n") end branches end |
.clone(repository, dest, ctx: Context.new) ⇒ Object
will make calls to git to clone a new repo into a supplied destination, it will also output progress of the cloning process.
#### Parameters
-
repository- a git url for git to clone the repo from -
dest- a filepath to where the repo should be cloned to -
ctx- the current running context of your command, defaults to a new context.
#### Returns
-
sha_string- string of the sha of the most recent commit to the repo
#### Example
ShopifyCli::Git.clone('[email protected]:shopify/test.git', 'test-app')
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/shopify-cli/git.rb', line 45 def clone(repository, dest, ctx: Context.new) if Dir.exist?(dest) ctx.abort(ctx.('core.git.error.directory_exists')) else = ctx.('core.git.cloned', dest) CLI::UI::Frame.open(ctx.('core.git.cloning', repository, dest), success_text: ) do clone_progress('clone', '--single-branch', repository, dest, ctx: ctx) end end end |
.init(ctx) ⇒ Object
will initialize a new repo in the current directory. This will output if it was successful or not.
#### Parameters
-
ctx- the current running context of your command, defaults to a new context.
#### Example
ShopifyCli::Git.init(@ctx)
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/shopify-cli/git.rb', line 96 def init(ctx) output, status = ctx.capture2e('git', 'status') unless status.success? ctx.abort(ctx.('core.git.error.repo_not_initiated')) end if output.include?('No commits yet') ctx.abort(ctx.('core.git.error.no_commits_made')) end end |
.sha(dir: Dir.pwd, ctx: Context.new) ⇒ Object
will return the current sha of the cli repo
#### Parameters
-
dir- the directory of the git repo. This defaults to the cli repo -
ctx- the current running context of your command
#### Returns
-
sha_string- string of the sha of the most recent commit to the repo
#### Example
ShopifyCli::Git.sha
23 24 25 |
# File 'lib/shopify-cli/git.rb', line 23 def sha(dir: Dir.pwd, ctx: Context.new) rev_parse('HEAD', dir: dir, ctx: ctx) end |