|
41 | 41 | ---Get the current Git branch
|
42 | 42 | ---@return string
|
43 | 43 | function M.get_branch()
|
44 |
| - vim.fn.system([[git rev-parse 2> /dev/null]]) |
45 |
| - local git_enabled = (vim.v.shell_error == 0) |
46 |
| - |
47 |
| - if config.options.use_git_branch and git_enabled then |
48 |
| - local branch = vim.fn.systemlist([[git rev-parse --abbrev-ref HEAD 2>/dev/null]]) |
49 |
| - if vim.v.shell_error == 0 then |
50 |
| - branch = config.options.branch_separator .. branch[1]:gsub("/", "%%") |
51 |
| - local branch_session = config.options.save_dir |
52 |
| - .. vim.fn.getcwd():gsub(utils.get_dir_pattern(), "%%") |
53 |
| - .. branch |
54 |
| - .. ".vim" |
55 |
| - |
56 |
| - -- Try to load the session for the current branch and if not, use the value of default_branch |
57 |
| - if vim.fn.filereadable(branch_session) ~= 0 then |
58 |
| - return branch |
59 |
| - else |
60 |
| - vim.g.persisted_branch_session = branch_session |
61 |
| - return config.options.branch_separator .. default_branch |
| 44 | + if config.options.use_git_branch then |
| 45 | + vim.fn.system([[git rev-parse 2> /dev/null]]) |
| 46 | + local git_enabled = (vim.v.shell_error == 0) |
| 47 | + |
| 48 | + if git_enabled then |
| 49 | + local branch = vim.fn.systemlist([[git rev-parse --abbrev-ref HEAD 2>/dev/null]]) |
| 50 | + if vim.v.shell_error == 0 then |
| 51 | + branch = config.options.branch_separator .. branch[1]:gsub("/", "%%") |
| 52 | + local branch_session = config.options.save_dir |
| 53 | + .. vim.fn.getcwd():gsub(utils.get_dir_pattern(), "%%") |
| 54 | + .. branch |
| 55 | + .. ".vim" |
| 56 | + |
| 57 | + -- Try to load the session for the current branch and if not, use the value of default_branch |
| 58 | + if vim.fn.filereadable(branch_session) ~= 0 then |
| 59 | + return branch |
| 60 | + else |
| 61 | + vim.g.persisted_branch_session = branch_session |
| 62 | + return config.options.branch_separator .. default_branch |
| 63 | + end |
62 | 64 | end
|
63 | 65 | end
|
64 | 66 | end
|
|
0 commit comments