Remember a bug that is raised by Windows command line

Source: Internet
Author: User
Tags windows support

Article Source: http://www.51testing.com/html/30/n-3724330.html?
2018 just started to step on a very crazy thunder, incredibly still about the command line of Windows.
   background
The background is that, in the process of developing the lavas CLI, the corresponding repo address and branch name will need to be stitched out through the template type selected by the developer and then pulled from GitHub by node. js to be used locally to the developer. The requirement is clear: it involves the need to use node. js to manipulate the git command line, and then it's natural to use child_process.exec.
To implement this requirement, you might want to organize the command line first, presumably to do the following several things:

Then the question comes, child_process.exec how do you execute multiple command lines? The CHILD_PRECESS.EXEC command can only support passing in a command. So you need to synthesize multiple commands into a single command line.
   execute multiple-line commands at the same time
Shell commands for both LINUX/MAC and Windows support a command to execute multiple commands. There are &&,&,| |,|. There are several ways in which these ways represent different meanings:
&&:command1 && Command2, if Command1 execution succeeds, execute command command2, if Command1 fails, Command2 will not be executed.
&:command1 & Command2, regardless of whether Command1 execution succeeds or not, Command2 will be executed.
|| : Command1 | | Command2, if Command1 execution succeeds, Command2 will not be executed, and if Command1 fails, Command2 will continue to execute.
|:command1 | The result of Command2,command1 is a command2 parameter, and if the Command1 fails, the entire command fails.
can also be used under Linux/mac; To link two commands, execute commands sequentially, regardless of success or not, and & meaning.
After understanding these logic, our demand must be to choose && to achieve the requirements we have previously said:
# If you have clone the template to the/some/target/path directory
Cd/some/target/path && git pull && git checkout some_branch_name
Based on our analysis above, our code is basically the following:

Then I tested it on LINUX/MAC and windows and found that there was nothing wrong with it, but until today it was exposed by Windows users to the Fatal:not a git repository (or any of the parent directories):. Git error.
   Troubleshooting Errors
Look at this error, should be the execution of the GIT command, did not find the corresponding directory, so the focus of the troubleshooting is these commands, if you do not find the corresponding Git directory, the CD command is very easy to be suspected.
Here we need to give an account of the background, our TargetPath is obtained by process.env[' APPDATA ' and process.env[' HOME ']:

In other words, there are two things we can be clear about TargetPath:
· Under Linux/mac, the path to TargetPath is/user/zoumiaojiang/.lavas-project
· Under Windows is C:\\users\\administrator\\appdata\\roaming\\.lavas-project
Only in Windows will you get an error, so what's wrong with executing the command CD C:\\users\\administrator\\appdata\\roaming\\.lavas-project? Why do I have to test on Windows myself without problems? Then I hit the same command on my computer, it's all right:

Suddenly caught in a state of anarchy, feeling deadlocked.
   Windows CD Command
In the process of the Meng, the Blind knock command line, incredibly found this situation:

And this is a failure, and there is no CD success, but this and the success of the case difference, just because this time I was in d:\ Disk execution. Recall the lavas CLI error, sure enough not in C \ The disk executes the command line, and I have been tested successfully since I am always in C: \ Disk execution commands. Here's a thorough understanding:
· Windows does not support direct cross-disk execution of CD commands
· Before executing the CD command, you must specify a disk

This is a success indeed. The problem finally found, suddenly recalled, this error committed is too low-level, before the operation of Windows command line, this operation is simply subconscious, after a long time sparse Windows, incredibly put such a thing to forget. Now that we have found the cause, we can solve the problem by changing the Downloadfromgit code:

The previous Bug is because Windows cannot cross disk direct CD, resulting in no direct CD to TargetPath, so does not enter the Git directory correctly, resulting in fatal:not a git repository (or any of the par ENT directories):. Git error.
PS: Often solve bugs are easy to solve, locate the bug is very difficult, write down this interesting bug, remind oneself after must carefully, test must be full.
To learn more about the Windows command-line-raised bug, go to 51Testing Software Test network (http://www.51testing.com) Ha ~

Remember a bug that is raised by Windows command line

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.