Skip to content

Commit

Permalink
feat: revert file when change all is cancelled
Browse files Browse the repository at this point in the history
Refs #1
	modified:   change
  • Loading branch information
adamtabrams committed Oct 29, 2020
1 parent 4e4816f commit 94556ac
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.7.0] - 2020-10-28
### Added
- Revert file when `change all` command is cancelled (see #1).

### Changed
- Removed duplicates in changelog added during testing.

## [0.6.1] - 2020-06-06
### Fixed
- Error handling within functions. Replaced exit with return.
Expand Down Expand Up @@ -75,7 +82,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Created a proof of concept for a changelog updater.

[Unreleased]: https://github.com/adamtabrams/change/compare/0.6.1...HEAD
[Unreleased]: https://github.com/adamtabrams/change/compare/0.7.0...HEAD
[0.7.0]: https://github.com/adamtabrams/change/compare/0.6.1...0.7.0
[0.6.1]: https://github.com/adamtabrams/change/compare/0.6.0...0.6.1
[0.6.0]: https://github.com/adamtabrams/change/compare/0.5.2...0.6.0
[0.5.2]: https://github.com/adamtabrams/change/compare/0.5.1...0.5.2
Expand Down
32 changes: 17 additions & 15 deletions change
Original file line number Diff line number Diff line change
Expand Up @@ -244,16 +244,19 @@ $(format_commits "$first_commits")
}

run_all() {
change_file
save_file=$(cat $change_file)
! modify_file && return 1
first_change=$(stat -qf "%Sc" $change_file)
${EDITOR:-vi} $change_file
last_change=$(stat -qf "%Sc" $change_file)
[ "$first_change" = "$last_change" ] &&
echo "cancelling because no manual edits were made to $change_file" >&2 && return 1
echo "cancelling because no manual edits were made to $change_file" >&2 &&
echo "$save_file" > $change_file &&
return 1
git add $change_file && git commit --amend --no-edit && make_and_push_tag && post_release
}

change_file() {
modify_file() {
! startup_checks && return 1

latest_git_ver_name=$(git tag --list "[[:digit:]]*\.[[:digit:]]*" --sort="-v:refname" | head -1)
Expand All @@ -272,15 +275,14 @@ change_file() {
done
}


[ "$2" ] && { echo "change currently accepts only one argument" >&2; exit 1; }
[ ! "$1" ] && { change_file; exit; }
[ "$1" = "init" ] && { init; exit; }
[ "$1" = "tag" ] && { make_and_push_tag; exit; }
[ "$1" = "auth" ] && { auth; exit; }
[ "$1" = "post" ] && { post_release; exit; }
[ "$1" = "all" ] && { run_all; exit; }
[ "$1" = "-h" ] && { usage; exit; }
[ "$1" = "help" ] && { usage; exit; }
[ "$1" = "--help" ] && { usage; exit; }
[ "$1" ] && { printf "couldn't recognize argument\n\n" >&2; usage >&2; exit 1; }
[ "$2" ] && { echo "change currently accepts only one argument" >&2; exit 1; }
[ ! "$1" ] && { modify_file; exit; }
[ "$1" = "init" ] && { init; exit; }
[ "$1" = "tag" ] && { make_and_push_tag; exit; }
[ "$1" = "auth" ] && { auth; exit; }
[ "$1" = "post" ] && { post_release; exit; }
[ "$1" = "all" ] && { run_all; exit; }
[ "$1" = "-h" ] && { usage; exit; }
[ "$1" = "help" ] && { usage; exit; }
[ "$1" = "--help" ] && { usage; exit; }
[ "$1" ] && { printf "couldn't recognize argument\n\n" >&2; usage >&2; exit 1; }

0 comments on commit 94556ac

Please sign in to comment.