-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for setting execute_filemode on commit create
- Loading branch information
1 parent
59fb347
commit 3b65179
Showing
5 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#if NET7_0_OR_GREATER | ||
using System; | ||
#endif | ||
|
||
using System.IO; | ||
using LibGit2Sharp; | ||
using NGitLab.Models; | ||
|
||
namespace NGitLab.Mock; | ||
|
||
internal sealed class CommitActionChmodHandler : ICommitActionHandler | ||
{ | ||
public void Handle(CreateCommitAction action, string repoPath, LibGit2Sharp.Repository repository) | ||
{ | ||
if (!Directory.Exists(repoPath)) | ||
throw new DirectoryNotFoundException(); | ||
|
||
var filePath = Path.Combine(repoPath, action.FilePath); | ||
|
||
if (!System.IO.File.Exists(filePath)) | ||
throw new FileNotFoundException("File does not exist."); | ||
|
||
#if NET7_0_OR_GREATER | ||
if (!OperatingSystem.IsWindows()) | ||
{ | ||
var fileMode = UnixFileMode.UserRead | UnixFileMode.UserWrite | | ||
UnixFileMode.GroupRead | UnixFileMode.GroupWrite | | ||
UnixFileMode.OtherRead | UnixFileMode.OtherWrite | | ||
(action.IsExecutable | ||
? UnixFileMode.UserExecute | UnixFileMode.GroupExecute | UnixFileMode.OtherExecute | ||
: UnixFileMode.None); | ||
System.IO.File.SetUnixFileMode(filePath, fileMode); | ||
} | ||
#endif | ||
|
||
var blob = repository.ObjectDatabase.CreateBlob(filePath); | ||
repository.Index.Add(blob, action.FilePath, action.IsExecutable ? Mode.ExecutableFile : Mode.NonExecutableFile); | ||
repository.Index.Write(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters