mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-23 05:05:00 +00:00
refactor: diff for staged file with --amend
enabled (#1231)
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
78f4809875
commit
345ad06aba
4 changed files with 9 additions and 3 deletions
|
@ -16,6 +16,7 @@ namespace SourceGit.Commands
|
||||||
WorkingDirectory = repo;
|
WorkingDirectory = repo;
|
||||||
Context = repo;
|
Context = repo;
|
||||||
Args = $"diff-index --cached -M {parent}";
|
Args = $"diff-index --cached -M {parent}";
|
||||||
|
_parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Models.Change> Result()
|
public List<Models.Change> Result()
|
||||||
|
@ -37,6 +38,7 @@ namespace SourceGit.Commands
|
||||||
{
|
{
|
||||||
FileMode = match.Groups[1].Value,
|
FileMode = match.Groups[1].Value,
|
||||||
ObjectHash = match.Groups[2].Value,
|
ObjectHash = match.Groups[2].Value,
|
||||||
|
ParentSHA = _parent,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
change.Set(Models.ChangeState.Renamed);
|
change.Set(Models.ChangeState.Renamed);
|
||||||
|
@ -54,6 +56,7 @@ namespace SourceGit.Commands
|
||||||
{
|
{
|
||||||
FileMode = match.Groups[1].Value,
|
FileMode = match.Groups[1].Value,
|
||||||
ObjectHash = match.Groups[2].Value,
|
ObjectHash = match.Groups[2].Value,
|
||||||
|
ParentSHA = _parent,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -88,5 +91,7 @@ namespace SourceGit.Commands
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string _parent = string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ namespace SourceGit.Models
|
||||||
{
|
{
|
||||||
public string FileMode { get; set; } = "";
|
public string FileMode { get; set; } = "";
|
||||||
public string ObjectHash { get; set; } = "";
|
public string ObjectHash { get; set; } = "";
|
||||||
|
public string ParentSHA { get; set; } = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Change
|
public class Change
|
||||||
|
|
|
@ -40,7 +40,7 @@ namespace SourceGit.Models
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (change.DataForAmend != null)
|
if (change.DataForAmend != null)
|
||||||
_extra = "--cached HEAD^";
|
_extra = $"--cached {change.DataForAmend.ParentSHA}";
|
||||||
else
|
else
|
||||||
_extra = "--cached";
|
_extra = "--cached";
|
||||||
|
|
||||||
|
|
|
@ -1526,7 +1526,7 @@ namespace SourceGit.ViewModels
|
||||||
if (_useAmend)
|
if (_useAmend)
|
||||||
{
|
{
|
||||||
var head = new Commands.QuerySingleCommit(_repo.FullPath, "HEAD").Result();
|
var head = new Commands.QuerySingleCommit(_repo.FullPath, "HEAD").Result();
|
||||||
return new Commands.QueryStagedChangesWithAmend(_repo.FullPath, head.Parents.Count == 0 ? "4b825dc642cb6eb9a060e54bf8d69288fbee4904" : "HEAD^").Result();
|
return new Commands.QueryStagedChangesWithAmend(_repo.FullPath, head.Parents.Count == 0 ? "4b825dc642cb6eb9a060e54bf8d69288fbee4904" : $"{head.SHA}^").Result();
|
||||||
}
|
}
|
||||||
|
|
||||||
var rs = new List<Models.Change>();
|
var rs = new List<Models.Change>();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue