Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run gitdist from anywhere in repo #203

Merged
merged 6 commits into from
Jul 26, 2017

Conversation

jmgate
Copy link
Collaborator

@jmgate jmgate commented Jul 6, 2017

Look at the current working directory when gitdist is executed, determine the top-level git repo in that path, and change to it before continuing. This allows gitdist to be run from anywhere in a git repository, including within a nesting of repositories. For instance, if you have a directory structure like the following

/some/path/to/wherever/
  metaRepo/
    .git/
    .gitdist
    repo1/
      .git
    repo2/
      .git
    etc.

executing gitdist anywhere down in the metaRepo directory tree will change you to the metaRepo directory, execute gitdist, and then leave you back where you started when gitdist finishes.

If, for whatever reason, this change is not a good idea, just let me know and I can simply write a shell script to wrap gitdist for my own personal use.

jmgate and others added 2 commits July 6, 2017 15:41
Look at the current working directory when gitdist is executed,
determine the top-level git repo in that path, and change to it before
continuing.  This allows gitdist to be run from anywhere in a git
repository, including within a nesting of repositories.  For instance,
if you have a directory structure like the following
metaRepo/
  .git/
  .gitdist
  repo1/
    .git
  repo2/
    .git
  etc.
executing gitdist anywhere in that directory tree will change you to the
metaRepo directory, execute gitdist, and then leave you back where you
started when gitdist finishes.
This is closing but does not quite work for all use cases.  It fails when
there is a set of nested git repos and .gitdist[.default] files like:

Trilinos/
  .git/
  .gitdist.default
  TriBITS/
    .git/
    .gitdist.default
    TriBITSDoc/
      .git/
  kokkos/
    .git/

When I run the new gitdist in Trilinos/ or Trilinos/kokkos/, it finds the
right directory to run in.  But when I try to run in Trilinos/TriBITS/ or
Trilinos/TriBITS/TriBITSDoc/, it always goes back to the base Trilinos/ dir.
It should stop at the first directory where .gitdist or .gitdist.default is
found.
@bartlettroscoe
Copy link
Member

I checked out the branch and it seems to have broken the usage for me. For example, the current version of gitdist shows:

[rabartl@crf450 Trilinos (develop)]$ gitdist dist-repo-status
---------------------------------------------------------------------
| ID | Repo Dir           | Branch  | Tracking Branch   | C | M | ? |
|----|--------------------|---------|-------------------|---|---|---|
|  0 | Trilinos (Base)    | develop | github/develop    |   |   |   |
|  1 | TriBITS            | master  | github/master     |   |   |   |
|  2 | TriBITS/TriBITSDoc | master  | bb/master         |   |   |   |
|  3 | kokkos             | master  | github/master     |   |   |   |
|  4 | seacas             | master  | gsjaardema/master |   |   |   |
|  5 | DrekarBase         | master  | ssg/master        |   |   |   |
|  6 | DrekarResearch     | master  | ssg/master        |   |   |   |
---------------------------------------------------------------------

But with the version on this branch, it shows:

[rabartl@crf450 Trilinos (develop)]$ gitdist dist-repo-status
---------------------------------------------------------------
| ID | Repo Dir       | Branch | Tracking Branch | C | M | ?  |
|----|----------------|--------|-----------------|---|---|----|
|  0 | rabartl (Base) | master | origin/master   |   | 1 | 13 |
---------------------------------------------------------------

The issue is that I use git to manage my home directory so when I run gitdist it will always just run in my home dir.

I think I know how to fix this so I will give it a shot based on your branch real quick. But before we can push to TirBITS, we will need some automated tests to demonstrate and protect correct behavior.

@jmgate
Copy link
Collaborator Author

jmgate commented Jul 6, 2017

It may be better for me to just write a little wrapper script for my own personal use case, which is totally fine.

@bartlettroscoe
Copy link
Member

If I was somewhere in Trilinos, I'd want to run git commands (checkout, etc.) on Trilinos, tcad-charon, charon-data, etc., which would require going up to charonMetaRepo. If it stopped after finding the .gitdist.default in Trilinos, it would only execute them in the Trilinos repo, right? Then I would potentially be on a different branch in Trilinos compared to the other repos.

But that is the problem with changing this behavior. Different people will want different behavior for different use cases.

We might be able to resolve this with some system-level preferences. We might, for example, allow the definition of a ~/.gitdistconfig file that would be read by gitdist that would allow an individual user to select how they want gitdist to behave. For example, there might be an option in ~/.gitdistconfig called moveToBaseDirMode and it could have options like noMove (the current behavior), moveToImmediateBase (the behavior I want) and moveToExtremeBase (the behavior that you want).

If this sounds like a good idea to you, we can create a new GitHub issue for gitdist to support a .gitdistconfig file and then a new GitHub issue for the allowing customization of the behavior of moving to subdirs as described above.

P.S. the updated commit I just pushed implements the mode moveToBaseDirMode = moveToExtremeBase.

@bartlettroscoe
Copy link
Member

@jmgate,

I just pushed the commit 82822cb to your branch for this PR which causes gitdist to read an env var GITDIST_MOVE_TO_BASE_DIR. If that env var is set to EXTREME_BASE, then I think the script has the behavior your want. Please pull this branch and give it a try with:

$ export GITDIST_MOVE_TO_BASE_DIR=EXTREME_BASE
$ cd charonMetaRepo/Trilinos/
$ gitdist dist-repo-status

(where gitdist is the updated script in your path)

That should skip over the Trilinos/ dir and move down to the charonMetaRepo/ dir and run gitdist from there and print the status table starting with charonMetaRepo/.

If setting and env var is an acceptable solution, then I can add documentation and automated testing and push to the 'master' branch. That way, you would not need to create your own script for this behavior.

Let me know if you are interested.

@bartlettroscoe
Copy link
Member

The reason I checked for the existence of a .git directory as opposed to the .gitdist or .gitdist.default files is it looked like it was possible to run gitdist without either of those files—if it didn't find them, it would assume their contents to be ..

If the gitdist script can't find the .gitdist or .gitdist.default files, then it should just run in the current directory. If one of those two files have not been set, then gitdist is pretty worthless.

Again, think of the use case where a user will use git to manage their home directory files (see, for example, http://www.bitflop.dk/tutorials/keeping-your-home-in-git.html). If they do that, then looking for the base most .git/ directory will result in gitdist always running in the user's home directory. That would make gitdist worthless on that system.

Again, let me know if you are okay with having to set export GITDIST_MOVE_TO_BASE_DIR=EXTREME_BASE to get the behavior you want.

When the GITDIST_MOVE_TO_BASE_DIR environment variable is set to
IMMEDIATE_BASE, gitdist will move up the directory tree from where it's
run until it finds a .gitdist[.default] file and then run from there.
@jmgate
Copy link
Collaborator Author

jmgate commented Jul 7, 2017

@bartlettroscoe, this all sounds good to me. I also just pushed 442848e, which I think gives you the moveToBaseDirMode = moveToImmediateBase functionality you'd like. It works for my mocked up setup, but you should try it on your home directory to see if it actually works. I'd never heard of managing your home directory as a git repo—thanks for the link.

@bartlettroscoe
Copy link
Member

@jmgate, this looks great. Now I will need to add some unit testing and documentation before this gets merged to the 'master' branch. I will likely need to refactor this some to make it easier to unit test as well, but we will see. But I many not be able to get to that cleanup until later next week (unless you need this merged urgently).

I think it is best to keep the default behavior not to move to the base directory since I think that should be the least surprising to people. But I suspect that once they read the documentation on this feature most users will want to set either EXTREME_BASE or IMMEDIATE_BASE (I will set IMMEDIATE_BASE).

Thanks for this great addition to the code!

@jmgate
Copy link
Collaborator Author

jmgate commented Jul 10, 2017

Thanks, @bartlettroscoe—no rush on my end. It'd be nice if it was available to users whenever I try to transition Charon, Drekar, and EMPIRE over to the meta-repo way of doing things, but that's still a ways out.

@bartlettroscoe
Copy link
Member

@jmgate, this is now merged and you should be able to use this on the 'master' branch of TriBITS.

I have created #212 to follow up with adding the automated tests and documentation needed to complete this.

@jmgate
Copy link
Collaborator Author

jmgate commented Jul 26, 2017

Sounds good. Thanks @bartlettroscoe.

@jmgate jmgate deleted the runGitdistAnywhere branch July 26, 2017 19:30
bartlettroscoe added a commit to jmgate/TriBITS that referenced this pull request Nov 3, 2017
Looks better formatted especially when using --dist-help=all.

Also, moved --dist-help=move-to-base-dir above 'usage-tips' and
'script-dependencies' since I think that order seems a little better,
especially for --dist-help=all.

I also had to fix the tests to work when GITDIST_MOVE_TO_BASE_DIR is not set
in the outer shell.
bartlettroscoe added a commit to jmgate/TriBITS that referenced this pull request Nov 3, 2017
…e exists (TriBITSPub#203)

Currently, this unit test just causes gitdist to hang until the overall test
times out.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants