Skip to content

Commit

Permalink
repository.has_local_changes
Browse files Browse the repository at this point in the history
  • Loading branch information
coenm committed Nov 27, 2024
1 parent a8d5753 commit f19f488
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 28 deletions.
21 changes: 21 additions & 0 deletions docs/mdsource/script_variables_repository.generated.source.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This module contains the following methods, variables and/or constants:

- [`repository.branch`](#branch)
- [`repository.branches`](#branches)
- [`repository.has_local_changes`](#has_local_changes)
- [`repository.is_bare`](#is_bare)
- [`repository.linux_path`](#linux_path)
- [`repository.local_branches`](#local_branches)
Expand Down Expand Up @@ -35,6 +36,26 @@ Gets the current branch of the repository

The name of the current branch.

## has_local_changes

`repository.has_local_changes`

Gets if there are local changes

### Returns

true when there are local changes, false otherwise.

### Example
#### Usage


```
repository.has_local_changes
```


## is_bare

`repository.is_bare`
Expand Down
46 changes: 23 additions & 23 deletions src/RepoM.ActionMenu.Core/ActionMenu/Context/FileFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public FileFunctions()
/// solution_files = file.find_files('C:\Project\', '*.sln');
/// </code>
/// <result/>
/// As a result, the variable `solution_files` is an ennumerable of strings, for example:
/// As a result, the variable `solution_files` is an enumerable of strings, for example:
/// <code-file language='yaml' filename='file.find_files.verified.yaml' />
/// <repository-action-sample/>
/// <snippet name='find_files@actionmenu01' mode='snippet' />
Expand All @@ -58,19 +58,6 @@ public static string[] FindFiles(ActionMenuGenerationContext /*IMenuContext*/ co
return FindFilesInner(context, span, rootPath, searchPattern);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static string[] FindFilesInner(IMenuContext context, SourceSpan span, string rootPath, string searchPattern)
{
try
{
return GetFileEnumerator(context.FileSystem, rootPath, searchPattern).ToArray();
}
catch (Exception e)
{
throw new ScriptRuntimeException(span, "Could not get files.", e);
}
}

/// <summary>
/// Checks if the specified file path exists on the disk.
/// </summary>
Expand All @@ -89,14 +76,7 @@ internal static string[] FindFilesInner(IMenuContext context, SourceSpan span, s
[ActionMenuContextMember("file_exists")]
public static bool FileExists(ActionMenuGenerationContext context, string path)
{
return FileExistsInner(context as IMenuContext, path);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static bool FileExistsInner(IMenuContext context, string path)
{
ArgumentException.ThrowIfNullOrWhiteSpace(path);
return context.FileSystem.File.Exists(path);
return FileExistsInner(context, path);
}

/// <summary>
Expand All @@ -123,7 +103,20 @@ public static bool DirectoryExists(ActionMenuGenerationContext context, string p
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static bool DirectoryExistsInner(IMenuContext context, string path)
internal static string[] FindFilesInner(IMenuContext context, SourceSpan span, string rootPath, string searchPattern)
{
try
{
return GetFileEnumerator(context.FileSystem, rootPath, searchPattern).ToArray();
}
catch (Exception e)
{
throw new ScriptRuntimeException(span, "Could not get files.", e);
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool DirectoryExistsInner(IMenuContext context, string path)
{
ArgumentException.ThrowIfNullOrWhiteSpace(path);
return context.FileSystem.Directory.Exists(path);
Expand All @@ -134,4 +127,11 @@ private static IEnumerable<string> GetFileEnumerator(IFileSystem fileSystem, str
{
return fileSystem.Directory.EnumerateFileSystemEntries(path, searchPattern, _findFilesOptions);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool FileExistsInner(IMenuContext context, string path)
{
ArgumentException.ThrowIfNullOrWhiteSpace(path);
return context.FileSystem.File.Exists(path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ public RepositoryFunctions(IRepository repository)
/// </example>
[ActionMenuContextMember("is_bare")]
public bool IsBare => _repository.IsBare;



/// <summary>
/// Gets the path of the repository. The path is windows or linux based (depending on the running OS) and does NOT end with a (back)slash.
/// </summary>
Expand Down Expand Up @@ -107,4 +106,17 @@ public RepositoryFunctions(IRepository repository)
/// <returns>Remotes.</returns>
[ActionMenuContextMember("remotes")]
public IEnumerable Remotes => _repository.Remotes;

/// <summary>
/// Gets if there are local changes
/// </summary>
/// <returns><c>true</c> when there are local changes, <c>false</c> otherwise.</returns>
/// <example>
/// <usage/>
/// <code>
/// repository.has_local_changes
/// </code>
/// </example>
[ActionMenuContextMember("has_local_changes")]
public bool HasLocalChanges => _repository.HasLocalChanges;
}
1 change: 1 addition & 0 deletions src/RepoM.ActionMenu.Core/RepoMCodeGen.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ protected sealed override void RegisterFunctions()
{
RegisterConstant("branch", CurrentBranch);
RegisterConstant("branches", Branches);
RegisterConstant("has_local_changes", HasLocalChanges);
RegisterConstant("is_bare", IsBare);
RegisterConstant("linux_path", LinuxPath);
RegisterConstant("local_branches", LocalBranches);
Expand Down
1 change: 0 additions & 1 deletion src/RepoM.Api/IO/AppDataPathProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public sealed class AppDataPathProvider : IAppDataPathProvider
{
public AppDataPathProvider(AppDataPathConfig config, IFileSystem fileSystem)
{
ArgumentNullException.ThrowIfNull(config);
ArgumentNullException.ThrowIfNull(fileSystem);

if (!string.IsNullOrWhiteSpace(config.AppSettingsPath))
Expand Down
3 changes: 1 addition & 2 deletions src/RepoM.Core.Plugin/Repository/IRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public interface IRepository
bool HasUnpushedChanges { get; }

public string[] ReadAllBranches();



public bool HasLocalChanges { get; }

public bool IsBehind { get; }
Expand Down

0 comments on commit f19f488

Please sign in to comment.