Class: AvoDeploy::ScmProvider::GitScmProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/avodeploy/scm_provider/git_scm_provider.rb

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ GitScmProvider

Initializes the provider

 @param env [TaskExecutionEnvironment] Environment for the commands to be executed in

Raises:

  • (ArgumentError)


26
27
28
29
30
# File 'lib/avodeploy/scm_provider/git_scm_provider.rb', line 26

def initialize(env)
	raise ArgumentError, "env must be a TaskExecutionEnvironment" unless env.kind_of?(AvoDeploy::Task::TaskExecutionEnvironment)

	@env = env
end

Instance Method Details

#checkout_from_remote(url, local_dir, branch) ⇒ Object

Checks out repository code from a system and switches to the given branch

Parameters:

  • url (String)

    the repository location

  • local_dir (String)

    path to the working copy

  • branch (String)

    the branch to check out

Raises:

  • (RuntimeError)


37
38
39
40
41
42
43
44
45
46
# File 'lib/avodeploy/scm_provider/git_scm_provider.rb', line 37

def checkout_from_remote(url, local_dir, branch)
	res = @env.command("git clone #{url} #{local_dir}")
	raise RuntimeError, "Could not clone from git url #{url}" unless res.retval == 0

	@env.chdir(local_dir)
	res = @env.command("git checkout #{branch}")
	@env.chdir('../')
	
	raise RuntimeError, "could not switch to branch #{branch}" unless res.retval == 0
end

#cli_utilsArray

Returns the scm tools that have to be installed on specific systems

Returns:

  • (Array)

    array of utilities



67
68
69
# File 'lib/avodeploy/scm_provider/git_scm_provider.rb', line 67

def cli_utils
	[ 'git' ]
end

#revisionString

Returns the current revision of the working copy

Returns:

  • (String)

    the current revision of the working copy



51
52
53
54
55
# File 'lib/avodeploy/scm_provider/git_scm_provider.rb', line 51

def revision
	res = @env.command("git rev-parse HEAD")

	res.stdout.gsub("\n", "")
end

#scm_filesArray

Returns scm files to be executed in the deployment process

Returns:

  • (Array)

    array of scm control files



60
61
62
# File 'lib/avodeploy/scm_provider/git_scm_provider.rb', line 60

def scm_files
	[ '.git', '.gitignore' ]
end