Difference between revisions of "Git and Gitweb"

From Amahi Wiki
Jump to: navigation, search
 
(49 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
{{NeedsUpdate}}
 +
 +
 +
'''NOTE:'''  There is a [http://www.amahi.org/apps/gitweb one-click app] currently in ALPHA being tested.
 +
 
[http://git-scm.com/ Git] is a free & open source, distributed version control system designed to handle everything from small to very large projects with speed and efficiency.  Every Git clone is a full-fledged repository with complete history and full revision tracking capabilities, not dependent on network access or a central server. Branching and merging are fast and easy to do.  Coupled with [http://sourceforge.net/apps/trac/sourceforge/wiki/GitWeb%20repository%20browser Gitweb], provides a web interface for browsing your project.
 
[http://git-scm.com/ Git] is a free & open source, distributed version control system designed to handle everything from small to very large projects with speed and efficiency.  Every Git clone is a full-fledged repository with complete history and full revision tracking capabilities, not dependent on network access or a central server. Branching and merging are fast and easy to do.  Coupled with [http://sourceforge.net/apps/trac/sourceforge/wiki/GitWeb%20repository%20browser Gitweb], provides a web interface for browsing your project.
  
This tutorial will show you how to install, create a repo, and browse that repo on your HDA.
+
This tutorial will show you how to install, create a repo, and browse that repo on your HDA.
  
  
Line 16: Line 21:
 
<li>Choose '''Create'''</li>
 
<li>Choose '''Create'''</li>
 
<li>[[Open_Terminal_as_root|Open a terminal as root]] user and do the following:
 
<li>[[Open_Terminal_as_root|Open a terminal as root]] user and do the following:
{{Code|cd /etc/httpd/conf.d}}</li>
+
<li>Install dependencies
<li>Look for the ''####-gitweb.conf'' (#### is some number, i.e. 1000) file and open it in your favorite editor.  Remove the text between '''ServerAlias''' and the last two lines, then add the following
+
<pre>yum -y install git git-daemon gitweb</pre></li>
{{Text|Text=Alias /git /var/hda/web-apps/gitweb/html/
+
<li>Look for the ''####-gitweb.conf'' in '''/etc/httpd/conf.d''' (#### is some number, i.e. 1000) file and open it in your favorite editor.  Add text after '''ServerAlias''' line
 +
<pre>Text=Alias /git /var/hda/web-apps/gitweb/html
 
RewriteEngine On
 
RewriteEngine On
 
RewriteRule ^git$ git/ [R]
 
RewriteRule ^git$ git/ [R]
 
DirectoryIndex gitweb.cgi
 
DirectoryIndex gitweb.cgi
 
SetEnv GITWEB_CONFIG "/etc/gitweb.conf"
 
SetEnv GITWEB_CONFIG "/etc/gitweb.conf"
AddHandler cgi-script .cgi
+
AddHandler cgi-script .cgi</pre></li>
 
 
/etc/httpd/conf.d/git.conf  
 
<Directory /var/hda/web-apps/gitweb/html>   
 
      RewriteEngine On
 
      RewriteBase /git/
 
      RewriteRule ^$ gitweb.cgi  [L]
 
      RewriteCond %{REQUEST_FILENAME} !-f
 
      RewriteCond %{REQUEST_FILENAME} !-d
 
      RewriteRule (.*) gitweb.cgi/$1  [QSA,L]
 
</Directory>}}</li>
 
<li>Restart web server to enable the changes
 
{{Code|/etc/init.d/httpd restart;}}</li>
 
 
<li>Create web page to browse repository</li>
 
<li>Create web page to browse repository</li>
{{Code|cd /var/hda/web-apps/gitweb
+
<pre>cd /var/hda/web-apps/gitweb
 
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
 
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
 
<html>
 
<html>
 
<head>
 
<head>
 
<title>Your Page Title</title>
 
<title>Your Page Title</title>
<meta http-equiv<nowiki>=</nowiki>"REFRESH" content<nowiki>=</nowiki>"0;url<nowiki>=</nowiki>http://git/git/"></HEAD>
+
<meta http-equiv<nowiki>=</nowiki>"REFRESH" content<nowiki>=</nowiki>"0;url<nowiki>=</nowiki>http://gitweb/git/"></HEAD>
 
<BODY>
 
<BODY>
 
Optional page text here.
 
Optional page text here.
 
</BODY>
 
</BODY>
 
</HTML>' > html/index.html
 
</HTML>' > html/index.html
chown apache.users html/index.html}}</li>
+
chown apache.users html/index.html</pre></li>
 
</ol>
 
</ol>
<li>Install dependencies
 
{{Code|yum -y install git git-daemon gitweb}}</li>
 
 
<li>Add user
 
<li>Add user
{{Code|useradd -U -d /var/cache/git -s /usr/libexec/git-core/git-shell git}}</li>
+
<pre>useradd -U -d /var/cache/git -s /usr/libexec/git-core/git-shell git</pre></li>
 
<li>Set directory permissions
 
<li>Set directory permissions
{{Code|cd /var/cache
+
<pre>cd /var/cache
 
chown -R git:git git
 
chown -R git:git git
chmod 755 git}}</li>
+
chmod 755 git/</pre></li>
<li>Create public SSH key storage
 
{{Code|cd /var/cache/git;
 
mkdir .ssh
 
chmod 700 .ssh
 
touch .ssh/authorized_keys
 
chmod 600 .ssh/authorized_keys
 
chown -R git:git .ssh/}}</li>
 
 
<li>Create '''/etc/init.d/git''' file and add the following
 
<li>Create '''/etc/init.d/git''' file and add the following
{{Text|Text=#!/bin/sh
+
<pre>#!/bin/sh
 
<nowiki>#</nowiki>
 
<nowiki>#</nowiki>
 
<nowiki>#</nowiki>  Startup/shutdown script for Git Daemon
 
<nowiki>#</nowiki>  Startup/shutdown script for Git Daemon
Line 77: Line 62:
 
   
 
   
 
DAEMON=/usr/libexec/git-core/git-daemon
 
DAEMON=/usr/libexec/git-core/git-daemon
ARGS<nowiki>=</nowiki>'--base-path<nowiki>=</nowiki>/var/cache/git --detach --syslog --export-all --user=git --group<nowiki>=</nowiki>git'
+
ARGS='--base-path=/var/cache/git --detach --syslog --export-all --user=git --group=git'
 
   
 
   
prog<nowiki>=</nowiki>git-daemon
+
prog=git-daemon
 
   
 
   
 
start () {
 
start () {
Line 86: Line 71:
 
  # start daemon
 
  # start daemon
 
  daemon $DAEMON $ARGS
 
  daemon $DAEMON $ARGS
  RETVAL<nowiki>=</nowiki>$?
+
  RETVAL=$?
 
  echo
 
  echo
  [ $RETVAL <nowiki>=</nowiki> 0 ] && touch /var/lock/git-daemon
+
  [ $RETVAL = 0 ] && touch /var/lock/git-daemon
 
  return $RETVAL
 
  return $RETVAL
 
}
 
}
Line 96: Line 81:
 
  echo -n $"Stopping $prog: "
 
  echo -n $"Stopping $prog: "
 
  killproc $DAEMON
 
  killproc $DAEMON
  RETVAL<nowiki>=</nowiki>$?
+
  RETVAL=$?
 
  echo
 
  echo
  [ $RETVAL <nowiki>=</nowiki> 0 ] && rm -f /var/lock/git-daemon
+
  [ $RETVAL = 0 ] && rm -f /var/lock/git-daemon
 
}
 
}
 
   
 
   
restart() <nowiki>{</nowiki>
+
restart() {
 
  stop
 
  stop
 
  start
 
  start
<nowiki>}</nowiki>
+
}
 
   
 
   
 
case $1 in
 
case $1 in
Line 118: Line 103:
 
  status)
 
  status)
 
  status $DAEMON
 
  status $DAEMON
  RETVAL<nowiki>=</nowiki>$?
+
  RETVAL=$?
 
  ;;
 
  ;;
 
  *)
 
  *)
 
   
 
   
  echo $"Usage: $prog <nowiki>{</nowiki>start<nowiki>|</nowiki>stop<nowiki>|</nowiki>restart<nowiki>|</nowiki>status<nowiki>}</nowiki>"
+
  echo $"Usage: $prog {start<nowiki>|</nowiki>stop<nowiki>|</nowiki>restart<nowiki>|</nowiki>status}"
 
  exit 3
 
  exit 3
 
esac
 
esac
 
   
 
   
exit $RETVAL}}</li>
+
exit $RETVAL</pre></li>
 
<li>Set init script to run
 
<li>Set init script to run
{{Code|chmod 755 /etc/init.d/git;
+
<pre>chmod 755 /etc/init.d/git;
chkconfig git on
+
/etc/init.d/git start
service git start}}</li>
+
/sbin/chkconfig git on</pre></li>
<li>Create repository
+
<li>Set User information (change '''user.name''' and '''user.email''' accordingly)
{{Code|cd /var/cache/git/
+
<pre>git config --global user.name "MyHDA"
mkdir test.git
+
git config --global user.email myhda@localhost</pre></li>
 +
<li>Create temporary repository
 +
<pre>cd /var/cache/git/
 +
git init test
 +
cd test</pre></li>
 +
<li>Add test file and a short description
 +
<pre>echo 'test' > README
 +
git add README
 +
git commit -a -m "initial README file"</pre></li>
 +
<li>Create local repository
 +
<pre>cd /var/cache/git/
 +
git clone test test.git
 
cd test.git
 
cd test.git
git init --bare
+
git push origin master</pre></li>
chown -R git:git ../test.git/}}</li>
+
<li>Edit '''/var/cache/git/test/.git/config''' and add the following at the bottom (change '''MyHDA''' as desired)
<li>Add a short description
+
<pre>[gitweb]
{{Code|cd /var/cache/git/test.git/
+
       owner = MyHDA</pre></li>
echo "test test repo" > description}}</li>
 
<li>Update '''config''' file as follows
 
{{Text|Text=[core]
 
      repositoryformatversion = 0
 
      filemode = true
 
      bare = true
 
 
[gitweb]
 
       owner = Your Name}}</li>
 
<li>Create local repository and commit
 
{{Code|mkdir ~/test
 
cd ~/test && git init
 
echo 'test' > README
 
git add README
 
git commit -m "initial README file"}}</li>
 
<li>Create SSH rsa public key
 
{{Code|ssh-keygen -t rsa -C "admin@yourisp.com" -N amahi -f /var/cache/git/.ssh/authorized_keys}}</li>
 
<li>Push to the repository
 
{{Code|git remote add origin git@git.yourisp.com:test.git
 
git push origin master}}</li>
 
 
<li>Add to bottom of '''/etc/gitweb.conf''' file
 
<li>Add to bottom of '''/etc/gitweb.conf''' file
{{Text|Text=$feature{'blame'}{'default'} = [undef];
+
<pre>$feature{'blame'}{'default'} = [undef];
 
$feature{'pickaxe'}{'default'} = [undef];
 
$feature{'pickaxe'}{'default'} = [undef];
 
$feature{'search'}{'default'} = [undef];
 
$feature{'search'}{'default'} = [undef];
Line 179: Line 155:
 
$feature{'pathinfo'}{'default'} = [1];
 
$feature{'pathinfo'}{'default'} = [1];
 
$my_uri = "http://gitweb/git/";
 
$my_uri = "http://gitweb/git/";
$home_link = "http://gitweb/git/;"}}</li>
+
$home_link = "http://gitweb/git/;"</pre></li>
 
<li>Copy web files and set permissions
 
<li>Copy web files and set permissions
{{Code|cp -r /var/www/git/* html
+
<pre>d /var/hda/web-apps/gitweb
chown -R apache:users html}}</li>
+
cp -r /var/www/git/* html
 +
chown -R apache:users html/</pre></li>
 +
<li>Update local repository description
 +
<pre>cd /var/cache/git
 +
sed -i '1d' test.git​/.git/description
 +
echo 'Test Repo' >> test.git​/.git/description</pre></li>
 +
<li>Edit '''/etc/httpd/conf.d/git.conf''' and replace with this text
 +
<pre><Directory /var/hda/web-apps/gitweb/html>   
 +
      RewriteEngine On
 +
      RewriteBase /git/
 +
      RewriteRule ^$ gitweb.cgi  [L]
 +
      RewriteCond %{REQUEST_FILENAME} !-f
 +
      RewriteCond %{REQUEST_FILENAME} !-d
 +
      RewriteRule (.*) gitweb.cgi/$1  [QSA,L]
 +
</Directory></pre></li>
 +
<li>Update permissions, remove temporary repository, and restart web server
 +
<pre>chown -R git.git /var/cache/git
 +
rm -rf /var/cache/git/test
 +
/etc/init.d/httpd restart</pre></li>
 
</ul>
 
</ul>
  
 
==Complete==
 
==Complete==
 
That is it.  Navigate to <nowiki>http://gitweb/git</nowiki> to browse the newly created repository.
 
That is it.  Navigate to <nowiki>http://gitweb/git</nowiki> to browse the newly created repository.
 +
 +
==Optional==
 +
You can add the Amahi repo by doing the following:
 +
<pre>cd /var/cache/git
 +
git clone git://git.amahi.org/amahi.git</pre>
  
 
==References==
 
==References==
 
[http://www.kutukupret.com/2010/03/26/hosting-your-own-git-repository-on-fedora-12/ Hosting your own Git Repository on Fedora 12]
 
[http://www.kutukupret.com/2010/03/26/hosting-your-own-git-repository-on-fedora-12/ Hosting your own Git Repository on Fedora 12]
 +
 +
[[Contribute_code|Contribute Code]]

Latest revision as of 17:00, 9 January 2021

Msgbox.update.png Update Needed
The contents of this page have become outdated or irrelevant. Please consider updating it.


NOTE: There is a one-click app currently in ALPHA being tested.

Git is a free & open source, distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Every Git clone is a full-fledged repository with complete history and full revision tracking capabilities, not dependent on network access or a central server. Branching and merging are fast and easy to do. Coupled with Gitweb, provides a web interface for browsing your project.

This tutorial will show you how to install, create a repo, and browse that repo on your HDA.


NOTE: Tested on Fedora 14.

Setup

  • Create web app (Advanced Settings must be enabled on HDA)
    1. From the Dashboard main page, select Apps at the top.
    2. Choose Webapps
    3. Select New Web App button at the bottom
    4. Enter gitweb for the Name (ensure the path reflects the name correctly)
    5. Choose Create
    6. Open a terminal as root user and do the following:
    7. Install dependencies
      yum -y install git git-daemon gitweb
    8. Look for the ####-gitweb.conf in /etc/httpd/conf.d (#### is some number, i.e. 1000) file and open it in your favorite editor. Add text after ServerAlias line
      Text=Alias /git /var/hda/web-apps/gitweb/html
      RewriteEngine On
      RewriteRule ^git$ git/ [R]
      DirectoryIndex gitweb.cgi
      SetEnv GITWEB_CONFIG "/etc/gitweb.conf"
      AddHandler cgi-script .cgi
    9. Create web page to browse repository
    10. cd /var/hda/web-apps/gitweb
      echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
      <html>
      <head>
      <title>Your Page Title</title>
      <meta http-equiv="REFRESH" content="0;url=http://gitweb/git/"></HEAD>
      <BODY>
      Optional page text here.
      </BODY>
      </HTML>' > html/index.html
      chown apache.users html/index.html
  • Add user
    useradd -U -d /var/cache/git -s /usr/libexec/git-core/git-shell git
  • Set directory permissions
    cd /var/cache
    chown -R git:git git
    chmod 755 git/
  • Create /etc/init.d/git file and add the following
    #!/bin/sh
    #
    #   Startup/shutdown script for Git Daemon
    #
    #   Linux chkconfig stuff:
    #
    #   chkconfig: 345 56 10
    #   description: Startup/shutdown script for Git Daemon
    #
    . /etc/init.d/functions
     
    DAEMON=/usr/libexec/git-core/git-daemon
    ARGS='--base-path=/var/cache/git --detach --syslog --export-all --user=git --group=git'
     
    prog=git-daemon
     
    start () {
     echo -n $"Starting $prog: "
     
     # start daemon
     daemon $DAEMON $ARGS
     RETVAL=$?
     echo
     [ $RETVAL = 0 ] && touch /var/lock/git-daemon
     return $RETVAL
    }
     
    stop () {
     # stop daemon
     echo -n $"Stopping $prog: "
     killproc $DAEMON
     RETVAL=$?
     echo
     [ $RETVAL = 0 ] && rm -f /var/lock/git-daemon
    }
     
    restart() {
     stop
     start
    }
     
    case $1 in
     start)
     start
     ;;
     stop)
     stop
     ;;
     restart)
     restart
     ;;
     status)
     status $DAEMON
     RETVAL=$?
     ;;
     *)
     
     echo $"Usage: $prog {start|stop|restart|status}"
     exit 3
    esac
     
    exit $RETVAL
  • Set init script to run
    chmod 755 /etc/init.d/git;
    /etc/init.d/git start
    /sbin/chkconfig git on
  • Set User information (change user.name and user.email accordingly)
    git config --global user.name "MyHDA"
    git config --global user.email myhda@localhost
  • Create temporary repository
    cd /var/cache/git/
    git init test
    cd test
  • Add test file and a short description
    echo 'test' > README
    git add README
    git commit -a -m "initial README file"
  • Create local repository
    cd /var/cache/git/
    git clone test test.git
    cd test.git
    git push origin master
  • Edit /var/cache/git/test/.git/config and add the following at the bottom (change MyHDA as desired)
    [gitweb]
           owner = MyHDA
  • Add to bottom of /etc/gitweb.conf file
    $feature{'blame'}{'default'} = [undef];
    $feature{'pickaxe'}{'default'} = [undef];
    $feature{'search'}{'default'} = [undef];
    $feature{'grep'}{'default'} = 1;
    $feature{'snapshot'}{'default'} = ['tgz', 'gzip', 'zip'];
    $feature{'snapshot'}{'override'} = 1;
    $site_name = "HDA Git";
    $projectroot = '/var/cache/git/';
    $projects_list_description_width = 50;
    $git_temp = "/tmp";
    $home_text = "indextext.html";
    $site_footer = "indexfooter.html";
    $projects_list = $projectroot;
    $home_link_str = "http://gitweb / git ";
    $stylesheet = "/git/static/gitweb.css";
    $logo = "/git/static/git-logo.png";
    $favicon = "/git/static/git-favicon.png";
    $feature{'pathinfo'}{'default'} = [1];
    $my_uri = "http://gitweb/git/";
    $home_link = "http://gitweb/git/;"
  • Copy web files and set permissions
    d /var/hda/web-apps/gitweb
    cp -r /var/www/git/* html
    chown -R apache:users html/
  • Update local repository description
    cd /var/cache/git
    sed -i '1d' test.git​/.git/description
    echo 'Test Repo' >> test.git​/.git/description
  • Edit /etc/httpd/conf.d/git.conf and replace with this text
    <Directory /var/hda/web-apps/gitweb/html>     
           RewriteEngine On
           RewriteBase /git/
           RewriteRule ^$ gitweb.cgi  [L]
           RewriteCond %{REQUEST_FILENAME} !-f
           RewriteCond %{REQUEST_FILENAME} !-d
           RewriteRule (.*) gitweb.cgi/$1  [QSA,L]
    </Directory>
  • Update permissions, remove temporary repository, and restart web server
    chown -R git.git /var/cache/git
    rm -rf /var/cache/git/test
    /etc/init.d/httpd restart

Complete

That is it. Navigate to http://gitweb/git to browse the newly created repository.

Optional

You can add the Amahi repo by doing the following:

cd /var/cache/git
git clone git://git.amahi.org/amahi.git

References

Hosting your own Git Repository on Fedora 12

Contribute Code