git can not create directory, Invalid argument, when using Windows reserved word, NUL AUX CON

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

    

Summary

Build fails with the following error message when run on a Windows Agent:

atlassian-bamboo-agent.log
30-Jun-2021 15:40:43	Caused by: com.atlassian.bamboo.plugins.git.GitCommandException: command ['C:\Program Files\Git\bin\git.exe' checkout -f master] failed with code 128. Working directory was [C:\Users\Administrator\bamboo-agent-home\xml-data\build-dir\ABC-PLAN6-JOB1]., stderr:
30-Jun-2021 15:40:43	fatal: cannot create directory at 'src/object/aux': Invalid argument

Environment

Any version of git and Bamboo running on all versions of Windows.

Diagnosis

The same error, Invalid argument, happens when cloning the repository outside of Bamboo/ Bamboo agent. Confirm by checking out the same revision from the command line on Windows to see if it fails with a similar error.  Using bash on windows or the linux subsystem on windows is not a valid test for this error.

Cause

When a Source code checkout task is run in a build, the checkout operation fails because of reserved word in windows

Git stores directory names as trees.  When checking out a branch or commit, the commit message has the base directory as a tree.  Here is an example commit:

$ git cat-file -p db6dcce40dc0ad38367ab78ada5fa9c19cefaddb
tree 71e5c0c4dd88d18acef02a04e6dea51d47026349
parent cf3c70fea8f7f6105c15a32e22eb26d31ba52b01
author dlaser <dlaser@atlassian.com> 1634132364 -0500
committer dlaser <dlaser@atlassian.com> 1634132364 -0500

Commit message

Files are stored as blobs and tree is a directory.  When git checks out a tree it creates a directory for the tree object.   Blobs are read and created with the file name in the tree. Here is an example tree:

$ git cat-file -p 71e5c0c4dd88d18acef02a04e6dea51d47026349
040000 tree d5ba3bd4a6b4395e5ef22c6e17c5fe6e954f816f	aux
100644 blob 63256c40f08b28532963a474e30f9456e9c5a6ad	file.txt

When git checkout this directory, it can not create a directory with the atl name, from the error above.  This issue happens because the directory alt was allowed on the system that made the commit but is not valid on the system that was checked out.

The following are some of the Windows reserved names that cannot be used in a folder name:

CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9

Solution

This issue only happens when the tree with the invalid directory name is checked out on Windows.  To avoid this issue you just need to create a commit that does not try to create this directory.  Here are the possible resolutions:

  • Rename the directory in git on another system and attempt the build again. 
  • Delete the branch or branches with offending directory name.  This will remove all references to this tree.
  • Deploy a git pre-commit  hook to all git clients that does not allow any invalid directories for windows.

In this example, you can avoid this issue if any commit or branch that has tree 71e5c0c4dd88d18acef02a04e6dea51d47026349 is not checked out on the windows system.  Depending how much of your git repository has this invalid directory and how often these commits are checked out on Windows will define how much action you need to take to resolve this issue.  Removing or rewriting history for this tree is a viable solution but yet dangerous solution.


Last modified on Oct 14, 2021

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.