How to use git restore to unstage a file which name contains dot - powershell

I'm going to unstage a file which name contains dot. It game me a fetal error when I ran below command
git restore --staged MS0010-7(d.18) TSG Automated Buildouts - PaaSV2 buildout failed in initialize step due to DA could not ping any of the provided Service Fabric gateway endpoints-img001.png
with error :
The term 'd.18' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Could anybody guide me how to fix this error and unstage this file? Thanks.

The problem is not the dot, but the parentheses ( and ) around d.18 being interpreted by the shell. Quoting the whole argument will stop the shell from interpreting the parentheses inside the string, which will also keep the whole string including spaces as one argument:
git restore --staged "MS0010-7(d.18) TSG Automated Buildouts - PaaSV2 buildout failed in initialize step due to DA could not ping any of the provided Service Fabric gateway endpoints-img001.png"
(This is going off my extensive knowledge of PowerShell which extends to quickly glancing at https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-7.2, the "cmdlet" part of the error message being the hint that you are probably using PowerShell and not a Unix shell.)

Related

code --diff fails when filename contains an ampersand '&'

I am experiencing a rather puzzling error while trying to perform a diff on two files using Visual Studio Code from the command line. I have a text file in the cloud where I save some work related notes. I need to resolve conflicts with other clients editing the file. Usually this only happens during a loss of connection though somehow I find myself having to resolve a lot of them so between this and other uses of diff I will use the usual syntax. It looks something like this:
code --diff "R&D (cloud conflict 2-5-23).txt" "R&D.txt"
My filename happens to have a '&' in it and this command launches the usual 2-way diff in VS Code and reads through the first file name with no problem but doesn't read past the second '&' and the resulting diff tab in VS Code looks something like:
R&D (cloud conflict 2-25-23).txt <-> R
Where the right side "R" doesn't exist. So it would seem '&' needs to be processed literally.
No problem, let's see if backslash \ is an accepted escape parameter...
code --diff "R\&D (cloud conflict 2-5-23).txt" "R\&D.txt"
Nope. Same problem. 🤔 In fact this outputs something even stranger:
Code diff tab:
&D (cloud conflict 2-25-23).txt <-> R
with shell output:
'D.txt' is not recognized as an internal or external command, operable program or batch file.
I also tried the carrot symbol '^' as an escape parameter to a similar effect. I just includes it in the first file and the editor still thinks the second file name is just "R".
The help file for the VS Code command line integration didn't have a lot to say about the --diff parameter other than a short description and I was hoping to get something about processing strings literally or escape characters. Perhaps another parameter that I need or maybe this has more to do with the shell in general.
I find it really strange that it can read the first full file name but breaks at the second '&'. Weirder still that if a supposed escape character is included in the second file name, it will omit that as well. 😵
For now all I can do is rename the file which is a bummer. 🤷‍♂️ I have VS Code version 1.75.0 on Windows 10 Home latest version/build and I'm using PowerShell version 5.1.19041.2364.
Edit: The issue definitely appears to be PowerShell related as it turns out. I was finally able to run this command successfully in a regular command prompt. (Simply typing "cmd" and Enter into the PowerShell window before running the diff command). Unfortunately, I happen to be running this command as part of PowerShell script. I may have to figure out how to run a CMD command from inside my PowerShell script if that is at all possible. I'm not sure. 🤔 If not, I need to figure out what exactly PowerShell is doing to my command when it reaches the '&' character.
tl;dr
You need a workaround:
cmd /c 'code --diff "R&D (cloud conflict 2-5-23).txt" "R&D.txt"'
Alternatively, using --%, the stop-parsing token:
code --diff "R&D (cloud conflict 2-5-23).txt" --% "R&D.txt"
Note: --% comes with fundamental limitations, notably the inability to reference PowerShell variables - see this answer.
Background information:
The root cause is that code is implemented as a batch file (code.cmd) and that cmd.exe, the interpreter that executes batch file inappropriately parses its list of arguments as if they had been submitted from INSIDE a cmd.exe session.
PowerShell, which - of necessity - has to rebuild the process command line behind the scenes on Windows after having performed argument parsing based on its rules, and - justifiably - places "R&D.txt" as verbatim R&D.txt on the process command line, given that the argument value contains no spaces.
The result is that cmd.exe interprets the unquoted R&D.txt argument on its command line as containing metacharacter &, which is its command-sequencing operator, causing the call to break.
Given that cmd.exe, the legacy Windows shell, is unlikely to receive fixes, the actively maintained PowerShell (Core) 7+ edition could as a courtesy compensate for cmd.exe's inappropriate behavior.
Doing so has been proposed in GitHub issue #15143, but, alas, it looks like these accommodations will not be implemented.

'sed' is not recognized as an internal or external command- ETHERMINT

Im having trouble following the tutorial for the node start on Ethermint.
After passing in the cmd: make install, i get the following error.
In my work computer, is not working, but in my personal computer is ?
What seems to be the issue ?
'sed' is not recognized as an internal or external command,
operable program or batch file.
process_begin: CreateProcess(NULL, which docker, ...) failed.
Makefile:29: pipe: Bad file descriptor
Makefile:187: *** missing separator. Stop.
I tried to install a windows version of "sed" but cant find a proper version.

Variables in argument doesn't seems to be replaced with the value from the library

In azure devops I am trying to figure out how to build a release pipeline to release a static website to firebase cloud. I found this guide to help me with that.
I added 2 variables in the library in a variable group with the names 'firebase_token' and 'projectId' I try to use these variables in a release pipeline with one task which executes a powershell script from my repository. I do that via the next argument:
-fireBaseToken $(firebase_token) -fireBaseProject $(projectId) -releaseMessage $(Release.ReleaseName)
When I try to execute the release pipeline I get an error when the powershell script is being called. This is the error I get
firebase_token : The term 'firebase_token' is not recognized as the
name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the
path is correct and try again.
When I look at the command that has been tried to execute, I see this:
Formatted command: . 'D:\a\r1\a\test-project\drop\deploy.ps1' -fireBaseToken $(firebase_token) -fireBaseProject $(projectId) -releaseMessage Release-3
As far as I can see and think of, for some reason $(firebase_token) and $(projectId) aren't replaced by their values.
In my guess that thesee variables should be replaced by there values, what am I doing wrong? What is causing the issue that these variables aren't replaced?
You need to link the variable group into your release definition. Simply creating a variable group isn't enough.

TFS2015 Release Management Execute Powershell on Remote Machine

Evening,
I have recently installed TFS2015 and investigating the Release Management integrated solution, but have come across a huge blocker that I just cannot make sense of.
I currently have a RM2013 build working with TFS, RM Server 2013, and Powershell DSC and have setup a new deployment in RM2015, it has a single task in it 'Execute Powershell on Remote Machine' - with a very simple powershell script just writing out a string to the verbose listener.
I have verified that the file is transferred to the Agent working directory as part of the artifact transfer process, and if I call Import-Module "path to script" (Which is what the PowerShellonTargetMachines script seems to do under the hood) in the ISE of the remote server, my script runs perfectly fine - but no matter what I do, in TFS release 2015 I get this error without fail:
[error]The term 'path to script\test.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. For more info please refer to http://aka.ms/powershellontargetmachinesreadme
Now just to double confirm, the path to the scrpt is 100% correct, I have pasted it into a local ISE on the remote server, and it executes perfectly fine - but from TFS2015 Execute Powershell on Remote Server - it simply fails to run, in fact any script I point at fails to run with the exact same error (I initially thought it might be a DSC component install failure, but even with a simple test script the same issue occurs without fail!
My path in the tasks Deployment>Powershell Script parameter input is:
c:\test_scripts\test.ps1
I have tried with quotes, without quotes, dot sourcing - nothing makes a difference which is making me think something fundamentally is either broken with my installation, or I am simply doing this wrong.
Any ideas gratefully received!!!
The script has to already be on the machine. You can push the script using the "Windows Machine File Copy" task.
Fixed this... make sure you execute the PS1 file on the release agent itself unless copying the powershell files to the remote node via file copy first as indicated below

run specific perl script from command line

Not that much experience programming, but I saw this open source code for one of those speed readers everyone is talking about and thought it would be cool to try to run it on my own computer.
The files are available here: https://github.com/pasky/speedread
I was wondering what exactly I should type into the command prompt to get the program running. I already have a perl interpreter on my computer. But I'm not sure how to get the program running. Sorry if this is a super noobish question.
I've tried
perl C:\speadread-master\speedread (and yes, it was on the C: drive)
I got the error:
Use of encoding pragma is deprecated at C:\speadread-master\speedread line 39.
'stts' is not recognized as an internal or external command, operable program of batch file.
←[31mc←[0←[K
I also tried (because it appears in the gifs on github)
~/speedread$ head -n 21 tea.txt | ./speedread -w 250
I got the error:
'~' is not recognized as an internal or external command, operable program or batch file
In addition to amon's comment, wo points out a strong dependency to Unix commands/display, you also misinterpreted the head command:
~/speedread$ is a Unix command prompt, with ~ refering to your HOME directory (USERPROFILE in Windows). You are not supposed to type it.
The actual command is:
head -n 21 tea.txt | ./speedread -w 250
Adn you have an head.exe (Windows version of the unix command head) in your git msysgit distribution (bin/head.exe).