Skip to content

Commit

Permalink
Fix creating initial commit, when there is no head (fixes #5514)
Browse files Browse the repository at this point in the history
  • Loading branch information
spdr870 committed Oct 18, 2018
1 parent 4db9564 commit c709221
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions GitUI/CommandsDialogs/FormCommit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -939,11 +939,10 @@ private void InitializedStaged()
{
using (WaitCursorScope.Enter())
{
var headId = Module.RevParse("HEAD");
SolveMergeconflicts.Visible = Module.InTheMiddleOfConflictedMerge();
Staged.SetDiffs(
new GitRevision(ObjectId.IndexId),
new GitRevision(headId),
GetHeadRevision(),
Module.GetIndexFilesWithSubmodulesStatus());
}
}
Expand Down Expand Up @@ -974,10 +973,8 @@ private void LoadUnstagedOutput(IReadOnlyList<GitItemStatus> allChangedFiles)
}
}

var headId = Module.RevParse("HEAD");
var headRevision = headId != null ? new GitRevision(headId) : null;
Unstaged.SetDiffs(new GitRevision(ObjectId.WorkTreeId), new GitRevision(ObjectId.IndexId), unstagedFiles);
Staged.SetDiffs(new GitRevision(ObjectId.IndexId), headRevision, stagedFiles);
Staged.SetDiffs(new GitRevision(ObjectId.IndexId), GetHeadRevision(), stagedFiles);

var doChangesExist = Unstaged.AllItems.Any() || Staged.AllItems.Any();

Expand Down Expand Up @@ -1620,9 +1617,8 @@ private void Unstage(bool canUseUnstageAll = true)
unstagedFiles.Add(item);
}

var headId = Module.RevParse("HEAD");
Unstaged.SetDiffs(new GitRevision(ObjectId.WorkTreeId), new GitRevision(ObjectId.IndexId), unstagedFiles);
Staged.SetDiffs(new GitRevision(ObjectId.IndexId), new GitRevision(headId), stagedFiles);
Staged.SetDiffs(new GitRevision(ObjectId.IndexId), GetHeadRevision(), stagedFiles);
_skipUpdate = false;
Staged.SelectStoredNextIndex();

Expand Down Expand Up @@ -1656,6 +1652,18 @@ private void Unstage(bool canUseUnstageAll = true)
}
}

[CanBeNull]
private GitRevision GetHeadRevision()
{
var headId = Module.RevParse("HEAD");
if (headId != null)
{
return new GitRevision(headId);
}

return null;
}

private void StageClick(object sender, EventArgs e)
{
if (_currentFilesList != Unstaged || Module.IsBareRepository())
Expand Down

0 comments on commit c709221

Please sign in to comment.