예제 #1
0
 public IGitStashResults ApplyStash(IGitStashApplyOptions options, int index)
 {
     lock (lockObject)
     {
         if (repo == null)
         {
             return(new GitStashResultsFailure("Repository not initialized"));
         }
         int count = repo.Stashes.Count();
         Logger.WriteLine(T["Apllying stash: {0}", index]);
         CheckForValidStashIndex(index);
         if (UntrackedFileChanges(index))
         {
             Logger.WriteLine(T["There are changes in your working directory, aborting."]);
             return(new GitStashResultsFailure(T["There are changes in your working directory, aborting."]));
         }
         StashApplyOptions sao = new StashApplyOptions();
         sao.ApplyModifiers = (options.Index ? StashApplyModifiers.ReinstateIndex : 0);
         StashApplyStatus status  = repo.Stashes.Apply(index, sao);
         GitStashResults  results = new GitStashResults(status, T["Succesfully applied stash."]);
         if (results.Success == false)
         {
             results.Message = T["There are changes in your working directory."];
             Logger.WriteLine(T["There are changes in your working directory, aborting."]);
         }
         if (repo.Stashes.Count() != count && results.Success)
         {
             Logger.WriteLine(T["Failed."]);
             throw new GitStashException(T["Command apply was called and reported success, but stash count changed."]);
         }
         Logger.WriteLine(T["Done."] + Environment.NewLine);
         return(results);
     }
 }
예제 #2
0
        public IGitStashResults SaveStash(IGitStashSaveOptions options)
        {
            lock (lockObject)
            {
                if (repo == null)
                {
                    return(new GitStashResultsFailure(T["Repository not initialized"]));
                }
                if (projects.IsDirty)
                {
                    Logger.WriteLine(T["Your project has not been saved, aborting"]);
                    return(new GitStashResultsFailure(T["Your project has not been saved"]));
                }
                Logger.WriteLine(T["Saving stash: {0}", options.Message]);
                bool hasChanges = WorkingDirHasChanges();
                int  count      = repo.Stashes.Count();
                if (!repo.RetrieveStatus().IsDirty)
                {
                    Logger.WriteLine(T["Nothing to save."]);
                    return(new GitStashResultsFailure(T["Nothing to stash."]));
                }
                StashModifiers sm = (options.KeepIndex ? StashModifiers.KeepIndex : 0);
                sm |= (options.Untracked ? StashModifiers.IncludeUntracked : 0);
                sm |= (options.Ignored ? StashModifiers.IncludeIgnored : 0);
                Stash stash = repo.Stashes.Add(Stasher, options.Message, sm);

                GitStashResults results = new GitStashResults(stash, T["Succesfully saved stash."]);
                if (results.Success == false)
                {
                    Logger.WriteLine(T["Failed."]);
                    results.Message = T["Failed to save stash."];
                }
                if (repo.Stashes.Count() <= count && results.Success)
                {
                    Logger.WriteLine(T["Failed."]);
                    throw new GitStashException("Command save was called and reported success, but stash didn't increase.");
                }
                if (results.Success == false)
                {
                    if (stash != null)
                    {
                        LogFilesInStash(stash);
                    }
                    if (hasChanges)
                    {
                        Logger.WriteLine(T["perhaps you have untracked files, and didn't select Untracked."]);
                        results.Message = T["perhaps you have untracked files, and didn't select Untracked."];
                    }
                    Logger.WriteLine(T["Failed."]);
                    OnStashesChanged(new StashesChangedEventArgs());
                    return(results);
                }
                LogFilesInStash(stash);
                Logger.WriteLine(T["Done."] + Environment.NewLine);
                OnStashesChanged(new StashesChangedEventArgs());
                return(results);
            }
        }