0

I'm definitely missing something about how to use hg blame.

I have a particular line in a file Foo.csproj that is suspicious and I want to see who modified it. According to other answers this should be a matter of hg blame Foo.csproj, maybe hg blame -unl Foo.csproj.

Either one of these returns to me

abort: Foo.csproj: no such file in rev xxxxx

I've tried with fully qualified paths and not. What's going on? Am I using the feature wrong? What is it meant for? How do I find out what I want to find out (the last person to modify line 1700 of that file).

Note, that while I'm interested in how this is done in Sourcetree, and TortoiseHg, and I'm sure others might be interested as well, I specifically want to know how to do this with the command line client.

Community
  • 1
  • 1
George Mauer
  • 117,483
  • 131
  • 382
  • 612
  • Can you be more specific about the commands you're using and the pwd at the time you are using them. [File names used in a blame command line are relative to the cwd of the shell.] – John Jefferies Dec 21 '14 at 13:35
  • @JohnJefferies as I said, I've tried many variations, but this is the one I was most sure should work `W:\surge\ogre> hg blame -uln w:\surge\ogre\ogre\Ogre.Web.csproj`. I've also tried `.\ogre\ogre.web.csproj`, `ogre\ogre.web.csproj` and just `ogre.web.csproj`. I'm on windows btw. The repository root is in `w:\surge\ogre` (where I currently am), but I've tried it from the same directory as the file too to no avail. – George Mauer Dec 21 '14 at 15:16
  • In that case we have to flail around a bit trying to work out why you are being picked on, because blame does work (including on Windows). Have you tried other repos? It may be that the one repo is corrupt for some reason. – John Jefferies Dec 21 '14 at 22:27
  • @JohnJefferies so you're saying that I am indeed using it correctly? Do you know what command TortoiseHg's "annotate line number" runs by any chance? I was able to get my answer through the tortoise ui, though that really doesn't address the underlying issue or give me confidence that I can replicate the solution. – George Mauer Dec 21 '14 at 22:37
  • I don't know the exact command line tortoise does, but it appears to be "hg blame -ln -r xxx file" where file is relative to the repo's directory, and the rev number does make a difference. If the rev doesn't have the file in question you will see the error you report. [If a line has been through several revisions and you want to see who to blame for the previous revision, the blame command should be repeated with the rev number prior to the one reported by blame. Ad nauseam.] – John Jefferies Dec 21 '14 at 23:46
  • I see, so it sounds like you're saying that I'm *not* using blame correctly. That you have to specify the revision, file, and line you're talking about, and blame merely tells you whether it's in that revset or not. – George Mauer Dec 22 '14 at 04:35
  • hg blame lists all lines in the file, the -l option merely tells blame to emit the line number at the start of each line. You don't have to specify the rev number, but the parent of the working directory will be assumed if you don't. So, taking a step back, is your file in the current working revision; does it show in "hg manifest | grep " – John Jefferies Dec 22 '14 at 09:42
  • No. The file has not been recently modified, I just noticed the change and I wanted to find out who did it. Is that not what blame is for? It does show up in `hg manifest`. – George Mauer Dec 22 '14 at 15:43

1 Answers1

3

Blame works exactly like you'd expect and your sample commands are correct, so I suspect you're running into something tricky. Here's an example of the normal case:

ry4an@four:~$ hg init GeorgeMauer
ry4an@four:~$ cd GeorgeMauer/
ry4an@four:~/GeorgeMauer$ echo test > afile.txt

ry4an@four:~/GeorgeMauer$ hg commit -Am first --user George
adding afile.txt
ry4an@four:~/GeorgeMauer$ echo more test >> afile.txt 
ry4an@four:~/GeorgeMauer$ hg commit -m second --user Other
ry4an@four:~/GeorgeMauer$ hg blame afile.txt
0: test
1: more test
ry4an@four:~/GeorgeMauer$ hg blame -u afile.txt
George: test
 Other: more test
ry4an@four:~/GeorgeMauer$

Is it possible that you're running afoul of the hideous "case-insensitive, but case-retentive" properties of Windows (and Mac) default file systems?

Try hg manifest to make sure the case of the filename you're providing is what's recorded in the repo, which may be different from the file you have on disk. For the example above mine looks like:

ry4an@four:~/GeorgeMauer$ hg manifest
afile.txt

If yours includes, for example, foo.csproj then that's how you have to ask about it.

The error message you're getting is the one you see when you ask about a file that's not in your repository:

ry4an@four:~/GeorgeMauer$ hg blame filedoesnotexist
abort: filedoesnotexist: no such file in rev 72a94e6fe429

So either it was never added and committed or, more likely, you're calling it by its wrong name.

Ry4an Brase
  • 78,112
  • 7
  • 148
  • 169