Skip to content
This repository was archived by the owner on Jun 25, 2020. It is now read-only.

Refresh Git index prior to fast-forward. - #144

Merged
clalancette merged 2 commits into
vcstools:masterfrom
magazino:refresh-index
Feb 5, 2019
Merged

clalancette merged 2 commits into
vcstools:masterfrom
magazino:refresh-index

Conversation

@MichaelGrupp

Copy link
Copy Markdown
Contributor

Fixes vcstools/wstool#77, see the discussion
there for more context.

Fixes vcstools/wstool#77, see the discussion
there for more context.
Comment thread src/vcstools/git.py Outdated
return True
print("Cannot fast-forward, local repository and remote '%s' have diverged." % branch_parent)
return False
# Refresh the index manually, just as 'git pull' does it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment here should explain why, or link to github issue at least.

@MichaelGrupp

Copy link
Copy Markdown
Contributor Author

@tkruse Looks like some (unrelated?) "tar" test on Travis failed to download some stuff, maybe you need to restart that build.

@tkruse

tkruse commented Oct 6, 2018 •

Copy link
Copy Markdown
Contributor

Test failure probably caused by #141

@MichaelGrupp

Copy link
Copy Markdown
Contributor Author

Any update?

@130s

130s commented Dec 27, 2018

Copy link
Copy Markdown

Like I mentioned in #141 (comment), the issue this PR tries to solve causes my team an issue almost everyday (requires manually workaround). It'd be great this merges in and new release will be made soon.

CI is failing. As suggested at #144 (comment), #141 might have to be processed first (I'm not sure though)?

If any help is needed I'm willing to provide just in general for maintenance BTW (I've been comfortably making releases into ROS for years, although never done ROS-standalone package like vcstools).

@130s

130s commented Jan 8, 2019

Copy link
Copy Markdown

#141 is merged. Can any admin (@tfoote / @clalancette) restart Travis CI?

@tfoote

tfoote commented Jan 8, 2019

Copy link
Copy Markdown
Contributor

reran travis

@MichaelGrupp

Copy link
Copy Markdown
Contributor Author

Travis is happy

@130s

130s commented Jan 9, 2019

Copy link
Copy Markdown

Please review @tkruse / @tfoote / @clalancette.

@130s 130s mentioned this pull request Jan 9, 2019
2 tasks done
@tkruse

tkruse commented Jan 10, 2019

Copy link
Copy Markdown
Contributor

I can reproduce a similar issue like this (changing file permissions before git reset keep, and changing them back):

cd /tmp
git init parent
cd parent/
touch foo.txt
git add foo.txt 
git commit -m foo
cd ..
git clone parent child
cd parent
echo 'hello' > foo.txt 
git add foo.txt 
git commit -m foo2
cd ../child/
chmod u+x foo.txt 
git fetch
git reset --keep remotes/origin/master # Error
chmod u-x foo.txt 
git reset --keep remotes/origin/master # still Error
git update-index -q --refresh
git reset --keep remotes/origin/master # works

Not sure what else can cause the index to go stale like that in the wild (https://stackoverflow.com/questions/1248029/git-pull-error-entry-foo-not-uptodate-cannot-merge suggests filename case on Mac could cause this. https://stackoverflow.com/questions/878554/why-do-i-sometimes-see-an-entry-filename-not-uptodate-cannot-merge-after-a/878742 also mentions this error happens spuriously).

I think the unit tests should be extended with the flow above, even if there is some risk that it cannot be reproduced with all git versions (in that case, tests should be run only for one git version known to reproduce the issue).

Another question to consider here is whether git update-index -q --refresh can fail in some situation where we don't want it to fail, or has other undesired side-effects. I think the unit tests protect us mostly from the first, and from the description I believe --refresh should not have undesired side-effects. There is also --really-refresh, but I believe that's not what we want.

@tkruse

tkruse commented Jan 15, 2019

Copy link
Copy Markdown
Contributor

This is really nasty to reproduce in tests. I automated these steps:

chmod u+x modified.txt
git reset --keep remotes/origin/master # error
sleep 1
chmod u-x modified.txt
git reset --keep remotes/origin/master # error again, but only if slept

And the second call to git only fails if I gave the first call to git reset --keep a second to do something unknown in the background. If I remove the sleep, the second call succeeds 9 out of 10 times or so.

In case someone else wants to retry this, here is the test source (to be added to test_git.py, run with nosetests test/test_git.py:GitClientUpdateStaleTest.test_update_stale_index

class GitClientUpdateStaleTest(GitClientTestSetups):

    @classmethod
    def setUpClass(self):
        GitClientTestSetups.setUpClass()
        # modify modified.txt on remote
        f = io.open(os.path.join(self.remote_path, "modified.txt"), 'a')
        f.write('0123456789abcdef')
        f.close()
        subprocess.check_call("git add modified.txt", shell=True, cwd=self.remote_path)
        subprocess.check_call("git commit -m modified", shell=True, cwd=self.remote_path)
    
    def test_update_stale_index(self):
        import sys, time
        client = GitClient(self.local_path)
        client.checkout(self.remote_path, self.readonly_version)
        subprocess.check_call("git co master", shell=True, cwd=self.local_path)
        subprocess.check_call("git reset --hard HEAD~1", shell=True, cwd=self.local_path)
        subprocess.check_call("chmod u+x modified.txt", shell=True, cwd=self.local_path)
        po = subprocess.Popen("git reset --keep remotes/origin/master", shell=True, cwd=self.local_path, stdout=subprocess.PIPE)
        po.communicate()
        self.assertEquals(128, po.returncode)
        # self.assertFalse(client.update())
        time.sleep(1)
        subprocess.check_call("chmod u-x modified.txt", shell=True, cwd=self.local_path)
        # still fails due to git quirk
        po = subprocess.Popen("git reset --keep remotes/origin/master", shell=True, cwd=self.local_path, stdout=subprocess.PIPE)
        po.communicate()
        self.assertEquals(128, po.returncode)
        self.assertTrue(client.update())

I'll report to git mailing list just in case. For these tests, not sure if its better to not have tests or to have a brittle test. I can't find a way to smartly wait for whatever needs to finish to reproduce the problem.

@MichaelGrupp

MichaelGrupp commented Jan 15, 2019 •

Copy link
Copy Markdown
Contributor Author

@tkruse Thanks for looking deeper into this. I'm also not sure if it's a git bug or just something that one has to know/resolve manually when using such low-level plumbing commands. I believe high-level commands like git merge refresh the index implicitly for a reason (e.g.: https://github.com/git/git/blob/ecbdaf0899161c067986e9d9d564586d4b045d62/builtin/merge.c#L688)


One nit: I would use full commands like git checkout instead of aliases like git co in your test sample.

@tkruse

tkruse commented Jan 15, 2019

Copy link
Copy Markdown
Contributor

Feel free to ask for merge in any case, I have no strong objection even without more tests.

I would be happy to accept the git behavior as normal low-level plumbing lacking a refresh step, but since it seems to have an asynchronous one that causes race conditions, I am not sure. We'll see if anyone answers https://marc.info/?l=git&m=154755707120508&w=2

@MichaelGrupp

Copy link
Copy Markdown
Contributor Author

Feel free to merge, especially since several people already complained.

@MichaelGrupp

Copy link
Copy Markdown
Contributor Author

Also, this should trigger a new wstool release soon. For anyone that is blocked by the missing index refresh, just calling wstool status is a workaround. I did this here for example: cartographer-project/cartographer_ros@8fab3fe

@130s

130s commented Jan 21, 2019

Copy link
Copy Markdown

@tfoote @clalancette Please review. @tkruse seems to have approved this at #144 (comment)

@tfoote tfoote left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this lgtm

@clalancette
clalancette merged commit 88e7065 into vcstools:master Feb 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants