Exemplo n.º 1
0
 /// <summary>Create a repository using the local file system.</summary>
 /// <remarks>Create a repository using the local file system.</remarks>
 /// <param name="options">description of the repository's important paths.</param>
 /// <exception cref="System.IO.IOException">
 /// the user configuration file or repository configuration file
 /// cannot be accessed.
 /// </exception>
 protected internal FileRepository(BaseRepositoryBuilder options) : base(options)
 {
     systemConfig = SystemReader.GetInstance().OpenSystemConfig(null, FileSystem);
     userConfig   = SystemReader.GetInstance().OpenUserConfig(systemConfig, FileSystem);
     repoConfig   = new FileBasedConfig(userConfig, FileSystem.Resolve(Directory, Constants
                                                                       .CONFIG), FileSystem);
     LoadSystemConfig();
     LoadUserConfig();
     LoadRepoConfig();
     repoConfig.AddChangeListener(new _ConfigChangedListener_171(this));
     refs           = new RefDirectory(this);
     objectDatabase = new ObjectDirectory(repoConfig, options.GetObjectDirectory(), options
                                          .GetAlternateObjectDirectories(), FileSystem);
     //
     //
     //
     if (objectDatabase.Exists())
     {
         long repositoryFormatVersion = ((FileBasedConfig)GetConfig()).GetLong(ConfigConstants
                                                                               .CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, 0);
         if (repositoryFormatVersion > 0)
         {
             throw new IOException(MessageFormat.Format(JGitText.Get().unknownRepositoryFormat2
                                                        , Sharpen.Extensions.ValueOf(repositoryFormatVersion)));
         }
     }
     if (!IsBare)
     {
         snapshot = FileSnapshot.Save(GetIndexFile());
     }
 }
Exemplo n.º 2
0
 /// <summary>Create a repository using the local file system.</summary>
 /// <remarks>Create a repository using the local file system.</remarks>
 /// <param name="options">description of the repository's important paths.</param>
 /// <exception cref="System.IO.IOException">
 /// the user configuration file or repository configuration file
 /// cannot be accessed.
 /// </exception>
 protected internal FileRepository(BaseRepositoryBuilder options) : base(options)
 {
     systemConfig = SystemReader.GetInstance().OpenSystemConfig(null, FileSystem);
     userConfig   = SystemReader.GetInstance().OpenUserConfig(systemConfig, FileSystem);
     repoConfig   = new FileBasedConfig(userConfig, FileSystem.Resolve(Directory, "config"
                                                                       ), FileSystem);
     //
     //
     LoadSystemConfig();
     LoadUserConfig();
     LoadRepoConfig();
     repoConfig.AddChangeListener(new _ConfigChangedListener_168(this));
     refs           = new RefDirectory(this);
     objectDatabase = new ObjectDirectory(repoConfig, options.GetObjectDirectory(), options
                                          .GetAlternateObjectDirectories(), FileSystem);
     //
     //
     //
     if (objectDatabase.Exists())
     {
         string repositoryFormatVersion = ((FileBasedConfig)GetConfig()).GetString(ConfigConstants
                                                                                   .CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION);
         if (!"0".Equals(repositoryFormatVersion))
         {
             throw new IOException(MessageFormat.Format(JGitText.Get().unknownRepositoryFormat2
                                                        , repositoryFormatVersion));
         }
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Construct a new
 /// <see cref="PersonIdent">PersonIdent</see>
 /// with current time.
 /// </summary>
 /// <param name="aName"></param>
 /// <param name="aEmailAddress"></param>
 public PersonIdent(string aName, string aEmailAddress)
 {
     name         = aName;
     emailAddress = aEmailAddress;
     when         = SystemReader.GetInstance().GetCurrentTime();
     tzOffset     = SystemReader.GetInstance().GetTimezone(when);
 }
        protected override void ConfigureVersionControlSystem()
        {
            var mockSystemReader = new MockSystemReader(SystemReader.GetInstance());

            SystemReader.SetInstance(mockSystemReader);

            For <IVersionControlSystem>().Use <GitVersionControlSystem>();
        }
Exemplo n.º 5
0
        /// <summary>Creates new PersonIdent from config info in repository, with current time.
        ///     </summary>
        /// <remarks>
        /// Creates new PersonIdent from config info in repository, with current time.
        /// This new PersonIdent gets the info from the default committer as available
        /// from the configuration.
        /// </remarks>
        /// <param name="repo"></param>
        public PersonIdent(Repository repo)
        {
            UserConfig config = repo.GetConfig().Get(UserConfig.KEY);

            name         = config.GetCommitterName();
            emailAddress = config.GetCommitterEmail();
            when         = SystemReader.GetInstance().GetCurrentTime();
            tzOffset     = SystemReader.GetInstance().GetTimezone(when);
        }
Exemplo n.º 6
0
        internal static bool IsValidPath(byte[] path)
        {
            if (path.Length == 0)
            {
                return(false);
            }
            // empty path is not permitted.
            bool componentHasChars = false;

            foreach (byte c in path)
            {
                switch (c)
                {
                case 0:
                {
                    return(false);
                }

                case (byte)('/'):
                {
                    // NUL is never allowed within the path.
                    if (componentHasChars)
                    {
                        componentHasChars = false;
                    }
                    else
                    {
                        return(false);
                    }
                    break;
                }

                case (byte)('\\'):
                case (byte)(':'):
                {
                    // Tree's never have a backslash in them, not even on Windows
                    // but even there we regard it as an invalid path
                    if (SystemReader.GetInstance().IsWindows())
                    {
                        return(false);
                    }
                    goto default;
                }

                default:
                {
                    //$FALL-THROUGH$
                    componentHasChars = true;
                    break;
                }
                }
            }
            return(componentHasChars);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Create a new Git repository initializing the necessary files and
        /// directories.
        /// </summary>
        /// <remarks>
        /// Create a new Git repository initializing the necessary files and
        /// directories.
        /// </remarks>
        /// <param name="bare">if true, a bare repository is created.</param>
        /// <exception cref="System.IO.IOException">in case of IO problem</exception>
        public override void Create(bool bare)
        {
            FileBasedConfig cfg = ((FileBasedConfig)GetConfig());

            if (cfg.GetFile().Exists())
            {
                throw new InvalidOperationException(MessageFormat.Format(JGitText.Get().repositoryAlreadyExists
                                                                         , Directory));
            }
            FileUtils.Mkdirs(Directory, true);
            refs.Create();
            objectDatabase.Create();
            FileUtils.Mkdir(new FilePath(Directory, "branches"));
            FileUtils.Mkdir(new FilePath(Directory, "hooks"));
            RefUpdate head = UpdateRef(Constants.HEAD);

            head.DisableRefLog();
            head.Link(Constants.R_HEADS + Constants.MASTER);
            bool fileMode;

            if (FileSystem.SupportsExecute())
            {
                FilePath tmp = FilePath.CreateTempFile("try", "execute", Directory);
                FileSystem.SetExecute(tmp, true);
                bool on = FileSystem.CanExecute(tmp);
                FileSystem.SetExecute(tmp, false);
                bool off = FileSystem.CanExecute(tmp);
                FileUtils.Delete(tmp);
                fileMode = on && !off;
            }
            else
            {
                fileMode = false;
            }
            cfg.SetInt(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION
                       , 0);
            cfg.SetBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE
                           , fileMode);
            if (bare)
            {
                cfg.SetBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_BARE
                               , true);
            }
            cfg.SetBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_LOGALLREFUPDATES
                           , !bare);
            if (SystemReader.GetInstance().IsMacOS())
            {
                // Java has no other way
                cfg.SetBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_PRECOMPOSEUNICODE
                               , true);
            }
            cfg.Save();
        }
Exemplo n.º 8
0
        public PluginRegistry()
        {
            For <ICustomPluginSpecifyMessageHandlerOrdering>().Singleton().Use
            <MashupManagerPluginSpecifyMessageHandlerOrdering>();
            For <IMashupInfoRepository>().Use <MashupInfoRepository>();
            For <ISingleProfile>().Singleton().Use <SingleProfile>();
            For <IMashupScriptStorage>().Use <MashupScriptStorage>();
            For <IMashupLocalFolder>().Use <MashupLocalFolder>();
            For <ILibrary>().Use <Library>();
            For <ILibraryLocalFolder>().Use <LibraryLocalFolder>();
            For <ILibraryRepositoryFactory>().Use <LibraryRepositoryFactory>();
            For <ILibraryRepositorySynchronizer>().Singleton().Use <LibraryRepositorySynchronizer>();
            For <ILibraryRepositoryConfigStorage>().Use <LibraryRepositoryConfigStorage>();
            For <IMashupLoader>().Use <MashupLoader>();

            SystemReader.SetInstance(new MockSystemReader(SystemReader.GetInstance()));
        }
Exemplo n.º 9
0
            /// <exception cref="NGit.Errors.TransportException"></exception>
            public virtual SystemProcess Exec(string command, int timeout)
            {
                string         ssh   = SystemReader.GetInstance().Getenv("GIT_SSH");
                bool           putty = ssh.ToLower().Contains("plink");
                IList <string> args  = new AList <string>();

                args.AddItem(ssh);
                if (putty && !ssh.ToLower().Contains("tortoiseplink"))
                {
                    args.AddItem("-batch");
                }
                if (0 < this._enclosing.GetURI().GetPort())
                {
                    args.AddItem(putty ? "-P" : "-p");
                    args.AddItem(this._enclosing.GetURI().GetPort().ToString());
                }
                if (this._enclosing.GetURI().GetUser() != null)
                {
                    args.AddItem(this._enclosing.GetURI().GetUser() + "@" + this._enclosing.GetURI().
                                 GetHost());
                }
                else
                {
                    args.AddItem(this._enclosing.GetURI().GetHost());
                }
                args.AddItem(command);
                ProcessStartInfo pb = new ProcessStartInfo();

                pb.SetCommand(args);
                if (this._enclosing.local.Directory != null)
                {
                    pb.EnvironmentVariables.Put(Constants.GIT_DIR_KEY, this._enclosing.local.Directory
                                                .GetPath());
                }
                try
                {
                    return(pb.Start());
                }
                catch (IOException err)
                {
                    throw new TransportException(err.Message, err);
                }
            }
Exemplo n.º 10
0
        public virtual void TestCloneWithAutoSetupRebase()
        {
            FilePath     directory = CreateTempDirectory("testCloneRepository1");
            CloneCommand command   = Git.CloneRepository();

            command.SetDirectory(directory);
            command.SetURI("file://" + git.GetRepository().WorkTree.GetPath());
            Git git2 = command.Call();

            AddRepoToClose(git2.GetRepository());
            NUnit.Framework.Assert.IsFalse(git2.GetRepository().GetConfig().GetBoolean(ConfigConstants
                                                                                       .CONFIG_BRANCH_SECTION, "test", ConfigConstants.CONFIG_KEY_REBASE, false));
            FileBasedConfig userConfig = SystemReader.GetInstance().OpenUserConfig(null, git.
                                                                                   GetRepository().FileSystem);

            userConfig.SetString(ConfigConstants.CONFIG_BRANCH_SECTION, null, ConfigConstants
                                 .CONFIG_KEY_AUTOSETUPREBASE, ConfigConstants.CONFIG_KEY_ALWAYS);
            userConfig.Save();
            directory = CreateTempDirectory("testCloneRepository2");
            command   = Git.CloneRepository();
            command.SetDirectory(directory);
            command.SetURI("file://" + git.GetRepository().WorkTree.GetPath());
            git2 = command.Call();
            AddRepoToClose(git2.GetRepository());
            NUnit.Framework.Assert.IsTrue(git2.GetRepository().GetConfig().GetBoolean(ConfigConstants
                                                                                      .CONFIG_BRANCH_SECTION, "test", ConfigConstants.CONFIG_KEY_REBASE, false));
            userConfig.SetString(ConfigConstants.CONFIG_BRANCH_SECTION, null, ConfigConstants
                                 .CONFIG_KEY_AUTOSETUPREBASE, ConfigConstants.CONFIG_KEY_REMOTE);
            userConfig.Save();
            directory = CreateTempDirectory("testCloneRepository2");
            command   = Git.CloneRepository();
            command.SetDirectory(directory);
            command.SetURI("file://" + git.GetRepository().WorkTree.GetPath());
            git2 = command.Call();
            AddRepoToClose(git2.GetRepository());
            NUnit.Framework.Assert.IsTrue(git2.GetRepository().GetConfig().GetBoolean(ConfigConstants
                                                                                      .CONFIG_BRANCH_SECTION, "test", ConfigConstants.CONFIG_KEY_REBASE, false));
        }
 public string Run()
 {
     return(SystemReader.GetInstance().GetProperty("line.separator"));
 }
 /// <summary>Read standard Git environment variables and configure from those.</summary>
 /// <remarks>
 /// Read standard Git environment variables and configure from those.
 /// <p>
 /// This method tries to read the standard Git environment variables, such as
 /// <code>GIT_DIR</code>
 /// and
 /// <code>GIT_WORK_TREE</code>
 /// to configure this builder
 /// instance. If an environment variable is set, it overrides the value
 /// already set in this builder.
 /// </remarks>
 /// <returns>
 ///
 /// <code>this</code>
 /// (for chaining calls).
 /// </returns>
 public virtual B ReadEnvironment()
 {
     return(ReadEnvironment(SystemReader.GetInstance()));
 }
Exemplo n.º 13
0
 private PersonIdent(string aName, string aEmailAddress, long when) : this(aName,
                                                                           aEmailAddress, when, SystemReader.GetInstance().GetTimezone(when))
 {
 }
Exemplo n.º 14
0
 /// <summary>
 /// Construct a new
 /// <see cref="PersonIdent">PersonIdent</see>
 /// with current time.
 /// </summary>
 /// <param name="aName"></param>
 /// <param name="aEmailAddress"></param>
 public PersonIdent(string aName, string aEmailAddress) : this(aName, aEmailAddress
                                                               , SystemReader.GetInstance().GetCurrentTime())
 {
 }
Exemplo n.º 15
0
 private static bool UseExtSession()
 {
     return(SystemReader.GetInstance().Getenv("GIT_SSH") != null);
 }
Exemplo n.º 16
0
 private static SystemReader System()
 {
     return(SystemReader.GetInstance());
 }