Esempio n. 1
0
        public void EditChangeLog(Entry selected)
        {
            if (selected == null)
                throw new ArgumentNullException ("You must select a file first");
            string changelog = FindChangeLog (selected);
            if (changelog == null)
                throw new Exception ("No changelog found");
            string sdiff = Execute ("git", "diff --staged " + changelog);
            string fn = selected.filename.Substring (Path.GetDirectoryName (changelog).Length == 0 ? 0 : Path.GetDirectoryName (changelog).Length + 1);
            string content = File.ReadAllText (changelog);

            if (string.IsNullOrEmpty (sdiff) || string.IsNullOrEmpty (content)) {
                string entry = string.Format (
            @"{0:yyyy-MM-dd}  Rolf Bjarne Kvinge  <*****@*****.**>

            * {1}:

            ", DateTime.Now, fn);

                File.WriteAllText (changelog, entry + content);
            } else {
                string eol = GetEol (changelog);
                string l = "\t* " + fn + ":" + eol;
                int idx = 0;
                idx = content.IndexOf (eol) + eol.Length;
                idx = content.IndexOf (eol, idx) + eol.Length;
                content = content.Substring (0, idx) + l + content.Substring (idx);
                File.WriteAllText (changelog, content);
            }
            Console.WriteLine ("Opening ChangeLog for editing...");
            //Execute ("gnome-terminal", "--maximize -e \"nano -c " + changelog + "\"", false);
            Execute ("meld", Path.Combine (Environment.CurrentDirectory, changelog), false);
            Execute ("git", "add " + changelog);
            Console.WriteLine ("ChangeLog added");
            selected.edited_changelog = true;
        }
Esempio n. 2
0
        static string FindChangeLog(Entry entry)
        {
            string find;
            string dir = Path.GetDirectoryName (entry.filename);
            do {
                find = Path.Combine (dir, "ChangeLog");
                if (File.Exists (find)) {
                    Console.WriteLine ("Found ChangeLog in: {0}", dir);
                    return find;
                }
                Console.WriteLine ("No ChangeLog in {0} (filename: {1})", dir, entry.filename);
                if (dir == "")
                    break;
                dir = Path.GetDirectoryName (dir);
            } while (dir != "/");

            return null;
        }
Esempio n. 3
0
        private void ShowDiff(Entry entry)
        {
            string staged = diff.GetDiff (entry, true);
            string unstaged = diff.GetDiff (entry, false);
            //ShowDiff (diff.GetDiff (entry, staged));

            ShowHunks (diff.GetDiff (entry, false), lstUnstagedHunks);
            if (string.IsNullOrEmpty (unstaged)) {
                if (tabDiff.TabPages.Contains (tabUnstaged))
                    tabDiff.TabPages.Remove (tabUnstaged);
            } else {
                if (!tabDiff.TabPages.Contains (tabUnstaged))
                    tabDiff.TabPages.Add (tabUnstaged);
            }

            ShowHunks (diff.GetDiff (entry, true), lstStagedHunks);
            if (string.IsNullOrEmpty (staged)) {
                if (tabDiff.TabPages.Contains (tabStaged))
                    tabDiff.TabPages.Remove (tabStaged);
            } else {
                if (!tabDiff.TabPages.Contains (tabStaged))
                    tabDiff.TabPages.Insert (0, tabStaged);
                if (!index_processing)
                    tabDiff.SelectedTab = tabStaged;
            }
            if (!index_processing)
                ActiveControl = lstFiles;
        }
Esempio n. 4
0
        public void RefreshList()
        {
            int Ac = 0, ADc = 0, DAc = 0, Dc = 0;
            List<string> diff = ExecuteToLines ("git", "diff --name-only --ignore-submodules");
            List<string> staged = ExecuteToLines ("git", "diff --name-only --staged");
            List<string> untracked = ExecuteToLines ("git", "ls-files --other --exclude-standard");
            List<string> all = new List<string> (diff);

            selected = null;
            foreach (var s in staged) {
                if (!all.Contains (s))
                    all.Add (s);
            }
            all.Sort ();

            entries.Clear ();
            foreach (var file in all) {
                if (PREFIX.Length > 1 && !file.StartsWith (PREFIX))
                    continue;
                Entry entry = new Entry ();
                entry.filename = file;
                entry.staged = staged.Contains (file);
                entry.staged_whole = !diff.Contains (file);
                if (Directory.Exists (file)) {
                    entry.is_directory = true;
                } else if (!File.Exists (file)) {
                    entry.deleted = true;
                } else {
                    entry.messed_up_eol = IsEolMessedUp (file, out Ac, out ADc, out DAc, out Dc, ref entry.is_binary);
                    if (!entry.messed_up_eol) {
                        if (Ac > 0) {
                            entry.eol = "LF  ";
                        } else if (ADc > 0) {
                            entry.eol = "LFCR";
                        } else if (DAc > 0) {
                            entry.eol = "CRLF";
                        } else if (Dc > 0) {
                            entry.eol = "CR  ";
                        }
                    }
                }
                entries.Add (entry);
            }
            foreach (var file in untracked) {
                if (PREFIX.Length > 1 && !file.StartsWith (PREFIX))
                    continue;
                Entry entry = new Entry ();
                entry.filename = file;
                entry.untracked = true;
                entries.Add (entry);
            }

            list_dirty = false;
        }
Esempio n. 5
0
        public string GetDiff(Entry selected, bool? staged)
        {
            string diff = null;
            string color = "--no-color";

            if (selected == null) {
                if (staged.HasValue && staged.Value) {
                    diff = Execute ("git", "diff --staged " + color, true);
                } else {
                    diff = Execute ("git", "diff " + color, true);
                }
            } else {
                if (selected.untracked) {
                    diff = File.ReadAllText (selected.filename);
                } else if (((selected.staged_whole || selected.staged) && !(staged.HasValue && !staged.Value)) || (staged.HasValue && staged.Value)) {
                    diff = Execute ("git", "diff --staged " + color + " -- " + selected.filename, true);
                } else {
                    diff = Execute ("git", "diff " + color + " -- " + selected.filename, true);
                }
            }

            return diff;
        }
Esempio n. 6
0
        public void Fixeol(Entry entry)
        {
            int Ac = 0, ADc = 0, DAc = 0, Dc = 0;
            bool dummy = false;
            if (!IsEolMessedUp (entry.filename, out Ac, out ADc, out DAc, out Dc, ref dummy))
                return;

            if (Dc == 0 && ADc == 0) {
                if (DAc < Ac) { // more unix than dos eols
                    Dos2Unix (entry.filename);
                } else {
                    Unix2Dos (entry.filename);
                }
            } else {
                Console.WriteLine ("Don't know how to convert {0}: A: {1}, AD: {2}, DA: {3}, D: {4}", entry.filename, Ac, ADc, DAc, Dc);
            }
        }