Welcome Guest, Not a member yet? Register   Sign In
Managing Git and .gitignore for a CI library..??
#1

Right now I have my PayPal CodeIgniter library in a Git repo with nothing but the library files themselves.  CI itself is not included in the project folder at all.  This makes it difficult for me to make quick changes and test them, though.

I'd like to create a new project locally that has CI fully installed, and then load my library into that, but I don't want Git to track CI itself.  I just want to track my library files only, so the GitHub repo would still only have the library files, but I could easily work locally.  

I was thinking I could just setup a .gitignore to ignore everything, and then un-ignore the library files/folders.  This is proving very difficult for some reason.  I've wasted lots of time on various forums and reading Git documentation on how to get this done with very sporadic results.

Is there any sort of a template or standard practice I can follow to easily manage my own CodeIgniter libraries in Git without simply including the entire CI structure with the library?

Any information on this would be greatly appreciated.  Thanks!
Reply
#2

If you are using Linux or Mac, you could use a bash script to quickly setup your development environment.

The following is a bash script that I use for my Community Auth project. It runs in less than 5 seconds:


Code:
#!/bin/bash
# This is the installer for those working on Community Auth development.
# Place and execute this script where IT WILL CREATE the web root directory.
# It will also create the database, as long as you set a valid user and password.

# The directory that git will clone into
SITEDIR="community_auth_ci_3"

# The base_url for CodeIgniter
# Note: make sure to escape slashes!
BASEURL="http:\/\/localhost.community_auth_ci_3\/"

# The name of the database to create
DBNAME="community_auth_ci_3"

# The DB user
DBUSER="root"

# The DB password
DBPASS=""

# If symlinks (soft links) should be used instead of copying files
SYMLINKS=false

# -------------------------------------------------------------------------

# Make sure not already installed
if [ ! -d ./$SITEDIR ];
then
# Clone the Community Auth repository on bitbucket
git clone [email protected]:skunkbad/community-auth-for-codeigniter-3.git $SITEDIR

# The web root directory should now exist
if [ -d ./$SITEDIR ];
then
# Move into web root
cd ./$SITEDIR

# Temporarily move Community Auth
mv ./application/third_party/community_auth/ ./community_auth_tmp/
rm -r ./application

# Temp file deleted after extract
TMPFILE=`mktemp`

# Download and extract CodeIgniter (skip old files so .gitignore is not replaced)
wget https://github.com/bcit-ci/CodeIgniter/archive/master.tar.gz -O $TMPFILE
tar -xf $TMPFILE --skip-old-files --strip 1
rm $TMPFILE

# Restore Community Auth to its third party location
mv ./community_auth_tmp/ ./application/third_party/community_auth/

# Move into application directory
cd ./application

# Copy or symlink core files
if [ "$SYMLINKS" = true ];
then
ln -s ../third_party/community_auth/core/MY_Controller.php ./core/MY_Controller.php
ln -s ../third_party/community_auth/core/MY_Input.php ./core/MY_Input.php
ln -s ../third_party/community_auth/core/MY_Model.php ./core/MY_Model.php
else
cp ./third_party/community_auth/core/MY_Controller.php ./core/MY_Controller.php
cp ./third_party/community_auth/core/MY_Input.php ./core/MY_Input.php
cp ./third_party/community_auth/core/MY_Model.php ./core/MY_Model.php
fi

# Copy or symlink hook files
if [ "$SYMLINKS" = true ];
then
ln -s ../third_party/community_auth/hooks/auth_constants.php ./hooks/auth_constants.php
ln -s ../third_party/community_auth/hooks/auth_sess_check.php ./hooks/auth_sess_check.php
else
cp ./third_party/community_auth/hooks/auth_constants.php ./hooks/auth_constants.php
cp ./third_party/community_auth/hooks/auth_sess_check.php ./hooks/auth_sess_check.php
fi

# Copy or symlink controller files
if [ "$SYMLINKS" = true ];
then
ln -s ../third_party/community_auth/controllers/Examples.php ./controllers/Examples.php
ln -s ../third_party/community_auth/controllers/Key_creator.php ./controllers/Key_creator.php
else
cp ./third_party/community_auth/controllers/Examples.php ./controllers/Examples.php
cp ./third_party/community_auth/controllers/Key_creator.php ./controllers/Key_creator.php
fi

# Copy or modify main .htaccess
cp ./third_party/community_auth/public_root/.htaccess ./../.htaccess

# Add autoload configuration
sed -i "s/\['packages'\] = array()/\['packages'\] = array(\n\tAPPPATH . 'third_party\/community_auth\/'\n)/g; \
s/\['libraries'\] = array()/\['libraries'\] = array(\n\t'database','session','tokens','Authentication'\n)/g; \
s/\['helper'\] = array()/\['helper'\] = array(\n\t'serialization','url','form','cookie'\n)/g; \
s/\['config'\] = array()/\['config'\] = array(\n\t'db_tables','authentication'\n)/g; \
s/\['model'\] = array()/\['model'\] = array(\n\t'auth_model'\n)/g;" ./config/autoload.php

# Add route to login page
echo "\$route[LOGIN_PAGE] = 'examples/login';" >> ./config/routes.php

# Set base_url, index_page, turn hooks on, add an encryption key, and configure sessions
sed -i "s/\['base_url'\] = ''/\['base_url'\] = '$BASEURL'/g; \
s/\['index_page'\] = 'index.php'/\['index_page'\] = ''/g; \
s/\['enable_hooks'\] = FALSE/\['enable_hooks'\] = TRUE/g; \
s/\['encryption_key'\] = ''/\['encryption_key'\] = hex2bin('5d3a06b1a1efeb861ad761fb8839794f')/g; \
s/\['sess_driver'\] = 'files'/\['sess_driver'\] = 'database'/g; \
s/\['sess_cookie_name'\] = 'ci_session'/\['sess_cookie_name'\] = 'ciSess'/g; \
s/\['sess_save_path'\] = NULL/\['sess_save_path'\] = 'ci_sessions'/g; \
s/\['sess_regenerate_destroy'\] = FALSE/\['sess_regenerate_destroy'\] = TRUE/g;" ./config/config.php

# Add hooks
printf "\$hook['pre_system'] = array(\n\t'function' => 'auth_constants',\n\t'filename' => 'auth_constants.php',\n\t'filepath' => 'hooks'\n);\n\$hook['post_system'] = array(\n\t'function' => 'auth_sess_check',\n\t'filename' => 'auth_sess_check.php',\n\t'filepath' => 'hooks'\n);" >> ./config/hooks.php

# Create DB
if [ -n "$DBPASS" ];
then
mysqladmin -u $DBUSER -p$DBPASS create $DBNAME
cat ./third_party/community_auth/sql/install.sql | mysql -u $DBUSER -p$DBPASS $DBNAME
else
mysqladmin -u $DBUSER create $DBNAME
cat ./third_party/community_auth/sql/install.sql | mysql -u $DBUSER $DBNAME
fi

# Configure DB
if [ -n "$DBPASS" ];
then
sed -i "s/'username' => ''/'username' => '$DBUSER'/g; \
s/'password' => ''/'password' => '$DBPASS'/g; \
s/'database' => ''/'database' => '$DBNAME'/g;" ./config/database.php
else
sed -i "s/'username' => ''/'username' => '$DBUSER'/g; \
s/'database' => ''/'database' => '$DBNAME'/g;" ./config/database.php
fi

# Pretty URLs
printf "\n\nRewriteEngine On\nRewriteBase /\n\nRewriteRule ^(system|application|cgi-bin) - [F,L]\nRewriteCond %%{REQUEST_FILENAME} !-f\nRewriteCond %%{REQUEST_FILENAME} !-d\nRewriteRule .* index.php/\$0 [PT,L]" >> ./../.htaccess

# Success
echo "REMOVE INSTALLER SCRIPT (THIS FILE)."
else
# Error
echo "INSTALLER ERROR: COMMUNITY AUTH DIR DOES NOT EXIST."
fi
else
# Error
echo "INSTALLER ERROR: COMMUNITY AUTH DIR ALREADY EXISTS."
fi


I'm sure if you are on Windows you could create some sort of batch file to do something similar.
Reply
#3

Thanks, but that's really not what I'm after. I'd really just like to be able to manage this project in Git like any other project I work with.
Reply
#4

(This post was last modified: 01-29-2016, 03:40 PM by skunkbad.)

Code:
application/cache/
application/config/file_to_ignore.php
application/config/another_file_to_ignore.php
application/core/
application/helpers/
application/hooks/
application/language/
application/logs/
application/models/
application/.htaccess
application/index.html
application/third_party/
system/
tests/
user_guide/
user_guide_src/
/index.php
/.htaccess
/DCO.txt
/composer.json
/contributing.md
/license.txt
/readme.rst


If it's just a gitignore you need, something like what I've showed above should work. Notice that each config file needs to be listed (except for yours).

When you run "git status", you'll be able to see the files that would be added. If you see ones you don't want to add, just add them to the gitignore file.
Reply
#5

Yeah, I guess I was just thinking it would be easier to ignore all and then un-ignore things I wanted to keep. Apparently that assumption was incorrect. I'll do it this way. Thanks for the snippet!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB