Add `on_conflict: skip` to add a file only if it doesn't exist
- 主要言語
- Go
- スター
- 16
- フォーク
- 4
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
### TL;DR
This has come up a couple of times now. As a template developer, I want the ability to place a file in the destination, iff there is not already a destination file of that name.
Use cases:
- Add `terraform.tf` files if they don't already exist
Some ways I can think of that this could work:
### Option 1: an option on the "include" action
```
steps:
- action: 'include'
params:
paths: ['mydir/my_file.txt']
on_conflict: 'skip'
```
EDIT: changed `skip_if_exists` to `on_conflict: skip`.
We'd prevent `skip_if_exists: true` from being used together with `from: destination`, because that would be silly: including a file from the destination only works if the file exists, and skip_if_exists:true only has an effect if the file doesn't exist.
How we'd implement it: when a file is included with skip_if_exists, we'd copy it to the scratch directory as usual, and remember to handle that filename specially later at the time we commit the scratch dir contents to the destination dir.
Upside: simple devex for template authors
Downside: it's a bit architecturally hacky because it mixes commit-time logic (skip_if_exists) with include-time logic (including a file into the scratch dir). If we ever offer the ability in the future to relocate files in the scratch directory, we'll have to track the filename changes so we know the final location.
### ~~Option 2: add commit options~~ (we like option 1)
```
steps:
- action: 'include'
params:
paths: ['mydir/my_file.txt']
commit_options:
skip_if_exists: ['mydir/my_file.txt']
```
Upside: more architecturally clean
Downside: requires repeating the filename. More confusing devex if the template author isn't thinking carefully about the scratch directory and how committing-to-destination works.
cc @verbanicm
### Detailed design
_No response_
### Alternatives considered
_No response_
### Additional information
_No response_
コントリビューションガイド
評価
この issue はまだ評価されていません。