.gitignore not ignoring files - ruby-on-rails

Here is my .gitignore file:
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'
# Ignore bundler config.
/.bundle
# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal
# Ignore all logfiles and tempfiles.
/log/*
!/log/.keep
/tmp
# Ignore application configuration
/config/application.yml
/config/application.yml.bak
*.bak
Now, my repository is at https://github.com/rmohan80/learn-rails
Why would my latest commit -- "add configuration for email" add Readme.rdoc.bak but ignore .gitignore.bak
Any clues?

The star character does do match files beginning with a period.
You can add .*.bak to ignore them in your case or you can change the glob option in your shell :
# capture dot file
shopt -s dotglob
# do git stuff here
# stop capturing dot file
shopt -u dotglob
A similar problem solved here : https://stackoverflow.com/a/19365350

You have to checkout the HEAD, so that your repository looks unmodified. Then run the following:
$ echo '*.*.bak' >> .gitignore
To exclude files that are formatted like README.md.bak.
And run
$ echo '**/*.bak' >> .gitignore
to exclude files that are formatted like README.bak anywhere in the tree below the current directory.
Having .bak.bak files is something you don't want.

Related

Unix. Parse file with full paths to SHA256 checksums files. Run command in each path/file

I have a file file.txt with filenames ending with *.sha256, including the full paths of each file. This is a toy example:
file.txt:
/path/a/9b/x3.sha256
/path/7c/7j/y2.vcf.gz.sha256
/path/e/g/7z.sha256
Each line has a different path/file. The *.sha256 files have checksums.
I want to run the command "sha256sum -c" on each of these *.sha256 files and write the output to an output_file.txt. However, this command only accepts the name of the .sha256 file, not the name including its full path. I have tried the following:
while read in; do
sha256sum -c "$in" >> output_file.txt
done < file.txt
but I get:
"sha256sum: WARNING: 1 listed file could not be read"
which is due to the path included in the command.
Any suggestion is welcome
#!/bin/bash
while read in
do
thedir=$(dirname "$in")
thefile=$(basename "$in")
cd "$thedir"
sha256sum -c "$thefile" >>output_file.txt
done < file.txt
Modify your code to extract the directory and file parts of your in variable.

Can I prevent clang-format from formatting some (generated) files?

Some of the C source files in my project are generated. They obviously are not formatted to the standard in the .clang-format file.
If I just clang-format or git clang-format that generate source is re-formatted causing unnecessary clutter in the commits.
Is there a way to specify that some files should be ignored by clang-format?
In the default implementation of the git clang-format there is no flag or something to ignore autogenerated files .
but it can be achieved by implementing a wrapper script ( I will show how to do that in bash) that will clean the files that you don't want to format and then using the git clang-format.
for example:
1.first of all lets say your generated files include a pattern for example auto_gen or generated .
2.define a regex exp for the auto generated patterns in our example
it can be : pattern_to_exclude_from_clang='.*auto_gen|.*generated'
3.define allfiles = git diff --name-only - this will give you all
the files that your commit change.
4.filter out generated files allfiles ( exclude generated files)
5.run git clang-format --diff -- ${wantedfiles[#]}
so the final script can be :
#!/bin/bash
pattern_to_exclude_from_clang='.*auto_gen|.*generated'
allfiles=`git diff --name-only`
files_array=($allfiles)
for i in "${!files_array[#]}":
do
if [[ "${files_array[$i]}" =~ $pattern_to_exclude_from_clang ]];then
printf "%s %s" "${files_array[$i]" "this file will be skipped by clang"
unset files_array[$i]
fi
done
git clang-format --diff -- ${allfiles[#]}

Can't add credentials.yml.enc file to VCS

I follow this tutorial to deploy my rails application using capistrano and ruby-mine, one step required to generate encrypted credentials.yml.enc and add it to VCS, but I can't add it using ruby-mine even git add however the file is not present in gitignore file.
You find bellow content of gitignore file, the credentials.yml.enc is part of config directory
>> find . -name ".gitignore" -exec cat {} +
/shelf/
/workspace.xml
/dataSources/
/dataSources.local.xml
/httpRequests/
/sassc
/sass-spec
VERSION
.DS_Store
.sass-cache
*.gem
*.gcno
.svn/*
.cproject
.project
.settings/
*.db
*.aps
GNUmakefile.in
GNUmakefile
/aclocal.m4
/autom4te.cache/
/src/config.h
/config.h.in
/config.log
/config.status
/configure
/libtool
/m4/libtool.m4
/m4/ltoptions.m4
/m4/ltsugar.m4
/m4/ltversion.m4
/m4/lt~obsolete.m4
/script/ar-lib
/script/compile
/script/config.guess
/script/config.sub
/script/depcomp
/script/install-sh
/script/ltmain.sh
/script/missing
/script/test-driver
/src/stamp-h1
/src/Makefile.in
/src/Makefile
libsass/*
*.o
*.lo
*.so
*.dll
*.a
*.suo
*.sdf
*.opendb
*.opensdf
a.out
libsass.js
tester
tester.exe
build/
config.h.in*
lib/pkgconfig/
bin/*
.deps/
.libs/
win/bin
*.user
win/*.db
sassc++
libsass.la
src/support/libsass.pc
sassc/
sass-spec/
installer
.idea
/bin
/.bundle
/db/*.sqlite3
/db/*.sqlite3-journal
/db/*.sqlite3-*
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep
/tmp/pids/*
!/tmp/pids/
!/tmp/pids/.keep
/storage/*
!/storage/.keep
/public/assets
.byebug_history
/config/master.key
/public/packs
/public/packs-test
/node_modules
/yarn-error.log
yarn-debug.log*
.yarn-integrity
>> cat .gitignore
.idea
/bin
/.bundle
/db/*.sqlite3
/db/*.sqlite3-journal
/db/*.sqlite3-*
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep
/tmp/pids/*
!/tmp/pids/
!/tmp/pids/.keep
/storage/*
!/storage/.keep
/public/assets
.byebug_history
/config/master.key
/public/packs
/public/packs-test
/node_modules
/yarn-error.log
yarn-debug.log*
.yarn-integrity
Any help is appreciated, thanks in advance
There is a possibility that the whole folder(and its
subdirectories)/the extension **.enc is excluded in gitignore.
Is the file present when you look at git status. If yes, you'll
need to git add the file before you do a git commit.
Is the file committed already, but not yet pushed?
These are some things on top of my head. Please post some more details to dig this up!

Why is there ```No value provided for required arguments 'app_path'``` when I try to create a rails app?

(this is my first post, sorry if i make a mistake),
In Iterm2 I put :
rails _5.2.3_ new -d postgresql
And the terminal answers:
No value provided for required arguments 'app_path'
I opened the .zshrc file and tried to figure out if the problem comes from this file and searched for the keyword PATHbut couldn't figure out if a path is wrong or not. Does the problem is on the .zshrc file ? Where is the problem and how to solve it ?
Here is my .zshrc file
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="/Users/thibaultguichard/.oh-my-zsh"
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="simple"
# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in ~/.oh-my-zsh/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )
# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"
# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"
# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"
# Uncomment the following line to automatically update without prompting.
# DISABLE_UPDATE_PROMPT="true"
# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13
# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS=true
# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"
# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"
# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"
# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"
# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"
# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"
# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder
# Which plugins would you like to load?
# Standard plugins can be found in ~/.oh-my-zsh/plugins/*
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(
git
bundler
dotenv
osx
rake
rbenv
ruby
zsh-syntax-highlighting
zsh-autosuggestions
)
source $ZSH/oh-my-zsh.sh
# User configuration
# export MANPATH="/usr/local/man:$MANPATH"
# You may need to manually set your language environment
# export LANG=en_US.UTF-8
# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
# export EDITOR='vim'
# else
# export EDITOR='mvim'
# fi
# Compilation flags
# export ARCHFLAGS="-arch x86_64"
# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
# export PATH="$PATH:$HOME/.rvm/bin"
# SYSTEM ALIAS
alias cls='clear' # Clear the terminal
alias c='clear' # Clear the terminal
alias h='history' # Print bash command history
alias ll='ls -l' # List files in a list
alias la='ls -al' # List files in a list with hidden files
# GIT ALIAS
alias gitalias='alias | grep git' # Show all alias for git (if you have OH MY ZSH you have lots of other aliases)
alias gs='git status' # Show the working tree status
alias gcl='git clone' # Clone a repository into a new directory
alias gpush='git push' # Update remote refs along with associated objects
alias gpull='git pull' # Fetch from and integrate with another repository or a local branch
alias ga='git add' # Add file contents to the index
alias gcm='git commit -m' # Record changes to the repository
alias gco='git checkout' # Switch branches or restore working tree files
alias gbr='git branch' # List, create, or delete branches
alias glog='git log' # Show commit logs
alias greset='git reset' # Reset current HEAD to the specified state
# BUNDLE ALIAS
alias bundlealias='alias | grep bundle' # Show all alias for bundle
alias bi='bundle install' # Install the current environment to the system
alias bl='bundle list' # List all gem in GEMFILE and version
alias bu='bundle update' # Update the current environment (update gem)
alias ba='bundle add' # Command for add multiple gem in gemfile and launch a bundle update
# HEROKU ALIAS
alias herokualias='alias | grep heroku' # Show all alias for Heroku
alias hrdbs='heroku run rake db:seed'
alias hrdbm='heroku run rails db:migrate'
alias hrc='heroku create'
alias hrrc='heroku run rails console'
alias hrbi='heroku run bundle install'
alias hrupdate='heroku update' # Update the Heroku CLI
alias hrpsql='heroku psql' # Open a psql shell to the database
alias hrlogs='heroku logs' # Display recent log output
alias hrlog='heroku logs' # Display recent log output
# APT ALIAS
alias aptalias='alias | grep apt' # show all alias for apt
alias update='sudo apt update -y' # Update list of available packages
alias upgrade='sudo apt upgrade -y' # Upgrade the system by installing/upgrading packages
alias full-upgrade='sudo apt full-upgrade -y' # Upgrade the system by removing/installing/upgrading packages
alias dist-upgrade='sudo apt dist-upgrade -y' # Upgrade your distributtion system with sudo and ask yes
alias autoremove='sudo apt autoremove' # Remove automatically all unused packages
# RAILS ALIAS
alias railsalias='alias | grep rails' # Show all alias for rails
### RAILS CREATION
alias nr='rails _5.2.3_ new'
alias nrp='rails _5.2.3_ new -d postgresql'
### RAILS OTHER
alias rc='rails console'
alias rd='rails destroy'
alias rp='rails plugin'
alias ru='rails runner'
alias rs='rails server'
alias rsd='rails server --debugger'
alias rr='rails routes'
### RAILS GENERATE
alias rg='rails generate'
alias rgmigration='rails generate migration'
alias rgmodel='rails generate model'
alias rgscaffold='rails generate scaffold'
alias rgc='rails generate controller'
### RAILS DATABASE
alias rdb='rails dbconsole' # Database console in the database of your Rails APP
alias rdbd='rails db:drop'
alias rdbc='rails db:create'
alias rdbs='rails db:seed'
alias rdbm='rails db:migrate'
alias rdbms='rails db:migrate status'
alias rdbr='rails db:rollback'
#OTHERS ALIAS
alias path='echo -e ${PATH//:/\\n}' # Print all PATH environnement in a list
alias now='date +"%T"' # Get the time now
alias nowdate='date +"%d-%m-%Y"' # Get the Date
alias vi='vim'
alias svim='sudo vim' # Launch Vim with sudo
alias edit='vim'
You don't specify a name for your new project.
Try with rails _5.2.3_ new NameOfTheApp -d postgresql
It should work. (:

Rename project in Ruby on Rails 4.0.2

I'm aware of the Rename plugin for rails (https://github.com/get/Rename), but does anyone know of a way to easily rename a project in Rails 4.0.2 seeing as plugins are deprecated beginning with Rails 4?
Just consider you have used
rails new blog
This will create a blog application. Now if you want to rename the folder blog, just use
$mv blog blog_new
This will just rename the folder and the application will run with no issues as external folder name changes will not affect the application. Else you need to change each file as specified by srt32 but i don't see any specific reason to change project name from inside.
Assuming your app name is my_app you can run something like grep -r 'my_app' . from the root of your project and find all the places where the app name is referenced. It shouldn't be that bad to go update them. The list of places should look something like:
config/application.rb
config/environment.rb
config/environments/development.rb
config/environments/test.rb
config/environments/production.rb
config/initializers/secret_token.rb
config/routes.rb
Rakefile
Enter following commands
$ rails new ProjectToRename
$ cd ProjectToRename
$ grep -ri 'project_?to_?rename'
Finally done.
You'll need to rename the top-level directory yourself:
$ cd ..
$ mv ProjectToRename SomeNewName
I've written the following script to do just that. You can see it also at https://gist.github.com/danielpclark/8dfcdd7ac63149323bbc
#!/usr/bin/ruby
# Rename Rails Project (File: rename_rails)
# Copyright 6ft Dan(TM) / MIT License
# Check the config/application.rb for capital usage in project name by model OldProjectName
# Usage: rename_rails OldProjectName NewAwesomeName
# Replace string instances of project name
`grep -lR #{ARGV[0]} | xargs sed -i 's/#{ARGV[0]}/#{ARGV[1]}/g'`
`grep -lR #{ARGV[0].downcase} | xargs sed -i 's/#{ARGV[0].downcase}/#{ARGV[1].downcase}/g'`
# Rename Rails directory if it exists
if File.directory?(ARGV[0])
`mv #{ARGV[0]} #{ARGV[1]}`
drc = ARGV[1]
elsif File.directory?(ARGV[0].downcase)
`mv #{ARGV[0].downcase} #{ARGV[1]}`
drc = ARGV[1]
end
# Delete temporary files (helps prevent errors)
drc ||= ''
if ['cache','pids','sessions','sockets'].all? {
|direc| File.directory?(File.join(drc,'tmp', direc)) }
FileUtils.rm_rf(File.join(drc,'tmp'))
end
And I've created a howto video on YouTube. http://youtu.be/dDw2RmczcDA

Resources