Skip to content

Commit

Permalink
fix: file not found after moving a file
Browse files Browse the repository at this point in the history
  • Loading branch information
pskrwe committed Mar 12, 2024
1 parent 1ab6b10 commit 963e8e7
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
uses: actions/setup-go@v5
with:
# Semantic version range syntax or exact version of Go
go-version: '1.22.x'
go-version: '1.22.1'

- name: Setup Syft
run: curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
build:
strategy:
matrix:
go-version: [ 1.22.x ]
go-version: [ 1.22.1 ]
os: [ ubuntu-latest, macos-latest, windows-latest ]
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/prskr/git-age

go 1.22

toolchain go1.22.0
toolchain go1.22.1

require (
filippo.io/age v1.1.1
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8=
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic=
golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
Expand Down
15 changes: 14 additions & 1 deletion handlers/cli/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (h *CleanCliHandler) Run(stdin ports.STDIN, stdout ports.STDOUT) error {
logger.Info("Hashing file at HEAD")
obj, headHash, err := h.hashFileAtHead(h.FileToCleanPath, true)
if err != nil {
if errors.Is(err, plumbing.ErrObjectNotFound) || errors.Is(err, plumbing.ErrReferenceNotFound) {
if isFileNotFound(err) {
logger.Info("Could not compare file to HEAD, handling as new")
return h.copyEncryptedFileToStdout(fileToClean, stdout)
}
Expand Down Expand Up @@ -176,3 +176,16 @@ func (h *CleanCliHandler) hashFileAt(f io.ReadSeeker) (hash []byte, err error) {

return fsx.HashFile(f)
}

func isFileNotFound(err error) bool {
switch {
case errors.Is(err, plumbing.ErrObjectNotFound):
return true
case errors.Is(err, plumbing.ErrReferenceNotFound):
return true
case errors.Is(err, object.ErrFileNotFound):
return true
default:
return false
}
}

0 comments on commit 963e8e7

Please sign in to comment.