question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

post-checkout hook breaks checkout and rebase when adopting DVC in a branch

See original GitHub issue

When 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:closed
  • Created 4 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
gthbcommented, Jul 24, 2019

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 https://github.com/gthb Not sure if the message got lost or if I should take this as “no” 😃

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/iterative/dvc/issues/2208?email_source=notifications&email_token=AABFP3HVQOQAZ665CT3GTWTQAY7M5A5CNFSM4H4GTSKKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2ROSZQ#issuecomment-513993062, or mute the thread https://github.com/notifications/unsubscribe-auth/AABFP3HERHVVK3TS5E7DQG3QAY7M5ANCNFSM4H4GTSKA .

1reaction
efiopcommented, Jul 24, 2019

@gthb We would really appreciate that 🙂 Have a great vacation!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Weird behavior with git post-checkout hook and rebase
When I remove the git rebase from the hook and manually do rebase after the checkout, the rebase succeeds without any issues.
Read more >
install | Data Version Control - DVC
A post-checkout hook executes dvc checkout after git checkout to automatically update the workspace with the correct data file versions. A pre-commit hook...
Read more >
Git Hooks | Atlassian Git Tutorial
Git Hooks are scripts that run automatically every time a particular event occurs in a Git repository. Learn what they do and how...
Read more >
How to Use Git Hooks for Shift Left on Continuous Integration
git/hooks” folder, which is a hidden file in my repository. I checkout a branch from the Master according to the branch name I...
Read more >
Elevate your automation game by using Git Hooks - Medium
Again, we'll want to make use of the post-checkout hook. We need to: Determine when a new branch is created; Read the current/master ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found