tummychow / git-absorb

git commit --fixup, but automatic
https://crates.io/crates/git-absorb
BSD 3-Clause "New" or "Revised" License
3.39k stars 58 forks source link

Hides commits from downstream branches #9

Open Nemo157 opened 5 years ago

Nemo157 commented 5 years ago

I have the current commit tree in my repository

* f2a4584 (min-version) Get min versions build working
* 5261bac (origin/all-the-ci) Cirrus CI
* 3ca1ca4 Circle CI
* a2e3d45 (HEAD -> travis, origin/travis) Fix clippy issues in tests
* c85d370 cargo fmt, again
* 37b490a Add travis config
* 8ea0653 (origin/master, origin/HEAD) Merge pull request #4 from Nemo157/fixes

I have changed the .travis.yml file and staged it, which should be absorbed into 37b490a, running git-absorb -v -n gives

Feb 09 17:23:06.222 DEBG repository found, path: /Users/nemo157/sources/cbor-diag-rs/.git/, line: 22, module: git_absorb
Feb 09 17:23:06.223 DEBG head found, head: refs/heads/travis, line: 26, module: git_absorb::stack
Feb 09 17:23:06.224 DEBG head pushed, head: refs/heads/travis, line: 35, module: git_absorb::stack
Feb 09 17:23:06.224 DEBG branch hidden, branch: refs/heads/fixes, line: 48, module: git_absorb::stack
Feb 09 17:23:06.225 DEBG branch hidden, branch: refs/heads/master, line: 48, module: git_absorb::stack
Feb 09 17:23:06.225 DEBG branch hidden, branch: refs/heads/min-version, line: 48, module: git_absorb::stack
Feb 09 17:23:06.225 DEBG branch not hidden, branch: refs/heads/travis, line: 51, module: git_absorb::stack
Feb 09 17:23:06.229 DEBG commuting hunk, header: -26,5 +25,0, path: .travis.yml, line: 93, module: git_absorb
Feb 09 17:23:06.230 DEBG could not find noncommutative commit, line: 156, module: git_absorb

Because it has hidden commits from min-version, a downstream branch from the one I'm currently fixing up, there are no commits available to absorb the change into. Deleting min-version and running git absorb -v -n again gives:

Feb 09 17:23:41.229 DEBG repository found, path: /Users/nemo157/sources/cbor-diag-rs/.git/, line: 22, module: git_absorb
Feb 09 17:23:41.230 DEBG head found, head: refs/heads/travis, line: 26, module: git_absorb::stack
Feb 09 17:23:41.231 DEBG head pushed, head: refs/heads/travis, line: 35, module: git_absorb::stack
Feb 09 17:23:41.232 DEBG branch hidden, branch: refs/heads/fixes, line: 48, module: git_absorb::stack
Feb 09 17:23:41.232 DEBG branch hidden, branch: refs/heads/master, line: 48, module: git_absorb::stack
Feb 09 17:23:41.232 DEBG branch not hidden, branch: refs/heads/travis, line: 51, module: git_absorb::stack
Feb 09 17:23:41.234 DEBG commit pushed onto stack, commit: a2e3d45c498c4693c2197b8125d98f5e65e93cf0, line: 75, module: git_absorb::stack
Feb 09 17:23:41.235 DEBG commit pushed onto stack, commit: c85d370703849bf12196e91b78cb410fc14e057e, line: 75, module: git_absorb::stack
Feb 09 17:23:41.236 DEBG commit pushed onto stack, commit: 37b490a805ca4b94ba68f88acb2347cdbc76ea0f, line: 75, module: git_absorb::stack
Feb 09 17:23:41.237 WARN merge commit found, commit: 8ea0653e9d2e1a83f48a3aefa15424bbe09352ef, line: 62, module: git_absorb::stack
Feb 09 17:23:41.249 DEBG commuting hunk, header: -26,5 +25,0, path: .travis.yml, line: 93, module: git_absorb
Feb 09 17:23:41.249 DEBG skipped commit with no path, commit: a2e3d45c498c4693c2197b8125d98f5e65e93cf0, line: 117, module: git_absorb
Feb 09 17:23:41.250 DEBG skipped commit with no path, commit: c85d370703849bf12196e91b78cb410fc14e057e, line: 117, module: git_absorb
Feb 09 17:23:41.250 DEBG found noncommutative commit by add, commit: 37b490a805ca4b94ba68f88acb2347cdbc76ea0f, line: 122, module: git_absorb
Feb 09 17:23:41.251 INFO would have committed, header: -26,5 +25,0, fixup: Add travis config, line: 185, module: git_absorb

I'm not sure of the best solution here to support all usecases, I think personally what I would want is for git-absorb to walk down the first parent line from the current commit until it encounters any branch (local or remote) and hide commits from that point, you might notice I don't use a local master branch so the current behaviour of only hiding local branches would fail to correctly identify the point at which to stop anyway.

(EDIT: Sorry, accidentally submitted this with an old issue I was writing before I managed to debug where this was actually going wrong)

Nemo157 commented 5 years ago

(For now I'm working around this with an alias abs = absorb -b origin/HEAD which should cover most of my uses correctly)

tummychow commented 5 years ago

hmm, very interesting. just to make sure i understand - that commit tree you mentioned, it's a linear sequence? you have travis checked out right now, but you also have local branches that are descendants of travis, so git-absorb hides those branches from the commit stack and there's nothing to commute into.

let me noodle on this a bit. i think you have at least two (non-mutually-exclusive) suggestions that are interesting here:

Nemo157 commented 5 years ago

that commit tree you mentioned, it's a linear sequence? you have travis checked out right now, but you also have local branches that are descendants of travis, so git-absorb hides those branches from the commit stack and there's nothing to commute into.

Yep