News for hackers. Stuff that matters.
Re:Git: Deletion of merged branches taken beyond shell hacks by chmaynard on Wednesday August 12, 2020 @04:24PM (#24136477)
Instead of re-packaging various git commands, I'd like to encourage people to contribute their ideas and skills to the actual git project. Send an email to [email protected], volunteer to help, and ask for advice and direction. Git needs you!
Re:Git: Deletion of merged branches taken beyond shell hacks by RyJones on Wednesday August 12, 2020 @05:28PM (#24137219)
Maybe? We've had mentorships over the last couple of years trying to introduce some crypto features to Git, and they've been rebuffed.
Re:Git: Deletion of merged branches taken beyond shell hacks by justincormack on Wednesday August 12, 2020 @06:53PM (#24138026)
What sort of features?
Re:Git: Deletion of merged branches taken beyond shell hacks by RyJones on Wednesday August 12, 2020 @07:08PM (#24138146)
Re:Git: Deletion of merged branches taken beyond shell hacks by fouc on Thursday August 13, 2020 @01:15AM (#24140136)
Interesting hyperledger is backed by the Linux Foundation.. which is a front for large corporations to try to gain control over linux/FOSS/etc hmm
Re:Git: Deletion of merged branches taken beyond shell hacks by justincormack on Saturday August 15, 2020 @06:34AM (#24167836)
Good luck keep working on it!
Re:Git: Deletion of merged branches taken beyond shell hacks by maximilianroos on Wednesday August 12, 2020 @04:54PM (#24136852)
Does this have any advantage over git trim?

That's worked really well for me

https://github.com/foriequal0/git-trim

Re:Git: Deletion of merged branches taken beyond shell hacks by vikin9 on Wednesday August 12, 2020 @05:25PM (#24137188)
Not so fancy, but a one-liner

  # Remove all local branches for which there is no remote
  git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -D
Re:Git: Deletion of merged branches taken beyond shell hacks by lixtra on Wednesday August 12, 2020 @11:48PM (#24139774)
> # Remove all local branches for which there is no remote

The merged branches part is missing.

Re:Git: Deletion of merged branches taken beyond shell hacks by vikin9 on Thursday August 13, 2020 @09:39AM (#24143202)
I setup Github repos to automatically delete merged branches - in this case, the remote counterpart will be gone. There might be just the following missing to sync remove `origin/*` branches locally: `git fetch --prune`
Re:Git: Deletion of merged branches taken beyond shell hacks by lixtra on Thursday August 13, 2020 @12:33PM (#24145198)
Your newly created local branch might be gone as well.
Re:Git: Deletion of merged branches taken beyond shell hacks by spyc on Thursday August 13, 2020 @10:18AM (#24143562)
Careful with "git branch -D" — it's a sharp knife.
Re:Git: Deletion of merged branches taken beyond shell hacks by toastal on Thursday August 13, 2020 @03:08AM (#24140729)
The <() is a Bashism isn't it?
Re:Git: Deletion of merged branches taken beyond shell hacks by spyc on Thursday August 13, 2020 @10:15AM (#24143538)
Yes. See "Process Substitution" in "man bash". It works great, e.g. with diff (or meld):

  # diff -u <(echo $'one\ntwo') <(echo one)
  --- /dev/fd/63  2020-08-13 16:14:44.449379498 +0200
  +++ /dev/fd/62  2020-08-13 16:14:44.450379506 +0200
  @@ -1,2 +1 @@
   one
  -two
Re:Git: Deletion of merged branches taken beyond shell hacks by toastal on Thursday August 13, 2020 @12:10PM (#24144887)
Gotcha. I wanted to know if it was POSIX compliant (it wasn't clear to me last time I looked it up).
Re:Git: Deletion of merged branches taken beyond shell hacks by gravitas on Thursday August 13, 2020 @08:05AM (#24142479)
< is a redirect operator, the out of the item on the right is redirected to the in of the item on the left; () are just grouping operators like math to ensure that bit is self contained inline for the parser.
Re:Git: Deletion of merged branches taken beyond shell hacks by inyourtenement on Thursday August 13, 2020 @11:32AM (#24144396)
That might be a way to remember what it does, but I don't think that's how it works. Try doing `echo <(ls)` to see how it differs. Or, from the manpage:

> Process substitution is supported on systems that support named pipes (FIFOs) or the /dev/fd method of naming open files. It takes the form of <(list) or >(list). The process list is run with its input or output connected to a FIFO or some file in /dev/fd. The name of this file is passed as an argument to the current command as the result of the expansion. If the >(list) form is used, writing to the file will provide input for list. If the <(list) form is used, the file passed as an argument should be read to obtain the output of list.

Re:Git: Deletion of merged branches taken beyond shell hacks by chrisweekly on Wednesday August 12, 2020 @04:31PM (#24136560)
Amazing timing! I was just auditing a colleague's (admittedly fairly well-written) shell script for this purpose. Nice to have this alternative.
Re:Git: Deletion of merged branches taken beyond shell hacks by nhumrich on Wednesday August 12, 2020 @05:37PM (#24137294)
why not just set `git config fetch.prune true`?
Re:Git: Deletion of merged branches taken beyond shell hacks by brown9-2 on Wednesday August 12, 2020 @05:57PM (#24137493)
I don’t think this detects a branch that can be deleted after a squash merge to master
Re:Git: Deletion of merged branches taken beyond shell hacks by nhumrich on Wednesday August 12, 2020 @09:38PM (#24139144)
as long as the remote branch is deleted it does. Both github and gitlab can delete branch on merge
Re:Git: Deletion of merged branches taken beyond shell hacks by spyc on Thursday August 13, 2020 @05:55AM (#24141623)
`git fetch --prune` only deletes remote-tracking branches (`refs/remotes/<remote>/<branch>`) but not local tracking branches (`refs/heads/<branch>`).
Re:Git: Deletion of merged branches taken beyond shell hacks by exabrial on Wednesday August 12, 2020 @04:59PM (#24136905)
requires a python installation which brings a lot of stuff and new vulnerabilities... instead, see the other post about contributing straight to the git project
Re:Git: Deletion of merged branches taken beyond shell hacks by CognitiveLens on Wednesday August 12, 2020 @05:56PM (#24137490)
yeah it's been awhile since I've set up a python-ready environment, and trying to install this reminded me of the challenge of just getting to the expected starting point.

  $ pip install git-delete-merged-branches
  zsh: command not found: pip
  $ brew install pip
  Error: No available formula with the name "pip"
  pip is part of the python formula:
    brew install python
  $ brew install python
  ...
  OK
  $ pip install git-delete-merged-branches
  zsh: command not found: pip
  
  (look up how to install pip)
  $ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
  $ python get-pip.py
  WARNING: The scripts pip, pip2 and pip2.7 are installed in 
  '/Users/{me}/Library/Python/2.7/bin' which is not on PATH.
    Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  Successfully installed pip-20.2.2
  $ pip install git-delete-merged-branches
  zsh: command not found: pip
  (walk away)
I know there are solutions to all this, and it's mainly that I don't already have my $PATH set up the way that pip expects, etc, but really??
Re:Git: Deletion of merged branches taken beyond shell hacks by fuhrysteve on Wednesday August 12, 2020 @06:36PM (#24137879)
To be fair, python isn't the only language whose package management system is all but incoherent to folks who don't use python every day (and sometimes even to them!). npm is pretty rough to get setup too, and you run into a lot of issues similar to this.
Re:Git: Deletion of merged branches taken beyond shell hacks by wonderlg on Wednesday August 12, 2020 @06:44PM (#24137950)
I don’t think Node has trouble from the very first installation. A brew install will set you up with the latest version of both node and npm and they will work.

At most you’ll have trouble running the right version (rare nowadays, unlike in pre-v1 days)

Re:Git: Deletion of merged branches taken beyond shell hacks by viraptor on Wednesday August 12, 2020 @06:43PM (#24137940)
This looks like brew issue more than python. `brew unlink python ; brew link python` may help you.
Re:Git: Deletion of merged branches taken beyond shell hacks by caymanjim on Wednesday August 12, 2020 @07:40PM (#24138405)
Homebrew has always been a hacky abomination. I get that it has made life easier for many people, but MacPorts is so much better. It's basically apt for Macs.

Homebrew used to unilaterally take over /usr/local, and do all sorts of unconventional things. A few years ago it started playing nicer, but at its core, it's eschewing time-honored conventions across the board.

One of the biggest things about Homebrew that is annoying is that it tries to reuse the stock MacOS libraries to avoid installing dependencies. So you end up with things built against ancient broken regex libs, etc.

MacPorts takes longer to install because it does things right. After you install all the MacPorts GNU libraries and utilities, you have a real Unix system that closely resembles Linux, which is what all the development tools expect.

Linux won the Unix war decades ago, whether anyone likes it or not. MacOS's BSD heritage is still causing pain for people today, especially since the core libraries are literally a decade out of date.

Re:Git: Deletion of merged branches taken beyond shell hacks by fouc on Wednesday August 12, 2020 @10:55PM (#24139520)
I've been a long time user of homebrew but lately I've been getting ticked off with the design choices its made.

In particular it will update things and break perfectly fine apps, and then make it hard to revert or downgrade.

I should look into macports or nix or one of the bsd package managers.

Re:Git: Deletion of merged branches taken beyond shell hacks by ilikepi on Wednesday August 12, 2020 @11:59PM (#24139829)
Same. Long ago, I finally got fed up with MacPorts when it insisted on building an entire Perl distribution as a dependency of a package I asked it to install. I found Homebrew, and I was very happy to learn that it offered a way install the same package with an optional flag that disabled the Perl dependency. It reminded me of Portage, the powerful package manager from Gentoo, so I migrated from MacPorts to Homebrew. I happily ran it out of ~/usr/brew for years, which allowed me to trivially clone my entire installation and experiment with potentially destructive operations like major database upgrades.

As Homebrew became more popular, it got more opinionated. The system that supports optional flags is effectively (if not officially) deprecated, and running it outside of /usr/local is unsupported. I recently tried to install a fresh Homebrew in a different custom location (/opt/brew). Many packages require building from source in this scenario, but I accepted that trade-off. I even begrudgingly accepting building an entire Python distribution as a dependency, because I really wanted everything to live under /opt/brew. But no matter what I tried, I could not get any of the modern postgresql packages to build. I burned several multi-hour sessions trying different versions of XCode CLT and alternate build flags. I really wanted to inquire how the maintainers actually manage to build the binary packages in the first place, but my impression from reading Github issues and mailing list posts is that I'd basically be told I was running an unsupported configuration, and that my only recourse would be to create my own formula and run it from a tap. But that finally was a bridge too far (been there done that), so I just gave up and let it make its mess in /usr/local.

I do think I understand why Homebrew has evolved this way. They are trying to support a huge userbase, and they're also subject to Apple's whims with regards to their development tools[1]. It's a massive project every year when new versions of macOS and XCode are released. They have to set limits to keep their sanity. It's just a bummer that I'm considering migrating again...

[1]: https://github.com/Homebrew/brew/pull/4334#issuecomment-4029...

EDIT: remove unnecessary bits; add forgotten link

Re:Git: Deletion of merged branches taken beyond shell hacks by soraminazuki on Wednesday August 12, 2020 @09:21PM (#24139044)
Executables from the Python package aren't placed in $PATH because it clashes with the system-provided one. You have to explicitly add /usr/local/opt/python/libexec/bin in $PATH in order to use Homebrew python and pip. Homebrew warns you when you install packages that have these kinds of gotchas at the last stage of "brew install", so you could've avoided all the hassle if you actually read them. Looking at your command history, you've been using the system Python all along, not the Homebrew one.

Install-time warning message:

https://github.com/Homebrew/homebrew-core/blob/087008a4c8cfb...

Documentation referenced in the message:

https://docs.brew.sh/Homebrew-and-Python

--

Though not mandatory, you'd also want to add the following to your shell config so that you can have things you install with "pip --user" ready in $PATH:

    PATH+="$(/usr/local/opt/libexec/bin/python -c 'import site; print(site.getuserbase())')/bin"
This advice would also apply for Linux, but it's even more important for macOS/Homebrew because otherwise you'd end up messing up /usr/local.
Re:Git: Deletion of merged branches taken beyond shell hacks by mappu on Wednesday August 12, 2020 @07:35PM (#24138346)
And - somehow this installed Python 2 in 2020.
Re:Git: Deletion of merged branches taken beyond shell hacks by soraminazuki on Wednesday August 12, 2020 @09:30PM (#24139104)
No, it doesn't. Parent commenter has been macOS stock Python instead of the Homebrew one.
Re:Git: Deletion of merged branches taken beyond shell hacks by fernandotakai on Wednesday August 12, 2020 @09:26PM (#24139081)
brew's fault. also, pip not being in the path is also brew's fault -- it installs in a non-default location so it doesn't conflict.
Re:Git: Deletion of merged branches taken beyond shell hacks by piahoo on Thursday August 13, 2020 @05:28AM (#24141458)
this script just removed my local, never pushed, never merged branch
Re:Git: Deletion of merged branches taken beyond shell hacks by spyc on Thursday August 13, 2020 @10:10AM (#24143498)
Which script are you referring to?