commit 2e869d2d3fd88be77b6292aba2382a3724b4b145
parent 8a5c5c09d4339e077534ea568cf57c8b2f62ab65
Author: Daniel Barlow <dan@telent.net>
Date: Fri, 13 Aug 2021 22:54:38 +0100
make removal work in git-controlled stores
Diffstat:
3 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/features/moss.feature b/features/moss.feature
@@ -47,6 +47,14 @@ Feature: command-line password management
When I delete the secret for "home/ebay"
Then "home/ebay.age" does not exist
+ Scenario: I can delete a secret in a git-managed store
+ Given I am using a temporary password store
+ And the store is version-controlled
+ And there is a secret for "home/ebay"
+ When I delete the secret for "home/ebay"
+ Then "home/ebay.age" does not exist
+ And the removal of "home/ebay.age" is committed to version control
+
Scenario: I can search for a secret
Given I am using the example password store
When I search for "mail"
diff --git a/features/step_definitions/steps.rb b/features/step_definitions/steps.rb
@@ -183,6 +183,11 @@ Then("the change to {string} is committed to version control") do |name|
expect(log).to match /new secret/
end
+Then("the removal of {string} is committed to version control") do |name|
+ log = shell "cd #{ENV["MOSS_HOME"]}/store && git log --follow -- #{name}"
+ expect(log).to match /removed secret/
+end
+
Given("I do not specify a store") do
ENV.delete('MOSS_HOME')
end
diff --git a/moss.rb b/moss.rb
@@ -125,6 +125,12 @@ class Moss
pathname = store.join("#{name}.age")
File.exist?(pathname) or raise MossError, "Can't remove non-existent file #{pathname}"
pathname.delete
+ if git_managed?
+ Kernel.system(GIT, "rm", pathname.relative_path_from(store).to_s,
+ {chdir: MOSS.store})
+ Kernel.system(GIT, "commit", "-m", "removed secret",
+ {chdir: MOSS.store})
+ end
end
def rebuild_store(verbose:)