Esempio n. 1
0
        private static bool UpdateIfType(Ref newRef, string relPath, RefType refType)
        {
            var type = NameFromType(refType);

            if (!relPath.StartsWith(type))
                return false;

            newRef.Type = refType;
            var temp = relPath.Substring(type.Length + 1).Split(new[] { '/', '\\' }, 2);

            newRef.RemoteName = temp[0];
            newRef.Name = relPath.Substring(type.Length + 1);

            return true;
        }
Esempio n. 2
0
        async Task ICommands.SaveAsync(string id, byte[] data)
        {
            ((ICommands)this).Delete(id);

            var sha = await this._objectStorage.WriteAsync(data);

            var @ref = new Ref
            {
                Id = sha,
                Type = RefType.Head,
                Name = id,
                IsPacked = false,
                Location = System.IO.Path.Combine(this._refStorage.HeadsLocation, id.Replace('/', '\\')) //TODO windows
            };

            this._refStorage.Branches.Add(@ref);
        }
Esempio n. 3
0
        ///// <summary>
        ///// Gets or sets the path of the parent directory ie .git/refs/heads.
        ///// </summary>
        ///// <value>
        ///// The refs location.
        ///// </value>
        //public string RefsLocation { get; set; }
        public static Ref FromLocation(string path, string refsPath)
        {
            var newRef = new Ref
            {
                Location = path,
                Id = File.ReadAllText(path).TrimEnd()
            };

            var relPath = Helper.MakeRelativePath(refsPath, path);
            if (UpdateIfType(newRef, relPath, RefType.Tag) ||
                UpdateIfType(newRef, relPath, RefType.Remote) ||
                UpdateIfType(newRef, relPath, RefType.Head))
            {
                return newRef;
            }

            throw new ArgumentException("The location provided does not appear to be in the repository.");
        }