Permalink
Browse files

add commit (pending changes).

Dragon tool is intended to be a standalone Git tool that be integrated with other IDE, such as WebMatrix. The commit window provides the Git commit function. A command line options -c or --commit is added to launch the commit window from other IDE.
  • Loading branch information...
1 parent b82ca37 commit 5a2bb41be6a6a31621e004b721babc25c54e7fd4 @yysun committed Jun 17, 2012
View
@@ -29,4 +29,5 @@ _ReSharper*/
[Tt]est[Rr]esult*
Publish*/
GitUI/Resources/*.dll
+GitUI/Resources/*.xml
*.pkg
@@ -242,7 +242,7 @@ public void AmendCommitTest()
File.WriteAllText(tempFile, "changed text");
tracker.StageFile(tempFile);
- tracker.AmendCommit("new message");
+ tracker.Commit("new message", true);
Assert.IsTrue(tracker.LastCommitMessage.StartsWith("new message"));
}
@@ -527,7 +527,8 @@ public void CheckOutBranch(string branch, bool createNew = false)
{
try
{
- GitBash.Run(string.Format("checkout {0} {1}", (createNew ? "-b" : ""), branch), this.GitWorkingDirectory);
+ var msg = GitBash.Run(string.Format("checkout {0} {1}", (createNew ? "-b" : ""), branch), this.GitWorkingDirectory);
+ if (msg.Contains("fatal:")) throw new Exception(msg);
}
catch (Exception ex)
{
@@ -650,7 +651,7 @@ public void StageFile(string fileName)
this.changedFiles = null;
}
- public string Commit(string message)
+ public string Commit(string message, bool amend = false, bool signoff = false)
{
if (!this.HasGitRepository) return null;
@@ -660,16 +661,13 @@ public string Commit(string message)
string msg = "";
if (GitBash.Exists)
{
- var msgFile = Path.Combine(this.repository.Directory, "COMMITMESSAGE");
-
+ var msgFile = Path.Combine(this.repository.Directory, "COMMITMESSAGE");
File.WriteAllText(msgFile, message);
- //using (var textWriter = new StreamWriter(msgFile, false, GetCommentEncoding()))
- //{
- // textWriter.Write(message);
- //}
-
- msg = GitBash.Run(string.Format("commit -F \"{0}\"", msgFile), this.GitWorkingDirectory);
+ string opt = "";
+ if (amend) opt += "--amend";
+ if (signoff) opt += "--signoff";
+ msg = GitBash.Run(string.Format("commit -F {1} \"{0}\"", msgFile, opt), this.GitWorkingDirectory);
if (msg.IndexOf('\n') > 0) msg = msg.Split('\n')[0];
File.Delete(msgFile);
}
@@ -684,46 +682,54 @@ public string Commit(string message)
return msg;
}
- public string AmendCommit(string message)
- {
- if (!HasGitRepository) return null;
-
- if (string.IsNullOrEmpty(message))
- throw new ArgumentException("Commit message must not be null or empty!", "message");
-
- string msg = "";
- if (GitBash.Exists)
- {
- var msgFile = Path.Combine(this.repository.Directory, "COMMITMESSAGE");
- File.WriteAllText(msgFile, message);
- msg = GitBash.Run(string.Format("commit --amend -F \"{0}\"", msgFile), this.GitWorkingDirectory);
- if (msg.IndexOf('\n') > 0) msg = msg.Split('\n')[0];
- File.Delete(msgFile);
- }
- else
- {
- var git = new Git(this.repository);
- var rev = git.Commit().SetAmend(true).SetMessage(message).Call();
- msg = rev.Name;
- }
- Refresh();
-
- return msg;
- }
+ //public string AmendCommit(string message)
+ //{
+ // if (!HasGitRepository) return null;
+
+ // if (string.IsNullOrEmpty(message))
+ // throw new ArgumentException("Commit message must not be null or empty!", "message");
+
+ // string msg = "";
+ // if (GitBash.Exists)
+ // {
+ // var msgFile = Path.Combine(this.repository.Directory, "COMMITMESSAGE");
+ // File.WriteAllText(msgFile, message);
+ // msg = GitBash.Run(string.Format("commit --amend -F \"{0}\"", msgFile), this.GitWorkingDirectory);
+ // if (msg.IndexOf('\n') > 0) msg = msg.Split('\n')[0];
+ // File.Delete(msgFile);
+ // }
+ // else
+ // {
+ // var git = new Git(this.repository);
+ // var rev = git.Commit().SetAmend(true).SetMessage(message).Call();
+ // msg = rev.Name;
+ // }
+ // Refresh();
+
+ // return msg;
+ //}
public string LastCommitMessage
{
get
{
if (!HasGitRepository) return null;
- var headId = this.repository.Resolve(Constants.HEAD);
- if (headId != null)
+
+ if (GitBash.Exists)
{
- var revWalk = new RevWalk(this.repository);
- var commit = revWalk.ParseCommit(headId);
- return commit == null ? null : commit.GetFullMessage();
+ return GitBash.Run("log -1 --format=%s\r\n\r\n%b", this.GitWorkingDirectory);
+ }
+ else
+ {
+ var headId = this.repository.Resolve(Constants.HEAD);
+ if (headId != null)
+ {
+ var revWalk = new RevWalk(this.repository);
+ var commit = revWalk.ParseCommit(headId);
+ return commit == null ? null : commit.GetFullMessage();
+ }
+ return null;
}
- return null;
}
}
View
@@ -64,6 +64,7 @@
<Compile Include="GitIntellisenseHelper.cs" />
<Compile Include="GitSccOptions.cs" />
<Compile Include="GitViewModel.cs" />
+ <Compile Include="Options.cs" />
<Compile Include="UI\BottomToolBar.xaml.cs">
<DependentUpon>BottomToolBar.xaml</DependentUpon>
</Compile>
View
@@ -7,6 +7,7 @@
using System.Windows.Threading;
using GitScc;
using Microsoft.Windows.Shell;
+using Mono.Options;
namespace GitUI
{
@@ -36,7 +37,7 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
this.Style = (Style)Resources["GradientStyle"];
GitBash.GitExePath = GitSccOptions.Current.GitBashPath;
- GitBash.UseUTF8FileNames = GitSccOptions.Current.UseUTF8FileNames;
+ GitBash.UseUTF8FileNames = GitSccOptions.Current.UseUTF8FileNames;
if (!GitBash.Exists) GitBash.GitExePath = TryFindFile(new string[] {
@"C:\Program Files\Git\bin\sh.exe",
@@ -67,6 +68,7 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
this.txtPrompt.Text = GitIntellisenseHelper.GetPrompt();
}
this.graph.Show(gitViewModel.Tracker, reload != null);
+ this.pendingChanges.Refresh(gitViewModel.Tracker);
};
this.Dispatcher.BeginInvoke(act, DispatcherPriority.ApplicationIdle);
};
@@ -75,6 +77,19 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
Action a1 = () => this.WindowState = WindowState.Maximized;
this.Dispatcher.BeginInvoke(a1, DispatcherPriority.ApplicationIdle);
+
+ var optionSet = new OptionSet()
+ {
+ {"c|commit", "show commit UI", v => {
+ if (!string.IsNullOrWhiteSpace(v))
+ {
+ Action act = () => HistoryViewCommands.PendingChanges.Execute(null, this);
+ this.Dispatcher.BeginInvoke(act, DispatcherPriority.ApplicationIdle);
+ }
+ } },
+ };
+
+ optionSet.Parse(Environment.GetCommandLineArgs());
}
private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
@@ -254,7 +269,7 @@ private void PendingChanges_Executed(object sender, ExecutedRoutedEventArgs e)
loading.Visibility = Visibility.Visible;
animation.Completed += (_, x) =>
{
- this.pendingChanges.Refresh();
+ this.pendingChanges.Refresh(gitViewModel.Tracker);
loading.Visibility = Visibility.Collapsed;
};
this.pendingChanges.RenderTransform.BeginAnimation(TranslateTransform.XProperty, animation);
Oops, something went wrong.

0 comments on commit 5a2bb41

Please sign in to comment.