post-checkout hook breaks checkout and rebase when adopting DVC in a branch
See original GitHub issueWhen adopting DVC in an existing repository with PR code-review workflow, it will be landing in a branch that isn’t master. This branch then has problematic interactions where work continues on master before the dvc adoption lands there.
Specifically, once you’ve done dvc init
, committed that, and then dvc install
, the post-checkout hook breaks git checkout
and git rebase
between the master branch and the adopting-dvc branch.
To reproduce:
mkdir dvc-test
cd dvc-test
git init
echo "Testing" > README.md
git add README.md
git commit -m "Initial commit"
git checkout -b start-using-dvc
dvc init
git commit -m "dvc init"
dvc install
I go on experimenting with dvc, but then I have to pause the dvc adoption to do some work on the master branch.:
git stash save "experimenting with dvc"
git checkout master
This last command succeeds but outputs:
Switched to branch 'master'
Adding '.dvc/state' to '.dvc/.gitignore'.
Adding '.dvc/lock' to '.dvc/.gitignore'.
Adding '.dvc/config.local' to '.dvc/.gitignore'.
Adding '.dvc/updater' to '.dvc/.gitignore'.
Adding '.dvc/updater.lock' to '.dvc/.gitignore'.
Adding '.dvc/repos' to '.dvc/.gitignore'.
Adding '.dvc/state-journal' to '.dvc/.gitignore'.
Adding '.dvc/state-wal' to '.dvc/.gitignore'.
Adding '.dvc/cache' to '.dvc/.gitignore'.
… uh-oh. I’m on master where dvc hasn’t been taken into use, so I (or my tooling) shouldn’t be putting anything in .dvc
.
I continue with the master work and then return to DVC:
echo "Progress" > README.md
git commit README.md -m "Progress"
git checkout start-using-dvc
That last command fails with:
error: The following untracked working tree files would be overwritten by checkout:
.dvc/.gitignore
Please move or remove them before you switch branches.
Aborting
… which is not normal in git; with a clean working tree, git checkout
to switch branches should always work.
I workaround this and want to keep going, rebasing my dvc experiment branch on current tip of master:
rm .dvc/.gitignore
git checkout start-using-dvc
git rebase master
That rebase fails with:
First, rewinding head to replay your work on top of it...
Adding '.dvc/state' to '.dvc/.gitignore'.
Adding '.dvc/lock' to '.dvc/.gitignore'.
Adding '.dvc/config.local' to '.dvc/.gitignore'.
Adding '.dvc/updater' to '.dvc/.gitignore'.
Adding '.dvc/updater.lock' to '.dvc/.gitignore'.
Adding '.dvc/repos' to '.dvc/.gitignore'.
Adding '.dvc/state-journal' to '.dvc/.gitignore'.
Adding '.dvc/state-wal' to '.dvc/.gitignore'.
Adding '.dvc/cache' to '.dvc/.gitignore'.
Applying: dvc init
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
error: The following untracked working tree files would be overwritten by merge:
.dvc/.gitignore
Please move or remove them before you merge.
Aborting
error: Failed to merge in the changes.
Patch failed at 0001 dvc init
hint: Use 'git am --show-current-patch' to see the failed patch
Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".
Deleting the post-checkout hook makes the rebase work just fine:
rm .git/hooks/post-checkout
git rebase master
So probably the post-checkout hook should abort with an informative message if you’re on a branch where dvc hasn’t been adopted. Not sure whether that check is as simple as checking existence of .dvc
or whether that breaks other legitimate uses of the hook.
My dvc --version
is 0.50.1, installed with homebrew (brew cask
).
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (10 by maintainers)
Ah, whoops, sorry, you should take it as “away on vacation and not paying much attention” 😃 … I can whip up a simple PR when I’m back home next weekend.
On Mon, Jul 22, 2019, 23:31 Ruslan Kuprieiev notifications@github.com wrote:
@gthb We would really appreciate that 🙂 Have a great vacation!