lib/gitolite/gitolite_admin.rb in gitolite-rugged-1.2.1.pre.devel vs lib/gitolite/gitolite_admin.rb in gitolite-rugged-1.2.2
- old
+ new
@@ -18,11 +18,15 @@
# Gitolite-Admin settings
config_dir: "conf",
key_dir: "keydir",
key_subdir: "",
config_file: "gitolite.conf",
- lock_file_path: '.lock'
+ lock_file_path: '.lock',
+
+ # Repo settings
+ update_on_init: true,
+ reset_before_update: true
}
class << self
# Checks if the given path is a gitolite-admin repository
@@ -31,11 +35,11 @@
def is_gitolite_admin_repo?(dir)
# First check if it is a git repository
begin
repo = Rugged::Repository.new(dir)
return false if repo.empty?
- rescue Rugged::RepositoryError
+ rescue Rugged::RepositoryError, Rugged::OSError
return false
end
# Check if config file, key directory exist
[ File.join(dir, DEFAULTS[:config_dir]), File.join(dir, DEFAULTS[:key_dir]),
@@ -44,11 +48,11 @@
true
end
def admin_url(settings)
- [settings[:git_user], '@', settings[:host], '/gitolite-admin.git'].join
+ ['ssh://', settings[:git_user], '@', settings[:host], '/gitolite-admin.git'].join
end
end
# Intialize with the path to
# the gitolite-admin repository
@@ -77,26 +81,31 @@
@settings.fetch(:public_key)
@settings.fetch(:private_key)
# setup credentials
@credentials = Rugged::Credentials::SshKey.new(
- username: settings[:git_user], publickey: settings[:public_key],
- privatekey: settings[:private_key] )
-
- @repo =
- if self.class.is_gitolite_admin_repo?(path)
- Rugged::Repository.new(path, credentials: @credentials)
- else
- clone
- end
+ username: @settings[:git_user],
+ publickey: settings[:public_key],
+ privatekey: settings[:private_key]
+ )
@config_dir_path = File.join(@path, @settings[:config_dir])
@config_file_path = File.join(@config_dir_path, @settings[:config_file])
@key_dir_path = File.join(@path, relative_key_dir)
- @commit_author = { email: settings[:author_email], name: settings[:author_name] }
+ @commit_author = { email: @settings[:author_email], name: @settings[:author_name] }
+ if self.class.is_gitolite_admin_repo?(path)
+ @repo = Rugged::Repository.new(path, credentials: @credentials )
+ # Update repository
+ if @settings[:update_on_init]
+ update
+ end
+ else
+ @repo = clone
+ end
+
reload!
end
#
@@ -147,14 +156,13 @@
ssh_keys[key.owner].delete key
end
# This method will destroy all local tracked changes, resetting the local gitolite
- # git repo to HEAD and reloading the entire repository
+ # git repo to HEAD
def reset!
@repo.reset('origin/master', :hard)
- reload!
end
# This method will destroy the in-memory data structures and reload everything
# from the file system
@@ -199,11 +207,11 @@
# Write index to git and resync fs
commit_tree = index.write_tree @repo
index.write
- commit_author = { email: 'wee@example.org', name: 'gitolite-rugged gem', time: Time.now }
+ commit_author = @commit_author.merge(time: Time.now)
Rugged::Commit.create(@repo,
author: commit_author,
committer: commit_author,
message: commit_msg || @settings[:commit_msg],
@@ -240,28 +248,35 @@
end
# Updates the repo with changes from remote master
# Warning: This resets the repo before pulling in the changes.
- def update(settings = {})
- reset!
+ def update()
- # Currently, this only supports merging origin/master into master.
- master = repo.branches["master"].target
- origin_master = repo.branches["origin/master"].target
+ # Reset --hard repo before update
+ if @settings[:reset_before_update]
+ reset!
+ end
+ # Fetch changes from origin
+ @repo.fetch('origin', credentials: @credentials )
+
+ # Currently, only merging from origin/master into master is supported.
+ master = @repo.references["refs/heads/master"].target
+ origin_master = @repo.references["refs/remotes/origin/master"].target
+
# Create the merged index in memory
merge_index = repo.merge_commits(master, origin_master)
# Complete the merge by comitting it
merge_commit = Rugged::Commit.create(@repo,
parents: [ master, origin_master ],
tree: merge_index.write_tree(@repo),
message: '[gitolite-rugged] Merged `origin/master` into `master`',
author: @commit_author,
committer: @commit_author,
- update_ref: 'master'
+ update_ref: 'refs/heads/master'
)
reload!
end
@@ -276,11 +291,11 @@
# +(:git_user)@(:hostname)/gitolite-admin.git+
#
# The hostname may use an optional :port to allow for custom SSH ports.
# E.g., +git@localhost:2222/gitolite-admin.git+
#
- def clone()
- Rugged::Repository.clone_at(admin_url(@settings), File.expand_path(@path), credentials: @credentials)
+ def clone
+ Rugged::Repository.clone_at(GitoliteAdmin.admin_url(@settings), File.expand_path(@path), credentials: @credentials )
end
def load_config
Config.new(@config_file_path)