4729: rbtools 1.0 has problems finding the correct object hashes in git repos

pprkut

What version are you running?

RBTools 1.0, also happens on a different system (Arch Linux) with 1.0.1

What steps will reproduce the problem?

  1. rbt post -sg

What is the expected output? What do you see instead?

Diff posted to reviewboard

What operating system are you using?

Fedora 28

Attach the debug out from the command.

```
rbt post -sg --parent=master --tracking-branch=master --debug

RBTools 1.0
Python 3.6.6 (default, Jul 19 2018, 14:25:17)
[GCC 8.1.1 20180712 (Red Hat 8.1.1-5)]
Running on Linux-4.17.11-200.fc28.x86_64-x86_64-with-fedora-28-Twenty_Eight
Home = /home/mathijs
Current directory = /home/mathijs/m2mobi/lunr
Command line: rbt post -sg --parent=master --tracking-branch=master --debug
Running: tf vc help
Checking for a Bazaar repository...
Unable to execute "bzr help": skipping Bazaar
Checking for a ClearCase repository...
Unable to execute "cleartool help": skipping ClearCase
Checking for a CVS repository...
Unable to execute "cvs": skipping CVS
Checking for a Git repository...
Running: git rev-parse --git-dir
Running: git config core.bare
Running: git rev-parse --show-toplevel
Running: git symbolic-ref -q HEAD
Running: git config --get branch.feature-delete-returning.merge
Running: git config --get branch.feature-delete-returning.remote
Running: git config --get remote.master.url
Command exited with rc 1: ['git', 'config', '--get', 'remote.master.url']


Running: git config --get remote.master.url
Command exited with rc 1: ['git', 'config', '--get', 'remote.master.url']


Repository info: Path: /home/mathijs/m2mobi/lunr/.git, Base path: , Supports changesets: False
Checking for a Mercurial repository...
Unable to execute "hg --help": skipping Mercurial
Checking for a Perforce repository...
Unable to execute "p4 help": skipping Perforce
Checking for a Plastic repository...
Unable to execute "cm version": skipping Plastic
Checking for a Subversion repository...
Unable to execute "svn help": skipping SVN
Checking for a Team Foundation Server repository...
Unable to execute "tf help": skipping TFS
Making HTTP GET request to http://reviews.lunr.nl/api/
Running: git config --get remote.master.url
Command exited with rc 1: ['git', 'config', '--get', 'remote.master.url']


Running: git rev-parse refs/heads/feature-delete-returning
Running: git rev-list f7fdf7e08b82e7eeac061d7a3c6daed13268d104 --not --remotes=origin
Running: git rev-parse master
Running: git status --porcelain --untracked-files=no --ignore-submodules=dirty
Running: git version
Running: git -c core.quotepath=false -c diff.noprefix=false diff --no-color --full-index --ignore-submodules -M --no-ext-diff 1dd7281ef5bf3b2eed52029bc9813c7dfd98f0a5..f7fdf7e08b82e7eeac061d7a3c6daed13268d104
Running: git -c core.quotepath=false -c diff.noprefix=false diff --no-color --full-index --ignore-submodules -M --no-ext-diff f7fdf7e08b82e7eeac061d7a3c6daed13268d104..1dd7281ef5bf3b2eed52029bc9813c7dfd98f0a5
Generated diff size: 4475 bytes
Generated parent diff size: 4475 bytes
Making HTTP GET request to https://reviews.lunr.nl/api/validation/diffs/
Cached response for HTTP GET https://reviews.lunr.nl/api/validation/diffs/ expired and was modified
Making HTTP POST request to https://reviews.lunr.nl/api/validation/diffs/
Got API Error 207 (HTTP code 400): The file was not found in the repository.
Error data: {'stat': 'fail', 'err': {'msg': 'The file was not found in the repository.', 'code': 207}, 'file': 'src/Lunr/Gravity/Database/DatabaseDMLQueryBuilder.php', 'revision': 'a004e9af0e2ad775284d57652222e3c0e5c77c82'}
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/rbtools/api/request.py", line 601, in make_request
request.url, body, headers, request.method))
File "/usr/lib/python3.6/site-packages/rbtools/api/cache.py", line 209, in make_request
return self.urlopen(request)
File "/usr/lib64/python3.6/urllib/request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib64/python3.6/urllib/request.py", line 532, in open
response = meth(req, response)
File "/usr/lib/python3.6/site-packages/rbtools/api/request.py", line 239, in http_response
response.info())
File "/usr/lib64/python3.6/urllib/request.py", line 570, in error
return self._call_chain(args)
File "/usr/lib64/python3.6/urllib/request.py", line 504, in _call_chain
result = func(
args)
File "/usr/lib64/python3.6/urllib/request.py", line 650, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: BAD REQUEST

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/rbtools/commands/post.py", line 867, in main
validate_kwargs)
File "/usr/lib/python3.6/site-packages/rbtools/api/decorators.py", line 27, in request_method
*args,
kwargs)
File "/usr/lib/python3.6/site-packages/rbtools/api/transport/sync.py", line 77, in execute_request_method
return self._execute_request(request)
File "/usr/lib/python3.6/site-packages/rbtools/api/transport/sync.py", line 86, in _execute_request
rsp = self.server.make_request(request)
File "/usr/lib/python3.6/site-packages/rbtools/api/request.py", line 603, in make_request
self.process_error(e.code, e.read())
File "/usr/lib/python3.6/site-packages/rbtools/api/request.py", line 577, in process_error
rsp['err']['msg'])
rbtools.api.errors.BadRequestError: The file was not found in the repository. (HTTP 400, API Error 207)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/bin/rbt", line 11, in <module>
load_entry_point('RBTools==1.0', 'console_scripts', 'rbt')()
File "/usr/lib/python3.6/site-packages/rbtools/commands/main.py", line 120, in main
command.run_from_argv([RB_MAIN, command_name] + args)
File "/usr/lib/python3.6/site-packages/rbtools/commands/init.py", line 720, in run_from_argv
exit_code = self.main(*args) or 0
File "/usr/lib/python3.6/site-packages/rbtools/commands/post.py", line 875, in main
(msg_prefix, e))
rbtools.commands.CommandError: Error validating diff

src/Lunr/Gravity/Database/DatabaseDMLQueryBuilder.php: The file was not found in the repository. (HTTP 400, API Error 207)```

Please provide any additional information below.

This happens regularly, although it's not really reproduceable. It looks like rbt post has a problem identifying the right object hash for some files. The hash in question here (a004e9af0e2ad775284d57652222e3c0e5c77c82) is present in the local repo, but it's the hash of the file with the diff already applied, not the one from master (which explains why it's not found in the main repo).

If I read the diff generation correctly, it also looks like it creates two diffs, where the second completely reverts the first. The diff also seems to be created based on the wrong branch.

1dd7281ef5bf3b2eed52029bc9813c7dfd98f0a5 is master
f7fdf7e08b82e7eeac061d7a3c6daed13268d104 is the remote tracking branch

but the locally checked out branch has a different hash. It shouldn't even check the remote tracking branch though, since I'm overriding that on the command line (--tracking-branch=master).

tardypad
#1 tardypad

I encounter the same issue regularly on my environment too without being able to clearly identify what leads to it
I seems to happen after doing some rebasing but not always

I ran a git bisect the last time it happened, which resulted in the culprit being the commit https://github.com/reviewboard/rbtools/commit/659203b0e2ce1aec034067fa8e74cafe192fa134
This commit was written 2 years ago but was not present indeed in the releases until the 1.x ones