0

I have the following folder structure...

\GitRepo
    \.git
    [files]
    \IgnoredFolder #ignored from .gitignore
        \SubRepo

I'm trying to right a script function in my .gitconfig file and I need to know the current directory, but I'm getting weird behavior.

For all my tests, I've opened a Console2 window hosting Windows PowerShell to run my git commands.

At the prompt if I type $pwd it 'correctly' displays C:\GitRepo\IgnoredFolder\SubRepo. I say 'correctly' but it is in Windows format instead of *Nix.

In my .git config, I've created this alias:

test = "!f() { echo ${PWD}; }; f"

Now, if I type git test from the prompt, I get the 'incorrect' display of /c/GitRepo. I say 'incorrect' because, ignoring Windows vs *Nix format, I would have expected/liked it to return /c/GitRepo/IgnoredFolder/SubRepo.

Other commands behave same way (i.e. operating in the first folder containing a .git repository instead of the current working directory.

For example, the real alias I want to create basically is a shortcut for init, add, commit, remote, config all in one command. A pseudo alias would look like this...

create = "!f() { git init; git add .; git commit -am "$1"; ... anything else ... }; f"

But instead of running on the current directory (the new SubRepo folder I want to 'act on'), it works on the first ancestor folder containing a git repo (c:\GitRepo in this case).

Is there any way to make git alias script functions work on the current directory regardless of whether or not it might be found with in a folder containing a repo or not?

Thanks in advance.

Terry
  • 2,148
  • 2
  • 32
  • 53
  • `git` aliases work from the root of the repository. – devnull Apr 26 '14 at 05:18
  • [This answer](http://stackoverflow.com/a/17969370/2235132) might help. – devnull Apr 26 '14 at 05:19
  • Thanks for the attempt @devnull, but it didn't seem to change the behavior. I made a test alias like this: createEcho = "!f() { shift; echo ${PWD}; echo "git init"; }; f, and ran it in my SubRepo directory and PWD is still showing \GitRepo. Do I have shift in the right place? – Terry Apr 28 '14 at 03:44
  • No, it's incorrect. Look at how the example passes the current working directory as the first parameter. Moreover, use the first parameter in the function to `cd`, then `shift` and get the remaining arguments. – devnull Apr 28 '14 at 03:47
  • Where is documentation on 'shift'? I was googling for git shift, but doesn't seem to be part of that. Would like to read up a bit on it. I *was* hoping to not have to pass in the $PWD to the alias if possible (looking like it isn't), but I'd still like to read up on shift to better understand your answer/syntax. – Terry Apr 28 '14 at 14:09

0 Answers0