Ignoring a local file is deleting the depot file - github

I am using smartgit with github.
I have a config.json file on my remote github depot, with hidden passwords, at the root of the app .
I need to keep a different config.json file on my local depot, with real passwords.
As long as I try to ignore config.json locally, sometimes , it is still recorded as 'modified'
Some others times, when it finally gets ignored, by right clicking/ignore, It says 1'staged' , config.json finally gets deleted from Github when pushing the commit, I don't understand why:
THis is my .gitignore file :
.DS_Store
/config.json
config.json
node_modules
/uploads
/node_module
/dist
# local env files
.env.local
.env.*.local
# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
My config.json file , with blank that I need to leave as this on Github, because Heroku needs it :
{
"localhost_db": "mongodb://localhost:27017/",
"mongoDb_atlas_db": "mongodb+srv://jose:x#cluster0-6kmcn.azure.mongodb.net/vue-starter-webpack?retryWrites=true&w=majority",
"dev": false,
"db_name": "vue-starter-webpack",
"ftp_config": {
"host": "ftpupload.net",
"user": "epiz_26763901",
"password": "x",
"secure": false
},
"node_file_path": "./tmp/files/",
"cloudinary_token": {
"cloud_name": "ddq5asuy2",
"api_key": "354237299578646",
"api_secret": "x"
},
"logs_path": "tmp/logs/logs.txt"
}
Is there any workaround ? I have tried plenty of things already. What does "staged" means ? How can I keep a different version of file on github and locally ?
EDIT : I am trying out this command, it seems to work ! :
git update-index --assume-unchanged config/database.yml
Ignore modified (but not committed) files in git?

I have a config.json file on my remote GitHub depot, with hidden passwords, at the root of the app.
That... is not a good practice. If that file (config.json) contains any sensitive information, it should not be added/committed, but explicitely ignored.
What you can commit is config.json.tpl, a template file (which is essentially what your config.json is right now)
From there, you could generate the right config.json file locally, and automatically on git clone/git checkout.
The generation script will:
search the right passwords from an external secure referential (like a vault)
replace the placeholder value in config.json.tpl to generate the right config.json
For that, do register (in a .gitattributes declaration) a content filter driver.
(image from "Customizing Git - Git Attributes", from "Pro Git book")
The smudge script will generate (automatically, on git checkout or git switch) the actual config.json file as mentioned above.
Again, the generated actual config.json file remains ignored (by the .gitignore).
See a complete example at "git smudge/clean filter between branches".

Related

How to patch remote source code locally in yocto project?

Sometimes, We meet a situation that remote source code fetched by a recipe need to be modified so that suit a specific machine.
How do we create a patch for remote source code locally? After that everytime we build the recipe (even clean it all) we can patch the remote source code automatically.
For example, I have a special machine with architecture A which is not common, so the remote source code need to be modified so that support architecture A.
Suppose there was a file called utils.h (which is code that we fetched by example.bb from remote git repository)
#if defined(__x86_64__) || \
defined(__mips__) || \
defined(__powerpc__) || defined(__ppc__) || defined(__ppc64__) \
#define SOME_FUNCTIONALITY 1
Apparently I need to add archtecture A support in the file.
#if defined(__x86_64__) || \
defined(__mips__) || \
defined(__powerpc__) || defined(__ppc__) || defined(__ppc64__) || \
defined(__A__) \
#define SOME_FUNCTIONALITY 1
But if we just modified like that, next time we execute
bitbake -c cleanall example
bitbake example
then we get a unchanged copies again(which means we have to modify it again).
How do we create a Add-architecture-A-support.patch locally so that we can patch the remote source code automatically?
This is a simple one from answers.
(Note: If there was no git in the source code directory, before modifying the source code, you need to create a git repository and commit all in the top directory of the source code.)
git init # create a git repository
git add .
git commit -m "First commit" # first commit
After change the utils.h as above, we can check the git status. It usually looks like that.
$ git status
HEAD detached from 87b933c420
Changes not staged for commit:
(use "git add <file>..." to update what will be comitted)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: ../../utils.h
...
no changes added to commit (use "git add" and/or "git commit -a")
Then we add and commit the change locally (usually we don't have the permission to push to upper stream).
$ git add utils.h
$ git commit -m "Patch test"
After that we can use git to create a patch for the recent commit.
$ git show >Add-architecture-A-support.patch
It will creat a patch in the current directory with contents looks like that
commit a79e523...
Author: 杨...
Date: ...
Patch test
diff --git a/somedir/utils.h b/somedir/utils.h
index 20bfd36c84..
--- a/somedir/utils.h
+++ b/somedir/utils.h
...
+ defined(__A__) \
...
Then we can move the patch to the local layer where the recipe stayed.
recipe-example
|-- example
| |-- Add-architecture-A-support.patch
|-- example.bb
And add the patch in example.bb with this.
SRC_URI += "\
file://Add-architecture-A-support.patch \
"
Work finished. (Also, if want to undo the local commit after creating the patch, you can use git reset HEAD^ utils.h. emmm, I think so, maybe there are some faults, just google it)

how to regenerate meson for newly added yaml files

I have added yaml files to add new dbus objects and I added PHOSPHOR_MAPPER_SERVICE_append = " com/newCoName"
(newCoName is the name of my company)
But when I run bitbake, do_configure for phosphor_mapper bails when it passes the option -Ddata_com_newCoName to meson. The following readme says I need to run ./regenerate_meson from the gen directory when I add new YAML files. But how do I do that from a recipe file?
https://github.com/openbmc/phosphor-dbus-interfaces
One option is to generate these files outside ot yocto environment (i.e. not involving bitbake). Thus
clone that git repo
place your yaml file where you cloned repo
do what readme tells, i.e. go to gen directory and execute meson-regenerate script
collect changes that are done by script and create patch
add patch to your layer and reference it in .bbappend file (meta-/recipes-phosphor/dbus/phosphor-dbus-interfaces_git.bbappend)
Another option would be to add to .bbappend file additional task that runs before do_configure - and call that script from there:
do_configure_prepend() {
cd ${S}/gen && ./meson-regenerate
}
Along this .bbappend you should add your yaml so that it lands inside gen folder in patch or directly in your layer (check FILESEXTRAPATHS).
In both cases you'll need to patch meson_options.txt: add option
option('data_com_newCoName', type: 'boolean', value: true)

cvs2svn cvs2git: map cvs users to github users

I used cvs2git to convert 1 cvs repo to git and push it to github. Everything works except that I don't see any contributors for my repo on github. I am wondering if there is a way to bring all the users from cvs and map them to github users.
If you are ok with converting the repository again, you should use the author_transforms field in the options file.
Here is the example from the example options file I linked to:
author_transforms={
'jrandom' : ('J. Random', 'jrandom#example.com'),
'mhagger' : 'Michael Haggerty <mhagger#alum.mit.edu>',
'brane' : (u'Branko Čibej', 'brane#xbc.nu'),
'ringstrom' : 'Tobias Ringström <tobias#ringstrom.mine.nu>',
'dionisos' : (u'Erik Hülsmann', 'e.huelsmann#gmx.net'),
# This one will be used for commits for which CVS doesn't record
# the original author, as explained above.
'cvs2git' : 'cvs2git <admin#example.com>',
}
The example file has more details.
If you need to keep the existing repo in github, you may be able to do some form of rewriting of the commit history, but I don't know anything about that.

Referencing current branch in github readme.md

In my github repo's readme.md file I have a Travis-CI badge. I use the following link:
https://travis-ci.org/joegattnet/joegattnet_v3.png?branch=staging
The obvious problem is that the branch is hardcoded. Is it possible to use some sort of variable so that the branch is the one currently being viewed?
Not that I know of.
GitHub support confirms (through OP Joe Gatt 's comment)
The only way to do this would be to pass the link through my own service which would use the github's http referrer header to determine which branch is being referenced and then fetch the appropriate image from Travis CI
I would rather make one Travis-CI badge per branch, for the reader to choose or consider the appropriate when seeing the README.md.
Update 2016 (3 years later): while nothing has changed on the GitHub side, fedorqui reports in the workaround mentioned in "Get Travis Shield on Github to Reflect Selected Branch Status" by Andrie.
Simply display all the branches and their respective TravisCI badges.
If you have only two or three branches, that could be enough.
I worked around this issue with a git pre-commit hook that re-writes the Travis line in the README.md with the current branch. An example of usage and pre-commit (Python) code (for the question as asked) are below.
Usage
dandye$ git checkout -b feature123 origin/master
Branch feature123 set up to track remote branch master from origin.
Switched to a new branch 'feature123'
dandye$ echo "* Feature123" >> README.md
dandye$ git add README.md
dandye$ git commit -m "Added Feature123"
Starting pre-commit hook...
Replacing:
[![Build Status](https://travis-ci.org/joegattnet/joegattnet_v3.png?branch=master)][travis]
with:
[![Build Status](https://travis-ci.org/joegattnet/joegattnet_v3.png?branch=feature123)][travis]
pre-commit hook complete.
[feature123 54897ee] Added Feature123
1 file changed, 2 insertions(+), 1 deletion(-)
dandye$ cat README.md |grep "Build Status"
[![Build Status](https://travis-ci.org/joegattnet/joegattnet_v3.png?branch=feature123)][travis]
dandye$
Python code for the pre-commit code
dandye$ cat .git/hooks/pre-commit
#!/usr/bin/python
"""
Referencing current branch in github readme.md[1]
This pre-commit hook[2] updates the README.md file's
Travis badge with the current branch. Gist at[4].
[1] http://stackoverflow.com/questions/18673694/referencing-current-branch-in-github-readme-md
[2] http://www.git-scm.com/book/en/v2/Customizing-Git-Git-Hooks
[3] https://docs.travis-ci.com/user/status-images/
[4] https://gist.github.com/dandye/dfe0870a6a1151c89ed9
"""
import subprocess
# Hard-Coded for your repo (ToDo: get from remote?)
GITHUB_USER="joegattnet"
REPO="joegattnet_v3"
print "Starting pre-commit hook..."
BRANCH=subprocess.check_output(["git",
"rev-parse",
"--abbrev-ref",
"HEAD"]).strip()
# String with hard-coded values
# See Embedding Status Images[3] for alternate formats (private repos, svg, etc)
# [![Build Status](https://travis-ci.org/
# joegattnet/joegattnet_v3.png?
# branch=staging)][travis]
# Output String with Variable substitution
travis="[![Build Status](https://travis-ci.org/" \
"{GITHUB_USER}/{REPO}.png?" \
"branch={BRANCH})][travis]\n".format(BRANCH=BRANCH,
GITHUB_USER=GITHUB_USER,
REPO=REPO)
sentinel_str="[![Build Status]"
readmelines=open("README.md").readlines()
with open("README.md", "w") as fh:
for aline in readmelines:
if sentinel_str in aline and travis != aline:
print "Replacing:\n\t{aline}\nwith:\n\t{travis}".format(
aline=aline,
travis=travis)
fh.write(travis)
else:
fh.write(aline)
subprocess.check_output(["git", "add", "README.md" ])
print "pre-commit hook complete."
I updated the work of Dan Dye so it's now able to change any git variable into a readme. It also works now with python 3. For example, handling badges by branch for Github actions:
[![Integration Tests](https://github.com/{{ repository.name }}/actions/workflows/integration-tests.yaml/badge.svg?branch={{ current.branch }})](https://github.com/{{ repository.name }}/actions/workflows/integration-tests.yaml?query=branch%3A{{ current.branch }})
And in your pre-commit file add:
.githooks/replace_by_git_vars.py readme.md README.md -v
-v displays the available variables and more
https://gist.github.com/jclaveau/af2271b9fdf05f7f1983f492af5592f8
Thanks a lot for the solution and inspiration!
The best solution for me was to create a server where I send a query with username and repo's name and get a svg image with the build status for all branches.

Subversion (SVN) and static libraries (.a files) compatibility?

I can't add .a files (static libraries) into my repository. Why?
Is there a way to "force" SVN to accept them (at least as static files...)?
The svn:ignore property contains a list of file patterns which certain Subversion operations will ignore.
Also do you have a configuration file that global-ignores. It is a list of whitespace-delimited globs which describe the names of files and directories
The svn status, svn add, and svn import commands also ignore files that match the list.
To override for a certain instance, use the --no-ignore command-line flag:
>>>>svn help add
usage: add PATH...
Valid options:
--targets ARG : pass contents of file ARG as additional args
-N [--non-recursive] : obsolete; try --depth=files or --depth=immediates
--depth ARG : limit operation by depth ARG ('empty', 'files',
'immediates', or 'infinity')
-q [--quiet] : print nothing, or only summary information
--force : force operation to run
--no-ignore : disregard default and svn:ignore property ignores
--auto-props : enable automatic properties
--no-auto-props : disable automatic properties
Make sure your issue is caused by the SVN ignore configuration. With `svn status' your '*.a' file will be missing, while 'svn status --no-ignore' shall display it with a question mark in front.
Open the Subversion configuration file in your home directory:
~/.subversion/config
Search for the 'global-ignores' section:
global-ignores = *.o *.lo *.la *.al .libs *.so *.so.[0-9]* *.a *.pyc *.pyo *.rej *~ #*# .#* .*.swp .DS_Store
Remove *.a from the list of ignored files.