Yurik has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/133120

Change subject: Set proper SSH URL for all GIT repos (with username) - take 2
......................................................................

Set proper SSH URL for all GIT repos (with username) - take 2

This reverts commit aaa9ba98f1e4ac2f1103b22784db3f5dfab9d88a.

Change-Id: Id5938b55093afde571dd67e4e93d5ca98379d5f3
---
M README
M Vagrantfile
M lib/settings.rb
M puppet/modules/git/manifests/clone.pp
4 files changed, 85 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/vagrant 
refs/changes/20/133120/1

diff --git a/README b/README
index 9dca22c..ec0acd2 100644
--- a/README
+++ b/README
@@ -34,17 +34,22 @@
  * Git: `git clone https://gerrit.wikimedia.org/r/mediawiki/vagrant`
 
 If you download the zip file or tarball, you will need to extract it to a
-directory of your choice. Once you do that, open up a terminal or a
-command-prompt, and change your working directory to the location of the
-extracted (or git-cloned) files. From there, run `vagrant up` to provision and
-boot the virtual machine.
+directory of your choice.
+
+Once you do that, open up a terminal or a command-prompt, and change your 
working
+directory to the location of the extracted (or git-cloned) files. From there,
+run `vagrant up` to provision and boot the virtual machine.
+
+If you have a Gerrit account, and plan to submit patches, enter your username 
at the prompt,
+otherwise just hit ENTER. You can always change it later in .settings.yaml and 
re-run `vagrant provision`.
 
 You'll now have to wait a bit, as Vagrant needs to retrieve the base image from
 Canonical, retrieve some additional packages, and install and configure each of
 them in turn.
 
 If it all worked, you should be able to browse to http://127.0.0.1:8080/ and
-see the main page of your MediaWiki instance.
+see the main page of your MediaWiki instance. http://127.0.0.1:8080/info.php
+will show PHP settings of the instance.
 
 
 ## Use
diff --git a/Vagrantfile b/Vagrantfile
index b5f18d0..48293a8 100644
--- a/Vagrantfile
+++ b/Vagrantfile
@@ -35,6 +35,7 @@
 # ----------------------
 # These can be changed by making a `.settings.yaml` file that contains YAML
 # replacements. Example:
+#   git_user: "username"
 #   box_name: "foo"
 #   vagrant_ram: 2048
 #   forward_ports:
@@ -43,6 +44,9 @@
 # Some roles may also provide new settings values. When applied these roles
 # will require a `vagrant reload` call for their changes to take effect.
 settings = Settings.new({
+    # Gerrit username, as used at gerrit.wikimedia.org, or '' if anonymous
+    'git_user' => '',
+
     # The vagrant box to load on the VM
     'box_name' => 'precise-cloud',
 
@@ -80,8 +84,19 @@
     end
 end
 
+# On first run prompt user to set username
+root_settings_file = File.join($DIR, '.settings.yaml')
+if !File.file?(root_settings_file)
+    print("Your GIT/Gerrit username has not been set. Please enter your 
username or hit ENTER for anonymous.\n")
+    print("If VM has already been created, run 'vagrant provision' to fix all 
remote git URLs.\n")
+    print("You can always set it later by editing .settings.yaml file\n")
+    print(' ==> ')
+    s = Settings.new({'git_user' => STDIN.gets.chomp})
+    s.save(root_settings_file)
+end
+
 # Read local configuration overrides
-settings.load(File.join($DIR, '.settings.yaml'))
+settings.load(root_settings_file)
 
 Vagrant.configure('2') do |config|
     config.vm.hostname = 'mediawiki-vagrant.dev'
@@ -165,6 +180,7 @@
             'fqdn'               => config.vm.hostname,
             'forwarded_port'     => settings['http_port'],
             'shared_apt_cache'   => '/vagrant/apt-cache/',
+            'git_user'           => settings['git_user'],
         }
     end
 
diff --git a/lib/settings.rb b/lib/settings.rb
index bbca438..ca9b2b9 100644
--- a/lib/settings.rb
+++ b/lib/settings.rb
@@ -6,6 +6,7 @@
 require 'yaml'
 
 class Settings
+
     def initialize(defaults)
         @settings = {}
         update(defaults)
@@ -41,4 +42,8 @@
             end
         end
     end
+
+    def save(file)
+        File.open(file, "w") { |f| f.write(@settings.to_yaml) }
+    end
 end
diff --git a/puppet/modules/git/manifests/clone.pp 
b/puppet/modules/git/manifests/clone.pp
index 8f3e97f..6c8a23e 100644
--- a/puppet/modules/git/manifests/clone.pp
+++ b/puppet/modules/git/manifests/clone.pp
@@ -29,16 +29,23 @@
     $remote = undef,
     $owner  = 'vagrant',
     $group  = 'vagrant',
+    $user = $::git_user,
 ) {
     include git
 
-    $url = $remote ? {
-        undef   => sprintf($git::urlformat, $title),
-        default => $remote,
+    if ( $remote ) {
+        $url = $remote
+        $origin = 'origin'
+    } else {
+        $url = sprintf($git::urlformat, $title)
+        $origin = $user ? {
+            ''      => 'origin',
+            default => 'gerrit',
+        }
     }
 
     exec { "git clone ${title}":
-        command     => "git clone --recursive --branch ${branch} ${url} 
${directory}",
+        command     => "git clone --origin ${origin} --recursive --branch 
${branch} ${url} ${directory}",
         creates     => "${directory}/.git",
         require     => Package['git'],
         user        => $owner,
@@ -46,4 +53,46 @@
         environment => 'HOME=/home/vagrant',
         timeout     => 0,
     }
+
+    #
+    # If remote is not set, configure the name and URL of the remote
+    #
+    if ( !$remote ) {
+        #
+        # Force remote name to "origin" for anonymous git, and "gerrit" when 
GIT_USER is set
+        #
+        $badorigin = $user ? {
+            ''      => 'gerrit',
+            default => 'origin',
+        }
+        exec { "git rename ${title}: ${badorigin} -> ${origin}":
+            command     => "git remote rename ${badorigin} ${origin}",
+            onlyif      => "test $(git config --get branch.${branch}.remote) = 
'${badorigin}'",
+            cwd         => $directory,
+            require     => Package['git'],
+            user        => $owner,
+            group       => $group,
+            environment => 'HOME=/home/vagrant',
+            timeout     => 0,
+        }
+
+        #
+        # Set GIT URL to SSH-based URL if GIT_USER is set, or HTTPS for 
anonymous
+        #
+        if ( $user ) {
+            $url2 = "ssh://${user}@gerrit.wikimedia.org:29418/${title}.git"
+        } else {
+            $url2 = "https://gerrit.wikimedia.org/r/${title}.git";
+        }
+        exec { "git set-remote ${url2}":
+            command     => "git remote set-url ${origin} ${url2}",
+            onlyif      => "test $(git config --get remote.${origin}.url) != 
'${url2}'",
+            cwd         => $directory,
+            require     => Package['git'],
+            user        => $owner,
+            group       => $group,
+            environment => 'HOME=/home/vagrant',
+            timeout     => 0,
+        }
+    }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/133120
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id5938b55093afde571dd67e4e93d5ca98379d5f3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/vagrant
Gerrit-Branch: master
Gerrit-Owner: Yurik <yu...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to