Code Monkey home page Code Monkey logo

git-delete-squashed's People

Contributors

colonelpopcorn avatar not-an-aardvark avatar prgtw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

git-delete-squashed's Issues

[feature request] --dry-run option

Hi! Thanks for this ๐Ÿ˜„. I would love to see a --dry-run option so that I can see what will be deleted before going ahead. Would that be feasible?

Npm release is outdated

The version on npm is outdated and isn't updated with the latest change that allows branch name specification. Manual clone and install works but not everyone will know that. Can we have an NPM update?

"[[ not found" using bash

i added this git alias, per docs:

$ git config --global alias.delete-squashed '!f() { local targetBranch=${1:-main} && git checkout -q $targetBranch && git branch --merged | grep -v "\*" | xargs -n 1 git branch -d && git for-each-ref refs/heads/ "--format=%(refname:short)" | while read branch; do mergeBase=$(git merge-base $targetBranch $branch) && [[ $(git cherry $targetBranch $(git commit-tree $(git rev-parse $branch^{tree}) -p $mergeBase -m _)) == "-"* ]] && git branch -D $branch; done; }; f' with bin/bash 

But it's failing for some branches, probably since [[ is disabled when run as sh.

git delete-squashed 
Deleted branch my-branch (was d7be4206).
f() { local targetBranch=${1:-main} && git checkout -q $targetBranch && git branch --merged | grep -v "\*" | xargs -n 1 git branch -d && git for-each-ref refs/heads/ "--format=%(refname:short)" | while read branch; do mergeBase=$(git merge-base $targetBranch $branch) && [[ $(git cherry $targetBranch $(git commit-tree $(git rev-parse $branch^{tree}) -p $mergeBase -m _)) == "-"* ]] && git branch -D $branch; done; }; f: 1: [[: not found
f() { local targetBranch=${1:-main} && git checkout -q $targetBranch && git branch --merged | grep -v "\*" | xargs -n 1 git branch -d && git for-each-ref refs/heads/ "--format=%(refname:short)" | while read branch; do mergeBase=$(git merge-base $targetBranch $branch) && [[ $(git cherry $targetBranch $(git commit-tree $(git rev-parse $branch^{tree}) -p $mergeBase -m _)) == "-"* ]] && git branch -D $branch; done; }; f: 1: [[: not found
f() { local targetBranch=${1:-main} && git checkout -q $targetBranch && git branch --merged | grep -v "\*" | xargs -n 1 git branch -d && git for-each-ref refs/heads/ "--format=%(refname:short)" | while read branch; do mergeBase=$(git merge-base $targetBranch $branch) && [[ $(git cherry $targetBranch $(git commit-tree $(git rev-parse $branch^{tree}) -p $mergeBase -m _)) == "-"* ]] && git branch -D $branch; done; }; f: 1: [[: not found

Using Ubuntu 22.04 (bin/bash).

Add merge checks.

I had to run the npm test/npm run lint script manually to catch errors. It would be good if there was a CI step to run this check on each pull request.

EAGAIN error when running on a very large repository

Running this on a very large repository (hundreds of thousands of commits) results in an EAGAIN error from spawning a process. This is probably because git-delete-squashed exceeds the user process limit from spawning so many parallel git processes.

There are a few potential ways to solve this:

  1. Throttle the git processes so that only a limited number can exist at a time
  2. Batch the queries somehow (not sure whether this is possible with git)
  3. Get the git data from the filesystem manually and/or with the help of a library, and stop spawning git processes at all. (This would also improve performance because there wouldn't be so much process overhead.)

Allow customizable branch name

Some repos now use the name main instead of master. This project seems to assume that the primary branch is named master. I'd like to request that the name of the primary branch be customizable.

For example:

$ git-delete-squashed --into main
$ git-delete-squashed --into primary
$ git-delete-squashed --into dev

EAGAIN error

possibly related to #1

When I run this tool via node on a big repo, I'm getting EAGAIN error on git rev-parse or merge-base

Error is like below (branch name is different every time I run the command)

git-delete-squashed
events.js:377
      throw er; // Unhandled 'error' event
      ^

Error: spawn git EAGAIN
    at Process.ChildProcess._handle.onexit (internal/child_process.js:274:19)
    at onErrorNT (internal/child_process.js:469:16)
    at processTicksAndRejections (internal/process/task_queues.js:82:21)
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:280:12)
    at onErrorNT (internal/child_process.js:469:16)
    at processTicksAndRejections (internal/process/task_queues.js:82:21) {
  errno: -35,
  code: 'EAGAIN',
  syscall: 'spawn git',
  path: 'git',
  spawnargs: [ 'merge-base', 'master', 'mynicebranch' ]
}

Crash when master contains a new root commit

If a merge commit has been applied to master since a local branch was created, and the parents in the merge commit have no common ancestors (e.g. after a subtree merge), git-delete-squashed crashes with an error:

fatal: ambiguous argument 'aaaaaaa^': unknown revision or path not in the working tree.

(where aaaaaaa is the commit hash of the root commit from the merged branch).

Doesn't work when a branch contains commits that have been applied in more than one merge

For example:

  1. I make a branch "develop-B" which is branched off "develop-A"
  2. "develop-A" is squash-merged into main branch
  3. "develop-B" is squash-merged into main branch

Now the approach this script uses (git cherry) fails because there is not a single commit that matches the squashed commit representing "develop-B", it's spread across two commits.

I think that it's possible to fix this and simplify the script by using git merge-tree and git merge-base. Here's an example: https://github.com/ggilder/dotfiles/blob/master/bin/git-delete-merged-branches#L9

Invalid objects on ZSH

Get the following error:

zsh: no matches found: master^e
fatal: 200af0b2ff7f00000000000000000000200af0b2 is not a valid object
zsh: no matches found: rick-jones^e
fatal: 1075c4a1fe7f000000000000000000001075c4a1 is not a valid object
zsh: no matches found: rickjones/ch3576/create-ruby-client-library^e
fatal: 006bf092fd7f00000000000000000000006bf092 is not a valid object
zsh: no matches found: rickjones/ch3759/create-endpoints-on-payment-service-for-new^e
fatal: f0e65a70ff7f00000000000000000000f0e65a70 is not a valid object
zsh: no matches found: rickjones/ch4459/extend-ruby-client-to-fetch-loan-information^e
fatal: 10f0d693fe7f0000000000000000000010f0d693 is not a valid object
zsh: no matches found: rickjones/ch4477/fix-create-cbpf-loan^e
fatal: a054e4d4fe7f00000000000000000000a054e4d4 is not a valid object
zsh: no matches found: rickjones/ch4506/make-create-loan-rate-dynamic^e
fatal: 20c79a2bfc7f0000000000000000000020c79a2b is not a valid object

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.