gitslave icon indicating copy to clipboard operation
gitslave copied to clipboard

Feature Request: gits add ./specific-file.js

Open reggi opened this issue 10 years ago • 4 comments

Because I'm using links to distribute the same file across multiple repos I could the ability to add specific files to a commit. For instance

  • ./sub-repo
    • file.js -> linked to ../file.js
  • file.js -> linked to ./sub-repo/file.js

I'd love to be able to:

gits add **/file.js
gits commit -m "changed file"

However gitslave prevents the adding of individual files.

reggi avatar Aug 12 '15 09:08 reggi

@reggi wrote:

However gitslave prevents the adding of individual files.

gits add file-in-multiple-repos works for me. The path has to be relative to each subproject's root.

What you're doing is misusing recursive globbing (for example the globstar option in bash4+) relative to the superproject. You could perhaps see the effect by running echo **/file.js Paths won't match because they need to be relative to each subproject's root.

You might have more luck quoting the globbing, letting the next command after argument expansion deal with it. This isn't necessary if all file.js are in a fixed location (like the root) of reach subproject.

gits add '**/file.js'

I'm sure you have your reasons, but I would generally avoid linking files across repos.

joelpurra avatar Aug 12 '15 10:08 joelpurra

I just got on bash 4 (here's my tutorial).

Minus the globbing I tried to add a link I get prevent from adding any type of add of a file.

Given the structure

.
├── file.js
└── plugin
    └── file.js

and this git status

$ gits status
# On branch master
On: ./plugin:
  #
  # Initial commit
  #
  # Changes to be committed:
  #   (use "git rm --cached <file>..." to unstage)
  #
  #     new file:   file.js
  #
On: (host):
  # Your branch is based on 'origin/master', but the upstream is gone.
  #   (use "git branch --unset-upstream" to fixup)
  #
  # Untracked files:
  #   (use "git add <file>..." to include in what will be committed)
  #
  #     file.js
  #

When I try to add these files I get these messages.

$ gits add file.js 
There is a pathname in a generic gits command; this is a sign that the command
will not work since it is unlikely to exist in all repositories.
Probably you want to run a raw git command

and

$ gits add plugin/file.js 
There is a pathname in a generic gits command; this is a sign that the command
will not work since it is unlikely to exist in all repositories.
Probably you want to run a raw git command
Aborting gits add, failed for: '(host)': exit 1
 (first entry, no other successfully executed)
  The following paths are ignored by one of your .gitignore files:
plugin/file.js
Use -f if you really want to add them.

So I used force

$ gits add file.js -f
$ gits add plugin/file.js -f
Aborting gits add, failed for: './plugin': exit 128
 (ran fine on:  (host), did not run on 0 other(s); no rollbacks)
  fatal: pathspec 'plugin/file.js' did not match any files

Your right it seems I can add file.js and it just works for both because in both repos they have a root file.js.

What am I supposed to do when the files I want to add to a commit aren't named the same across the repos? I want to be able to specify a repo from the superproject to add.

gits add readme.js -project ./plugin 
gits add ./docs/plugin-readme.js --project ./ 

Does this functionality exist?

Not sure of the dangers of linking files across repos, tell me more, please :)

reggi avatar Aug 12 '15 17:08 reggi

There is currently no way to add an untracked file from an attached repo, that is only in the attached repo.

mkdir super
mkdir plugin
git -C super/ init --bare
git -C plugin/ init --bare
git clone super ./master
cd master
gits prepare
gits attach ../plugin ./plugin
echo 'hello' > file.txt
echo 'hello' > plugin/file.txt
gits add -A 
gits commit -m "added file.txt"
echo 'untracked' > plugin/untracked.txt
.
├── file.js
└── plugin
    ├── file.js
    └── untracked.js

I tried all of these:

gits add plugin/untracked.txt -f
gits add 'plugin/untracked.txt' -f
gits add untracked.txt -f
gits add 'untracked.txt' -f
gits add ./plugin/untracked.txt -f
gits add './plugin/untracked.txt' -f
gits add ./untracked.txt -f
gits add './untracked.txt' -f

The only way to get that specific file added was:

git -C ./plugin/ add ./untracked.txt

However I can't run this command recursively. Meaning if the untracked.txt file was spread across 10 plugins I'd need to run it for each...

reggi avatar Aug 13 '15 22:08 reggi

@reggi wrote:

There is currently no way to add an untracked file from an attached repo, that is only in the attached repo.

Thanks for the setup script -- makes it much easier for me to get to the core of the problem!

I tried all of these:

gits add stops execution because files are missing in at least one repository, which causes git add to bail. The way to get around is to use --keep-going (at your own risk).

gits --keep-going add untracked.txt

However I can't run this command recursively. Meaning if the untracked.txt file was spread across 10 plugins I'd need to run it for each...

The above command works for this scenario.

If you want to run an arbitrary command in each folder you can always use bash.

# Simple version; also outputs directory changes
for repo in */; do cd $repo; echo $PWD; cd -; done

# Simple version
for repo in */; do cd $repo >/dev/null; echo $PWD; cd - >/dev/null; done

# Using pushd/popd; also outputs directory changes
for repo in */; do pushd $repo; echo $PWD; popd; done

# Using pushd/popd
for repo in */; do pushd $repo >/dev/null; echo $PWD; popd >/dev/null; done

While there might be simpler versions, these are bit long to type -- and perhaps not every subdirectory is a repository. gits exec can help you address these problems, including collecting outputs.

gits exec echo $PWD

If you want to add files which may not exits you can optionally combine it with --keep-going.

gits --keep-going exec git add untracked.txt

joelpurra avatar Aug 13 '15 22:08 joelpurra