FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Modernize git invocations & fix a few bugs along the way by jamiew · Pull Request #128 · git-friendly/git-friendly · GitHub

Modernize git invocations & fix a few bugs along the way - #128

Merged
jamiew merged 8 commits into
mainfrom
modernize-git-commands
Jun 3, 2026
Merged

Modernize git invocations & fix a few bugs along the way#128
jamiew merged 8 commits into
mainfrom
modernize-git-commands

Conversation

jamiew commented Apr 20, 2026
edited
Loading

Copy link
Copy Markdown
Collaborator

quick swap of legacy git incantations across the 5 scripts for modern equivalents:

  • git switch / git switch -c instead of git checkout / -b for branch switching
  • grep -E instead of egrep (deprecated since 2007 lol)
  • git branch --show-current instead of git branch | sed-style parsing
  • git show-ref --verify --quiet for branch existence checks (no more grepping branch output)
  • git rev-parse --abbrev-ref "$b@{upstream}" for tracking detection (was awk-ing git branch -vv)
  • git remote get-url --push for the remote URL in push
  • bug: branch -d/-D on a nonexistent branch was silently exit 0 — now propagates git's exit code
  • bug: push had [ -z $* ] which is a glob/word-splitting bug — switched to $# + an args array
  • bug: pull's stash detection matched the literal english string "No local changes to save", so non-en-US locales would have the wrong stash popped — now compares refs/stash before and after
  • bug: pull, push, merge now detect detached HEAD up-front instead of falling through to raw git errors
  • bug: install.sh added -fL to curl so a 404 doesn't silently land an HTML error page in the script file
  • cleanup: pull, push swapped deprecated which for command -v; branch dropped redundant [ -n "$x" ] && [ ! "$x" == '' ] patterns and quoted some loose vars

git 2.23 (Aug 2019) becomes the new floor, which feels safe.

to test:

  • usual flows (branch foo, branch -, pull, push) work as before
  • branch -d definitely-no-such-branch now exits non-zero (was 0)
  • on detached HEAD, pull / push / merge main print a friendly error and exit non-zero
  • existing CI green (25/25). new regression tests live in the stacked PR (add-test-coverage)

jamiew added 2 commits April 20, 2026 14:36
- checkout → switch (git 2.23+)
- branch parsing via sed/grep/tr → branch --show-current (git 2.22+)
- egrep → grep -E (egrep is deprecated)
jamiew marked this pull request as ready for review April 20, 2026 19:01
sapegin added a commit to sapegin/dotfiles that referenced this pull request Apr 22, 2026
nicksp added a commit to nicksp/dotfiles that referenced this pull request Apr 23, 2026
jamiew added 5 commits May 6, 2026 08:49
- branch: use 'git show-ref --verify --quiet' for branch existence checks instead of parsing 'git branch --no-color | grep'
- branch, merge: use 'git rev-parse --abbrev-ref @{upstream}' for tracking detection instead of parsing 'git branch -vv | awk'
- push: use 'git remote get-url --push' instead of parsing 'git remote show | grep Push | awk'
- drop the stray 'echo tracking=' debug line in merge
- branch: propagate exit code from 'git branch -d/-D' so failures (nonexistent branch, unmerged with -d) return non-zero
- branch: quote $branch in git switch calls so names with spaces don't break (slashes already worked)
- branch: drop redundant `[ -n "$x" ] && [ \! "$x" == '' ]` duplications
- push: fix `[ -z $* ]` glob bug by switching to `$#` and an args array, so passthrough args with spaces/globs no longer misbehave
- pull: replace locale-fragile "No local changes to save" string match with a refs/stash before/after comparison; bug would have caused 'git stash pop' to run against the wrong stash on localized git installs
- pull, push: swap deprecated `which` for `command -v`
- pull, push, merge: detect detached HEAD up-front with a friendly error instead of falling through to confusing git output and bogus exit codes
- install.sh: add -fL to curl so HTTP errors fail loudly and redirects are followed, and quote paths
- branch: quote $branch in the list-mode test so weird names don't trip it
- pull: simplify has_changed to drop the outer $(...). same behavior either way (bash propagates the inner exit code when the substitution is empty, and grep --quiet always is) but the unwrapped form doesn't depend on that quirk to read correctly
jamiew changed the title Modernize git commands (switch, --show-current, grep -E) Modernize git invocations + fix a few bugs along the way Jun 1, 2026
This was referenced Jun 1, 2026
jamiew changed the title Modernize git invocations + fix a few bugs along the way Modernize git invocations & fix a few bugs along the way Jun 2, 2026
sapegin added a commit to sapegin/dotfiles that referenced this pull request Jun 2, 2026
* Expand CI test coverage + add shellcheck job

new test steps:
- branch -d on a nonexistent branch must exit non-zero (was silently exit 0)
- branch name with `/` in it (common feature/* flow, never tested)
- detached HEAD: pull/push/merge must fail cleanly (was confusing fallthrough)
- pull: skips `git stash pop` when nothing was stashed
- pull: pop runs exactly once when something was stashed
- pull: package-manager install hooks (yarn) don't fire when their lockfile didn't change
- push: passthrough flag (--force-with-lease) doesn't get mangled

also a separate shellcheck job (warning-level) so we catch unquoted vars and similar before they ship.

stacked on top of modernize-git-commands — most of these tests rely on those fixes.

* Fix shellcheck warnings across scripts

- branch: replace `remotes=($(git remote))` with a portable while-read loop (mapfile isn't in macOS /bin/bash 3.2)
- pull: quote `cd "$(dirname ...)"` and add `|| return 1` on both `cd` calls
- push: use `grep -F '*'` for the literal-asterisk match, and unquote the rhs of `=~` so github.com matches as a regex
- install.sh: iterate with `"${FILES[@]}"` instead of `${FILES[*]}`

* Fix flaky CI test by resetting working tree after stash test

The "stash - passthrough arguments" test runs `stash pop` which reapplies its modification to file.txt, leaving every subsequent test running on a dirty working tree. That made the "pull - skips pop when nothing was stashed" assertion fail because pull correctly stashed the lingering modification.

- restore file.txt at the end of the stash passthrough test so later steps start clean

jamiew commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator Author

working OK for me so far on modern macOS and Ubuntu Linux 25

jamiew merged commit 9d2902a into main Jun 3, 2026
2 checks passed
jamiew deleted the modernize-git-commands branch June 3, 2026 02:20
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant


Back | FazBrowse Home | New Git URL