forked from gdevic/GitForce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassConfig.cs
More file actions
64 lines (56 loc) · 2.41 KB
/
ClassConfig.cs
File metadata and controls
64 lines (56 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
namespace GitForce
{
/// <summary>
/// Class Config gets and sets values of either global git configuration or a local repository
/// </summary>
public static class ClassConfig
{
/// <summary>
/// Sets or removes a global git configuration value.
/// If the value is null or empty string, the key will be removed (unset).
/// </summary>
public static void SetGlobal(string key, string value)
{
string setkey = string.IsNullOrEmpty(value) ? "--unset " : "";
string val = string.IsNullOrEmpty(value) ? "" : " \"" + value + "\"";
string cmd = setkey + key + val;
if (ClassGit.Run("config --global " + cmd).Success() == false)
App.PrintLogMessage("Error setting global git config parameter!", MessageType.Error);
}
/// <summary>
/// Sets or removes a local git configuration value.
/// If the value is null or empty string, the key will be removed (unset).
/// </summary>
public static void SetLocal(ClassRepo repo, string key, string value)
{
string setkey = string.IsNullOrEmpty(value) ? "--unset " : "";
string val = string.IsNullOrEmpty(value) ? "" : " \"" + value + "\"";
string cmd = setkey + key + val;
if (repo.Run("config --local " + cmd).Success() == false)
App.PrintLogMessage("Error setting local git config parameter!", MessageType.Error);
}
/// <summary>
/// Returns a value of a global git configuration key
/// </summary>
public static string GetGlobal(string key)
{
ExecResult result = ClassGit.Run("config --global --get " + key);
if (result.Success())
return result.stdout;
App.PrintLogMessage("Error getting global git config parameter!", MessageType.Error);
return String.Empty;
}
/// <summary>
/// Returns a value of a local git configuration key
/// </summary>
public static string GetLocal(ClassRepo repo, string key)
{
ExecResult result = repo.Run("config --local --get " + key);
if (result.Success())
return result.stdout;
App.PrintLogMessage("Error getting local git config parameter!", MessageType.Error);
return string.Empty;
}
}
}