Recover uncommitted changes

Deleting an uncommitted file is a rare yet painful event. Especially if we have spent a couple of hours working on it. It’s useful to know there’s a chance to recover the change. If the change has been staged we can find it as a dangling blob with git fsck1. Git will create a dangling blog every time we stage a change. So even if we remove a file or stage another change on top of the old one theoretically, we’ve got a chance to recover. ...

19 Jun 2024 · 2 min · 341 words

Scopes, query builders and missing methods

If your models have fluent APIs you can work on the right level of abstraction and hide DB specific information. And here is an example of what this looks like. Order::wherePaid() ->whereLocalDelivery() ->whereHasExtraPackaging(); To enhance your model in Laravel is quite easy. namespace App\QueryBuilders; use Illuminate\Database\Eloquent\Builder; class OrderQueryBuilder extends Builder { public function wherePaid(): Builder { return $this->where('status', 'PAID'); } public function whereHasExtraPackaging(): Builder { return $this->where('extra_packaging', true); } public function whereLocalDelivery(): Builder { return $this->where('local_delivery', true); } } namespace App; use Illuminate\Database\Eloquent\Model; use App\QueryBuilders\OrderQueryBuilder; class Order extends Model { public function newEloquentBuilder($query): OrderQueryBuilder { return new OrderQueryBuilder($query); } } The trouble is, that none of the query builder’s methods are showing up in the autocomplete of the text editor or IDE. Let’s be honest. Once you’ve got more than 10 models in a system and pretty much the same amount of query builders you need an autocomplete. At least I do. ...

21 Feb 2024 · 3 min · 530 words

Improve your git stash workflow in fugitive

If you’re a vim/neovim user and your git interactions are through vim-fugitive1. By some point, you probably needed to stash some work. And you probably use the fugitive :Git stash command. But plain git stash will create a stash with a random hash. $ git stash Saved working directory and index state WIP on main: 44bc329 The annoying part is when you have more than one stash, and you need to remember the hash. If you use git stash save you can provide a proper name for your stash. ...

11 Sep 2023 · 3 min · 599 words