13

This is my submodule redmine_dashboard config file:

Submodule config file:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    worktree = /Users/daniel/redmine/vendor/plugins/redmine_dashboard
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = git@github.com:ebc/redmine_dashboard.git
[branch "master"]
    remote = origin
    merge = refs/heads/master
[gui]
    wmstate = normal
    geometry = 841x391+-8+43 187 177

Mac

worktree = /Users/daniel/redmine/vendor/plugins/redmine_dashboard

Linux

worktree = /home/daniel/redmine/vendor/plugins/redmine_dashboard

Issue

Can I change this absolute path for a relative? Something like:

worktree = ../../vendor/plugins/redmine_dashboard
flapjack
  • 704
  • 1
  • 8
  • 13

3 Answers3

9

Yes, you should be able to update the config file with a relative path. You should also update the worktree dir in the .git file in the submodule root to be a relative path back to that module.

I believe this is fixed in (at least) the most current version of git (1.7.10.1). I can't seem to find a changelog, so I have no idea when it got fixed. I was able to have git fix the issue by deleting both the submodule and the folder in the .git/modules folder and then redoing git submodule init and git submodule update.

Andy
  • 778
  • 5
  • 16
  • I was having a very problem after moving my git "supermodule" to a new local directory. Based in this answer, I build git from source to obtain 1.7.11.3, and then running a `git submodule init` and `git submodule update` automatically reconfigured all of the submodule roots. – jarvisschultz Jul 30 '12 at 20:44
  • So to clarify the only fix is to edit a bunch of files or build from source. apt-get currently has 1.7.9 version for git. – JaseC Dec 30 '13 at 06:19
  • Note that if you have an old repository and you have originally cloned the submodules with older variant of git you'll have absolute paths in `.git/modules/**/config`. Recent git versions *will* generate relative paths by default but OLD configuration files will not be automatically rewritten to use relative paths. – Mikko Rantalainen Feb 05 '21 at 11:04
3

Note that the git config man page mentions:

core.worktree

Set the path to the root of the work tree. This can be overridden by the GIT_WORK_TREE environment variable and the --work-tree command line option.
It can be an absolute path or a relative path to the .git directory, either specified by --git-dir or GIT_DIR, or automatically discovered.
If --git-dir or GIT_DIR are specified but none of --work-tree, GIT_WORK_TREE and core.worktree is specified, the current working directory is regarded as the root of the work tree.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
2

Why are you setting worktree at all? By default, the work tree is where you run your commands from, where the .git directory is. See this question for more information.

Community
  • 1
  • 1
Daniel C. Sobral
  • 295,120
  • 86
  • 501
  • 681
  • 3
    @daniel-c-sobral I made something like [this](http://help.github.com/submodules/), so this path was created by `git add submodule` command. When my **Dropbox** syncronized that source code from Linux to other SO, like MAC or Win for example, the tree was broken: `fatal: Not a git repository: /home/daniel/redmine/vendor/plugins/redmine_dashboard`. – flapjack Jan 19 '12 at 23:57
  • 8
    More like *Why is git making these absolute paths for us?* – David Rivers Aug 04 '12 at 18:34