Class: Fastlane::Actions::GitCloneAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/git_clone/actions/git_clone_action.rb

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



95
96
97
# File 'lib/fastlane/plugin/git_clone/actions/git_clone_action.rb', line 95

def self.authors
  ["xiongzenghui"]
end

.available_optionsObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/fastlane/plugin/git_clone/actions/git_clone_action.rb', line 46

def self.available_options
  [
    FastlaneCore::ConfigItem.new(
      key: :git,
      env_name: "FL_GIT_CLONE_GIT",
      description: "where from clone",
      verify_block: proc do |value|
        UI.user_error!("No git given, pass using `git: 'git'`") unless (value and not value.empty?)
      end
    ),
    FastlaneCore::ConfigItem.new(
      key: :path,
      env_name: "FL_GIT_CLONE_PATH",
      description: "where clone to dir",
      optional: true
    ),
    FastlaneCore::ConfigItem.new(
      key: :depth,
      env_name: "FL_GIT_CLONE_DEPTH",
      description: "--depth=1",
      is_string: false,
      type: Integer,
      optional: true
    ),
    FastlaneCore::ConfigItem.new(
      key: :branch,
      env_name: "FL_GIT_CLONE_BRANCH",
      description: "-b master",
      optional: true
    ),
    FastlaneCore::ConfigItem.new(
      key: :single_branch,
      env_name: "FL_GIT_CLONE_SINGLE_BRANCH",
      description: "--single-branch",
      optional: true,
      default_value: false,
      is_string: false
    )
  ]
end

.categoryObject



125
126
127
# File 'lib/fastlane/plugin/git_clone/actions/git_clone_action.rb', line 125

def self.category
  :source_control
end

.descriptionObject



38
39
40
# File 'lib/fastlane/plugin/git_clone/actions/git_clone_action.rb', line 38

def self.description
  "this is a wrapper for git clone command"
end

.detailsObject



42
43
44
# File 'lib/fastlane/plugin/git_clone/actions/git_clone_action.rb', line 42

def self.details
  "exec like this: git clone xxx.git -b master /path/to/xxx --single-branch --depth=1"
end

.example_codeObject



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/fastlane/plugin/git_clone/actions/git_clone_action.rb', line 99

def self.example_code
  [
    'git_clone(
      git: "[email protected]:user/app.git"
    )',
    'git_clone(
      git: "[email protected]:user/app.git", 
      path: "/Users/xiongzenghui/Desktop/cartool", 
      branch: "master"
    )',
    'git_clone(
      git: "[email protected]:user/app.git", 
      path: "/Users/xiongzenghui/Desktop/cartool", 
      branch: "master", 
      depth: 1
    )',
    'git_clone(
      git: "[email protected]:user/app.git", 
      path: "/Users/xiongzenghui/Desktop/cartool", 
      branch: "master", 
      depth: 1, 
      single_branch: true
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


129
130
131
# File 'lib/fastlane/plugin/git_clone/actions/git_clone_action.rb', line 129

def self.is_supported?(platform)
  true
end

.return_typeObject



87
88
89
# File 'lib/fastlane/plugin/git_clone/actions/git_clone_action.rb', line 87

def self.return_type
  :stirng
end

.return_valueObject



91
92
93
# File 'lib/fastlane/plugin/git_clone/actions/git_clone_action.rb', line 91

def self.return_value
  "return a status (boolean) of git clone sh exec result"
end

.run(params) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fastlane/plugin/git_clone/actions/git_clone_action.rb', line 7

def self.run(params)
  git = params[:git]
  clone_path = params[:path]
  git_repo_name = File.basename(git, '.git')

  rm_cmd = if clone_path
    "rm -rf #{clone_path}"
  else
    "rm -rf #{git_repo_name}"
  end
  system(rm_cmd)

  clone_cmd = "git clone #{git} "
  clone_cmd << "-b #{params[:branch]} " if params[:branch]
  clone_cmd << "--depth=#{params[:depth]} " if params[:depth]
  clone_cmd << "--single-branch " if params[:single_branch]
  clone_cmd << clone_path if clone_path
  ret = system(clone_cmd)
  if ret
    UI.success "Successfully finished git clone"
  else
    UI.error "Failed finished git clone"
  end

  ret
end