Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
391 views
in Technique[技术] by (71.8m points)

Commands in a Git Script Functions (Windows) Not Working As Expected in Sub Folder Under a Git Repo

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:GitRepoIgnoredFolderSubRepo. 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...