mirror of
https://gitee.com/johng/gf
synced 2026-06-30 11:05:11 +08:00
## Summary - Fix `gf gen enums` output file created at wrong location when using relative path - Output was incorrectly relative to source directory instead of current working directory - Add `defer gfile.Chdir(originPwd)` to restore original working directory ## Root Cause The code calls `gfile.Chdir(realPath)` to change to source directory before `gfile.PutContents(in.Path, ...)`, causing relative output path to be resolved relative to source directory. ## Solution - Convert output path to absolute using `gfile.Abs()` before `Chdir` - Restore original working directory with `defer` (following `genpb.go` pattern) ## Test Cases - `Test_Gen_Enums_Issue4387_RelativePath` - standard project with relative path - `Test_Gen_Enums_AbsolutePath` - absolute path (should work as before) - `Test_Gen_Enums_Issue4387_Monorepo` - monorepo mode (`cd app/xxx && gf gen enums`) Closes #4387