Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[action][git_add] Add force option #21850

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 17 additions & 2 deletions fastlane/lib/fastlane/actions/git_add.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ def self.run(params)
success_message = "Successfully added all files 💾."
end

result = Actions.sh("git add #{paths}", log: FastlaneCore::Globals.verbose?).chomp
force = params[:force] ? "--force" : nil

command = [
"git",
"add",
force,
paths
].compact

result = Actions.sh(command.join(" "), log: FastlaneCore::Globals.verbose?).chomp
UI.success(success_message)
return result
end
Expand Down Expand Up @@ -47,6 +56,11 @@ def self.available_options
type: Boolean,
default_value: true,
optional: true),
FastlaneCore::ConfigItem.new(key: :force,
description: "Allow adding otherwise ignored files",
type: Boolean,
default_value: false,
optional: true),
# Deprecated
FastlaneCore::ConfigItem.new(key: :pathspec,
description: "The pathspec you want to add files from",
Expand Down Expand Up @@ -76,7 +90,8 @@ def self.example_code
'git_add(path: "./Frameworks/*", shell_escape: false)',
'git_add(path: ["*.h", "*.m"], shell_escape: false)',
'git_add(path: "./Frameworks/*", shell_escape: false)',
'git_add(path: "*.txt", shell_escape: false)'
'git_add(path: "*.txt", shell_escape: false)',
'git_add(path: "./tmp/.keep", force: true)'
]
end

Expand Down
11 changes: 11 additions & 0 deletions fastlane/spec/actions_specs/git_add_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@
end
end

context "as string with force option" do
let(:path) { "myfile.txt" }

it "executes the correct git command" do
allow(Fastlane::Actions).to receive(:sh).with("git add --force #{path}", anything).and_return("")
result = Fastlane::FastFile.new.parse("lane :test do
git_add(path: '#{path}', force: true)
end").runner.execute(:test)
end
end

context "without parameters" do
it "executes the correct git command" do
allow(Fastlane::Actions).to receive(:sh).with("git add .", anything).and_return("")
Expand Down