diff options
-rwxr-xr-x | bin/changelog | 8 | ||||
-rw-r--r-- | doc/development/changelog.md | 20 | ||||
-rw-r--r-- | spec/bin/changelog_spec.rb | 12 |
3 files changed, 38 insertions, 2 deletions
diff --git a/bin/changelog b/bin/changelog index a0d1ad2d730..2cd337af778 100755 --- a/bin/changelog +++ b/bin/changelog @@ -12,6 +12,7 @@ Options = Struct.new( :amend, :author, :dry_run, + :force, :merge_request, :title ) @@ -29,6 +30,10 @@ class ChangelogOptionParser options.amend = value end + opts.on('-f', '--force', 'Overwrite an existing entry') do |value| + options.force = value + end + opts.on('-m', '--merge-request [integer]', Integer, 'Merge Request ID') do |value| options.merge_request = value end @@ -111,8 +116,9 @@ class ChangelogEntry def assert_new_file! return unless File.exist?(file_path) + return if options.force - fail_with "#{file_path} already exists!" + fail_with "#{file_path} already exists! Use `--force` to overwrite." end def assert_title! diff --git a/doc/development/changelog.md b/doc/development/changelog.md index d08c476e9d6..390eb549d0b 100644 --- a/doc/development/changelog.md +++ b/doc/development/changelog.md @@ -46,13 +46,14 @@ author: The entry filename is based on the name of the current Git branch. If you run the command above on a branch called `feature/hey-dz`, it will generate a -`changelogs/unreleased/feature-hey-dz` file. +`changelogs/unreleased/feature-hey-dz.yml` file. ### Arguments | Argument | Shorthand | Purpose | | ----------------- | --------- | --------------------------------------------- | | `--amend` | | Amend the previous commit | +| `--force` | `-f` | Overwrite an existing entry | | `--merge-request` | `-m` | Merge Request ID | | `--dry-run` | `-n` | Don't actually write anything, just print | | `--git-username` | `-u` | Use Git user.name configuration as the author | @@ -79,6 +80,23 @@ merge_request: author: ``` +#### `--force` or `-f` + +Use **`--force`** or **`-f`** to overwrite an existing changelog entry if it +already exists. + +```text +$ bin/changelog 'Hey DZ, I added a feature to GitLab!' +error changelogs/unreleased/feature-hey-dz.yml already exists! Use `--force` to overwrite. + +$ bin/changelog 'Hey DZ, I added a feature to GitLab!' --force +create changelogs/unreleased/feature-hey-dz.yml +--- +title: Hey DZ, I added a feature to GitLab! +merge_request: 1983 +author: +``` + #### `--merge-request` or `-m` Use the **`--merge-request`** or **`-m`** argument to provide the diff --git a/spec/bin/changelog_spec.rb b/spec/bin/changelog_spec.rb index da167dc570f..8c8bc1b0f1c 100644 --- a/spec/bin/changelog_spec.rb +++ b/spec/bin/changelog_spec.rb @@ -10,6 +10,18 @@ describe 'bin/changelog' do expect(options.amend).to eq true end + it 'parses --force' do + options = described_class.parse(%w[foo --force bar]) + + expect(options.force).to eq true + end + + it 'parses -f' do + options = described_class.parse(%w[foo -f bar]) + + expect(options.force).to eq true + end + it 'parses --merge-request' do options = described_class.parse(%w[foo --merge-request 1234 bar]) |