killme2008 / killme2008/clojure-control

`ssh` execute command in path

Open
#25 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Clojure
Stars
137
Forks
10
PR merge metrics
No merged PRs in 30d

Description

I guess my post is more a question than a real issue, but here it is (worst case is, you get to see how a user of your lib for a few hours try to do) :
I am trying to define a task to get the git branch of a repository.

Here is what I have so far :

```
(deftask :git-branch []
(ssh (run
(cd (:path @config))
(run "pwd") ;; this println nicely /var/dev/my-repo => ok
(run "ls -a") ;; this lists the right content => ok
(run "git rev-parse --abbrev-ref HEAD") ;; master => ok

;; strangely this is listed before
;; and it fails with :
;; stderr fatal: Not a git repository (or any of the parent directories): .git
(let [rt (ssh "git rev-parse --abbrev-ref HEAD")]
(println "status " (:status rt))
(println "stdout " (:stdout rt))
(println "stderr " (:stderr rt)))

;; I am in my home repository
;; how can use `ssh` to get a result
;; while being in a repository ?
(let [rt (ssh "pwd")]
(println "status " (:status rt))
(println "stdout " (:stdout rt))
(println "stderr " (:stderr rt))))))
```

I am confused by the rules of the paths. I expected all calls inside `cd` to have the same path. Also, how can I get the result of "git rev-parse --abbrev-ref HEAD" in the right folder ?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the nested ssh, run, and cd calls shown in the issue, comparing commands executed inside run with the standalone ssh calls. Trace how the working directory is propagated and verify the result with git rev-parse --abbrev-ref HEAD; done means the command runs in the requested repository and returns its status and output.

Written by the indexing model from the issue text.

Assessment

Tech stack
clojure, git
Domain
devops
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.