Setting Mercurial's execute bit on Windows

浪尽此生 提交于 2019-12-09 15:34:30

问题


I work on a Mercurial repository that is checked out onto an Unix filesystem such as ext3 on some machines, and FAT32 on others.

In Subversion, I can set the svn:executable property to control whether a file should be marked executable when checked out on a platform that supports such a bit. I can do this regardless of the platform I'm running SVN on or the filesystem containing my working copy.

In Mercurial, I can chmod +x to get the same effect if the clone is on a Unix filesystem. But how can I set (or remove) the executable bit on a file on a FAT filesystem?


回答1:


Mercurial tracks the execute bit as part of the file metdata. There's no way to explictly set it in mercurial, but it tracks changes made by chmod on unix. Files added on windows will have the execute bit set by default, but the windows attrib command doesn't let you set them.

If you do a hg log -p --git you'll see the patch format that shows the altering of the execute bit, which looks like this:

$ hg log --git -p
changeset:   1:0d9a70aadc0a
tag:         tip
user:        Ry4an Brase <ry4an-hg@ry4an.org>
date:        Sat Apr 24 10:05:23 2010 -0500
summary:     added execute

diff --git a/that b/that
old mode 100644
new mode 100755

changeset:   0:06e25cb66089
user:        Ry4an Brase <ry4an-hg@ry4an.org>
date:        Sat Apr 24 10:05:09 2010 -0500
summary:     added no execute

diff --git a/that b/that
new file mode 100644
--- /dev/null
+++ b/that
@@ -0,0 +1,1 @@
+this

If you're not able to get on to a unix system to set them, you could probably fake up a patch like that and hg import it, but that's definitely sub optimal.




回答2:


For the time being you cannot change the execute bit if the filesystem doesn't support it (I have plan to support it in the future).




回答3:


For Windows you need to create a patch file and then apply it, like Ry4an has said, but with the --bypass argument to hg import. This could be done by creating a Powershell script file called SetFileExecutable.ps1 with the text below inside it

param (
  [String]$comment = "+execbit",
  [Parameter(Mandatory=$true)][string]$filePathRelativeTo,
  [Parameter(Mandatory=$true)][string]$repositoryRoot
)

if( Test-Path -Path "$($repositoryRoot)\.hg" -PathType Container )
{
  if( Test-Path -Path "$($repositoryRoot)\$($filePathRelativeTo)" -PathType Leaf )
  {
    $filePathRelativeTo = $filePathRelativeTo.Replace( '\', '/' )

    $diff = "$comment" + [System.Environment]::NewLine +
      [System.Environment]::NewLine +
      "diff --git a/$filePathRelativeTo b/$filePathRelativeTo" + [System.Environment]::NewLine +
      "old mode 100644" + [System.Environment]::NewLine +
      "new mode 100755"

    Push-Location
    cd $repositoryRoot
    $diff | Out-File -Encoding 'utf8' $env:tmp\exebit.diff
    hg import --bypass -m "$comment" $env:tmp\exebit.diff
    Pop-Location
  }
  else
  {
    Write-Host "filePathRelativeTo must the location of a file relative to repositoryRoot"
  }
}
else
{
  Write-Host "repositoryRoot must be the location of the .hg folder"
}

execute it as follows:

.\SetFileExecutable.ps1" -comment "Marking file as executable" -filePathRelativeTo mvnw -repositoryRoot "c:\myrepo"

The uses the solution provided by Matt Harbison in Mercurial's Bugzilla



来源:https://stackoverflow.com/questions/2702825/setting-mercurials-execute-bit-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!