0

I am using below code in PowerShell. Unfortunately it is not picking up $Startinghash and $lastHash value. If I pass value directly, code is working fine.

Not Working :-

$StartingHash = "f116bcce5cc0701cb0b5a673bc4ce9f723050f04"
$LastHash = "2870d215c7201e7cf65c71d4d0e732078b3bda31"

git log --pretty=format: --name-only $StartingHash..$LastHash | sort | uniq | grep -i '".sql"' > C:\Ashish\data\sqlRB.txt 

Working :-

git log --pretty=format: --name-only f116bcce5cc0701cb0b5a673bc4ce9f723050f04..2870d215c7201e7cf65c71d4d0e732078b3bda31 | sort | uniq | grep -i '".sql"' > C:\Ashish\data\sqlRB.txt

I think somehow variable value is not set.

Write-Host git log --pretty=format: --name-only $StartingHash..$LastHash | sort | uniq | grep -i '".sql"' > C:\Ashish\data\sqlRB.txt

Output :-

git log --pretty=format:--name-only f116bcce5cc0701cb0b5a673bc4ce9f723050f04..2870d215c7201e7cf65c71d4d0e732078b3bda31
6
  • @matt when i say its not working that means files C:\Ashish\data\sqlRB.txt is empty. Commented Oct 26, 2015 at 13:02
  • 1
    What is the output of just this then? git log --pretty=format: --name-only $StartingHash..$LastHash or git log --pretty=format: --name-only "$StartingHash..$LastHash" Commented Oct 26, 2015 at 13:04
  • @Matt git log --pretty=format: --name-only "$StartingHash..$LastHash" worked when I tested it. AFAICS your updated answer was correct. Voted to undelete. Commented Oct 26, 2015 at 13:25
  • @AnsgarWiechers Does that mean the quotes were required? Possibly the further filtering and redirection is the issue? Commented Oct 26, 2015 at 13:31
  • @Matt Yes. Without quotes: no output. With quotes: same output as with literal hashes. Commented Oct 26, 2015 at 14:39

1 Answer 1

2

I cannot speak for your Git code but, as PetSerAl points out there is whitespace inserted in your --name-only string. You can see this when you type:

Write-Output  $StartingHash..$LastHash

or

Write-Host  $StartingHash..$LastHash

What you can do is enclose those values in quotes so that PowerShell sees it as a single string without any whitespace or unanticipated formatting.

git log --pretty=format: --name-only "$StartingHash..$LastHash" | ....
Sign up to request clarification or add additional context in comments.

3 Comments

If definitely not interpreted as range operator. Try this: write $StartingHash..$LastHash. It does not produce any error.
@PetSerAl Crap. That is what you meant from your comment. Was my answer right but my assumption wrong
@PetSerAL it gives output f116bcce5cc0701cb0b5a673bc4ce9f723050f04 ..2870d215c7201e7cf65c71d4d0e732078b3bda31 which is correct

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.